Browse Source

fix updating of minimized modals / add resuming from desktop notifications

readme-update
Simon Grim 9 years ago
parent
commit
6a6b3aba5d
  1. 89
      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

89
js/interface_common.js

@ -139,10 +139,44 @@ function resumeModal(event) { @@ -139,10 +139,44 @@ function resumeModal(event) {
// TODO also need reset modal height here maybe and then compute new scroll
if (modal.scroll)
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) {
if (event && event.stopPropagation) {
event.stopPropagation();
@ -331,29 +365,37 @@ function openHashtagModalFromSearchHandler(hashtag) { @@ -331,29 +365,37 @@ function openHashtagModalFromSearchHandler(hashtag) {
title: '#' + hashtag
});
clearHashtagProcessed();
updateHashtagModal(modal.content.find('.postboard-posts'), hashtag, 'hashtag');
setupQueryModalUpdating(modal.content.find('.postboard-posts'), hashtag, 'hashtag');
}
function updateHashtagModal(postboard, hashtag, resource, timeoutArgs) {
if (postboard.is('html *')) {
requestHashtag(postboard, hashtag, resource, timeoutArgs);
function setupQueryModalUpdating(postboard, query, resource) {
var req = {
postboard: postboard,
query: query,
resource: resource,
id: query + '@' + resource
};
if (_hashtagPendingPostsUpdated) {
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() {
$('.postboard-news').hide();
displayHashtagPending($('.hashtag-modal .postboard-posts'));
}, false)
}
_hashtagPendingPostsUpdated = 0;
}
postboard.attr('data-request-id', req.id);
requestQuery(req);
// 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),
// 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) {
@ -382,12 +424,16 @@ function openMentionsModalHandler(username) { @@ -382,12 +424,16 @@ function openMentionsModalHandler(username) {
title: polyglot.t('users_mentions', {username: username})
});
clearHashtagProcessed();
updateHashtagModal(modal.content.find('.postboard-posts'), username, 'mention');
setupQueryModalUpdating(modal.content.find('.postboard-posts'), username, 'mention');
if (username === defaultScreenName) {
// 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();
}
}
@ -476,11 +522,6 @@ function newConversationModal(username, resource) { @@ -476,11 +522,6 @@ function newConversationModal(username, resource) {
}, {content: content}
);
content.find('.postboard-news').on('click', function () {
$(this).hide();
displayHashtagPending($('.conversation-modal .postboard-posts'));
});
return content;
}
@ -1693,7 +1734,7 @@ function initInterfaceCommon() { @@ -1693,7 +1734,7 @@ function initInterfaceCommon() {
$('#hashtag-modal-template .postboard-news').on('click', function () {
$(this).hide();
displayHashtagPending($('.hashtag-modal .postboard-posts'));
displayQueryPending($('.hashtag-modal .postboard-posts'));
});
replaceDashboards();

37
js/tmobile.js

@ -538,22 +538,27 @@ function encode_utf8(s) { @@ -538,22 +538,27 @@ function encode_utf8(s) {
return s;
}
var hashtag_elem;
var hashtag_tag;
var hashtag_res;
function setupHashtagOrMention( ulElem, tag, res) {
hashtag_elem = ulElem;
hashtag_tag = tag;
hashtag_res = res;
hashtag_elem.text("");
var tmobileQueryReq = {}; // FIXME need to rework all that searching
function setupHashtagOrMention(postboard, tag, res) {
$.MAL.setPostTemplate( $("#post-template-home") );
$.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
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.
@ -575,10 +580,12 @@ function tmobileTick() { @@ -575,10 +580,12 @@ function tmobileTick() {
}
}, {} );
}
if( curPage == "mentions" || curPage == "hashtag" ) {
autoUpdateHashtag = true;
requestHashtag(hashtag_elem,hashtag_tag,hashtag_res);
else if (curPage === 'mentions' || curPage === 'hashtag') {
autoUpdateQuery = true;
requestQuery(tmobileQueryReq);
}
if( curPage == "dmchat" ) {
requestDmConversation($("#dmchat ul.direct-messages-list"),dmChatUser);
}

110
js/twister_actions.js

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

5
js/twister_directmsg.js

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

52
js/twister_newmsgs.js

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

Loading…
Cancel
Save