Browse Source

rename some vars and restyle a bit in js/twister_directmsg.js

readme-update
Simon Grim 9 years ago
parent
commit
a6b89ce271
  1. 58
      js/twister_directmsg.js

58
js/twister_directmsg.js

@ -49,33 +49,33 @@ function processDMsnippet(dmUsers, dmThreadList, forGroup) {
$.MAL.dmThreadListLoaded(); $.MAL.dmThreadListLoaded();
} }
function requestDmConversationModal(postboard, dm_screenname) { function requestDmConversationModal(postboard, peerAlias) {
if (!isModalWithElemExists(postboard)) if (!isModalWithElemExists(postboard))
return; return;
requestDmConversation(postboard, dm_screenname); requestDmConversation(postboard, peerAlias);
setTimeout(requestDmConversationModal, 1000, postboard, dm_screenname); setTimeout(requestDmConversationModal, 1000, postboard, peerAlias);
} }
function requestDmConversation(postboard, dm_screenname) { function requestDmConversation(postboard, peerAlias) {
var since_id = undefined; var since_id = undefined;
var oldItems = postboard.children(); var oldItems = postboard.children();
if (oldItems.length) if (oldItems.length)
since_id = parseInt(oldItems.eq(oldItems.length - 1).attr('data-id')); since_id = parseInt(oldItems.eq(oldItems.length - 1).attr('data-id'));
var userDmReq = [{username: dm_screenname}]; var userDmReq = [{username: peerAlias}];
if (typeof since_id !== 'undefined') if (typeof since_id !== 'undefined')
userDmReq[0].since_id = since_id; userDmReq[0].since_id = since_id;
var count = 100; var count = 100;
twisterRpc('getdirectmsgs', [defaultScreenName, count, userDmReq], twisterRpc('getdirectmsgs', [defaultScreenName, count, userDmReq],
function(args, ret) {processDmConversation(args.postboard, args.dm_screenname, ret);}, function(req, ret) {processDmConversation(req.postboard, req.peerAlias, ret);},
{postboard: postboard, dm_screenname: dm_screenname}, {postboard: postboard, peerAlias: peerAlias},
function(arg, ret) { function(req, ret) {
var msg = (ret.message) ? ret.message : ret; var msg = (ret.message) ? ret.message : ret;
alert(polyglot.t('ajax_error', {error: msg})); alert(polyglot.t('ajax_error', {error: msg}));
}, null }
); );
} }
@ -117,25 +117,25 @@ function directMsgSubmit(e) {
replyText.val(''); replyText.val('');
} }
function newDirectMsg(msg, dm_screenname) { function newDirectMsg(msg, peerAlias) {
if (typeof lastPostId !== 'undefined') { if (typeof lastPostId !== 'undefined') {
var paramsOrig = [defaultScreenName, lastPostId + 1, dm_screenname, msg]; var paramsOrig = [defaultScreenName, lastPostId + 1, peerAlias, msg];
var paramsOpt = paramsOrig; var paramsOpt = paramsOrig;
var copySelf = $.Options.dmCopySelf.val === 'enable'; var copySelf = $.Options.dmCopySelf.val === 'enable';
if (copySelf && dm_screenname[0] !== '*') if (copySelf && peerAlias[0] !== '*')
paramsOpt = paramsOrig.concat(true) paramsOpt = paramsOrig.concat(true)
twisterRpc('newdirectmsg', paramsOpt, twisterRpc('newdirectmsg', paramsOpt,
function(arg, ret) { function(req, ret) {
incLastPostId(); incLastPostId();
if (arg.copySelf) if (req.copySelf)
incLastPostId(); incLastPostId();
}, {copySelf: copySelf}, }, {copySelf: copySelf},
function(arg, ret) { function(req, ret) {
// fallback for older twisterd (error: no copy_self parameter) // fallback for older twisterd (error: no copy_self parameter)
twisterRpc('newdirectmsg', arg.paramsOrig, twisterRpc('newdirectmsg', req.paramsOrig,
function(arg, ret) {incLastPostId();}, null, function(req, ret) {incLastPostId();}, null,
function(arg, ret) { function(req, ret) {
var msg = (ret.message) ? ret.message : ret; var msg = (ret.message) ? ret.message : ret;
alert('Ajax error: ' + msg); alert('Ajax error: ' + msg);
}, null }, null
@ -175,7 +175,7 @@ function directMessagesPopup() {
; ;
} }
function openDmWithUserModal(dm_screenname) { function openDmWithUserModal(peerAlias) {
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;
@ -184,17 +184,17 @@ function openDmWithUserModal(dm_screenname) {
var modal = openModal({ var modal = openModal({
classAdd: 'directMessages', classAdd: 'directMessages',
content: $('.messages-thread-template').children().clone(true), content: $('.messages-thread-template').children().clone(true),
title: polyglot.t('direct_messages_with', {username: '<span>' + dm_screenname + '</span>'}) title: polyglot.t('direct_messages_with', {username: '<span>' + peerAlias + '</span>'})
}); });
modal.self.attr('data-screen-name', dm_screenname); modal.self.attr('data-screen-name', peerAlias);
if (dm_screenname.length && dm_screenname[0] === '*') if (peerAlias.length && peerAlias[0] === '*')
getGroupChatName(dm_screenname, modal.self.find('.modal-header h3 span')); getGroupChatName(peerAlias, modal.self.find('.modal-header h3 span'));
else else
getFullname(dm_screenname, modal.self.find('.modal-header h3 span')); getFullname(peerAlias, modal.self.find('.modal-header h3 span'));
requestDmConversationModal(modal.self.find('.direct-messages-thread').empty(), dm_screenname); requestDmConversationModal(modal.self.find('.direct-messages-thread').empty(), peerAlias);
$('.dm-form-template').children().clone(true) $('.dm-form-template').children().clone(true)
.addClass('open').appendTo(modal.content).fadeIn('fast'); .addClass('open').appendTo(modal.content).fadeIn('fast');
@ -356,7 +356,7 @@ function openGroupMessagesJoinGroupModal() {
}, {groupAlias: groupAlias}, }, {groupAlias: groupAlias},
function(req, ret) { function(req, ret) {
alert(polyglot.t('Error in \'importprivkey\'', {rpc: ret.message})); alert(polyglot.t('Error in \'importprivkey\'', {rpc: ret.message}));
}, null }
); );
}); });
} }
@ -371,7 +371,7 @@ function groupMsgCreateGroup(description, peersToInvite) {
}, peersToInvite, }, peersToInvite,
function(req, ret) { function(req, ret) {
alert(polyglot.t('error', {error: 'can\'t create group — ' + ret.message})); alert(polyglot.t('error', {error: 'can\'t create group — ' + ret.message}));
}, null }
); );
} }
@ -450,9 +450,7 @@ function groupMsgInviteFormInputSetTextcompleteReq() {
})); }));
}, },
index: 1, index: 1,
replace: function (mention) { replace: function (mention) {return '@' + mention + ' ';}
return '@'+mention+' ';
}
}] }]
} }

Loading…
Cancel
Save