diff --git a/js/interface_common.js b/js/interface_common.js index e0e79cb..c0e0579 100644 --- a/js/interface_common.js +++ b/js/interface_common.js @@ -2460,9 +2460,10 @@ function postSubmit(e, oldLastPostId) { } if (btnPostSubmit.hasClass('with-reference')) { - var doSubmitPost = function (postText, postData) { - newRtMsg(postData, postText); - } + var doSubmitPost = function (postText, postDataElem) { + newRtMsg($.evalJSON(postDataElem.attr('data-content_to_rt')), + postDataElem.attr('data-content_to_sigrt'), postText); + }; } else { if (splitedPostsCount > 1) { if (textArea.length < splitedPostsCount) { @@ -2564,8 +2565,11 @@ function retweetSubmit(event) { event.stopPropagation(); var prompt = $(event.target).closest('.prompt-wrapper'); + var postDataElem = prompt.find('.post-data'); + + newRtMsg($.evalJSON(postDataElem.attr('data-content_to_rt')), + postDataElem.attr('data-content_to_sigrt')); - newRtMsg(prompt.find('.post-data')); closePrompt(prompt); } diff --git a/js/twister_actions.js b/js/twister_actions.js index 78d1bdf..5010f18 100644 --- a/js/twister_actions.js +++ b/js/twister_actions.js @@ -283,15 +283,37 @@ function newPostMsg(msg, reply_n, reply_k, cbFunc, cbReq) { ); } -function newRtMsg(postData, msg) { - var userpost = $.evalJSON(postData.attr('data-content_to_rt')); - var sig_userpost; +function newRtMsg(userpost, sig_userpost, comment, cbFunc, cbReq) { + if (typeof lastPostId === 'undefined') { + alertPopup({ + //txtTitle: polyglot.t(''), add some title (not 'error', please) or just KISS + txtMessage: 'Can\'t handle the retwisting of a twist —\n' + + polyglot.t('Internal error: lastPostId unknown (following yourself may fix!)') + }); + return; + } + if (typeof _sendedPostIDs !== 'object') { + alertPopup({ + //txtTitle: polyglot.t(''), add some title (not 'error', please) or just KISS + txtMessage: 'Can\'t handle the retwisting of a twist —\n' + + polyglot.t('this is undefined', {'this': '_sendedPostIDs'}) + }); + return; + } + if (typeof userpost !== 'object') { + alertPopup({ + //txtTitle: polyglot.t(''), add some title (not 'error', please) or just KISS + txtMessage: 'Can\'t handle the retwisting of a twist —\n' + + polyglot.t('this is undefined', {'this': 'userpost'}) + }); + return; + } if (userpost.rt) { if (parseInt(twisterVersion) <= 93000) { alertPopup({ //txtTitle: polyglot.t(''), add some title (not 'error', please) or just KISS - txtMessage: 'Can\'t handle retwisting of commented retwisted twists —\n' + txtMessage: 'Can\'t handle the retwisting of commented retwisted twists —\n' + polyglot.t('daemon_is_obsolete', {versionReq: '0.9.3+'}) }); @@ -302,14 +324,11 @@ function newRtMsg(postData, msg) { userpost.rt = undefined; userpost.sig_rt = undefined; } - } else { - sig_userpost = postData.attr('data-content_to_sigrt'); } - if (!sig_userpost) { alertPopup({ //txtTitle: polyglot.t(''), add some title (not 'error', please) or just KISS - txtMessage: 'Can\'t handle retwisting of a twist —\n' + txtMessage: 'Can\'t handle the retwisting of a twist —\n' + polyglot.t('this is undefined', {'this': 'sig_userpost'}) }); return; @@ -317,26 +336,27 @@ function newRtMsg(postData, msg) { userpost.sig_wort = undefined; - var rtObj = {sig_userpost: sig_userpost, userpost: userpost}; - - if (typeof lastPostId !== 'undefined') { - if (typeof _sendedPostIDs !== 'undefined') - _sendedPostIDs.push(lastPostId + 1); + _sendedPostIDs.push(lastPostId + 1); - var params = [defaultScreenName, lastPostId + 1, rtObj]; + var req = [defaultScreenName, lastPostId + 1, + {sig_userpost: sig_userpost, userpost: userpost}]; + if (typeof comment !== 'undefined') + req.push(comment); - if (typeof msg !== 'undefined') - params.push(msg); - - twisterRpc('newrtmsg', params, - function(arg, ret) {incLastPostId();}, null, - function(arg, ret) {var msg = ('message' in ret) ? ret.message : ret; - alert(polyglot.t('ajax_error', {error: msg})); - }, null - ); - } else { - alert(polyglot.t('Internal error: lastPostId unknown (following yourself may fix!)')); - } + twisterRpc('newrtmsg', req, + function(req, ret) { + incLastPostId(); + if (typeof req.cbFunc === 'function') + req.cbFunc(req.cbReq, ret); + }, {cbFunc: cbFunc, cbReq: cbReq}, + function(req, ret) { + alertPopup({ + //txtTitle: polyglot.t(''), add some title (not 'error', please) or just KISS + txtMessage: 'Can\'t handle the retwisting of a twist —\n' + + polyglot.t('ajax_error', {error: (ret.message) ? ret.message : ret}) + }); + } + ); } function newFavMsg(postData, priv, msg) {