Browse Source

add missing flags to clone event too from DM template textareas, code restyling

master
Simon Grim 9 years ago
parent
commit
5c35807932
  1. 168
      js/twister_directmsg.js
  2. 229
      js/twister_newmsgs.js

168
js/twister_directmsg.js

@ -5,41 +5,37 @@
function requestDMsnippetList(dmThreadList) { function requestDMsnippetList(dmThreadList) {
var followList = []; var followList = [];
for( var i = 0; i < followingUsers.length; i++ ) { for (var i = 0; i < followingUsers.length; i++)
followList.push({username:followingUsers[i]}); followList.push({username:followingUsers[i]});
} for (var i = 0; i < groupChatAliases.length; i++)
for( var i = 0; i < groupChatAliases.length; i++ ) {
followList.push({username:groupChatAliases[i]}); followList.push({username:groupChatAliases[i]});
}
twisterRpc("getdirectmsgs", [defaultScreenName, 1, followList], twisterRpc('getdirectmsgs', [defaultScreenName, 1, followList],
function(req, ret) {processDMsnippet(ret, dmThreadList);}, dmThreadList, function(req, ret) {processDMsnippet(ret, dmThreadList);}, dmThreadList,
function(req, ret) {console.log("ajax error:" + ret);}, null); function(req, ret) {console.log('ajax error:' + ret);}, null
);
} }
function processDMsnippet(dmUsers, dmThreadList) { function processDMsnippet(dmUsers, dmThreadList) {
dmThreadList.empty(); dmThreadList.empty();
for( var u in dmUsers ) { for (var u in dmUsers) {
if( dmUsers.hasOwnProperty(u) ) { if (dmUsers[u]) {
// convert snipped to html and add it to date-sorted list // convert snipped to html and add it to date-sorted list
var dmItem = dmDataToSnippetItem(dmUsers[u][0], u); var dmItem = dmDataToSnippetItem(dmUsers[u][0], u);
var timeDmItem = parseInt(dmItem.attr("data-time")); var timeDmItem = parseInt(dmItem.attr('data-time'));
var existingItems = dmThreadList.children(); var existingItems = dmThreadList.children();
var j = 0; for (var j = 0; j < existingItems.length; j++) {
for( j = 0; j < existingItems.length; j++) {
var streamItem = existingItems.eq(j); var streamItem = existingItems.eq(j);
var timeExisting = streamItem.attr("data-time"); var timeExisting = streamItem.attr('data-time');
if( timeExisting == undefined || if (typeof timeExisting === 'undefined' || timeDmItem > parseInt(timeExisting)) {
timeDmItem > parseInt(timeExisting) ) {
// this post in stream is older, so post must be inserted above // this post in stream is older, so post must be inserted above
streamItem.before(dmItem); streamItem.before(dmItem);
break; break;
} }
} }
if( j == existingItems.length ) { if (j === existingItems.length)
dmThreadList.append(dmItem); dmThreadList.append(dmItem);
}
} }
} }
$.MAL.dmThreadListLoaded(); $.MAL.dmThreadListLoaded();
@ -52,84 +48,86 @@ function requestDmConversationModal(postboard, dm_screenname) {
} }
} }
function requestDmConversation(dmConvo,dm_screenname) { function requestDmConversation(postboard, dm_screenname) {
var since_id = undefined; var since_id = undefined;
var oldItems = dmConvo.children(); var oldItems = postboard.children();
if( oldItems.length ) { if (oldItems.length)
since_id = parseInt(oldItems.eq(oldItems.length-1).attr("data-id")); since_id = parseInt(oldItems.eq(oldItems.length - 1).attr('data-id'));
}
var userDmReq = [{username: dm_screenname}];
if (typeof since_id !== 'undefined')
userDmReq[0].since_id = since_id;
var userDmReq = [{username:dm_screenname}];
if( since_id != undefined ) userDmReq[0].since_id = since_id;
var count = 100; var count = 100;
twisterRpc("getdirectmsgs", [defaultScreenName,count,userDmReq], twisterRpc('getdirectmsgs', [defaultScreenName, count, userDmReq],
function(args, ret) { processDmConversation(args.dmConvo, args.dmUser, ret); }, function(args, ret) {processDmConversation(args.postboard, args.dm_screenname, ret);},
{dmConvo:dmConvo,dmUser:dm_screenname}, {postboard: postboard, dm_screenname: dm_screenname},
function(arg, ret) { var msg = ("message" in ret) ? ret.message : ret; function(arg, ret) {
alert(polyglot.t("ajax_error", { error: msg })); }, null); var msg = (ret.message) ? ret.message : ret;
alert(polyglot.t('ajax_error', {error: msg}));
}, null
);
} }
function processDmConversation(dmConvo, dm_screenname, dmData) { function processDmConversation(postboard, dm_screenname, dmData) {
var lastId = undefined; var lastId = undefined;
if(dm_screenname in dmData) {
if (dmData[dm_screenname]) {
var dmList = dmData[dm_screenname]; var dmList = dmData[dm_screenname];
if( dmList.length ) { if (dmList.length) {
for( var i = 0; i < dmList.length; i++) {; for (var i = 0; i < dmList.length; i++) {
var dmItem = dmDataToConversationItem(dmList[i],defaultScreenName,dm_screenname); var dmItem = dmDataToConversationItem(dmList[i], defaultScreenName, dm_screenname)
dmItem.attr("data-id",dmList[i].id); .attr('data-id', dmList[i].id)
dmConvo.append(dmItem); .appendTo(postboard)
;
lastId = dmList[i].id; lastId = dmList[i].id;
} }
$.MAL.dmChatListLoaded(dmConvo); $.MAL.dmChatListLoaded(postboard);
} }
} }
if( lastId != undefined ) { if (typeof lastId !== 'undefined')
resetNewDMsCountForUser(dm_screenname, lastId); resetNewDMsCountForUser(dm_screenname, lastId);
}
} }
function directMsgSubmit(e) function directMsgSubmit(e) {
{
e.stopPropagation(); e.stopPropagation();
e.preventDefault(); e.preventDefault();
var $this = $( this );
var $replyText = $this.closest(".post-area-new").find("textarea");
var $dmConversation = $(".directMessages"); var replyText = $(this).closest('.post-area-new textarea');
newDirectMsg($replyText.val(), $dmConversation.attr("data-dm-screen-name")); newDirectMsg(replyText.val(), $('.directMessages').attr('data-dm-screen-name'));
$replyText.val(""); replyText.val('');
} }
function newDirectMsg(msg, dm_screenname) { function newDirectMsg(msg, dm_screenname) {
if( lastPostId != undefined ) { if (typeof lastPostId !== 'undefined') {
var paramsOrig = [defaultScreenName, lastPostId + 1, dm_screenname, msg] var paramsOrig = [defaultScreenName, lastPostId + 1, dm_screenname, msg];
var paramsOpt = paramsOrig var paramsOpt = paramsOrig;
var copySelf = ($.Options.dmCopySelf.val === 'enable') var copySelf = $.Options.dmCopySelf.val === 'enable';
if( copySelf && dm_screenname[0] !== '*' ) { if (copySelf && dm_screenname[0] !== '*')
paramsOpt = paramsOrig.concat(true) paramsOpt = paramsOrig.concat(true)
}
twisterRpc("newdirectmsg", paramsOpt, twisterRpc('newdirectmsg', paramsOpt,
function(arg, ret) { function(arg, ret) {
incLastPostId(); incLastPostId();
if( arg.copySelf ) incLastPostId(); if (arg.copySelf)
}, {copySelf:copySelf}, incLastPostId();
function(arg, ret) { }, {copySelf: copySelf},
// fallback for older twisterd (error: no copy_self parameter) function(arg, ret) {
twisterRpc("newdirectmsg", arg.paramsOrig, // fallback for older twisterd (error: no copy_self parameter)
function(arg, ret) { incLastPostId(); }, null, twisterRpc('newdirectmsg', arg.paramsOrig,
function(arg, ret) { function(arg, ret) {incLastPostId();}, null,
var msg = ("message" in ret) ? ret.message : ret; function(arg, ret) {
alert("Ajax error: " + msg); var msg = (ret.message) ? ret.message : ret;
}, null); alert('Ajax error: ' + msg);
}, {paramsOrig:paramsOrig} }, null
);
}, {paramsOrig: paramsOrig}
); );
} else { } else
alert(polyglot.t("Internal error: lastPostId unknown (following yourself may fix!)")); alert(polyglot.t('Internal error: lastPostId unknown (following yourself may fix!)'));
}
} }
// dispara o modal de direct messages // dispara o modal de direct messages
@ -141,7 +139,7 @@ function directMessagesPopup() {
modal = openModal({ modal = openModal({
classAdd: 'directMessages', classAdd: 'directMessages',
content: $('.direct-messages-template').children().clone(), content: $('.direct-messages-template').children().clone(true),
title: polyglot.t('Direct Messages') title: polyglot.t('Direct Messages')
}); });
@ -151,8 +149,8 @@ function directMessagesPopup() {
.css('display', 'inline') .css('display', 'inline')
.attr('title', polyglot.t('Mark all as read')) .attr('title', polyglot.t('Mark all as read'))
.on('click', function() { .on('click', function() {
for (var k in _newDMsPerUser) { for (var user in _newDMsPerUser) {
_newDMsPerUser[k] = 0; _newDMsPerUser[user] = 0;
} }
saveDMsToStorage(); saveDMsToStorage();
$.MAL.updateNewDMsUI(getNewDMsCount()); $.MAL.updateNewDMsUI(getNewDMsCount());
@ -168,7 +166,7 @@ function openDmWithUserModal(dm_screenname) {
modal = openModal({ modal = openModal({
classAdd: 'directMessages', classAdd: 'directMessages',
content: $('.messages-thread-template').children().clone(), content: $('.messages-thread-template').children().clone(true),
title: polyglot.t('direct_messages_with', {username: '<span>' + dm_screenname + '</span>'}) title: polyglot.t('direct_messages_with', {username: '<span>' + dm_screenname + '</span>'})
}); });
@ -181,24 +179,22 @@ function openDmWithUserModal(dm_screenname) {
requestDmConversationModal(modal.self.find('.direct-messages-thread').empty(), dm_screenname); requestDmConversationModal(modal.self.find('.direct-messages-thread').empty(), dm_screenname);
$('.dm-form-template').children().clone() $('.dm-form-template').children().clone(true)
.addClass('open').appendTo(modal.content).fadeIn('fast'); .addClass('open').appendTo(modal.content).fadeIn('fast');
} }
function initInterfaceDirectMsg() { function initInterfaceDirectMsg() {
$('.direct-messages').attr('href','#directmessages');
$('.userMenu-messages a').attr('href','#directmessages');
$( ".direct-messages" ).attr("href","#directmessages"); $('#dm-snippet-template').on('click', function() {
$( ".userMenu-messages a" ).attr("href","#directmessages"); window.location.hash = '#directmessages?user=' + $(this).attr('data-dm-screen-name');
});
$( "#dm-snippet-template" ).bind( "click", function(){
window.location.hash='#directmessages?user='+$(this).attr("data-dm-screen-name");
} );
$( ".dm-submit").click( directMsgSubmit );
$( ".direct-messages-with-user" ).bind( "click", function() {
window.location.hash='#directmessages?user='+$(this).closest("[data-screen-name]").attr("data-screen-name");
} );
$('.dm-submit').on('click', directMsgSubmit);
$('.direct-messages-with-user').on('click', function() {
window.location.hash = '#directmessages?user=' +
$(this).closest('[data-screen-name]').attr('data-screen-name');
});
} }

229
js/twister_newmsgs.js

@ -17,20 +17,20 @@ var groupChatAliases = []
// process a mention received to check if it is really new // process a mention received to check if it is really new
function processMention(user, mentionTime, data) { function processMention(user, mentionTime, data) {
var key = user + ";" + mentionTime; var key = user + ';' + mentionTime;
var curTime = new Date().getTime() / 1000; var curTime = new Date().getTime() / 1000;
if( mentionTime > curTime + 3600 * 2 ) { if (mentionTime > curTime + 7200) // 3600 * 2
console.log("mention from the future will be ignored"); console.warn('ignoring mention from the future');
} else { else {
if( !(key in _knownMentions) ) { if (!_knownMentions[key]) {
// mention must be somewhat recent compared to last known one to be considered new // mention must be somewhat recent compared to last known one to be considered new
if( mentionTime + 3600 * 24 * 3 > _lastMentionTime ) { if (mentionTime + 259200 > _lastMentionTime) { // 3600 * 24 * 3
_newMentions++; _newMentions++;
_newMentionsUpdated = true; _newMentionsUpdated = true;
_lastMentionTime = Math.max(mentionTime,_lastMentionTime); _lastMentionTime = Math.max(mentionTime, _lastMentionTime);
data["isNew"] = true; data.isNew = true;
} }
_knownMentions[key] = {mentionTime:mentionTime, data:data}; _knownMentions[key] = {mentionTime: mentionTime, data: data};
purgeOldMentions(); purgeOldMentions();
saveMentionsToStorage(); saveMentionsToStorage();
} }
@ -38,10 +38,10 @@ function processMention(user, mentionTime, data) {
} }
function purgeOldMentions() { function purgeOldMentions() {
for( var key in _knownMentions ) { for (var key in _knownMentions) {
if( _knownMentions.hasOwnProperty(key) ) { if (_knownMentions[key]) {
if( !_knownMentions[key].mentionTime || !_knownMentions[key].data || if (!_knownMentions[key].mentionTime || !_knownMentions[key].data ||
_knownMentions[key].mentionTime + PURGE_OLD_MENTIONS_TIMEOUT < _lastMentionTime ) { _knownMentions[key].mentionTime + PURGE_OLD_MENTIONS_TIMEOUT < _lastMentionTime) {
delete _knownMentions[key]; delete _knownMentions[key];
} }
} }
@ -49,87 +49,85 @@ function purgeOldMentions() {
} }
function saveMentionsToStorage() { function saveMentionsToStorage() {
var ns=$.initNamespaceStorage(defaultScreenName); var ns = $.initNamespaceStorage(defaultScreenName);
ns.localStorage.set("knownMentions", _knownMentions); ns.localStorage.set('knownMentions', _knownMentions);
ns.localStorage.set("lastMentionTime", _lastMentionTime); ns.localStorage.set('lastMentionTime', _lastMentionTime);
ns.localStorage.set("newMentions", _newMentions); ns.localStorage.set('newMentions', _newMentions);
ns.localStorage.set("lastLocalMentionId",_lastLocalMentionId); ns.localStorage.set('lastLocalMentionId', _lastLocalMentionId);
} }
function loadMentionsFromStorage() { function loadMentionsFromStorage() {
var ns=$.initNamespaceStorage(defaultScreenName); var ns = $.initNamespaceStorage(defaultScreenName);
if( ns.localStorage.isSet("knownMentions") ) if (ns.localStorage.isSet('knownMentions'))
_knownMentions = ns.localStorage.get("knownMentions"); _knownMentions = ns.localStorage.get('knownMentions');
if( ns.localStorage.isSet("lastMentionTime") ) if (ns.localStorage.isSet('lastMentionTime'))
_lastMentionTime = ns.localStorage.get("lastMentionTime"); _lastMentionTime = ns.localStorage.get('lastMentionTime');
if( ns.localStorage.isSet("newMentions") ) if (ns.localStorage.isSet('newMentions'))
_newMentions = ns.localStorage.get("newMentions"); _newMentions = ns.localStorage.get('newMentions');
if( ns.localStorage.isSet("lastLocalMentionId") ) if (ns.localStorage.isSet('lastLocalMentionId'))
_lastLocalMentionId = ns.localStorage.get("lastLocalMentionId"); _lastLocalMentionId = ns.localStorage.get('lastLocalMentionId');
} }
function requestMentionsCount() { function requestMentionsCount() {
// first: getmentions from torrents we follow // first: getmentions from torrents we follow
twisterRpc("getmentions", [defaultScreenName, 100, {"since_id":_lastLocalMentionId}], twisterRpc('getmentions', [defaultScreenName, 100, {since_id: _lastLocalMentionId}],
function(args, data) { function(args, data) {
if( data ) { if (data) {
for( var i = 0; i < data.length; i++ ) { for (var i = 0; i < data.length; i++) {
_lastLocalMentionId = Math.max(_lastLocalMentionId, data[i]["id"]); _lastLocalMentionId = Math.max(_lastLocalMentionId, data[i].id);
var userpost = data[i]["userpost"]; var userpost = data[i].userpost;
processMention( userpost["n"], userpost["time"], data[i]); processMention(userpost.n, userpost.time, data[i]);
} }
$.MAL.updateNewMentionsUI(_newMentions); $.MAL.updateNewMentionsUI(_newMentions);
} }
}, null, }, null,
function(req, ret) {console.log("getmentions API requires twister-core > 0.9.27");}, null); function(req, ret) {console.warn('getmentions API requires twister-core > 0.9.27');}, null
);
// second: get mentions from dht (not-following) // second: get mentions from dht (not-following)
dhtget( defaultScreenName, "mention", "m", dhtget(defaultScreenName, 'mention', 'm',
function(args, data) { function(args, data) {
if( data ) { if (data) {
for( var i = 0; i < data.length; i++ ) { for (var i = 0; i < data.length; i++) {
var userpost = data[i]["userpost"]; var userpost = data[i].userpost;
processMention( userpost["n"], userpost["time"], data[i]); processMention(userpost.n, userpost.time, data[i]);
} }
$.MAL.updateNewMentionsUI(_newMentions); $.MAL.updateNewMentionsUI(_newMentions);
} }
}, {}, }, {},
[10000,2000,3]); // use extended timeout parameters (requires twister_core >= 0.9.14) [10000, 2000, 3] // use extended timeout parameters (requires twister_core >= 0.9.14)
);
if( _newMentionsUpdated ) {
if (_newMentionsUpdated) {
_newMentionsUpdated = false; _newMentionsUpdated = false;
if ( _newMentions ) { if (_newMentions) {
$.MAL.soundNotifyMentions(); $.MAL.soundNotifyMentions();
if ($.Options.showDesktopNotifMentions.val === 'enable') { if ($.Options.showDesktopNotifMentions.val === 'enable')
$.MAL.showDesktopNotif(false, polyglot.t('You got')+' '+polyglot.t('new_mentions', _newMentions)+'.', false,'twister_notification_new_mentions', $.Options.showDesktopNotifMentionsTimer.val, function(){$.MAL.showMentions(defaultScreenName)}, false) $.MAL.showDesktopNotif(false, polyglot.t('You got')+' '+polyglot.t('new_mentions', _newMentions)+'.', false,'twister_notification_new_mentions', $.Options.showDesktopNotifMentionsTimer.val, function(){$.MAL.showMentions(defaultScreenName)}, false)
}
} }
} }
// was moved here from requestDMsCount() because that is not ticking right // was moved here from requestDMsCount() because that is not ticking right
// we would place it with other notifications into separate notification center // we would place it with other notifications into separate notification center
if( _newDMsUpdated ) { if (_newDMsUpdated) {
_newDMsUpdated = false; _newDMsUpdated = false;
var newDMs = getNewDMsCount(); var newDMs = getNewDMsCount();
if ( newDMs ) { if (newDMs) {
$.MAL.soundNotifyDM(); $.MAL.soundNotifyDM();
if ($.Options.showDesktopNotifDMs.val === 'enable') { if ($.Options.showDesktopNotifDMs.val === 'enable')
$.MAL.showDesktopNotif(false, polyglot.t('You got')+' '+polyglot.t('new_direct_messages', newDMs)+'.', false, 'twister_notification_new_DMs', $.Options.showDesktopNotifDMsTimer.val, function(){$.MAL.showDMchat()}, false) $.MAL.showDesktopNotif(false, polyglot.t('You got')+' '+polyglot.t('new_direct_messages', newDMs)+'.', false, 'twister_notification_new_DMs', $.Options.showDesktopNotifDMsTimer.val, function(){$.MAL.showDMchat()}, false)
}
} }
} }
} }
function resetMentionsCount() { function resetMentionsCount() {
_newMentions = 0; _newMentions = 0;
for( var key in _knownMentions ) { for (var key in _knownMentions) {
if( _knownMentions.hasOwnProperty(key) && _knownMentions[key].data ) { if (_knownMentions[key] && _knownMentions[key].data)
delete _knownMentions[key].data["isNew"] delete _knownMentions[key].data.isNew
}
} }
saveMentionsToStorage(); saveMentionsToStorage();
$.MAL.updateNewMentionsUI(_newMentions); $.MAL.updateNewMentionsUI(_newMentions);
@ -140,13 +138,13 @@ function initMentionsCount() {
loadMentionsFromStorage(); loadMentionsFromStorage();
$.MAL.updateNewMentionsUI(_newMentions); $.MAL.updateNewMentionsUI(_newMentions);
requestMentionsCount(); requestMentionsCount();
setInterval("requestMentionsCount()", 10000); setInterval(requestMentionsCount, 10000);
} }
function getMentionsData() { function getMentionsData() {
mentions = [] mentions = []
for( var key in _knownMentions ) { for (var key in _knownMentions) {
if( _knownMentions.hasOwnProperty(key) && _knownMentions[key].data ) { if (_knownMentions[key] && _knownMentions[key].data) {
mentions.push(_knownMentions[key].data); mentions.push(_knownMentions[key].data);
} }
} }
@ -159,61 +157,60 @@ var _lastDMIdPerUser = {};
var _newDMsPerUser = {}; var _newDMsPerUser = {};
function saveDMsToStorage() { function saveDMsToStorage() {
var ns=$.initNamespaceStorage(defaultScreenName); var ns = $.initNamespaceStorage(defaultScreenName);
ns.localStorage.set("lastDMIdPerUser", _lastDMIdPerUser); ns.localStorage.set('lastDMIdPerUser', _lastDMIdPerUser);
ns.localStorage.set("newDMsPerUser", _newDMsPerUser); ns.localStorage.set('newDMsPerUser', _newDMsPerUser);
} }
function loadDMsFromStorage() { function loadDMsFromStorage() {
var ns=$.initNamespaceStorage(defaultScreenName); var ns = $.initNamespaceStorage(defaultScreenName);
if( ns.localStorage.isSet("lastDMIdPerUser") ) if (ns.localStorage.isSet('lastDMIdPerUser'))
_lastDMIdPerUser = ns.localStorage.get("lastDMIdPerUser"); _lastDMIdPerUser = ns.localStorage.get('lastDMIdPerUser');
if( ns.localStorage.isSet("newDMsPerUser") ) if (ns.localStorage.isSet('newDMsPerUser'))
_newDMsPerUser = ns.localStorage.get("newDMsPerUser"); _newDMsPerUser = ns.localStorage.get('newDMsPerUser');
} }
function requestDMsCount() { function requestDMsCount() {
var followList = []; var followList = [];
for( var i = 0; i < followingUsers.length; i++ ) { for (var i = 0; i < followingUsers.length; i++)
followList.push({username:followingUsers[i]}); followList.push({username: followingUsers[i]});
} for (var i = 0; i < groupChatAliases.length; i++ )
for( var i = 0; i < groupChatAliases.length; i++ ) { followList.push({username: groupChatAliases[i]});
followList.push({username:groupChatAliases[i]});
} twisterRpc('getdirectmsgs', [defaultScreenName, 1, followList],
function(req, dmUsers) {
twisterRpc("getdirectmsgs", [defaultScreenName, 1, followList], for (var u in dmUsers) {
function(req, dmUsers) { if (dmUsers[u]) {
for( var u in dmUsers ) { var dmData = dmUsers[u][0];
if( dmUsers.hasOwnProperty(u) ) { if (u in _lastDMIdPerUser && u in _newDMsPerUser) {
var dmData = dmUsers[u][0]; if (dmData.id !== _lastDMIdPerUser[u]) {
if( (u in _lastDMIdPerUser) && (u in _newDMsPerUser) ) { _newDMsPerUser[u] += dmData.id - _lastDMIdPerUser[u];
if( dmData.id != _lastDMIdPerUser[u] ) { _newDMsUpdated = true;
_newDMsPerUser[u] += (dmData.id - _lastDMIdPerUser[u]); }
_newDMsUpdated = true; } else {
} _newDMsPerUser[u] = dmData.id + 1;
} else { _newDMsUpdated = true;
_newDMsPerUser[u] = dmData.id+1; }
_newDMsUpdated = true; _lastDMIdPerUser[u] = dmData.id;
} }
_lastDMIdPerUser[u] = dmData.id; }
} if (_newDMsUpdated) {
} saveDMsToStorage();
if( _newDMsUpdated ) { $.MAL.updateNewDMsUI(getNewDMsCount());
saveDMsToStorage(); }
$.MAL.updateNewDMsUI(getNewDMsCount()); }, null,
} function(req, ret) {console.warn('ajax error:' + ret);}, null
}, null, );
function(req, ret) {console.log("ajax error:" + ret);}, null);
} }
function getNewDMsCount() { function getNewDMsCount() {
var newDMs = 0; var newDMs = 0;
for( var key in _newDMsPerUser ) { for (var user in _newDMsPerUser) {
if( _newDMsPerUser.hasOwnProperty(key) ) { if (_newDMsPerUser[user])
newDMs += _newDMsPerUser[key]; newDMs += _newDMsPerUser[user];
}
} }
return newDMs; return newDMs;
} }
@ -226,22 +223,22 @@ function resetNewDMsCountForUser(user, lastId) {
} }
function updateGroupList() { function updateGroupList() {
twisterRpc("listgroups", [], twisterRpc('listgroups', [],
function(req, ret) {groupChatAliases=ret;}, null, function(req, ret) {groupChatAliases = ret;}, null,
function(req, ret) {console.log("twisterd >= 0.9.30 required for listgroups");}, null); function(req, ret) {console.warn('twisterd >= 0.9.30 required for listgroups');}, null
);
} }
function initDMsCount() { function initDMsCount() {
loadDMsFromStorage(); loadDMsFromStorage();
$.MAL.updateNewDMsUI(getNewDMsCount()); $.MAL.updateNewDMsUI(getNewDMsCount());
//quick hack to obtain list of group chat aliases //quick hack to obtain list of group chat aliases
updateGroupList(); updateGroupList();
setInterval("updateGroupList();", 60000); setInterval(updateGroupList, 60000);
setTimeout("requestDMsCount();", 200); setTimeout(requestDMsCount, 200);
//polling not needed: processNewPostsConfirmation will call requestDMsCount. //polling not needed: processNewPostsConfirmation will call requestDMsCount.
//setInterval("requestDMsCount()", 5000); //setInterval('requestDMsCount()', 5000);
} }
function newmsgsChangedUser() { function newmsgsChangedUser() {

Loading…
Cancel
Save