ability to forward unread messages through adhoc commands. fixes #1910
This commit is contained in:
parent
7abaabc4b8
commit
12bb72059f
|
@ -236,12 +236,42 @@ class LeaveGroupchatsCommand(AdHocCommand):
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
|
||||||
|
class ForwardMessagesCommand(AdHocCommand):
|
||||||
|
# http://www.xmpp.org/extensions/xep-0146.html#forward
|
||||||
|
commandnode = 'forward-messages'
|
||||||
|
commandname = _('Forward unread messages')
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def isVisibleFor(samejid):
|
||||||
|
''' Change status is visible only if the entity has the same bare jid. '''
|
||||||
|
return samejid
|
||||||
|
|
||||||
|
def execute(self, request):
|
||||||
|
account = self.connection.name
|
||||||
|
# Forward messages
|
||||||
|
events = gajim.events.get_events(account, types=['chat', 'normal'])
|
||||||
|
j, resource = gajim.get_room_and_nick_from_fjid(self.jid)
|
||||||
|
for jid in events:
|
||||||
|
for event in events[jid]:
|
||||||
|
self.connection.send_message(j, event.parameters[0], '',
|
||||||
|
type=event.type_, subject=event.parameters[1],
|
||||||
|
resource=resource, forward_from=jid)
|
||||||
|
|
||||||
|
# Inform other client of completion
|
||||||
|
response, cmd = self.buildResponse(request, status = 'completed')
|
||||||
|
cmd.addChild('note', {}, _('All unread messages have been forwarded.'))
|
||||||
|
|
||||||
|
self.connection.connection.send(response)
|
||||||
|
|
||||||
|
return False # finish the session
|
||||||
|
|
||||||
class ConnectionCommands:
|
class ConnectionCommands:
|
||||||
''' This class depends on that it is a part of Connection() class. '''
|
''' This class depends on that it is a part of Connection() class. '''
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
# a list of all commands exposed: node -> command class
|
# a list of all commands exposed: node -> command class
|
||||||
self.__commands = {}
|
self.__commands = {}
|
||||||
for cmdobj in (ChangeStatusCommand, LeaveGroupchatsCommand):
|
for cmdobj in (ChangeStatusCommand, ForwardMessagesCommand,
|
||||||
|
LeaveGroupchatsCommand):
|
||||||
self.__commands[cmdobj.commandnode] = cmdobj
|
self.__commands[cmdobj.commandnode] = cmdobj
|
||||||
|
|
||||||
# a list of sessions; keys are tuples (jid, sessionid, node)
|
# a list of sessions; keys are tuples (jid, sessionid, node)
|
||||||
|
|
|
@ -808,7 +808,7 @@ class Connection(ConnectionHandlers):
|
||||||
|
|
||||||
def send_message(self, jid, msg, keyID, type = 'chat', subject='',
|
def send_message(self, jid, msg, keyID, type = 'chat', subject='',
|
||||||
chatstate = None, msg_id = None, composing_xep = None, resource = None,
|
chatstate = None, msg_id = None, composing_xep = None, resource = None,
|
||||||
user_nick = None, xhtml = None):
|
user_nick = None, xhtml = None, forward_from = None):
|
||||||
if not self.connection:
|
if not self.connection:
|
||||||
return 1
|
return 1
|
||||||
if msg and not xhtml and gajim.config.get('rst_formatting_outgoing_messages'):
|
if msg and not xhtml and gajim.config.get('rst_formatting_outgoing_messages'):
|
||||||
|
@ -877,21 +877,27 @@ class Connection(ConnectionHandlers):
|
||||||
if chatstate is 'composing' or msgtxt:
|
if chatstate is 'composing' or msgtxt:
|
||||||
chatstate_node.addChild(name = 'composing')
|
chatstate_node.addChild(name = 'composing')
|
||||||
|
|
||||||
|
if forward_from:
|
||||||
|
addresses = msg_iq.addChild('addresses',
|
||||||
|
namespace=common.xmpp.NS_ADDRESS)
|
||||||
|
addresses.addChild('address', attrs = {'type': 'ofrom',
|
||||||
|
'jid': forward_from})
|
||||||
self.connection.send(msg_iq)
|
self.connection.send(msg_iq)
|
||||||
no_log_for = gajim.config.get_per('accounts', self.name, 'no_log_for')\
|
if not forward_from:
|
||||||
.split()
|
no_log_for = gajim.config.get_per('accounts', self.name, 'no_log_for')\
|
||||||
ji = gajim.get_jid_without_resource(jid)
|
.split()
|
||||||
if self.name not in no_log_for and ji not in no_log_for:
|
ji = gajim.get_jid_without_resource(jid)
|
||||||
log_msg = msg
|
if self.name not in no_log_for and ji not in no_log_for:
|
||||||
if subject:
|
log_msg = msg
|
||||||
log_msg = _('Subject: %s\n%s') % (subject, msg)
|
if subject:
|
||||||
if log_msg:
|
log_msg = _('Subject: %s\n%s') % (subject, msg)
|
||||||
if type == 'chat':
|
if log_msg:
|
||||||
kind = 'chat_msg_sent'
|
if type == 'chat':
|
||||||
else:
|
kind = 'chat_msg_sent'
|
||||||
kind = 'single_msg_sent'
|
else:
|
||||||
gajim.logger.write(kind, jid, log_msg)
|
kind = 'single_msg_sent'
|
||||||
self.dispatch('MSGSENT', (jid, msg, keyID))
|
gajim.logger.write(kind, jid, log_msg)
|
||||||
|
self.dispatch('MSGSENT', (jid, msg, keyID))
|
||||||
|
|
||||||
def send_stanza(self, stanza):
|
def send_stanza(self, stanza):
|
||||||
''' send a stanza untouched '''
|
''' send a stanza untouched '''
|
||||||
|
|
|
@ -1427,6 +1427,12 @@ class ConnectionHandlers(ConnectionVcard, ConnectionBytestream, ConnectionDisco,
|
||||||
tim = localtime(timegm(tim))
|
tim = localtime(timegm(tim))
|
||||||
frm = helpers.get_full_jid_from_iq(msg)
|
frm = helpers.get_full_jid_from_iq(msg)
|
||||||
jid = helpers.get_jid_from_iq(msg)
|
jid = helpers.get_jid_from_iq(msg)
|
||||||
|
addressTag = msg.getTag('addresses', namespace = common.xmpp.NS_ADDRESS)
|
||||||
|
if addressTag:
|
||||||
|
address = addressTag.getTag('address', attrs={'type': 'ofrom'})
|
||||||
|
if address:
|
||||||
|
frm = address.getAttr('jid')
|
||||||
|
jid = gajim.get_jid_without_resource(frm)
|
||||||
no_log_for = gajim.config.get_per('accounts', self.name,
|
no_log_for = gajim.config.get_per('accounts', self.name,
|
||||||
'no_log_for')
|
'no_log_for')
|
||||||
if not no_log_for:
|
if not no_log_for:
|
||||||
|
|
Loading…
Reference in New Issue