Skip to content
Snippets Groups Projects
Commit 25d251b4 authored by Yann Leboulanger's avatar Yann Leboulanger
Browse files

add new ad-hoc command to forward unread messages then disconnect. Thanks Geobert.

parent 3d6f65de
No related branches found
No related tags found
No related merge requests found
...@@ -290,6 +290,41 @@ class ForwardMessagesCommand(AdHocCommand): ...@@ -290,6 +290,41 @@ class ForwardMessagesCommand(AdHocCommand):
return False # finish the session return False # finish the session
class FwdMsgThenDisconnectCommand(AdHocCommand):
commandnode = 'fwd-msd-disconnect'
commandname = _('Forward unread message then disconnect')
@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, delayed=event.time_,
now=True)
response, cmd = self.buildResponse(request, status = 'completed')
cmd.addChild('note', {}, _('The status has been changed.'))
# if going offline, we need to push response so it won't go into
# queue and disappear
self.connection.connection.send(response, now = True)
# send new status
gajim.interface.roster.send_status(self.connection.name, 'offline', '')
# finish the session
return False
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
...@@ -299,7 +334,7 @@ class ConnectionCommands: ...@@ -299,7 +334,7 @@ class ConnectionCommands:
# 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, ForwardMessagesCommand, for cmdobj in (ChangeStatusCommand, ForwardMessagesCommand,
LeaveGroupchatsCommand): LeaveGroupchatsCommand, FwdMsgThenDisconnectCommand):
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)
......
...@@ -1606,11 +1606,12 @@ class Connection(CommonConnection, ConnectionHandlers): ...@@ -1606,11 +1606,12 @@ class Connection(CommonConnection, 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, session=None, forward_from=None, form_node=None, user_nick=None, xhtml=None, session=None, forward_from=None, form_node=None,
original_message=None, delayed=None, callback=None, callback_args=[]): original_message=None, delayed=None, callback=None, callback_args=[],
now=False):
def cb(jid, msg, keyID, forward_from, session, original_message, subject, def cb(jid, msg, keyID, forward_from, session, original_message,
type_, msg_iq): subject, type_, msg_iq):
msg_id = self.connection.send(msg_iq) msg_id = self.connection.send(msg_iq, now=now)
jid = helpers.parse_jid(jid) jid = helpers.parse_jid(jid)
self.dispatch('MSGSENT', (jid, msg, keyID)) self.dispatch('MSGSENT', (jid, msg, keyID))
if callback: if callback:
......
...@@ -310,7 +310,8 @@ class ConnectionZeroconf(CommonConnection, ConnectionHandlersZeroconf): ...@@ -310,7 +310,8 @@ class ConnectionZeroconf(CommonConnection, ConnectionHandlersZeroconf):
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, session=None, forward_from=None, form_node=None, user_nick=None, xhtml=None, session=None, forward_from=None, form_node=None,
original_message=None, delayed=None, callback=None, callback_args=[]): original_message=None, delayed=None, callback=None, callback_args=[],
now=True):
def on_send_ok(msg_id): def on_send_ok(msg_id):
self.dispatch('MSGSENT', (jid, msg, keyID)) self.dispatch('MSGSENT', (jid, msg, keyID))
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment