ability to forward unread messages through adhoc commands. fixes #1910

This commit is contained in:
Yann Leboulanger 2007-06-23 19:44:09 +00:00
parent 7abaabc4b8
commit 12bb72059f
3 changed files with 58 additions and 16 deletions

View File

@ -236,12 +236,42 @@ class LeaveGroupchatsCommand(AdHocCommand):
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:
''' This class depends on that it is a part of Connection() class. '''
def __init__(self):
# a list of all commands exposed: node -> command class
self.__commands = {}
for cmdobj in (ChangeStatusCommand, LeaveGroupchatsCommand):
for cmdobj in (ChangeStatusCommand, ForwardMessagesCommand,
LeaveGroupchatsCommand):
self.__commands[cmdobj.commandnode] = cmdobj
# a list of sessions; keys are tuples (jid, sessionid, node)

View File

@ -808,7 +808,7 @@ class Connection(ConnectionHandlers):
def send_message(self, jid, msg, keyID, type = 'chat', subject='',
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:
return 1
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:
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)
no_log_for = gajim.config.get_per('accounts', self.name, 'no_log_for')\
.split()
ji = gajim.get_jid_without_resource(jid)
if self.name not in no_log_for and ji not in no_log_for:
log_msg = msg
if subject:
log_msg = _('Subject: %s\n%s') % (subject, msg)
if log_msg:
if type == 'chat':
kind = 'chat_msg_sent'
else:
kind = 'single_msg_sent'
gajim.logger.write(kind, jid, log_msg)
self.dispatch('MSGSENT', (jid, msg, keyID))
if not forward_from:
no_log_for = gajim.config.get_per('accounts', self.name, 'no_log_for')\
.split()
ji = gajim.get_jid_without_resource(jid)
if self.name not in no_log_for and ji not in no_log_for:
log_msg = msg
if subject:
log_msg = _('Subject: %s\n%s') % (subject, msg)
if log_msg:
if type == 'chat':
kind = 'chat_msg_sent'
else:
kind = 'single_msg_sent'
gajim.logger.write(kind, jid, log_msg)
self.dispatch('MSGSENT', (jid, msg, keyID))
def send_stanza(self, stanza):
''' send a stanza untouched '''

View File

@ -1427,6 +1427,12 @@ class ConnectionHandlers(ConnectionVcard, ConnectionBytestream, ConnectionDisco,
tim = localtime(timegm(tim))
frm = helpers.get_full_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')
if not no_log_for: