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

This commit is contained in:
Yann Leboulanger 2010-04-27 11:31:36 +02:00
parent 3d6f65defb
commit 25d251b455
3 changed files with 43 additions and 6 deletions

View File

@ -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:
# 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)

View File

@ -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:

View File

@ -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))