pavelk2 / social-feed

JavaScript plugin that shows a user feed from the most popular social networks
http://pavelk2.github.io/social-feed-example/
MIT License
960 stars 303 forks source link

Fix callback not fired #173

Open DrJest opened 8 years ago

DrJest commented 8 years ago

Fixes an issue with callback not being fired if there are not enough post in the feed to reach the limit. Also fixes an error if pinterest response is empty

nicosuria commented 8 years ago

Found an issue where the loaded_post_count wasn't getting incremented in case the feed.render() call failed, thus failing the equality check between it and posts_to_load_count when attempting to call fireCallback. Example: if one of the posts fetched was a duplicate.

Fixed it by adding the following (using twitter as an example)

// js/jquery.socialfeed.js line 264

var post = new SocialFeedPost('twitter', Feed.twitter.utility.unifyPostData(element));
var render_successful = post.render();
// If we do not render the post because it was a duplicate or something, reduce the
// completion counter so that the `loaded_post_count` and `posts_to_load_count` resolve to equal

if(!render_successful)
  posts_to_load_count--
HartLarsson commented 8 years ago

there was already a fix that works perfectly, for example for twitter https://github.com/pavelk2/social-feed/pull/173/commits/1fe5903edff00946684fb210d5ac1afd6540aa90:

                    getPosts: function(json) {
                        if (json) {
                            // fix callback render
                            if(json.length<options.twitter.limit) posts_to_load_count -= options.twitter.limit - json.length;
                            $.each(json, function() {
                                var element = this;
                                var post = new SocialFeedPost('twitter', Feed.twitter.utility.unifyPostData(element));
                                post.render();
                            });
                        }
                    },