From 098cfa8e1cb05aeef0484cc6272b1961f45386d6 Mon Sep 17 00:00:00 2001 From: erqan Date: Sun, 25 May 2014 22:16:34 +0300 Subject: [PATCH] Deleting unfollowed user's following data from storage and fixing image preview maximum width --- css/style.css | 4 +-- js/twister_following.js | 60 ++++++++++++++++++++++++++++++++--------- js/twister_io.js | 28 ++++++++++++------- 3 files changed, 69 insertions(+), 23 deletions(-) diff --git a/css/style.css b/css/style.css index 804e2a4..e675f62 100644 --- a/css/style.css +++ b/css/style.css @@ -1058,10 +1058,10 @@ ol.toptrends-list { .image-preview { max-height: 500px; - max-width: 530px; + max-width: 495px; width: auto; display: block; - margin: 0 auto; + margin: 0 auto 10px auto; } .preview-container { diff --git a/js/twister_following.js b/js/twister_following.js index 04f252f..9bde14e 100644 --- a/js/twister_following.js +++ b/js/twister_following.js @@ -83,13 +83,27 @@ TwisterFollowing.prototype = { var oneshot = false; var i = 0; if (typeof(username) !== 'undefined') { - i = followingUsers[username]; + //activate updating for only one user... + i = followingUsers.indexOf(username); if (i > -1) oneshot = true; - else - i = 0; + else if (typeof(this.followingsFollowings[username]) !== 'undefined') { + delete this.followingsFollowings[username]; + this.save(); + return; + } + } + + var updated = false; + for (var user in this.followingsFollowings) { + if (followingUsers.indexOf(user) < 0) { + delete this.followingsFollowings[user]; + updated = true; + } } + if (updated) + this.save(); for (; i < followingUsers.length; i++) { var ctime = new Date().getTime() / 1000; @@ -98,15 +112,22 @@ TwisterFollowing.prototype = { ctime - this.followingsFollowings[followingUsers[i]]["lastUpdate"] >= this.followingsFollowings[followingUsers[i]]["updateInterval"]) { loadFollowingFromDht(followingUsers[i], 1, [], 0, function (args, following, seqNum) { + var updated = false; if (following.indexOf(args.tf.user) > -1) { - if (args.tf.knownFollowers.indexOf(args.fu) < 0) + if (args.tf.knownFollowers.indexOf(args.fu) < 0) { args.tf.knownFollowers.push(args.fu); + updated = true; + } } else { - if (args.tf.notFollowers.indexOf(args.fu) < 0) + if (args.tf.notFollowers.indexOf(args.fu) < 0) { args.tf.notFollowers.push(args.fu); + updated = true; + } var tmpi = args.tf.knownFollowers.indexOf(args.fu); - if (tmpi > -1) + if (tmpi > -1) { args.tf.knownFollowers.splice(tmpi, 1); + updated = true; + } } $(".open-followers").attr("title", args.tf.knownFollowers.length.toString()); @@ -118,28 +139,42 @@ TwisterFollowing.prototype = { args.tf.followingsFollowings[args.fu]["updateInterval"] = TwisterFollowing.minUpdateInterval; args.tf.followingsFollowings[args.fu]["following"] = following; - args.tf.save(); + updated = true; } else { - var diff = []; + var diff = []; //diff for following + var difu = []; //diff for unfollowing var ff = args.tf.followingsFollowings[args.fu]["following"]; + //is there any new following? for (var j = 0; j < following.length; j++) { if (ff.indexOf(following[j]) === -1) { diff.push(following[j]); ff.push(following[j]); } } + //did user unfollow someone? + for (var j = ff.length - 1; j >= 0 && ff.length > following.length; j--) { + if (following.indexOf(ff[j]) === -1) { + difu.push(ff[j]); + ff.splice(j, 1); + } + } - if (diff.length > 0) { + if (diff.length > 0 || difu.length > 0) { args.tf.followingsFollowings[args.fu]["updateInterval"] = TwisterFollowing.minUpdateInterval; args.tf.followingsFollowings[args.fu]["lastUpdate"] = ctime; - args.tf.save(); + updated = true; } else if (args.tf.followingsFollowings[args.fu]["updateInterval"] < TwisterFollowing.maxUpdateInterval) { args.tf.followingsFollowings[args.fu]["updateInterval"] *= 2; } + + if (updated) + args.tf.save(); } }, {"tf": this, "fu": followingUsers[i]}); } + if (oneshot) + break; } } }; @@ -339,6 +374,7 @@ function unfollow(user, cbFunc, cbArg) { var i = followingUsers.indexOf(user); if( i >= 0 ) { followingUsers.splice(i,1); + twisterFollowingO.update(user); } delete _isFollowPublic[user]; saveFollowing(); @@ -750,10 +786,10 @@ function initInterfaceFollowing() { $(".postboard-loading").fadeIn(); loadFollowing( function(args) { + twisterFollowingO = TwisterFollowing(defaultScreenName); + showFollowingUsers(); requestSwarmProgress(); - - twisterFollowingO = TwisterFollowing(defaultScreenName); }); initMentionsCount(); initDMsCount(); diff --git a/js/twister_io.js b/js/twister_io.js index 583fe5e..ea8f6f9 100644 --- a/js/twister_io.js +++ b/js/twister_io.js @@ -218,17 +218,27 @@ function getFullname( username, item ){ item.addClass('isFollowing'); item.attr("title", polyglot.t("follows you")); } else if (twisterFollowingO.notFollowers.indexOf(username) === -1) { - loadFollowingFromDht(username, 1, [], 0, function (args, following, seqNum) { - if (following.indexOf(args.user) > -1) { + if (typeof(twisterFollowingO.followingsFollowings[username]) !== 'undefined' && + typeof(twisterFollowingO.followingsFollowings[username]["following"]) !== 'undefined') { + if (twisterFollowingO.followingsFollowings[username]["following"].indexOf(defaultScreenName) > -1) { + twisterFollowingO.knownFollowers.push(username); + twisterFollowingO.save(); item.addClass('isFollowing'); item.attr("title", polyglot.t("follows you")); - if (twisterFollowingO.knownFollowers.indexOf(args.username) < 0) - twisterFollowingO.knownFollowers.push(args.username); - } else - twisterFollowingO.notFollowers.push(args.username); - - twisterFollowingO.save(); - }, {"user": defaultScreenName, "item": item, "username": username}); + } + } else { + loadFollowingFromDht(username, 1, [], 0, function (args, following, seqNum) { + if (following.indexOf(args.user) > -1) { + item.addClass('isFollowing'); + item.attr("title", polyglot.t("follows you")); + if (twisterFollowingO.knownFollowers.indexOf(args.username) < 0) + twisterFollowingO.knownFollowers.push(args.username); + } else + twisterFollowingO.notFollowers.push(args.username); + + twisterFollowingO.save(); + }, {"user": defaultScreenName, "item": item, "username": username}); + } } $(".open-followers").attr("title", twisterFollowingO.knownFollowers.length.toString());