Browse Source

very crude initial support to display group chat as standard direct messages.

still a lot to do: using the "from" field from group messages to display
who sent each message, options to invite, display members, change
group description, leave etc.
master
Miguel Freitas 10 years ago
parent
commit
cc1c5e5d11
  1. 10
      js/twister_directmsg.js
  2. 5
      js/twister_formatpost.js
  3. 10
      js/twister_io.js
  4. 17
      js/twister_newmsgs.js

10
js/twister_directmsg.js

@ -8,6 +8,9 @@ function requestDMsnippetList(dmThreadList) {
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++ ) {
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,
@ -43,7 +46,10 @@ function processDMsnippet(dmUsers, dmThreadList) {
} }
function openDmConversation(dm_screenname, dmTitleName, dmConversation) { function openDmConversation(dm_screenname, dmTitleName, dmConversation) {
getFullname( dm_screenname, dmTitleName ); if( dm_screenname.length && dm_screenname[0] === '*' )
getGroupChatName( dm_screenname, dmTitleName );
else
getFullname( dm_screenname, dmTitleName );
dmConversation.attr("data-dm-screen-name", dm_screenname); dmConversation.attr("data-dm-screen-name", dm_screenname);
var dmConvo = dmConversation.find(".direct-messages-thread"); var dmConvo = dmConversation.find(".direct-messages-thread");
@ -116,7 +122,7 @@ function newDirectMsg(msg, dm_screenname) {
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.getDMCopySelfOpt() === 'enable') var copySelf = ($.Options.getDMCopySelfOpt() === 'enable')
if( copySelf ) { if( copySelf && dm_screenname[0] !== '*' ) {
paramsOpt = paramsOrig.concat(true) paramsOpt = paramsOrig.concat(true)
} }

5
js/twister_formatpost.js

@ -153,7 +153,10 @@ function dmDataToSnippetItem(dmData, remoteUser) {
dmItem.find("a.post-info-name").attr("href", $.MAL.userUrl(remoteUser)); dmItem.find("a.post-info-name").attr("href", $.MAL.userUrl(remoteUser));
dmItem.find("a.dm-chat-link").attr("href", $.MAL.dmchatUrl(remoteUser)); dmItem.find("a.dm-chat-link").attr("href", $.MAL.dmchatUrl(remoteUser));
getAvatar( remoteUser, dmItem.find(".post-photo").find("img") ); getAvatar( remoteUser, dmItem.find(".post-photo").find("img") );
getFullname( remoteUser, dmItem.find("a.post-info-name") ); 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(escapeHtmlEntities(dmData.text)); dmItem.find(".post-text").html(escapeHtmlEntities(dmData.text));
dmItem.find(".post-info-time").text(timeGmtToText(dmData.time)); dmItem.find(".post-info-time").text(timeGmtToText(dmData.time));
dmItem.find(".post-info-time").attr("title",timeSincePost(dmData.time)); dmItem.find(".post-info-time").attr("title",timeSincePost(dmData.time));

10
js/twister_io.js

@ -296,6 +296,16 @@ function getWebpage( username, item ){
}, {item:item} ); }, {item:item} );
} }
function getGroupChatName( groupalias, item ){
twisterRpc("getgroupinfo", [groupalias],
function(args, ret) {
args.item.text(ret["description"]);
}, {item:item},
function(args, ret) {
args.item.text("getgroupinfo error");
}, {item:item});
}
// we must cache avatar results to disk to lower bandwidth on // we must cache avatar results to disk to lower bandwidth on
// other peers. dht server limits udp rate so requesting too much // other peers. dht server limits udp rate so requesting too much
// data will only cause new requests to fail. // data will only cause new requests to fail.

17
js/twister_newmsgs.js

@ -13,6 +13,7 @@ var _lastLocalMentionId = -1;
var PURGE_OLD_MENTIONS_TIMEOUT = 3600 * 24 * 30; // one month var PURGE_OLD_MENTIONS_TIMEOUT = 3600 * 24 * 30; // one month
var _newMentionsUpdated = false; var _newMentionsUpdated = false;
var _newDMsUpdated = false; var _newDMsUpdated = false;
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) {
@ -176,6 +177,9 @@ function requestDMsCount() {
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++ ) {
followList.push({username:groupChatAliases[i]});
}
twisterRpc("getdirectmsgs", [defaultScreenName, 1, followList], twisterRpc("getdirectmsgs", [defaultScreenName, 1, followList],
function(req, dmUsers) { function(req, dmUsers) {
@ -221,10 +225,21 @@ function resetNewDMsCountForUser(user, lastId) {
$.MAL.updateNewDMsUI(getNewDMsCount()); $.MAL.updateNewDMsUI(getNewDMsCount());
} }
function updateGroupList() {
twisterRpc("listgroups", [],
function(req, ret) {groupChatAliases=ret;}, null,
function(req, ret) {console.log("twisterd >= 0.9.30 required for listgroups");}, null);
}
function initDMsCount() { function initDMsCount() {
loadDMsFromStorage(); loadDMsFromStorage();
$.MAL.updateNewDMsUI(getNewDMsCount()); $.MAL.updateNewDMsUI(getNewDMsCount());
requestDMsCount();
//quick hack to obtain list of group chat aliases
updateGroupList();
setInterval("updateGroupList();", 60000);
setTimeout("requestDMsCount();", 200);
//polling not needed: processNewPostsConfirmation will call requestDMsCount. //polling not needed: processNewPostsConfirmation will call requestDMsCount.
//setInterval("requestDMsCount()", 5000); //setInterval("requestDMsCount()", 5000);
} }

Loading…
Cancel
Save