Browse Source

fixing & developing

readme-update
erqan 8 years ago
parent
commit
16da1c8e31
  1. 17
      js/interface_common.js
  2. 5
      js/interface_home.js
  3. 39
      js/interface_localization.js
  4. 7
      js/options.js
  5. 143
      js/twister_following.js
  6. 17
      options.html

17
js/interface_common.js

@ -119,6 +119,9 @@ function closeModal(req, switchMode) {
else else
this.remove(); // if it's minimized it will be removed with twister.modal[i].drapper 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].drapper.remove();
twister.modal[i] = undefined; twister.modal[i] = undefined;
} }
@ -731,9 +734,6 @@ function addPeerToFollowingList(list, peerAlias) {
} }
function fillWhoToFollowModal(list, hlist, start) { 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++) { for (var i = 0; i < followingUsers.length && list.length < start + 20; i++) {
if (typeof twisterFollowingO.followingsFollowings[followingUsers[i]] !== 'undefined') { if (typeof twisterFollowingO.followingsFollowings[followingUsers[i]] !== 'undefined') {
for (var j = 0; j < twisterFollowingO.followingsFollowings[followingUsers[i]].following.length && list.length < start + 25; j++) { 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) if (i >= followingUsers.length - 1)
return false; return false;
@ -778,7 +777,10 @@ function openWhoToFollowModal() {
function openNewUsersModal() { function openNewUsersModal() {
var modal = openModal({ var modal = openModal({
classAdd: 'new-users-modal', classAdd: 'new-users-modal',
title: polyglot.t('New Users') title: polyglot.t('New Users'),
onClose: function() {
NewUserSearch.isNewUserModalOpen = false;
}
}); });
var hlist = $('<ol class="follow-suggestions"></ol>') var hlist = $('<ol class="follow-suggestions"></ol>')
@ -787,12 +789,13 @@ function openNewUsersModal() {
modal.content.on('scroll', function() { modal.content.on('scroll', function() {
if (modal.content.scrollTop() >= hlist.height() - modal.content.height() - 20) { 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; count += 5;
} }
}); });
getLastNUsers(15, 0, modal.self); NewUserSearch.isNewUserModalOpen = true;
newUsers.getLastNUsers(15, 0, modal.self);
} }
function openModalUriShortener() function openModalUriShortener()

5
js/interface_home.js

@ -118,7 +118,7 @@ var InterfaceFunctions = function() {
if ($.Options.WebTorrent.val === 'enable') if ($.Options.WebTorrent.val === 'enable')
initWebTorrent(); initWebTorrent();
} }
} };
function initTopTrends() { function initTopTrends() {
var $tt = initInterfaceModule('toptrends'); var $tt = initInterfaceModule('toptrends');
@ -208,6 +208,7 @@ function refreshWhoToFollow() {
function initNewUsers() { function initNewUsers() {
var nus = initInterfaceModule('new-users'); var nus = initInterfaceModule('new-users');
newUsers = NewUserSearch();
if (nus.length) { if (nus.length) {
var nusRefresh = nus.find('.refresh-users'); var nusRefresh = nus.find('.refresh-users');
nusRefresh.on('click', refreshNewUsers); nusRefresh.on('click', refreshNewUsers);
@ -224,7 +225,7 @@ function refreshNewUsers() {
module.find('.refresh-users').hide(); module.find('.refresh-users').hide();
module.find('.loading-roller').show(); module.find('.loading-roller').show();
getLastNUsers(3, 0, module); newUsers.getLastNUsers(3, 0, module, true);
} }
} }

39
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.", "You have to log in to favorite messages.": "You have to log in to favorite messages.",
"fav_this": "Is it for you only?", "fav_this": "Is it for you only?",
"Last activity": "Last activity", "Last activity": "Last activity",
"New Users": "New Users" "New Users": "New Users",
"Live tracking" : "Live tracking"
}; };
} }
if(preferredLanguage == "es"){ 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.", "You have to log in to favorite messages.": "You have to log in to favorite messages.",
"fav_this": "Is it for you only?", "fav_this": "Is it for you only?",
"Last activity": "Last activity", "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.", "You have to log in to favorite messages.": "You have to log in to favorite messages.",
"fav_this": "Is it for you only?", "fav_this": "Is it for you only?",
"Last activity": "Last activity", "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.", "You have to log in to favorite messages.": "You have to log in to favorite messages.",
"fav_this": "Is it for you only?", "fav_this": "Is it for you only?",
"Last activity": "Last activity", "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.", "You have to log in to favorite messages.": "You have to log in to favorite messages.",
"fav_this": "Is it for you only?", "fav_this": "Is it for you only?",
"Last activity": "Last activity", "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.", "You have to log in to favorite messages.": "You have to log in to favorite messages.",
"fav_this": "Is it for you only?", "fav_this": "Is it for you only?",
"Last activity": "Last activity", "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", "Favorites": "Favorites",
"You have to log in to favorite messages.": "You have to log in to favorite messages.", "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" "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.", "You have to log in to favorite messages.": "You have to log in to favorite messages.",
"fav_this": "Is it for you only?", "fav_this": "Is it for you only?",
"Last activity": "Last activity", "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.", "You have to log in to favorite messages.": "You have to log in to favorite messages.",
"fav_this": "Is it for you only?", "fav_this": "Is it for you only?",
"Last activity": "Last activity", "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.", "You have to log in to favorite messages.": "You have to log in to favorite messages.",
"fav_this": "Is it for you only?", "fav_this": "Is it for you only?",
"Last activity": "Last activity", "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.", "You have to log in to favorite messages.": "You have to log in to favorite messages.",
"fav_this": "Is it for you only?", "fav_this": "Is it for you only?",
"Last activity": "Last activity", "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.", "You have to log in to favorite messages.": "İletileri favorine eklemek için giriş yapmalısın.",
"fav_this": "Sana özel mi?", "fav_this": "Sana özel mi?",
"Last activity": "Son etkinlik", "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.", "You have to log in to favorite messages.": "You have to log in to favorite messages.",
"fav_this": "Is it for you only?", "fav_this": "Is it for you only?",
"Last activity": "Last activity", "Last activity": "Last activity",
"New Users": "New Users" "New Users": "New Users",
"Live tracking" : "Live tracking"
}; };
} }

7
js/options.js

@ -43,6 +43,13 @@ function twisterOptions() {
}); });
this.add({ this.add({
name: 'NewUsers', name: 'NewUsers',
valDefault: 'enable',
tickMethod: function (elem) {
$('#NewUsersCont').css('display', (elem.value === 'enable') ? 'block' : 'none');
}
});
this.add({
name: 'NewUsersLiveTracking',
valDefault: 'enable' valDefault: 'enable'
}); });
this.add({ this.add({

143
js/twister_following.js

@ -15,11 +15,9 @@ var _searchKeypressTimer = undefined;
var _lastSearchUsersResults = []; var _lastSearchUsersResults = [];
var _lastSearchUsersResultsRemovedFromDHTgetQueue = true; var _lastSearchUsersResultsRemovedFromDHTgetQueue = true;
var _lastLoadFromDhtTime = 0; var _lastLoadFromDhtTime = 0;
var _lastProcessedBlock = -1;
var knownNewUsers = [];
var isNewUserThRunning = false;
var twisterFollowingO = undefined; var twisterFollowingO = undefined;
var newUsers = undefined;
var TwisterFollowing = function (user) { var TwisterFollowing = function (user) {
if (!(this instanceof TwisterFollowing)) if (!(this instanceof TwisterFollowing))
@ -430,46 +428,116 @@ function followingEmptyOrMyself() {
return (!followingUsers.length || (followingUsers.length === 1 && followingUsers[0] === defaultScreenName)) 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) this.init();
return false; };
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; if (NewUserSearch.isNewUserThRunning)
for (var i = offset; i < knownNewUsers.length && i < offset + n; i++) return false;
processWhoToFollowSuggestion(module, knownNewUsers[i]);
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; return true;
} },
if (_lastProcessedBlock == -1) processBlockUsers: function (block, args) {
requestBestBlock(processBlockUsers, {n: n, offset: offset, module: module}); if (NewUserSearch.startProcessedBlock === -1)
else NewUserSearch.startProcessedBlock = block.height;
requestNthBlock(_lastProcessedBlock - 1, processBlockUsers, {n: n, offset: offset, module: module}); 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){ setTimeout(function () {
_lastProcessedBlock = block.height; 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') } else {
setTimeout(function(){requestBlock(block.previousblockhash, processBlockUsers, users);}, 100); NewUserSearch.isNewUserThRunning = false;
else this.isForced = false;
isNewUserThRunning = false; }
for (var i = 0; i < block.usernames.length; i++) { for (var i = 0; i < block.usernames.length; i++) {
if (knownNewUsers.indexOf(block.usernames[i]) == -1) { if (NewUserSearch.knownNewUsers.indexOf(block.usernames[i]) == -1) {
processWhoToFollowSuggestion(users.module, block.usernames[i]); processWhoToFollowSuggestion(args.args.module, block.usernames[i], undefined, args.args.prepend);
knownNewUsers.push(block.usernames[i]); if (args.args.prepend)
if (knownNewUsers.length >= users.n + users.offset) NewUserSearch.knownNewUsers.unshift(block.usernames[i]);
break; 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 // 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 // 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) { if (suggestion) {
var list = module.find('.follow-suggestions'); var list = module.find('.follow-suggestions');
var item = $('#follow-suggestion-template').clone(true) var item = $('#follow-suggestion-template').clone(true)
@ -578,7 +646,14 @@ function processWhoToFollowSuggestion(module, suggestion, followedBy) {
item.find('.twister-user-remove').remove(); 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('.refresh-users').show();
module.find('.loading-roller').hide(); module.find('.loading-roller').hide();
} else } else

17
options.html

@ -357,10 +357,19 @@
<p class="label label-h"> New Users </p> <p class="label label-h"> New Users </p>
<div class="container"> <div class="container">
<form> <form>
<select id="NewUsers"> <p>
<option value="enable">Enable</option> <select id="NewUsers">
<option value="disable">Disable</option> <option value="enable">Enable</option>
</select> <option value="disable">Disable</option>
</select>
</p>
<div id="NewUsersCont" class="container">
<p class="label">Live tracking</p>
<select id="NewUsersLiveTracking" class="container">
<option value="enable">Enable</option>
<option value="disable">Disable</option>
</select>
</div>
</form> </form>
</div> </div>
</div> </div>

Loading…
Cancel
Save