From 8893d79eede710ea5c5a9396be7f222df8d1287b Mon Sep 17 00:00:00 2001 From: erqan Date: Sat, 19 Nov 2016 14:16:33 +0300 Subject: [PATCH 1/7] new users module --- css/style.css | 29 ++++++++++------ home.html | 19 +++++++++++ js/interface_common.js | 43 ++++++++++++++---------- js/interface_home.js | 28 ++++++++++++++++ js/interface_localization.js | 39 ++++++++++++++-------- js/options.js | 4 +++ js/twister_following.js | 62 +++++++++++++++++++++++++++++----- js/twister_network.js | 65 +++++++++++++++++++++--------------- options.html | 11 ++++++ theme_calm/css/style.css | 29 ++++++++++------ theme_nin/css/style.css | 41 +++++++++++++++-------- 11 files changed, 268 insertions(+), 102 deletions(-) diff --git a/css/style.css b/css/style.css index ef791bd..e04d0e2 100644 --- a/css/style.css +++ b/css/style.css @@ -843,13 +843,13 @@ textarea.splited-post { /*********************************** ********************* WHO TO FOLLOW ***********************************/ -.who-to-follow -{ +.who-to-follow, +.new-users { padding: 10px; margin-bottom: 10px; } -.who-to-follow h3 -{ +.who-to-follow h3, +.new-users h3 { display: inline; } .twister-user @@ -1943,32 +1943,39 @@ ol.toptrends-list { ********* WHO TO FOLLOW MODAL ******** **************************************/ -.who-to-follow-modal ol { +.who-to-follow-modal ol, +.new-users-modal ol { margin: 5px; } -.who-to-follow-modal .open-profile-modal:hover { +.who-to-follow-modal .open-profile-modal:hover, +.new-users-modal .open-profile-modal:hover { text-decoration: none; } -.who-to-follow-modal .open-profile-modal span { +.who-to-follow-modal .open-profile-modal span, +.new-users-modal .open-profile-modal span { vertical-align: middle; } -.who-to-follow-modal .open-profile-modal span:hover { +.who-to-follow-modal .open-profile-modal span:hover, +.new-users-modal .open-profile-modal span:hover { text-decoration: underline; } -.who-to-follow-modal .follow { +.who-to-follow-modal .follow, +.new-users-modal .follow { float: right; margin: -30px 10px 0 10px; } -.who-to-follow-modal .twister-user-info span { +.who-to-follow-modal .twister-user-info span, +.new-users-modal .twister-user-info span { vertical-align: bottom; } -.who-to-follow-modal .bio { +.who-to-follow-modal .bio, +.new-users-modal .bio { font-size: 12px; color: rgba( 0, 0, 0, .6 ); } diff --git a/home.html b/home.html index 2ff27ec..66c96bd 100644 --- a/home.html +++ b/home.html @@ -146,6 +146,8 @@ + + @@ -227,6 +229,23 @@ + +
+
+

New Users

+ . + Refresh + . + View All + +
+
+
+
+
+
diff --git a/js/interface_common.js b/js/interface_common.js index ec2acdd..ff248b9 100644 --- a/js/interface_common.js +++ b/js/interface_common.js @@ -741,22 +741,7 @@ function fillWhoToFollowModal(list, hlist, start) { if (followingUsers.indexOf(utf) < 0 && list.indexOf(utf) < 0) { list.push(utf); - var item = itemTmp.clone(true); - - item.find('.twister-user-info').attr('data-screen-name', utf); - item.find('.twister-user-name').attr('href', $.MAL.userUrl(utf)); - item.find('.twister-by-user-name').attr('href', $.MAL.userUrl(followingUsers[i])); - item.find('.twister-user-tag').text('@' + utf); - - getAvatar(utf, item.find('.twister-user-photo')); - getFullname(utf, item.find('.twister-user-full')); - getBioToElem(utf, item.find('.bio')); - getFullname(followingUsers[i], item.find('.followed-by').text(followingUsers[i])); - getStatusTime(utf, item.find('.latest-activity .time')); - - item.find('.twister-user-remove').remove(); - - hlist.append(item); + processWhoToFollowSuggestion(hlist, utf, followingUsers[i]); } } } @@ -782,12 +767,32 @@ function openWhoToFollowModal() { modal.content.on('scroll', function() { if (modal.content.scrollTop() >= hlist.height() - modal.content.height() - 20) { - if (!fillWhoToFollowModal(tmplist, hlist, tmplist.length)) + if (!fillWhoToFollowModal(tmplist, modal.self, tmplist.length)) modal.content.off('scroll'); } }); - fillWhoToFollowModal(tmplist, hlist, 0); + fillWhoToFollowModal(tmplist, modal.self, 0); +} + +function openNewUsersModal() { + var modal = openModal({ + classAdd: 'new-users-modal', + title: polyglot.t('New Users') + }); + + var hlist = $('') + .appendTo(modal.content); + var count = 10; + + modal.content.on('scroll', function() { + if (modal.content.scrollTop() >= hlist.height() - modal.content.height() - 20) { + !getLastNUsers(5, count, modal.self); + count += 10; + } + }); + + getLastNUsers(10, 0, modal.self); } function openModalUriShortener() @@ -1237,6 +1242,8 @@ function loadModalFromHash() { openWhoToFollowModal(); else if (hashstring === '#/uri-shortener') openModalUriShortener(); + else if (hashstring === '#newusers') + openNewUsersModal(); } function initHashWatching() { diff --git a/js/interface_home.js b/js/interface_home.js index 5b1984f..8d7f0a0 100644 --- a/js/interface_home.js +++ b/js/interface_home.js @@ -100,6 +100,11 @@ var InterfaceFunctions = function() { else killInterfaceModule('who-to-follow'); + if ($.Options.NewUsers.val === 'enable') + initNewUsers(); + else + killInterfaceModule('new-users'); + if ($.Options.TwistdayReminder.val === 'enable') initTwistdayReminder(); else @@ -200,6 +205,29 @@ function refreshWhoToFollow() { } } +function initNewUsers() { + var nus = initInterfaceModule('new-users'); + + if (nus.length) { + var nusRefresh = nus.find('.refresh-users'); + nusRefresh.on('click', refreshNewUsers); + setTimeout(function() {nusRefresh.click();}, 100); + } +} + +function refreshNewUsers() { + var module = $('.module.new-users'); + var list = module.find('.follow-suggestions'); + + if (list.length) { + list.empty().hide(); + module.find('.refresh-users').hide(); + module.find('.loading-roller').show(); + + getLastNUsers(3, 0, module); + } +} + function initTwistdayReminder() { var $module = initInterfaceModule('twistday-reminder'); diff --git a/js/interface_localization.js b/js/interface_localization.js index bef7976..78cf4b3 100644 --- a/js/interface_localization.js +++ b/js/interface_localization.js @@ -372,7 +372,8 @@ if(preferredLanguage == "en"){ "Favorites": "Favorites", "You have to log in to favorite messages.": "You have to log in to favorite messages.", "fav_this": "Is it for you only?", - "Last activity": "Last activity" + "Last activity": "Last activity", + "New Users": "New Users" }; } if(preferredLanguage == "es"){ @@ -717,7 +718,8 @@ if(preferredLanguage == "es"){ "Favorites": "Favorites", "You have to log in to favorite messages.": "You have to log in to favorite messages.", "fav_this": "Is it for you only?", - "Last activity": "Last activity" + "Last activity": "Last activity", + "New Users": "New Users" }; } @@ -1061,7 +1063,8 @@ if(preferredLanguage == "uk"){ "Favorites": "Favorites", "You have to log in to favorite messages.": "You have to log in to favorite messages.", "fav_this": "Is it for you only?", - "Last activity": "Last activity" + "Last activity": "Last activity", + "New Users": "New Users" }; } @@ -1410,7 +1413,8 @@ if(preferredLanguage == "zh-CN"){ "Favorites": "Favorites", "You have to log in to favorite messages.": "You have to log in to favorite messages.", "fav_this": "Is it for you only?", - "Last activity": "Last activity" + "Last activity": "Last activity", + "New Users": "New Users" }; } @@ -1756,7 +1760,8 @@ if(preferredLanguage == "nl"){ "Favorites": "Favorites", "You have to log in to favorite messages.": "You have to log in to favorite messages.", "fav_this": "Is it for you only?", - "Last activity": "Last activity" + "Last activity": "Last activity", + "New Users": "New Users" }; } @@ -2100,7 +2105,8 @@ if(preferredLanguage == "it"){ "Favorites": "Favorites", "You have to log in to favorite messages.": "You have to log in to favorite messages.", "fav_this": "Is it for you only?", - "Last activity": "Last activity" + "Last activity": "Last activity", + "New Users": "New Users" }; } @@ -2445,7 +2451,8 @@ if(preferredLanguage == "fr"){ "users_favs": "Favorites of @%{username}", "Favorites": "Favorites", "You have to log in to favorite messages.": "You have to log in to favorite messages.", - "Last activity": "Last activity" + "Last activity": "Last activity", + "New Users": "New Users" }; } @@ -2797,7 +2804,8 @@ if(preferredLanguage == "ru"){ "Favorites": "Favorites", "You have to log in to favorite messages.": "You have to log in to favorite messages.", "fav_this": "Is it for you only?", - "Last activity": "Last activity" + "Last activity": "Last activity", + "New Users": "New Users" }; } @@ -3145,7 +3153,8 @@ if(preferredLanguage == "de"){ "Favorites": "Favorites", "You have to log in to favorite messages.": "You have to log in to favorite messages.", "fav_this": "Is it for you only?", - "Last activity": "Last activity" + "Last activity": "Last activity", + "New Users": "New Users" }; } @@ -3488,7 +3497,8 @@ if(preferredLanguage == "ja"){ "Favorites": "Favorites", "You have to log in to favorite messages.": "You have to log in to favorite messages.", "fav_this": "Is it for you only?", - "Last activity": "Last activity" + "Last activity": "Last activity", + "New Users": "New Users" }; } @@ -3837,7 +3847,8 @@ if(preferredLanguage == "pt-BR"){ "Favorites": "Favorites", "You have to log in to favorite messages.": "You have to log in to favorite messages.", "fav_this": "Is it for you only?", - "Last activity": "Last activity" + "Last activity": "Last activity", + "New Users": "New Users" }; } @@ -4182,7 +4193,8 @@ if(preferredLanguage == "tr"){ "Favorites": "Favoriler", "You have to log in to favorite messages.": "İletileri favorine eklemek için giriş yapmalısın.", "fav_this": "Sana özel mi?", - "Last activity": "Son etkinlik" + "Last activity": "Son etkinlik", + "New Users": "Yeni Kullanıcılar" }; } @@ -4530,7 +4542,8 @@ if(preferredLanguage == "cs"){ "Favorites": "Favorites", "You have to log in to favorite messages.": "You have to log in to favorite messages.", "fav_this": "Is it for you only?", - "Last activity": "Last activity" + "Last activity": "Last activity", + "New Users": "New Users" }; } diff --git a/js/options.js b/js/options.js index 2acd553..8eb5612 100644 --- a/js/options.js +++ b/js/options.js @@ -41,6 +41,10 @@ function twisterOptions() { name: 'WhoToFollow', valDefault: 'enable' }); + this.add({ + name: 'NewUsers', + valDefault: 'enable' + }); this.add({ name: 'TwistdayReminder', valDefault: 'enable', diff --git a/js/twister_following.js b/js/twister_following.js index c736b05..98de68e 100644 --- a/js/twister_following.js +++ b/js/twister_following.js @@ -15,6 +15,8 @@ var _searchKeypressTimer = undefined; var _lastSearchUsersResults = []; var _lastSearchUsersResultsRemovedFromDHTgetQueue = true; var _lastLoadFromDhtTime = 0; +var _lastProcessedBlock = -1; +var knownNewUsers = []; var twisterFollowingO = undefined; @@ -427,6 +429,36 @@ function followingEmptyOrMyself() { return (!followingUsers.length || (followingUsers.length === 1 && followingUsers[0] === defaultScreenName)) } +function getLastNUsers(n,offset,module) { + + for (var i = offset; i < knownNewUsers.length && i < offset + n; i++) + processWhoToFollowSuggestion(module, knownNewUsers[i]); + + if (knownNewUsers.length >= n + offset) + return; + + if (_lastProcessedBlock == -1) + requestBestBlock(processBlockUsers, {n: n, offset: offset, module: module}); + else + requestNthBlock(_lastProcessedBlock - 1, processBlockUsers, {n: n, offset: offset, module: module}); +} + +function processBlockUsers(block, users){ + _lastProcessedBlock = block.height; + + if (knownNewUsers.length + block.usernames.length < users.n + users.offset) + setTimeout(function(){requestBlock(block.previousblockhash, processBlockUsers, users);}, 100); + + for (var i = 0; i < block.usernames.length; i++) { + if (knownNewUsers.indexOf(block.usernames[i]) == -1) { + processWhoToFollowSuggestion(users.module, block.usernames[i]); + knownNewUsers.push(block.usernames[i]); + if (knownNewUsers.length >= users.n + users.offset) + break; + } + } +} + // randomly choose a user we follow, get "following1" from him and them // choose a suggestion from their list. this function could be way better, but // that's about the simplest we may get to start with. @@ -446,10 +478,11 @@ function getRandomFollowSuggestion() { var suggested = false; var j = Math.floor(Math.random() * twisterFollowingO.followingsFollowings[followingUsers[i]].following.length); + var module = $('.module.who-to-follow'); for( ; j < twisterFollowingO.followingsFollowings[followingUsers[i]].following.length; j++ ) { if( followingUsers.indexOf(twisterFollowingO.followingsFollowings[followingUsers[i]].following[j]) < 0 && _followSuggestions.indexOf(twisterFollowingO.followingsFollowings[followingUsers[i]].following[j]) < 0) { - processWhoToFollowSuggestion(twisterFollowingO.followingsFollowings[followingUsers[i]].following[j], followingUsers[i]); + processWhoToFollowSuggestion(module, twisterFollowingO.followingsFollowings[followingUsers[i]].following[j], followingUsers[i]); _followSuggestions.push(twisterFollowingO.followingsFollowings[followingUsers[i]].following[j]); suggested = true; break; @@ -501,26 +534,37 @@ function getWhoFollows(peerAlias, elem) { ; } -function processWhoToFollowSuggestion(suggestion, followedBy) { +function processWhoToFollowSuggestion(module, suggestion, followedBy) { if (suggestion) { - var module = $('.module.who-to-follow'); var list = module.find('.follow-suggestions'); var item = $('#follow-suggestion-template').clone(true) .removeAttr('id'); item.find('.twister-user-info').attr('data-screen-name', suggestion); item.find('.twister-user-name').attr('href', $.MAL.userUrl(suggestion)); - item.find('.twister-by-user-name').attr('href', $.MAL.userUrl(followedBy)); item.find('.twister-user-tag').text('@' + suggestion); getAvatar(suggestion, item.find('.twister-user-photo')); - getFullname(followedBy, item.find('.followed-by').text(followedBy)); getStatusTime(suggestion, item.find('.latest-activity .time')); - item.find('.twister-user-remove').on('click', function() { - item.remove(); - getRandomFollowSuggestion(); - }); + if (module.hasClass('who-to-follow') || module.hasClass('who-to-follow-modal')) { + item.find('.twister-by-user-name').attr('href', $.MAL.userUrl(followedBy)); + getFullname(followedBy, item.find('.followed-by').text(followedBy)); + item.find('.twister-user-remove').on('click', function () { + item.remove(); + getRandomFollowSuggestion(); + }); + } + else if (module.hasClass('new-users') || module.hasClass('new-users-modal')){ + item.find('.followers').remove(); + item.find('.twister-user-remove').remove(); + } + + if (module.hasClass('modal-wrapper')) { + getFullname(suggestion, item.find('.twister-user-full')); + getBioToElem(suggestion, item.find('.bio')); + item.find('.twister-user-remove').remove(); + } list.append(item).show(); module.find('.refresh-users').show(); diff --git a/js/twister_network.js b/js/twister_network.js index 38694f7..4497937 100644 --- a/js/twister_network.js +++ b/js/twister_network.js @@ -146,46 +146,59 @@ function requestBestBlock(cbFunc, cbArg) { }, {}); } +function requestNthBlock(n, cbFunc, cbArg) { + twisterRpc("getblockhash", [n], + function(args, hash) { + requestBlock(hash, args.cbFunc, args.cbArg); + }, {cbFunc:cbFunc, cbArg:cbArg}, + function(args, ret) { + console.log("getblockhash error"); + }, {}); +} + function requestBlock(hash, cbFunc, cbArg) { twisterRpc("getblock", [hash], function(args, block) { - twisterdLastBlockTime = block.time; - $(".last-block-time").text( timeGmtToText(twisterdLastBlockTime) ); + //twisterdLastBlockTime = block.time; + //$(".last-block-time").text( timeGmtToText(twisterdLastBlockTime) ); if( args.cbFunc ) - args.cbFunc(args.cbArg); + args.cbFunc(block, args.cbArg); }, {cbFunc:cbFunc, cbArg:cbArg}, function(args, ret) { console.log("requestBlock error"); }, {}); } - function networkUpdate(cbFunc, cbArg) { requestNetInfo(function () { - requestBestBlock(function(args) { - var curTime = new Date().getTime() / 1000; - if( twisterdConnections ) { - if( twisterdLastBlockTime > curTime + 3600 ) { - $.MAL.setNetworkStatusMsg(polyglot.t("Last block is ahead of your computer time, check your clock."), false); - twisterdConnectedAndUptodate = false; - } else if( twisterdLastBlockTime > curTime - (2 * 3600) ) { - if( twisterDhtNodes ) { - $.MAL.setNetworkStatusMsg(polyglot.t("Block chain is up-to-date, twister is ready to use!"), true); - twisterdConnectedAndUptodate = true; - } else { - $.MAL.setNetworkStatusMsg(polyglot.t("DHT network down."), false); - twisterdConnectedAndUptodate = true; - } - } else { - var daysOld = (curTime - twisterdLastBlockTime) / (3600*24); - $.MAL.setNetworkStatusMsg(polyglot.t("downloading_block_chain", { days: daysOld.toFixed(2) }), false); - // don't alarm user if blockchain is just a little bit behind - twisterdConnectedAndUptodate = (daysOld < 2); + requestBestBlock(function(block, args) { + + twisterdLastBlockTime = block.time; + $(".last-block-time").text( timeGmtToText(twisterdLastBlockTime) ); + + var curTime = new Date().getTime() / 1000; + if (twisterdConnections) { + if (twisterdLastBlockTime > curTime + 3600) { + $.MAL.setNetworkStatusMsg(polyglot.t("Last block is ahead of your computer time, check your clock."), false); + twisterdConnectedAndUptodate = false; + } else if (twisterdLastBlockTime > curTime - (2 * 3600)) { + if (twisterDhtNodes) { + $.MAL.setNetworkStatusMsg(polyglot.t("Block chain is up-to-date, twister is ready to use!"), true); + twisterdConnectedAndUptodate = true; + } else { + $.MAL.setNetworkStatusMsg(polyglot.t("DHT network down."), false); + twisterdConnectedAndUptodate = true; + } + } else { + var daysOld = (curTime - twisterdLastBlockTime) / (3600 * 24); + $.MAL.setNetworkStatusMsg(polyglot.t("downloading_block_chain", {days: daysOld.toFixed(2)}), false); + // don't alarm user if blockchain is just a little bit behind + twisterdConnectedAndUptodate = (daysOld < 2); + } } - } - if( args.cbFunc ) - args.cbFunc(args.cbArg) + if (args.cbFunc) + args.cbFunc(args.cbArg); }, {cbFunc:cbFunc, cbArg:cbArg} ); }); } diff --git a/options.html b/options.html index 8338e62..ea4645e 100644 --- a/options.html +++ b/options.html @@ -353,6 +353,17 @@
+
+

New Users

+
+
+ +
+
+

Twistday Reminder

diff --git a/theme_calm/css/style.css b/theme_calm/css/style.css index 21f5be0..835dfbb 100644 --- a/theme_calm/css/style.css +++ b/theme_calm/css/style.css @@ -1024,12 +1024,12 @@ textarea.splited-post { /*********************************** ********************* WHO TO FOLLOW ***********************************/ -.who-to-follow -{ +.who-to-follow, +.new-users { padding: 10px; } -.who-to-follow h3 -{ +.who-to-follow h3, +.new-users h3 { display: inline; } .twister-user @@ -2345,19 +2345,23 @@ textarea.splited-post { ********* WHO TO FOLLOW MODAL ******** **************************************/ -.who-to-follow-modal .modal-content { +.who-to-follow-modal .modal-content, +.new-users-modal .modal-content { padding: 15px; } -.who-to-follow-modal ol { +.who-to-follow-modal ol, +.new-users-modal ol { margin: 5px; } -.who-to-follow-modal .open-profile-modal:hover { +.who-to-follow-modal .open-profile-modal:hover, +.new-users-modal .open-profile-modal span:hover { text-decoration: none; } -.who-to-follow-modal .open-profile-modal span { +.who-to-follow-modal .open-profile-modal span, +.new-users-modal .open-profile-modal span { vertical-align: middle; } @@ -2365,16 +2369,19 @@ textarea.splited-post { text-decoration: underline; } -.who-to-follow-modal .follow { +.who-to-follow-modal .follow, +.new-users-modal .follow { float: right; margin: -30px 10px 0 10px; } -.who-to-follow-modal .twister-user-info span { +.who-to-follow-modal .twister-user-info span, +.new-users-modal .twister-user-info span { vertical-align: bottom; } -.who-to-follow-modal .bio { +.who-to-follow-modal .bio, +.new-users-modal .bio { font-size: 12px; color: rgba( 0, 0, 0, .6 ); } diff --git a/theme_nin/css/style.css b/theme_nin/css/style.css index 1f5ba6b..14e9279 100644 --- a/theme_nin/css/style.css +++ b/theme_nin/css/style.css @@ -2159,27 +2159,32 @@ textarea.splited-post { /******** WHO TO FOLLOW ********/ /* line 411, ../sass/style.sass */ -.who-to-follow.module { +.who-to-follow.module, +.new-users.module { width: inherit; margin-bottom: 20px; } /* line 414, ../sass/style.sass */ -.who-to-follow small { +.who-to-follow small, +.new-users small { display: none; } /* line 416, ../sass/style.sass */ -.who-to-follow h3 { +.who-to-follow h3, +.new-users h3 { float: left; } /* line 418, ../sass/style.sass */ -.who-to-follow ol { +.who-to-follow ol, +.new-users ol { clear: both; } -.who-to-follow .twister-user-info { +.who-to-follow .twister-user-info, +.new-users .twister-user-info { margin-top: 8px; } @@ -3130,45 +3135,53 @@ ol.toptrends-list a:hover { /******* WHO TO FOLLOW MODAL****** */ /* line 943, ../sass/style.sass */ -.modal-wrapper.who-to-follow-modal { +.modal-wrapper.who-to-follow-modal, +.modal-wrapper.new-users-modal { width: 520px; height: 580px; margin: -290px 0 0 -260px; } /* line 949, ../sass/style.sass */ -.who-to-follow-modal .modal-content { +.who-to-follow-modal .modal-content, +.new-users-modal .modal-content { padding: 15px; } /* line 955, ../sass/style.sass */ -.who-to-follow-modal ol { +.who-to-follow-modal ol, +.new-users-modal ol { margin: 5px; } /* line 958, ../sass/style.sass */ -.who-to-follow-modal .open-profile-modal:hover { +.who-to-follow-modal .open-profile-modal:hover, +.new-users-modal .open-profile-modal:hover { text-decoration: none; } /* line 960, ../sass/style.sass */ -.who-to-follow-modal .twister-user { - position: relative; +.who-to-follow-modal .twister-user, +.new-users-modal .twister-user { +position: relative; padding: 5px; } /* line 963, ../sass/style.sass */ -.who-to-follow-modal .twister-user-photo { +.who-to-follow-modal .twister-user-photo, +.new-users-modal .twister-user-photo { position: relative; left: 0; float: left; display: block; } /* line 968, ../sass/style.sass */ -.who-to-follow-modal .twister-user-info { +.who-to-follow-modal .twister-user-info, +.new-users-modal .twister-user-info { position: relative; margin-top: 4px; padding-left: 70px; width: auto; } /* line 972, ../sass/style.sass */ -.who-to-follow-modal .bio { +.who-to-follow-modal .bio, +.new-users-modal .bio { color: rgba(0, 0, 0, 0.6); font-style: italic; } From c188e6d1348616def8f053edce487abb5a8a4df4 Mon Sep 17 00:00:00 2001 From: erqan Date: Sat, 19 Nov 2016 14:22:59 +0300 Subject: [PATCH 2/7] removes comment --- js/twister_network.js | 3 --- 1 file changed, 3 deletions(-) diff --git a/js/twister_network.js b/js/twister_network.js index 4497937..cac9384 100644 --- a/js/twister_network.js +++ b/js/twister_network.js @@ -159,9 +159,6 @@ function requestNthBlock(n, cbFunc, cbArg) { function requestBlock(hash, cbFunc, cbArg) { twisterRpc("getblock", [hash], function(args, block) { - //twisterdLastBlockTime = block.time; - //$(".last-block-time").text( timeGmtToText(twisterdLastBlockTime) ); - if( args.cbFunc ) args.cbFunc(block, args.cbArg); }, {cbFunc:cbFunc, cbArg:cbArg}, From 99f8940d38a2c49a054a0d0258f16c649c663d1f Mon Sep 17 00:00:00 2001 From: erqan Date: Sat, 19 Nov 2016 18:31:47 +0300 Subject: [PATCH 3/7] fix some silly mistakes --- js/interface_common.js | 8 ++++---- js/twister_following.js | 16 ++++++++++++++-- 2 files changed, 18 insertions(+), 6 deletions(-) diff --git a/js/interface_common.js b/js/interface_common.js index ff248b9..05f9c6f 100644 --- a/js/interface_common.js +++ b/js/interface_common.js @@ -783,16 +783,16 @@ function openNewUsersModal() { var hlist = $('') .appendTo(modal.content); - var count = 10; + var count = 15; modal.content.on('scroll', function() { if (modal.content.scrollTop() >= hlist.height() - modal.content.height() - 20) { - !getLastNUsers(5, count, modal.self); - count += 10; + if (getLastNUsers(5, count, modal.self)) + count += 5; } }); - getLastNUsers(10, 0, modal.self); + getLastNUsers(15, 0, modal.self); } function openModalUriShortener() diff --git a/js/twister_following.js b/js/twister_following.js index 98de68e..58d48a9 100644 --- a/js/twister_following.js +++ b/js/twister_following.js @@ -17,6 +17,7 @@ var _lastSearchUsersResultsRemovedFromDHTgetQueue = true; var _lastLoadFromDhtTime = 0; var _lastProcessedBlock = -1; var knownNewUsers = []; +var isNewUserThRunning = false; var twisterFollowingO = undefined; @@ -431,23 +432,34 @@ function followingEmptyOrMyself() { function getLastNUsers(n,offset,module) { + if (isNewUserThRunning) + return false; + + isNewUserThRunning = true; for (var i = offset; i < knownNewUsers.length && i < offset + n; i++) processWhoToFollowSuggestion(module, knownNewUsers[i]); if (knownNewUsers.length >= n + offset) - return; + { + isNewUserThRunning = false; + return true; + } if (_lastProcessedBlock == -1) requestBestBlock(processBlockUsers, {n: n, offset: offset, module: module}); else requestNthBlock(_lastProcessedBlock - 1, processBlockUsers, {n: n, offset: offset, module: module}); + + return true; } function processBlockUsers(block, users){ _lastProcessedBlock = block.height; - if (knownNewUsers.length + block.usernames.length < users.n + users.offset) + if (knownNewUsers.length + block.usernames.length < users.n + users.offset && typeof block.previousblockhash !== 'undefined') setTimeout(function(){requestBlock(block.previousblockhash, processBlockUsers, users);}, 100); + else + isNewUserThRunning = false; for (var i = 0; i < block.usernames.length; i++) { if (knownNewUsers.indexOf(block.usernames[i]) == -1) { From 16da1c8e31243b411a767dbeba3f77a653396c24 Mon Sep 17 00:00:00 2001 From: erqan Date: Thu, 24 Nov 2016 15:54:33 +0300 Subject: [PATCH 4/7] fixing & developing --- js/interface_common.js | 17 +++-- js/interface_home.js | 5 +- js/interface_localization.js | 39 ++++++---- js/options.js | 7 ++ js/twister_following.js | 143 ++++++++++++++++++++++++++--------- options.html | 17 ++++- 6 files changed, 168 insertions(+), 60 deletions(-) diff --git a/js/interface_common.js b/js/interface_common.js index 05f9c6f..4f513bc 100644 --- a/js/interface_common.js +++ b/js/interface_common.js @@ -119,6 +119,9 @@ function closeModal(req, switchMode) { else this.remove(); // if it's minimized it will be removed with twister.modal[i].drapper + if (typeof twister.modal[i].onClose === 'function') + twister.modal[i].onClose(twister.modal[i].closeArg); + twister.modal[i].drapper.remove(); twister.modal[i] = undefined; } @@ -731,9 +734,6 @@ function addPeerToFollowingList(list, peerAlias) { } function fillWhoToFollowModal(list, hlist, start) { - var itemTmp = $('#follow-suggestion-template').clone(true) - .removeAttr('id'); - for (var i = 0; i < followingUsers.length && list.length < start + 20; i++) { if (typeof twisterFollowingO.followingsFollowings[followingUsers[i]] !== 'undefined') { for (var j = 0; j < twisterFollowingO.followingsFollowings[followingUsers[i]].following.length && list.length < start + 25; j++) { @@ -746,7 +746,6 @@ function fillWhoToFollowModal(list, hlist, start) { } } } - itemTmp.remove(); if (i >= followingUsers.length - 1) return false; @@ -778,7 +777,10 @@ function openWhoToFollowModal() { function openNewUsersModal() { var modal = openModal({ classAdd: 'new-users-modal', - title: polyglot.t('New Users') + title: polyglot.t('New Users'), + onClose: function() { + NewUserSearch.isNewUserModalOpen = false; + } }); var hlist = $('') @@ -787,12 +789,13 @@ function openNewUsersModal() { modal.content.on('scroll', function() { if (modal.content.scrollTop() >= hlist.height() - modal.content.height() - 20) { - if (getLastNUsers(5, count, modal.self)) + if (newUsers.getLastNUsers(5, count, modal.self)) count += 5; } }); - getLastNUsers(15, 0, modal.self); + NewUserSearch.isNewUserModalOpen = true; + newUsers.getLastNUsers(15, 0, modal.self); } function openModalUriShortener() diff --git a/js/interface_home.js b/js/interface_home.js index 8d7f0a0..03116ec 100644 --- a/js/interface_home.js +++ b/js/interface_home.js @@ -118,7 +118,7 @@ var InterfaceFunctions = function() { if ($.Options.WebTorrent.val === 'enable') initWebTorrent(); } -} +}; function initTopTrends() { var $tt = initInterfaceModule('toptrends'); @@ -208,6 +208,7 @@ function refreshWhoToFollow() { function initNewUsers() { var nus = initInterfaceModule('new-users'); + newUsers = NewUserSearch(); if (nus.length) { var nusRefresh = nus.find('.refresh-users'); nusRefresh.on('click', refreshNewUsers); @@ -224,7 +225,7 @@ function refreshNewUsers() { module.find('.refresh-users').hide(); module.find('.loading-roller').show(); - getLastNUsers(3, 0, module); + newUsers.getLastNUsers(3, 0, module, true); } } diff --git a/js/interface_localization.js b/js/interface_localization.js index 78cf4b3..f3ee644 100644 --- a/js/interface_localization.js +++ b/js/interface_localization.js @@ -373,7 +373,8 @@ if(preferredLanguage == "en"){ "You have to log in to favorite messages.": "You have to log in to favorite messages.", "fav_this": "Is it for you only?", "Last activity": "Last activity", - "New Users": "New Users" + "New Users": "New Users", + "Live tracking" : "Live tracking" }; } if(preferredLanguage == "es"){ @@ -719,7 +720,8 @@ if(preferredLanguage == "es"){ "You have to log in to favorite messages.": "You have to log in to favorite messages.", "fav_this": "Is it for you only?", "Last activity": "Last activity", - "New Users": "New Users" + "New Users": "New Users", + "Live tracking" : "Live tracking" }; } @@ -1064,7 +1066,8 @@ if(preferredLanguage == "uk"){ "You have to log in to favorite messages.": "You have to log in to favorite messages.", "fav_this": "Is it for you only?", "Last activity": "Last activity", - "New Users": "New Users" + "New Users": "New Users", + "Live tracking" : "Live tracking" }; } @@ -1414,7 +1417,8 @@ if(preferredLanguage == "zh-CN"){ "You have to log in to favorite messages.": "You have to log in to favorite messages.", "fav_this": "Is it for you only?", "Last activity": "Last activity", - "New Users": "New Users" + "New Users": "New Users", + "Live tracking" : "Live tracking" }; } @@ -1761,7 +1765,8 @@ if(preferredLanguage == "nl"){ "You have to log in to favorite messages.": "You have to log in to favorite messages.", "fav_this": "Is it for you only?", "Last activity": "Last activity", - "New Users": "New Users" + "New Users": "New Users", + "Live tracking" : "Live tracking" }; } @@ -2106,7 +2111,8 @@ if(preferredLanguage == "it"){ "You have to log in to favorite messages.": "You have to log in to favorite messages.", "fav_this": "Is it for you only?", "Last activity": "Last activity", - "New Users": "New Users" + "New Users": "New Users", + "Live tracking" : "Live tracking" }; } @@ -2452,7 +2458,8 @@ if(preferredLanguage == "fr"){ "Favorites": "Favorites", "You have to log in to favorite messages.": "You have to log in to favorite messages.", "Last activity": "Last activity", - "New Users": "New Users" + "New Users": "New Users", + "Live tracking" : "Live tracking" }; } @@ -2805,7 +2812,8 @@ if(preferredLanguage == "ru"){ "You have to log in to favorite messages.": "You have to log in to favorite messages.", "fav_this": "Is it for you only?", "Last activity": "Last activity", - "New Users": "New Users" + "New Users": "New Users", + "Live tracking" : "Live tracking" }; } @@ -3154,7 +3162,8 @@ if(preferredLanguage == "de"){ "You have to log in to favorite messages.": "You have to log in to favorite messages.", "fav_this": "Is it for you only?", "Last activity": "Last activity", - "New Users": "New Users" + "New Users": "New Users", + "Live tracking" : "Live tracking" }; } @@ -3498,7 +3507,8 @@ if(preferredLanguage == "ja"){ "You have to log in to favorite messages.": "You have to log in to favorite messages.", "fav_this": "Is it for you only?", "Last activity": "Last activity", - "New Users": "New Users" + "New Users": "New Users", + "Live tracking" : "Live tracking" }; } @@ -3848,7 +3858,8 @@ if(preferredLanguage == "pt-BR"){ "You have to log in to favorite messages.": "You have to log in to favorite messages.", "fav_this": "Is it for you only?", "Last activity": "Last activity", - "New Users": "New Users" + "New Users": "New Users", + "Live tracking" : "Live tracking" }; } @@ -4194,7 +4205,8 @@ if(preferredLanguage == "tr"){ "You have to log in to favorite messages.": "İletileri favorine eklemek için giriş yapmalısın.", "fav_this": "Sana özel mi?", "Last activity": "Son etkinlik", - "New Users": "Yeni Kullanıcılar" + "New Users": "Yeni Kullanıcılar", + "Live tracking" : "Canlı takip" }; } @@ -4543,7 +4555,8 @@ if(preferredLanguage == "cs"){ "You have to log in to favorite messages.": "You have to log in to favorite messages.", "fav_this": "Is it for you only?", "Last activity": "Last activity", - "New Users": "New Users" + "New Users": "New Users", + "Live tracking" : "Live tracking" }; } diff --git a/js/options.js b/js/options.js index 8eb5612..84f17cb 100644 --- a/js/options.js +++ b/js/options.js @@ -43,6 +43,13 @@ function twisterOptions() { }); this.add({ name: 'NewUsers', + valDefault: 'enable', + tickMethod: function (elem) { + $('#NewUsersCont').css('display', (elem.value === 'enable') ? 'block' : 'none'); + } + }); + this.add({ + name: 'NewUsersLiveTracking', valDefault: 'enable' }); this.add({ diff --git a/js/twister_following.js b/js/twister_following.js index 58d48a9..462d82e 100644 --- a/js/twister_following.js +++ b/js/twister_following.js @@ -15,11 +15,9 @@ var _searchKeypressTimer = undefined; var _lastSearchUsersResults = []; var _lastSearchUsersResultsRemovedFromDHTgetQueue = true; var _lastLoadFromDhtTime = 0; -var _lastProcessedBlock = -1; -var knownNewUsers = []; -var isNewUserThRunning = false; var twisterFollowingO = undefined; +var newUsers = undefined; var TwisterFollowing = function (user) { if (!(this instanceof TwisterFollowing)) @@ -430,46 +428,116 @@ function followingEmptyOrMyself() { return (!followingUsers.length || (followingUsers.length === 1 && followingUsers[0] === defaultScreenName)) } -function getLastNUsers(n,offset,module) { +/* NEW USER SEARCH */ +var NewUserSearch = function(){ + if (!(this instanceof NewUserSearch)) + return new NewUserSearch(); - if (isNewUserThRunning) - return false; + this.init(); +}; + +NewUserSearch.knownNewUsers = []; +NewUserSearch.isNewUserThRunning = false; +NewUserSearch.isNewUserModalOpen = false; +NewUserSearch.startProcessedBlock = -1; +NewUserSearch.lastProcessedBlock = -1; +NewUserSearch.processBlockUsersProxy = function(block, args){ + if (args.obj instanceof NewUserSearch) + args.obj.processBlockUsers(block, args); +}; +NewUserSearch.live = function(module) { + newUsers.getNewUsers(module); +}; +NewUserSearch.processBestBlockUsersProxy = function(block, args){ + if (block.height > NewUserSearch.startProcessedBlock) { + if (args.obj instanceof NewUserSearch) + args.obj.processBlockUsers(block, {obj: args.obj, args: {n: 0, offset: 0, module: args.args.module, prepend: true, live: true}}); + } +}; + +NewUserSearch.prototype = { + storage: undefined, + isForced: false, + + init: function() { + this.storage = $.initNamespaceStorage(defaultScreenName).sessionStorage; + if (this.storage.isSet("knownNewUsers")) + NewUserSearch.knownNewUsers = this.storage.get("knownNewUsers"); + if (this.storage.isSet("lastProcessedBlock")) + NewUserSearch.lastProcessedBlock = this.storage.get("lastProcessedBlock"); + if (this.storage.isSet("startProcessedBlock")) + NewUserSearch.startProcessedBlock = this.storage.get("startProcessedBlock"); + + if ($.Options.NewUsersLiveTracking.val === 'enable') + setInterval(function(){NewUserSearch.live($('.module.new-users'));}, 10000); + }, + + save: function(){ + this.storage.set("knownNewUsers", NewUserSearch.knownNewUsers); + this.storage.set("lastProcessedBlock", NewUserSearch.lastProcessedBlock); + this.storage.set("startProcessedBlock", NewUserSearch.startProcessedBlock); + }, + + getNewUsers: function(module) { + requestBestBlock(NewUserSearch.processBestBlockUsersProxy, {obj: this, args: {module: module}}); + }, + + getLastNUsers: function (n, offset, module, forced) { + for (var i = offset; i < NewUserSearch.knownNewUsers.length && i < offset + n; i++) + processWhoToFollowSuggestion(module, NewUserSearch.knownNewUsers[i]); + + if (NewUserSearch.knownNewUsers.length >= n + offset) { + NewUserSearch.isNewUserThRunning = false; + return true; + } - isNewUserThRunning = true; - for (var i = offset; i < knownNewUsers.length && i < offset + n; i++) - processWhoToFollowSuggestion(module, knownNewUsers[i]); + if (NewUserSearch.isNewUserThRunning) + return false; + + NewUserSearch.isNewUserThRunning = true; + this.isForced = forced; + + if (NewUserSearch.lastProcessedBlock == -1) + requestBestBlock(NewUserSearch.processBlockUsersProxy, {obj: this, args: {n: n, offset: offset, module: module}}); + else + requestNthBlock(NewUserSearch.lastProcessedBlock - 1, NewUserSearch.processBlockUsersProxy, {obj: this, args: {n: n, offset: offset, module: module}}); - if (knownNewUsers.length >= n + offset) - { - isNewUserThRunning = false; return true; - } + }, - if (_lastProcessedBlock == -1) - requestBestBlock(processBlockUsers, {n: n, offset: offset, module: module}); - else - requestNthBlock(_lastProcessedBlock - 1, processBlockUsers, {n: n, offset: offset, module: module}); + processBlockUsers: function (block, args) { + if (NewUserSearch.startProcessedBlock === -1) + NewUserSearch.startProcessedBlock = block.height; + if (NewUserSearch.lastProcessedBlock === -1 || block.height < NewUserSearch.lastProcessedBlock) + NewUserSearch.lastProcessedBlock = block.height; - return true; -} + if ((this.isForced || NewUserSearch.isNewUserModalOpen) && + NewUserSearch.knownNewUsers.length + block.usernames.length < args.args.n + args.args.offset && + typeof block.previousblockhash !== 'undefined') { -function processBlockUsers(block, users){ - _lastProcessedBlock = block.height; + setTimeout(function () { + requestBlock(block.previousblockhash, NewUserSearch.processBlockUsersProxy, {obj: args.obj, args: args.args}); + }, 100); - if (knownNewUsers.length + block.usernames.length < users.n + users.offset && typeof block.previousblockhash !== 'undefined') - setTimeout(function(){requestBlock(block.previousblockhash, processBlockUsers, users);}, 100); - else - isNewUserThRunning = false; + } else { + NewUserSearch.isNewUserThRunning = false; + this.isForced = false; + } - for (var i = 0; i < block.usernames.length; i++) { - if (knownNewUsers.indexOf(block.usernames[i]) == -1) { - processWhoToFollowSuggestion(users.module, block.usernames[i]); - knownNewUsers.push(block.usernames[i]); - if (knownNewUsers.length >= users.n + users.offset) - break; + for (var i = 0; i < block.usernames.length; i++) { + if (NewUserSearch.knownNewUsers.indexOf(block.usernames[i]) == -1) { + processWhoToFollowSuggestion(args.args.module, block.usernames[i], undefined, args.args.prepend); + if (args.args.prepend) + NewUserSearch.knownNewUsers.unshift(block.usernames[i]); + else + NewUserSearch.knownNewUsers.push(block.usernames[i]); + if (!args.args.live && NewUserSearch.knownNewUsers.length >= args.args.n + args.args.offset) + break; + } } + this.save(); } -} +}; // randomly choose a user we follow, get "following1" from him and them // choose a suggestion from their list. this function could be way better, but @@ -546,7 +614,7 @@ function getWhoFollows(peerAlias, elem) { ; } -function processWhoToFollowSuggestion(module, suggestion, followedBy) { +function processWhoToFollowSuggestion(module, suggestion, followedBy, prepend) { if (suggestion) { var list = module.find('.follow-suggestions'); var item = $('#follow-suggestion-template').clone(true) @@ -578,7 +646,14 @@ function processWhoToFollowSuggestion(module, suggestion, followedBy) { item.find('.twister-user-remove').remove(); } - list.append(item).show(); + if (prepend) + list.prepend(item).show(); + else + list.append(item).show(); + + while (module.hasClass('new-users') && list.children().length > 3) + list.children().last().remove(); + module.find('.refresh-users').show(); module.find('.loading-roller').hide(); } else diff --git a/options.html b/options.html index ea4645e..a915fbc 100644 --- a/options.html +++ b/options.html @@ -357,10 +357,19 @@

New Users

- +

+ +

+
+

Live tracking

+ +
From 4637c68df7a582f4db4883e03fe159d740fb24da Mon Sep 17 00:00:00 2001 From: erqan Date: Thu, 24 Nov 2016 16:00:41 +0300 Subject: [PATCH 5/7] shaping --- js/twister_network.js | 44 +++++++++++++++++++++---------------------- 1 file changed, 22 insertions(+), 22 deletions(-) diff --git a/js/twister_network.js b/js/twister_network.js index cac9384..bbfb2df 100644 --- a/js/twister_network.js +++ b/js/twister_network.js @@ -171,31 +171,31 @@ function networkUpdate(cbFunc, cbArg) { requestNetInfo(function () { requestBestBlock(function(block, args) { - twisterdLastBlockTime = block.time; - $(".last-block-time").text( timeGmtToText(twisterdLastBlockTime) ); - - var curTime = new Date().getTime() / 1000; - if (twisterdConnections) { - if (twisterdLastBlockTime > curTime + 3600) { - $.MAL.setNetworkStatusMsg(polyglot.t("Last block is ahead of your computer time, check your clock."), false); - twisterdConnectedAndUptodate = false; - } else if (twisterdLastBlockTime > curTime - (2 * 3600)) { - if (twisterDhtNodes) { - $.MAL.setNetworkStatusMsg(polyglot.t("Block chain is up-to-date, twister is ready to use!"), true); - twisterdConnectedAndUptodate = true; - } else { - $.MAL.setNetworkStatusMsg(polyglot.t("DHT network down."), false); - twisterdConnectedAndUptodate = true; - } + twisterdLastBlockTime = block.time; + $(".last-block-time").text(timeGmtToText(twisterdLastBlockTime)); + + var curTime = new Date().getTime() / 1000; + if (twisterdConnections) { + if (twisterdLastBlockTime > curTime + 3600) { + $.MAL.setNetworkStatusMsg(polyglot.t("Last block is ahead of your computer time, check your clock."), false); + twisterdConnectedAndUptodate = false; + } else if (twisterdLastBlockTime > curTime - (2 * 3600)) { + if (twisterDhtNodes) { + $.MAL.setNetworkStatusMsg(polyglot.t("Block chain is up-to-date, twister is ready to use!"), true); + twisterdConnectedAndUptodate = true; } else { - var daysOld = (curTime - twisterdLastBlockTime) / (3600 * 24); - $.MAL.setNetworkStatusMsg(polyglot.t("downloading_block_chain", {days: daysOld.toFixed(2)}), false); - // don't alarm user if blockchain is just a little bit behind - twisterdConnectedAndUptodate = (daysOld < 2); + $.MAL.setNetworkStatusMsg(polyglot.t("DHT network down."), false); + twisterdConnectedAndUptodate = true; } + } else { + var daysOld = (curTime - twisterdLastBlockTime) / (3600 * 24); + $.MAL.setNetworkStatusMsg(polyglot.t("downloading_block_chain", {days: daysOld.toFixed(2)}), false); + // don't alarm user if blockchain is just a little bit behind + twisterdConnectedAndUptodate = (daysOld < 2); } - if (args.cbFunc) - args.cbFunc(args.cbArg); + } + if (args.cbFunc) + args.cbFunc(args.cbArg); }, {cbFunc:cbFunc, cbArg:cbArg} ); }); } From 46d62647430dae9fbb54bab1336d7b81ba845a53 Mon Sep 17 00:00:00 2001 From: erqan Date: Thu, 24 Nov 2016 18:10:26 +0300 Subject: [PATCH 6/7] decreasing delay between block and being sure all users in block is got --- js/twister_following.js | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/js/twister_following.js b/js/twister_following.js index 462d82e..ec1848e 100644 --- a/js/twister_following.js +++ b/js/twister_following.js @@ -517,7 +517,7 @@ NewUserSearch.prototype = { setTimeout(function () { requestBlock(block.previousblockhash, NewUserSearch.processBlockUsersProxy, {obj: args.obj, args: args.args}); - }, 100); + }, 10); } else { NewUserSearch.isNewUserThRunning = false; @@ -527,14 +527,15 @@ NewUserSearch.prototype = { for (var i = 0; i < block.usernames.length; i++) { if (NewUserSearch.knownNewUsers.indexOf(block.usernames[i]) == -1) { processWhoToFollowSuggestion(args.args.module, block.usernames[i], undefined, args.args.prepend); - if (args.args.prepend) - NewUserSearch.knownNewUsers.unshift(block.usernames[i]); - else - NewUserSearch.knownNewUsers.push(block.usernames[i]); if (!args.args.live && NewUserSearch.knownNewUsers.length >= args.args.n + args.args.offset) break; } } + if (args.args.prepend) + NewUserSearch.knownNewUsers.unshift(block.usernames); + else + NewUserSearch.knownNewUsers.push(block.usernames); + this.save(); } }; From a303cce84787c47743acbda91894f1251e4d5f44 Mon Sep 17 00:00:00 2001 From: erqan Date: Thu, 24 Nov 2016 19:02:44 +0300 Subject: [PATCH 7/7] fixing silliness (2) --- js/twister_following.js | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/js/twister_following.js b/js/twister_following.js index ec1848e..f0a700a 100644 --- a/js/twister_following.js +++ b/js/twister_following.js @@ -524,17 +524,26 @@ NewUserSearch.prototype = { this.isForced = false; } - for (var i = 0; i < block.usernames.length; i++) { + var i = 0; + for (; i < block.usernames.length; i++) { if (NewUserSearch.knownNewUsers.indexOf(block.usernames[i]) == -1) { processWhoToFollowSuggestion(args.args.module, block.usernames[i], undefined, args.args.prepend); + if (args.args.prepend) + NewUserSearch.knownNewUsers.unshift(block.usernames[i]); + else + NewUserSearch.knownNewUsers.push(block.usernames[i]); if (!args.args.live && NewUserSearch.knownNewUsers.length >= args.args.n + args.args.offset) break; } } - if (args.args.prepend) - NewUserSearch.knownNewUsers.unshift(block.usernames); - else - NewUserSearch.knownNewUsers.push(block.usernames); + for (; i < block.usernames.length; i++) { + if (NewUserSearch.knownNewUsers.indexOf(block.usernames[i]) == -1) { + if (args.args.prepend) + NewUserSearch.knownNewUsers.unshift(block.usernames[i]); + else + NewUserSearch.knownNewUsers.push(block.usernames[i]); + } + } this.save(); }