From cc1c5e5d119f9e221639b249bba3398d1f1d4a83 Mon Sep 17 00:00:00 2001 From: Miguel Freitas Date: Fri, 24 Apr 2015 17:49:55 -0300 Subject: [PATCH] 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. --- js/twister_directmsg.js | 10 ++++++++-- js/twister_formatpost.js | 5 ++++- js/twister_io.js | 10 ++++++++++ js/twister_newmsgs.js | 17 ++++++++++++++++- 4 files changed, 38 insertions(+), 4 deletions(-) diff --git a/js/twister_directmsg.js b/js/twister_directmsg.js index 8705636..b01a4a3 100644 --- a/js/twister_directmsg.js +++ b/js/twister_directmsg.js @@ -8,6 +8,9 @@ function requestDMsnippetList(dmThreadList) { for( var i = 0; i < followingUsers.length; i++ ) { followList.push({username:followingUsers[i]}); } + for( var i = 0; i < groupChatAliases.length; i++ ) { + followList.push({username:groupChatAliases[i]}); + } twisterRpc("getdirectmsgs", [defaultScreenName, 1, followList], function(req, ret) {processDMsnippet(ret, dmThreadList);}, dmThreadList, @@ -43,7 +46,10 @@ function processDMsnippet(dmUsers, dmThreadList) { } 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); 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 paramsOpt = paramsOrig var copySelf = ($.Options.getDMCopySelfOpt() === 'enable') - if( copySelf ) { + if( copySelf && dm_screenname[0] !== '*' ) { paramsOpt = paramsOrig.concat(true) } diff --git a/js/twister_formatpost.js b/js/twister_formatpost.js index 54a15fb..ac27e6c 100644 --- a/js/twister_formatpost.js +++ b/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.dm-chat-link").attr("href", $.MAL.dmchatUrl(remoteUser)); 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-info-time").text(timeGmtToText(dmData.time)); dmItem.find(".post-info-time").attr("title",timeSincePost(dmData.time)); diff --git a/js/twister_io.js b/js/twister_io.js index 4d36fc4..a6366db 100644 --- a/js/twister_io.js +++ b/js/twister_io.js @@ -296,6 +296,16 @@ function getWebpage( username, 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 // other peers. dht server limits udp rate so requesting too much // data will only cause new requests to fail. diff --git a/js/twister_newmsgs.js b/js/twister_newmsgs.js index a143198..bae9288 100644 --- a/js/twister_newmsgs.js +++ b/js/twister_newmsgs.js @@ -13,6 +13,7 @@ var _lastLocalMentionId = -1; var PURGE_OLD_MENTIONS_TIMEOUT = 3600 * 24 * 30; // one month var _newMentionsUpdated = false; var _newDMsUpdated = false; +var groupChatAliases = [] // process a mention received to check if it is really new function processMention(user, mentionTime, data) { @@ -176,6 +177,9 @@ function requestDMsCount() { for( var i = 0; i < followingUsers.length; i++ ) { followList.push({username:followingUsers[i]}); } + for( var i = 0; i < groupChatAliases.length; i++ ) { + followList.push({username:groupChatAliases[i]}); + } twisterRpc("getdirectmsgs", [defaultScreenName, 1, followList], function(req, dmUsers) { @@ -221,10 +225,21 @@ function resetNewDMsCountForUser(user, lastId) { $.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() { loadDMsFromStorage(); $.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. //setInterval("requestDMsCount()", 5000); }