From df66f54f2b1ad0c506f45ff15d71d585ec7bf354 Mon Sep 17 00:00:00 2001 From: Miguel Freitas Date: Sat, 27 Sep 2014 12:04:32 -0300 Subject: [PATCH] Direct Message's copy to self feature (requires twisterd 0.9.26) --- js/options.js | 13 +++++++++++++ js/twister_directmsg.js | 27 ++++++++++++++++++++++----- options.html | 10 ++++++++++ 3 files changed, 45 insertions(+), 5 deletions(-) diff --git a/js/options.js b/js/options.js index 7139780..62e026b 100644 --- a/js/options.js +++ b/js/options.js @@ -323,6 +323,18 @@ var TwisterOptions = function() }); }; + this.getDMCopySelfOpt = function() { + return $.Options.getOption('dmCopySelf',"enable"); + } + + this.setDMCopySelfOpt = function () { + $('#dmCopySelfOpt select')[0].value = this.getDMCopySelfOpt(); + + $('#dmCopySelfOpt select').on('change', function(){ + $.Options.setOption(this.id, this.value); + }); + } + this.InitOptions = function() { this.soundNotifOptions(); this.volumeControl(); @@ -343,6 +355,7 @@ var TwisterOptions = function() this.setHideCloseRTsHourOpt(); this.setHideCloseRTsOpt(); this.setIsFollowingMeOpt(); + this.setDMCopySelfOpt(); } } diff --git a/js/twister_directmsg.js b/js/twister_directmsg.js index f3e8a76..8738bb2 100644 --- a/js/twister_directmsg.js +++ b/js/twister_directmsg.js @@ -113,11 +113,28 @@ function directMsgSubmit(e) function newDirectMsg(msg, dm_screenname) { if( lastPostId != undefined ) { - var params = [defaultScreenName, lastPostId + 1, dm_screenname, msg] - twisterRpc("newdirectmsg", params, - function(arg, ret) { incLastPostId(); }, null, - function(arg, ret) { var msg = ("message" in ret) ? ret.message : ret; - alert("Ajax error: " + msg); }, null); + var paramsOrig = [defaultScreenName, lastPostId + 1, dm_screenname, msg] + var paramsOpt = paramsOrig + var copySelf = ($.Options.getDMCopySelfOpt() === 'enable') + if( copySelf ) { + paramsOpt = paramsOrig.concat(true) + } + + twisterRpc("newdirectmsg", paramsOpt, + function(arg, ret) { + incLastPostId(); + if( arg.copySelf ) incLastPostId(); + }, {copySelf:copySelf}, + function(arg, ret) { + // fallback for older twisterd (error: no copy_self parameter) + twisterRpc("newdirectmsg", arg.paramsOrig, + function(arg, ret) { incLastPostId(); }, null, + function(arg, ret) { + var msg = ("message" in ret) ? ret.message : ret; + alert("Ajax error: " + msg); + }, null); + }, {paramsOrig:paramsOrig} + ); } else { alert(polyglot.t("Internal error: lastPostId unknown (following yourself may fix!)")); } diff --git a/options.html b/options.html index 98ccf5e..a567981 100644 --- a/options.html +++ b/options.html @@ -263,6 +263,16 @@ +
+
+

Direct Message's copy to self

+ +
+
+