Browse Source

optimization of DMs list handling

readme-update
Simon Grim 9 years ago
parent
commit
f6f807205b
  1. 15
      home.html
  2. 51
      js/interface_common.js
  3. 23
      js/mobile_abstract.js
  4. 10
      js/tmobile.js
  5. 50
      js/twister_directmsg.js
  6. 26
      js/twister_formatpost.js
  7. 35
      tmobile.html

15
home.html

@ -457,23 +457,22 @@
<!-- MODAL DE DIRECT MESSAGES INIT --> <!-- MODAL DE DIRECT MESSAGES INIT -->
<!-- Este modal possui dois templates, o primeiro da lista de pessoas que enviaram mensagens e o segundo <!-- Este modal possui dois templates, o primeiro da lista de pessoas que enviaram mensagens e o segundo
com a thread de mensagens individual --> com a thread de mensagens individual -->
<div class="direct-messages-template"> <div id="template-direct-messages-list">
<ol class="direct-messages-list"> <ol class="direct-messages-list"></ol>
<!-- use "dm-snippet-template here -->
</ol>
</div> </div>
<li id="dm-snippet-template" class="module post message"> <div id="template-direct-messages-list-item">
<li class="module post message">
<div class="post-photo"><img src="img/grayed_avatar_placeholder_24.png" alt="user-photo"/></div> <div class="post-photo"><img src="img/grayed_avatar_placeholder_24.png" alt="user-photo"/></div>
<div class="post-info"> <div class="post-info">
<a href="#" class="post-info-name open-profile-modal"></a> <a class="post-info-name open-profile-modal"></a>
<span class="post-info-tag">@</span> <span class="post-info-tag">@</span>
<a href="#" class="post-info-time" title=""><span></span></a> <a class="post-info-time"><span></span></a>
</div> </div>
<!-- o texto do post (restrição de caracteres?) -->
<p class="post-text"></p> <p class="post-text"></p>
<div class="messages-qtd">0</div> <div class="messages-qtd">0</div>
</li> </li>
</div>
<div class="messages-thread-template"> <div class="messages-thread-template">
<ol class="direct-messages-thread"> <ol class="direct-messages-thread">

51
js/interface_common.js

@ -674,6 +674,46 @@ function newConversationModal(peerAlias, resource) {
return content; return content;
} }
function addToCommonDMsList(list, targetAlias, message) {
var item = twister.tmpl.commonDMsListItem.clone(true)
.attr('data-screen-name', targetAlias)
.attr('data-last_id', message.id)
.attr('data-time', message.time)
;
item.find('.post-info-tag').text('@' + targetAlias);
item.find('.post-info-name').attr('href', $.MAL.userUrl(targetAlias));
item.find('.post-text').html(htmlFormatMsg(message.text).html);
item.find('.post-info-time')
.attr('title', timeSincePost(message.time))
.find('span:last')
.text(timeGmtToText(message.time))
;
if (targetAlias[0] === '*') {
getAvatar(message.from, item.find('.post-photo img')); // it's impossible yet to get group avatar
getGroupChatName(targetAlias, item.find('a.post-info-name'));
} else {
getAvatar(targetAlias, item.find('.post-photo img'));
getFullname(targetAlias, item.find('a.post-info-name'));
}
if (_newDMsPerUser[targetAlias] > 0)
item.addClass('new')
.find('.messages-qtd').text(_newDMsPerUser[targetAlias]).show();
var items = list.children();
for (var i = 0; i < items.length; i++) {
var elem = items.eq(i);
var time = elem.attr('data-time');
if (typeof time === 'undefined' || message.time > parseInt(time)) {
elem.before(item);
break;
}
}
if (i === items.length) // equals to !item.parent().length
list.append(item);
}
function openConversationClick(event) { function openConversationClick(event) {
event.preventDefault(); event.preventDefault();
event.stopPropagation(); event.stopPropagation();
@ -775,7 +815,7 @@ function loadModalFromHash() {
openConversationModal(splithashdata2[0], splithashdata2[1]); openConversationModal(splithashdata2[0], splithashdata2[1]);
} }
} else if (hashstring === '#directmessages') } else if (hashstring === '#directmessages')
directMessagesPopup(); openCommonDMsModal();
else if (hashstring === '#following') else if (hashstring === '#following')
openFollowingModal(); openFollowingModal();
else if (hashstring === '#groupmessages') else if (hashstring === '#groupmessages')
@ -1959,6 +1999,8 @@ function replaceDashboards() {
} }
function initInterfaceCommon() { function initInterfaceCommon() {
twister.tmpl.commonDMsList = extractTemplate('#template-direct-messages-list');
$('.modal-close, .modal-blackout').not('.prompt-close').on('click', closeModal); $('.modal-close, .modal-blackout').not('.prompt-close').on('click', closeModal);
$('.minimize-modal').on('click', function (event) { $('.minimize-modal').on('click', function (event) {
@ -2148,6 +2190,13 @@ $(document).ready(function () {
twister.html.blanka.appendTo('body').hide(); twister.html.blanka.appendTo('body').hide();
twister.tmpl.followingList = extractTemplate('#template-following-list'); twister.tmpl.followingList = extractTemplate('#template-following-list');
twister.tmpl.followingUser = extractTemplate('#template-following-user'); twister.tmpl.followingUser = extractTemplate('#template-following-user');
twister.tmpl.commonDMsListItem = extractTemplate('#template-direct-messages-list-item')
.on('mouseup', function (event) {
event.data = {route:
$.MAL.dmchatUrl($(event.target).closest('.module').attr('data-screen-name'))};
routeOnClick(event);
})
;
twister.tmpl.postRtReference = extractTemplate('#template-post-rt-reference') twister.tmpl.postRtReference = extractTemplate('#template-post-rt-reference')
.on('mouseup', {feeder: '.post-rt-reference'}, openConversationClick) .on('mouseup', {feeder: '.post-rt-reference'}, openConversationClick)
.on('click', muteEvent) // to prevent post expanding or collapsing .on('click', muteEvent) // to prevent post expanding or collapsing

23
js/mobile_abstract.js

@ -31,27 +31,24 @@ var MAL = function()
} }
} }
this.dmThreadListLoaded = function() { this.commonDMsListLoaded = function () {
if( $.hasOwnProperty("mobile") ) { if ($.hasOwnProperty('mobile')) {
$.mobile.hidePageLoadingMsg(); $.mobile.hidePageLoadingMsg();
var $dmThreadList = $("#directmsg ul.direct-messages-thread"); $('#directmsg .direct-messages-list').listview('refresh');
$dmThreadList.listview('refresh');
} else { } else {
} }
} };
this.dmChatListLoaded = function(dmConvo) { this.dmConversationLoaded = function (dmConvo) {
if( $.hasOwnProperty("mobile") ) { if ($.hasOwnProperty('mobile')) {
$.mobile.hidePageLoadingMsg(); $.mobile.hidePageLoadingMsg();
var $dmChatList = $("#dmchat ul.direct-messages-list"); $('#dmchat .direct-messages-thread').listview('refresh');
$dmChatList.listview('refresh'); $.mobile.silentScroll($('.dm-form').offset().top);
$.mobile.silentScroll( $(".dm-form").offset().top );
} else { } else {
var modalContent = dmConvo.closest(".modal-content"); var modalContent = dmConvo.closest('.modal-content');
modalContent.scrollTop(modalContent[0].scrollHeight); modalContent.scrollTop(modalContent[0].scrollHeight);
} }
} };
this.relatedPostLoaded = function() { this.relatedPostLoaded = function() {
if( $.hasOwnProperty("mobile") ) { if( $.hasOwnProperty("mobile") ) {

10
js/tmobile.js

@ -272,9 +272,8 @@ var router=new $.mobile.Router(
directmsg: function(type,match,ui) { directmsg: function(type,match,ui) {
$.mobile.showPageLoadingMsg(); $.mobile.showPageLoadingMsg();
initializeTwister( true, true, function() { initializeTwister( true, true, function() {
var $dmThreadList = $("#directmsg ul.direct-messages-thread");
$.mobile.showPageLoadingMsg(); $.mobile.showPageLoadingMsg();
requestDMsnippetList($dmThreadList); requestDMsnippetList($('#directmsg .direct-messages-list'));
}); });
}, },
dmchat: function(type,match,ui) { dmchat: function(type,match,ui) {
@ -282,7 +281,7 @@ var router=new $.mobile.Router(
$.mobile.showPageLoadingMsg(); $.mobile.showPageLoadingMsg();
initializeTwister( true, true, function() { initializeTwister( true, true, function() {
var user = params.user; var user = params.user;
var dmConvo = $("#dmchat ul.direct-messages-list"); var dmConvo = $('#dmchat .direct-messages-thread');
$("#dmchat .rtitle").text("Chat @" + user); $("#dmchat .rtitle").text("Chat @" + user);
$("#dmchat textarea").val(""); $("#dmchat textarea").val("");
dmConvo.html(""); dmConvo.html("");
@ -590,9 +589,8 @@ function tmobileTick() {
requestQuery(tmobileQueryReq); requestQuery(tmobileQueryReq);
} }
if( curPage == "dmchat" ) { if (curPage === 'dmchat')
requestDmConversation($("#dmchat ul.direct-messages-list"),dmChatUser); requestDmConversation($('#dmchat .direct-messages-thread'), dmChatUser);
}
} }
$(document).bind('mobileinit', function () { $(document).bind('mobileinit', function () {

50
js/twister_directmsg.js

@ -5,7 +5,7 @@
var _groupMsgInviteToGroupQueue = []; var _groupMsgInviteToGroupQueue = [];
function requestDMsnippetList(dmThreadList, forGroup) { function requestDMsnippetList(elemList, forGroup) {
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]});
@ -13,40 +13,19 @@ function requestDMsnippetList(dmThreadList, forGroup) {
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, req.dmThreadList, req.forGroup);}, processDMsnippet, {elemList: elemList, forGroup: forGroup},
{dmThreadList: dmThreadList, forGroup: forGroup},
function(req, ret) {console.log('ajax error:' + ret);}, null function(req, ret) {console.log('ajax error:' + ret);}, null
); );
} }
function processDMsnippet(dmUsers, dmThreadList, forGroup) { function processDMsnippet(req, DMs) {
dmThreadList.empty(); req.elemList.empty();
for (var u in dmUsers) { for (var alias in DMs)
if ((forGroup && u[0] !== '*') || (!forGroup && u[0] === '*')) if ((req.forGroup && alias[0] === '*') || (!req.forGroup && alias[0] !== '*'))
continue; addToCommonDMsList(req.elemList, alias, DMs[alias][0]);
// convert snipped to html and add it to date-sorted list $.MAL.commonDMsListLoaded();
var dmItem = dmDataToSnippetItem(dmUsers[u][0], u);
if (_newDMsPerUser[u] > 0) {
dmItem.addClass('new')
.find('.messages-qtd').text(_newDMsPerUser[u]).show();
}
var timeDmItem = parseInt(dmItem.attr('data-time'));
var existingItems = dmThreadList.children();
for (var j = 0; j < existingItems.length; j++) {
var streamItem = existingItems.eq(j);
var timeExisting = streamItem.attr('data-time');
if (typeof timeExisting === 'undefined' || timeDmItem > parseInt(timeExisting)) {
// this post in stream is older, so post must be inserted above
streamItem.before(dmItem);
break;
}
}
if (j === existingItems.length)
dmThreadList.append(dmItem);
}
$.MAL.dmThreadListLoaded();
} }
function requestDmConversationModal(postboard, peerAlias) { function requestDmConversationModal(postboard, peerAlias) {
@ -103,7 +82,7 @@ function processDmConversation(stream, peerAlias, posts) {
streamPostsIDs.push(lastPostID); streamPostsIDs.push(lastPostID);
} }
} }
$.MAL.dmChatListLoaded(stream); $.MAL.dmConversationLoaded(stream);
} }
if (newPosts) { if (newPosts) {
@ -183,7 +162,7 @@ function newDirectMsg(msg, peerAlias) {
} }
// dispara o modal de direct messages // dispara o modal de direct messages
function directMessagesPopup() { function openCommonDMsModal() {
if (!defaultScreenName) { if (!defaultScreenName) {
alert(polyglot.t('You have to log in to use direct messages.')); alert(polyglot.t('You have to log in to use direct messages.'));
return; return;
@ -191,7 +170,7 @@ function directMessagesPopup() {
var modal = openModal({ var modal = openModal({
classAdd: 'directMessages', classAdd: 'directMessages',
content: $('.direct-messages-template').children().clone(true), content: twister.tmpl.commonDMsList.clone(true),
title: polyglot.t('Direct Messages') title: polyglot.t('Direct Messages')
}); });
@ -245,7 +224,7 @@ function openGroupMessagesModal(groupAlias) {
if (typeof groupAlias === 'undefined') { if (typeof groupAlias === 'undefined') {
var modal = openModal({ var modal = openModal({
classAdd: 'directMessages groupMessages', classAdd: 'directMessages groupMessages',
content: $('.direct-messages-template').children().clone(true), content: twister.tmpl.commonDMsList.clone(true),
title: polyglot.t('Group Messages') title: polyglot.t('Group Messages')
}); });
@ -496,11 +475,6 @@ function initInterfaceDirectMsg() {
$('.groupmessages').attr('href', '#groupmessages'); $('.groupmessages').attr('href', '#groupmessages');
$('.userMenu-groupmessages a').attr('href', '#groupmessages'); $('.userMenu-groupmessages a').attr('href', '#groupmessages');
$('#dm-snippet-template').on('click', function() {
var alias = $(this).attr('data-screen-name');
window.location.hash = '#directmessages?' + (alias[0] === '*' ? 'group' : 'user') + '=' + alias;
});
$('.dm-submit').on('click', directMsgSubmit); $('.dm-submit').on('click', directMsgSubmit);
$('.direct-messages-with-user').on('click', function() { $('.direct-messages-with-user').on('click', function() {
window.location.hash = '#directmessages?user=' + window.location.hash = '#directmessages?user=' +

26
js/twister_formatpost.js

@ -251,32 +251,6 @@ function setPostInfoSent(n, k, item) {
} }
} }
// format dmdata (returned by getdirectmsgs) to display in "snippet" per user list
function dmDataToSnippetItem(dmData, remoteUser) {
var dmItem = $("#dm-snippet-template").clone(true);
dmItem.removeAttr('id');
dmItem.attr('data-screen-name', remoteUser);
dmItem.attr("data-last_id", dmData.id);
dmItem.attr("data-time", dmData.time);
dmItem.find(".post-info-tag").text("@" + remoteUser);
dmItem.find("a.post-info-name").attr("href", $.MAL.userUrl(remoteUser));
dmItem.find("a.dm-chat-link").attr("href", $.MAL.dmchatUrl(remoteUser));
getAvatar( remoteUser, dmItem.find(".post-photo").find("img") );
if( remoteUser.length && remoteUser[0] === '*' )
getGroupChatName( remoteUser, dmItem.find("a.post-info-name") );
else
getFullname( remoteUser, dmItem.find("a.post-info-name") );
dmItem.find(".post-text").html(htmlFormatMsg(dmData.text).html);
dmItem.find('.post-info-time')
.attr('title', timeSincePost(dmData.time))
.find('span:last')
.text(timeGmtToText(dmData.time))
;
return dmItem;
}
// format dmdata (returned by getdirectmsgs) to display in conversation thread // format dmdata (returned by getdirectmsgs) to display in conversation thread
function postToElemDM(dmData, localUser, remoteUser) { function postToElemDM(dmData, localUser, remoteUser) {
var senderAlias = (dmData.from && dmData.from.length && dmData.from.charCodeAt(0)) var senderAlias = (dmData.from && dmData.from.length && dmData.from.charCodeAt(0))

35
tmobile.html

@ -131,6 +131,19 @@
font-size: 9px; font-size: 9px;
float: right; float: right;
} }
.direct-messages-list .post-info {
position: absolute;
top: 4px;
left: 72px;
width: 90%;
}
.direct-messages-list .post-text {
position: absolute;
top: 32px;
left: 72px;
}
</style> </style>
<div id="index" data-role="page"> <div id="index" data-role="page">
@ -589,8 +602,7 @@
</div> </div>
<div class="content" data-role="content"> <div class="content" data-role="content">
<ul class="direct-messages-thread" data-role="listview"> <ul class="direct-messages-list" data-role="listview"></ul>
</ul>
</div> </div>
<div class="footer" data-role="footer" data-position="fixed" data-tap-toggle="false"> <div class="footer" data-role="footer" data-position="fixed" data-tap-toggle="false">
@ -607,8 +619,7 @@
</div> </div>
<div class="content" data-role="content"> <div class="content" data-role="content">
<ul class="direct-messages-list" data-role="listview"> <ul class="direct-messages-thread" data-role="listview"></ul>
</ul>
<div class="dm-form" style="padding:15px 20px 20px 20px;"> <div class="dm-form" style="padding:15px 20px 20px 20px;">
<form class="post-area-new open"> <form class="post-area-new open">
@ -812,19 +823,17 @@
<img class="avatar size24" src="img/grayed_avatar_placeholder_24.png" alt="user-photo"/> <img class="avatar size24" src="img/grayed_avatar_placeholder_24.png" alt="user-photo"/>
</a> </a>
<!-- template for dm-snippet (dm threads list) --> <div id="template-direct-messages-list-item">
<li id="dm-snippet-template" class="module post message" data-icon="arrow-r"> <li class="module post message" data-icon="arrow-r">
<a class="dm-chat-link post-photo" href="#dmchat"> <div class="post-photo"><img class="avatar" src="img/grayed_avatar_placeholder_24.png" alt="user-photo"/></div>
<img class="avatar" src="img/grayed_avatar_placeholder_24.png" alt="user-photo"/> <div class="post-info">
<h4 class="post-info"> <a class="post-info-name"></a>
<span class="post-info-name open-profile-modal"></span>
<span class="post-info-tag">@</span> <span class="post-info-tag">@</span>
<a class="post-info-time ui-li-aside"><span></span></a> <a class="post-info-time ui-li-aside"><span></span></a>
</h4> </div>
<!-- o texto do post (restrição de caracteres?) -->
<p class="post-text"></p> <p class="post-text"></p>
</a>
</li> </li>
</div>
<!-- template for each dm (chat window) --> <!-- template for each dm (chat window) -->
<li id="dm-chat-template" class="module post message"> <li id="dm-chat-template" class="module post message">

Loading…
Cancel
Save