Browse Source

fix updating of minimized modals / add resuming from desktop notifications

readme-update
Simon Grim 9 years ago
parent
commit
6a6b3aba5d
  1. 93
      js/interface_common.js
  2. 37
      js/tmobile.js
  3. 110
      js/twister_actions.js
  4. 5
      js/twister_directmsg.js
  5. 52
      js/twister_newmsgs.js

93
js/interface_common.js

@ -139,10 +139,44 @@ function resumeModal(event) {
// TODO also need reset modal height here maybe and then compute new scroll // TODO also need reset modal height here maybe and then compute new scroll
if (modal.scroll) if (modal.scroll)
modal.self.find($(modal.scroll.targetSelector).scrollTop(modal.scroll.top)); modal.self.find($(modal.scroll.targetSelector).scrollTop(modal.scroll.top));
if (modal.resume && typeof modal.resume.cbFunc === 'function')
modal.resume.cbFunc(modal.resume.cbArg);
}); });
} }
} }
function focusModalWithElement(elem, cbFunc, cbArg) {
if (elem.jquery ? elem.is('html *') : $(elem).is('html *')) {
cbFunc(cbArg);
return true;
}
var hash = getHashOfMinimizedModalWithElem(elem);
if (hash) {
_minimizedModals[hash].resume = {cbFunc: cbFunc, cbArg: cbArg};
_minimizedModals[hash].btnResume.click();
return true;
}
return false;
}
function getHashOfMinimizedModalWithElem(elem) {
for (var i in _minimizedModals)
if (_minimizedModals[i] && _minimizedModals[i].self.find(elem).length)
return i;
return '';
}
function isModalWithElemExists(elem) {
if (elem.jquery ? elem.is('html *') : $(elem).is('html *'))
return true;
else
return getHashOfMinimizedModalWithElem(elem) ? true : false;
}
function confirmPopup(event, req) { function confirmPopup(event, req) {
if (event && event.stopPropagation) { if (event && event.stopPropagation) {
event.stopPropagation(); event.stopPropagation();
@ -331,29 +365,37 @@ function openHashtagModalFromSearchHandler(hashtag) {
title: '#' + hashtag title: '#' + hashtag
}); });
clearHashtagProcessed(); setupQueryModalUpdating(modal.content.find('.postboard-posts'), hashtag, 'hashtag');
updateHashtagModal(modal.content.find('.postboard-posts'), hashtag, 'hashtag');
} }
function updateHashtagModal(postboard, hashtag, resource, timeoutArgs) { function setupQueryModalUpdating(postboard, query, resource) {
if (postboard.is('html *')) { var req = {
requestHashtag(postboard, hashtag, resource, timeoutArgs); postboard: postboard,
query: query,
resource: resource,
id: query + '@' + resource
};
if (_hashtagPendingPostsUpdated) { postboard.attr('data-request-id', req.id);
if (resource !== 'mention' && $.Options.showDesktopNotifPostsModal.val === 'enable') {
$.MAL.showDesktopNotif (false, polyglot.t('You got')+' '+polyglot.t('new_posts', _hashtagPendingPostsUpdated)+' '+polyglot.t('in search result')+'.', false,'twister_notification_new_posts_modal', $.Options.showDesktopNotifPostsModalTimer.val, function() { requestQuery(req);
$('.postboard-news').hide();
displayHashtagPending($('.hashtag-modal .postboard-posts'));
}, false)
}
_hashtagPendingPostsUpdated = 0;
}
// use extended timeout parameters on modal refresh (requires twister_core >= 0.9.14). // use extended timeout parameters on modal refresh (requires twister_core >= 0.9.14).
// our first query above should be faster (with default timeoutArgs of twisterd), // our first query above should be faster (with default timeoutArgs of twisterd),
// then we may possibly collect more posts on our second try by waiting more. // then we may possibly collect more posts on our second try by waiting more.
setTimeout(updateHashtagModal, 5000, postboard, hashtag, resource, [10000,2000,3]); req.timeoutArgs = [10000, 2000, 3];
postboard.attr('data-request-interval', setInterval(updateQueryModal, 5000, req)); // FIXME
}
function updateQueryModal(req) {
if (!isModalWithElemExists(req.postboard)) {
clearInterval(req.postboard.attr('data-request-interval'));
clearQueryProcessed(req.id);
return;
} }
requestQuery(req);
} }
function openMentionsModal(e) { function openMentionsModal(e) {
@ -382,12 +424,16 @@ function openMentionsModalHandler(username) {
title: polyglot.t('users_mentions', {username: username}) title: polyglot.t('users_mentions', {username: username})
}); });
clearHashtagProcessed(); setupQueryModalUpdating(modal.content.find('.postboard-posts'), username, 'mention');
updateHashtagModal(modal.content.find('.postboard-posts'), username, 'mention');
if (username === defaultScreenName) { if (username === defaultScreenName) {
// obtain already cached mention posts from twister_newmsgs.js // obtain already cached mention posts from twister_newmsgs.js
processHashtag(modal.content.find('.postboard-posts'), defaultScreenName, getMentionsData()); processQuery({
postboard: modal.content.find('.postboard-posts'),
query: defaultScreenName,
resource: 'mention',
posts: getMentionsData()
});
resetMentionsCount(); resetMentionsCount();
} }
} }
@ -473,14 +519,9 @@ function newConversationModal(username, resource) {
var postLi = postboard.children().first() var postLi = postboard.children().first()
.css('display', 'none'); .css('display', 'none');
getTopPostOfConversation(postLi, null, postboard); getTopPostOfConversation(postLi, null, postboard);
}, {content:content} }, {content: content}
); );
content.find('.postboard-news').on('click', function () {
$(this).hide();
displayHashtagPending($('.conversation-modal .postboard-posts'));
});
return content; return content;
} }
@ -494,7 +535,7 @@ function openConversationClick(e) {
':post' + postData.attr('data-id'); ':post' + postData.attr('data-id');
} }
function openConversationModal(username,resource) { function openConversationModal(username, resource) {
openModal({ openModal({
classAdd: 'conversation-modal', classAdd: 'conversation-modal',
content: newConversationModal(username, resource), content: newConversationModal(username, resource),
@ -1693,7 +1734,7 @@ function initInterfaceCommon() {
$('#hashtag-modal-template .postboard-news').on('click', function () { $('#hashtag-modal-template .postboard-news').on('click', function () {
$(this).hide(); $(this).hide();
displayHashtagPending($('.hashtag-modal .postboard-posts')); displayQueryPending($('.hashtag-modal .postboard-posts'));
}); });
replaceDashboards(); replaceDashboards();

37
js/tmobile.js

@ -538,22 +538,27 @@ function encode_utf8(s) {
return s; return s;
} }
var hashtag_elem; var tmobileQueryReq = {}; // FIXME need to rework all that searching
var hashtag_tag;
var hashtag_res; function setupHashtagOrMention(postboard, tag, res) {
function setupHashtagOrMention( ulElem, tag, res) {
hashtag_elem = ulElem;
hashtag_tag = tag;
hashtag_res = res;
hashtag_elem.text("");
$.MAL.setPostTemplate( $("#post-template-home") ); $.MAL.setPostTemplate( $("#post-template-home") );
$.mobile.showPageLoadingMsg(); $.mobile.showPageLoadingMsg();
clearHashtagProcessed();
if( tag == defaultScreenName && res == "mention" ) { var reqId = tag + '@' + res;
clearQueryProcessed(reqId);
tmobileQueryReq.postboard = postboard.text('').attr('data-request-id', reqId);
tmobileQueryReq.query = tag;
tmobileQueryReq.resource = res;
if (tag === defaultScreenName && res === 'mention') {
// obtain already cached mention posts from twister_newmsgs.js // obtain already cached mention posts from twister_newmsgs.js
processHashtag(hashtag_elem, defaultScreenName, getMentionsData() ); tmobileQueryReq.posts = getMentionsData();
processQuery(tmobileQueryReq);
} }
requestHashtag(hashtag_elem,hashtag_tag,hashtag_res);
requestQuery(tmobileQueryReq);
} }
// every 2 seconds do something page specific. // every 2 seconds do something page specific.
@ -575,10 +580,12 @@ function tmobileTick() {
} }
}, {} ); }, {} );
} }
if( curPage == "mentions" || curPage == "hashtag" ) {
autoUpdateHashtag = true; else if (curPage === 'mentions' || curPage === 'hashtag') {
requestHashtag(hashtag_elem,hashtag_tag,hashtag_res); autoUpdateQuery = true;
requestQuery(tmobileQueryReq);
} }
if( curPage == "dmchat" ) { if( curPage == "dmchat" ) {
requestDmConversation($("#dmchat ul.direct-messages-list"),dmChatUser); requestDmConversation($("#dmchat ul.direct-messages-list"),dmChatUser);
} }

110
js/twister_actions.js

@ -12,10 +12,9 @@
var postsPerRefresh = 10; var postsPerRefresh = 10;
var maxExpandPost = 8; var maxExpandPost = 8;
var maxExpandPostTop = 4; var maxExpandPostTop = 4;
var _hashtagProcessedMap = {}; var _queryProcessedMap = {};
var _hashtagPendingPosts = []; var _queryPendingPosts = {};
var _hashtagPendingPostsUpdated = 0; var autoUpdateQuery = false;
var autoUpdateHashtag = false;
// ---------------- // ----------------
@ -365,63 +364,98 @@ function updateProfilePosts(postsView, username, useGetposts) {
}); });
} }
function clearHashtagProcessed() { function clearQueryProcessed(id) {
_hashtagProcessedMap = {}; if (!id) return;
_hashtagPendingPosts = [];
_queryProcessedMap[id] = {};
_queryPendingPosts[id] = [];
} }
function requestHashtag(postboard, hashtag, resource, timeoutArgs) { function requestQuery(req) {
postboard.closest("div").find(".postboard-loading").show(); req.postboard.closest('div').find('.postboard-loading').show();
dhtget(hashtag, resource, "m", dhtget(req.query, req.resource, 'm',
function(args, data) {processHashtag(args.postboard, args.hashtag, data);}, function(req, posts) {
{postboard:postboard,hashtag:hashtag}, req.posts = posts;
timeoutArgs processQuery(req);
},
req,
req.timeoutArgs
); );
} }
function processHashtag(postboard, hashtag, data) { function processQuery(req) {
if( data && window.location.hash.indexOf(encodeURIComponent(hashtag)) != -1 ) { if (!isModalWithElemExists(req.postboard) || !req.posts || !req.posts.length)
for( var i = data.length-1; i >= 0; i-- ) { return;
var userpost = data[i]["userpost"];
var key = userpost["n"] + ";" + userpost["time"]; if (!req.id)
if( !(key in _hashtagProcessedMap) ) { req.id = req.query + '@' + req.resource;
_hashtagProcessedMap[key] = true; if (typeof _queryProcessedMap[req.id] !== 'object')
_queryProcessedMap[req.id] = {};
if (typeof _queryPendingPosts[req.id] !== 'object')
_queryPendingPosts[req.id] = [];
for (var i = req.posts.length - 1; i >= 0; i--) {
var userpost = req.posts[i].userpost;
var key = userpost.n + ';' + userpost.time;
if (!_queryProcessedMap[req.id][key]) {
_queryProcessedMap[req.id][key] = true;
if ($.Options.filterLang.val !== 'disable' && $.Options.filterLangForSearching.val) { if ($.Options.filterLang.val !== 'disable' && $.Options.filterLangForSearching.val) {
if (typeof(userpost['rt']) !== 'undefined') { if (typeof userpost.rt !== 'undefined') {
var msg = userpost['rt']['msg']; var msg = userpost.rt.msg;
} else { } else {
var msg = userpost['msg']; var msg = userpost.msg;
} }
langFilterData = filterLang(msg); langFilterData = filterLang(msg);
if ($.Options.filterLangSimulate.val) { if ($.Options.filterLangSimulate.val) {
data[i]['langFilter'] = langFilterData; req.posts[i].langFilter = langFilterData;
} else { } else {
if (!langFilterData['pass']) if (!langFilterData.pass)
continue; continue;
} }
} }
_hashtagPendingPosts.push(data[i]); _queryPendingPosts[req.id].push(req.posts[i]);
_hashtagPendingPostsUpdated++;
} }
} }
if( _hashtagPendingPosts.length ) { if (_queryPendingPosts[req.id].length) {
if( !postboard.children().length || autoUpdateHashtag ) { if (!$.hasOwnProperty('mobile') && $.Options.showDesktopNotifPostsModal.val === 'enable'
displayHashtagPending(postboard); && (req.resource !== 'mention' || req.query !== defaultScreenName)) {
} else { $.MAL.showDesktopNotification({
var newTweetsBar = postboard.closest("div").find(".postboard-news"); body: polyglot.t('You got') + ' ' + polyglot.t('new_posts', _queryPendingPosts[req.id].length) + ' '
newTweetsBar.text(polyglot.t("new_posts", _hashtagPendingPosts.length)); + polyglot.t('in search result') + '.',
newTweetsBar.fadeIn("slow"); tag: 'twister_notification_new_posts_modal',
postboard.closest("div").find(".postboard-loading").hide(); timeout: $.Options.showDesktopNotifPostsModalTimer.val,
funcClick: (function() {
focusModalWithElement(this.postboard,
function (req) {
req.postboard.closest('.postboard').find('.postboard-news').hide();
displayQueryPending(req.postboard);
}, {postboard: this.postboard}
);
}).bind({postboard: req.postboard})
});
} }
if (!req.postboard.children().length || autoUpdateQuery) {
displayQueryPending(req.postboard);
} else {
req.postboard.closest('div').find('.postboard-news') // FIXME we'd replace 'div' with '.postboard' but need to dig through tmobile first
.text(polyglot.t('new_posts', _queryPendingPosts[req.id].length))
.fadeIn('slow')
;
req.postboard.closest('div').find('.postboard-loading').hide();
} }
} }
} }
function displayHashtagPending(postboard) { function displayQueryPending(postboard) {
attachPostsToStream(postboard, _hashtagPendingPosts, false); var reqId = postboard.attr('data-request-id');
attachPostsToStream(postboard, _queryPendingPosts[reqId], false);
_queryPendingPosts[reqId] = [];
$.MAL.postboardLoaded(); $.MAL.postboardLoaded();
_hashtagPendingPosts = [];
} }

5
js/twister_directmsg.js

@ -50,10 +50,11 @@ function processDMsnippet(dmUsers, dmThreadList, forGroup) {
} }
function requestDmConversationModal(postboard, dm_screenname) { function requestDmConversationModal(postboard, dm_screenname) {
if (postboard.is('html *')) { if (!isModalWithElemExists(postboard))
return;
requestDmConversation(postboard, dm_screenname); requestDmConversation(postboard, dm_screenname);
setTimeout(requestDmConversationModal, 1000, postboard, dm_screenname); setTimeout(requestDmConversationModal, 1000, postboard, dm_screenname);
}
} }
function requestDmConversation(postboard, dm_screenname) { function requestDmConversation(postboard, dm_screenname) {

52
js/twister_newmsgs.js

@ -29,6 +29,11 @@ function processMention(user, mentionTime, data) {
_newMentionsUpdated = true; _newMentionsUpdated = true;
_lastMentionTime = Math.max(mentionTime, _lastMentionTime); _lastMentionTime = Math.max(mentionTime, _lastMentionTime);
data.isNew = true; data.isNew = true;
var reqId = defaultScreenName + '@mention';
if (typeof _queryPendingPosts[reqId] !== 'object')
_queryPendingPosts[reqId] = [];
_queryPendingPosts[reqId].push(data);
} }
_knownMentions[key] = {mentionTime: mentionTime, data: data}; _knownMentions[key] = {mentionTime: mentionTime, data: data};
purgeOldMentions(); purgeOldMentions();
@ -103,8 +108,25 @@ function requestMentionsCount() {
if (_newMentions) { if (_newMentions) {
$.MAL.soundNotifyMentions(); $.MAL.soundNotifyMentions();
if ($.Options.showDesktopNotifMentions.val === 'enable') if (!$.hasOwnProperty('mobile') && $.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.showDesktopNotification({
body: polyglot.t('You got') + ' ' + polyglot.t('new_mentions', _newMentions) + '.',
tag: 'twister_notification_new_mentions',
timeout: $.Options.showDesktopNotifMentionsTimer.val,
funcClick: function () {
var postboardSelector =
'.postboard-posts[data-request-id="' + defaultScreenName + '@mention"]';
if (!focusModalWithElement(postboardSelector,
function (req) {
var postboard = $(req.postboardSelector);
postboard.closest('.postboard').find('.postboard-news').hide();
displayQueryPending(postboard);
resetMentionsCount();
}, {postboardSelector: postboardSelector}
))
$.MAL.showMentions(defaultScreenName);
}
});
} }
} }
@ -117,24 +139,26 @@ function requestMentionsCount() {
if (newDMs) { if (newDMs) {
$.MAL.soundNotifyDM(); $.MAL.soundNotifyDM();
if ($.Options.showDesktopNotifDMs.val === 'enable') { if (!$.hasOwnProperty('mobile') && $.Options.showDesktopNotifDMs.val === 'enable') {
$.MAL.showDesktopNotif(false, $.MAL.showDesktopNotification({
polyglot.t('You got') + ' ' + polyglot.t('new_direct_messages', newDMs) + '.', body: polyglot.t('You got') + ' ' + polyglot.t('new_direct_messages', newDMs) + '.',
false, 'twister_notification_new_DMs', $.Options.showDesktopNotifDMsTimer.val, tag: 'twister_notification_new_DMs',
function () {$.MAL.showDMchat();}, false timeout: $.Options.showDesktopNotifDMsTimer.val,
); funcClick: function () {$.MAL.showDMchat();}
});
} }
} }
var newDMs = getNewGroupDMsCount(); var newDMs = getNewGroupDMsCount();
if (newDMs) { if (newDMs) {
$.MAL.soundNotifyDM(); $.MAL.soundNotifyDM();
if ($.Options.showDesktopNotifDMs.val === 'enable') { if (!$.hasOwnProperty('mobile') && $.Options.showDesktopNotifDMs.val === 'enable') {
$.MAL.showDesktopNotif(false, $.MAL.showDesktopNotification({
polyglot.t('You got') + ' ' + polyglot.t('new_group_messages', newDMs) + '.', body: polyglot.t('You got') + ' ' + polyglot.t('new_group_messages', newDMs) + '.',
false, 'twister_notification_new_DMs', $.Options.showDesktopNotifDMsTimer.val, tag: 'twister_notification_new_DMs',
function () {$.MAL.showDMchat({group: true});}, false timeout: $.Options.showDesktopNotifDMsTimer.val,
); funcClick: function () {$.MAL.showDMchat({group: true});}
});
} }
} }
} }

Loading…
Cancel
Save