comparison src/plugins/plugin_xep_0033.py @ 1955:633b5c21aefd

backend, frontend: messages refactoring (huge commit, not finished): /!\ database schema has been modified, do a backup before updating message have been refactored, here are the main changes: - languages are now handled - all messages have an uid (internal to SàT) - message updating is anticipated - subject is now first class - new naming scheme is used newMessage => messageNew, getHistory => historyGet, sendMessage => messageSend - minimal compatibility refactoring in quick_frontend/Primitivus, better refactoring should follow - threads handling - delayed messages are saved into history - info messages may also be saved in history (e.g. to keep track of people joining/leaving a room) - duplicate messages should be avoided - historyGet return messages in right order, no need to sort again - plugins have been updated to follow new features, some of them need to be reworked (e.g. OTR) - XEP-0203 (Delayed Delivery) is now fully handled in core, the plugin just handle disco and creation of a delay element - /!\ jp and Libervia are currently broken, as some features of Primitivus It has been put in one huge commit to avoid breaking messaging between changes. This is the main part of message refactoring, other commits will follow to take profit of the new features/behaviour.
author Goffi <goffi@goffi.org>
date Tue, 24 May 2016 22:11:04 +0200
parents 2daf7b4c6756
children a2bc5089c2eb
comparison
equal deleted inserted replaced
1943:ccfe45302a5c 1955:633b5c21aefd
70 """ 70 """
71 def __init__(self, host): 71 def __init__(self, host):
72 log.info(_("Extended Stanza Addressing plugin initialization")) 72 log.info(_("Extended Stanza Addressing plugin initialization"))
73 self.host = host 73 self.host = host
74 self.internal_data = {} 74 self.internal_data = {}
75 host.trigger.add("sendMessage", self.sendMessageTrigger, trigger.TriggerManager.MIN_PRIORITY) 75 host.trigger.add("messageSend", self.messageSendTrigger, trigger.TriggerManager.MIN_PRIORITY)
76 host.trigger.add("MessageReceived", self.messageReceivedTrigger) 76 host.trigger.add("MessageReceived", self.messageReceivedTrigger)
77 77
78 def sendMessageTrigger(self, mess_data, pre_xml_treatments, post_xml_treatments, profile): 78 def messageSendTrigger(self, client, mess_data, pre_xml_treatments, post_xml_treatments):
79 """Process the XEP-0033 related data to be sent""" 79 """Process the XEP-0033 related data to be sent"""
80 profile = client.profile
80 81
81 def treatment(mess_data): 82 def treatment(mess_data):
82 if not 'address' in mess_data['extra']: 83 if not 'address' in mess_data['extra']:
83 return mess_data 84 return mess_data
84 85
115 # FIXME: for now we duplicate the messages in the history for each recipient, this should change 116 # FIXME: for now we duplicate the messages in the history for each recipient, this should change
116 # FIXME: for now we duplicate the echoes to the sender, this should also change 117 # FIXME: for now we duplicate the echoes to the sender, this should also change
117 Ideas: 118 Ideas:
118 - fix Prosody plugin to check if target server support the feature 119 - fix Prosody plugin to check if target server support the feature
119 - redesign the database to save only one entry to the database 120 - redesign the database to save only one entry to the database
120 - change the newMessage signal to eventually pass more than one recipient 121 - change the messageNew signal to eventually pass more than one recipient
121 """ 122 """
122 def send(mess_data, skip_send=False): 123 def send(mess_data, skip_send=False):
123 client = self.host.profiles[profile] 124 client = self.host.profiles[profile]
124 d = defer.Deferred() 125 d = defer.Deferred()
125 if not skip_send: 126 if not skip_send:
159 d.callback([NS_ADDRESS]) 160 d.callback([NS_ADDRESS])
160 defer_list.append(d) 161 defer_list.append(d)
161 d = defer.Deferred().addCallback(lambda dummy: self.internal_data.pop(timestamp)) 162 d = defer.Deferred().addCallback(lambda dummy: self.internal_data.pop(timestamp))
162 defer.DeferredList(defer_list).chainDeferred(d) 163 defer.DeferredList(defer_list).chainDeferred(d)
163 164
164 def messageReceivedTrigger(self, message, post_treat, profile): 165 def messageReceivedTrigger(self, client, message, post_treat):
165 """In order to save the addressing information in the history""" 166 """In order to save the addressing information in the history"""
166 def post_treat_addr(data, addresses): 167 def post_treat_addr(data, addresses):
167 data['extra']['addresses'] = "" 168 data['extra']['addresses'] = ""
168 for address in addresses: 169 for address in addresses:
169 # Depending how message has been constructed, we could get here 170 # Depending how message has been constructed, we could get here
172 data['extra']['addresses'] += '%s:%s\n' % (address['type'], address['jid']) 173 data['extra']['addresses'] += '%s:%s\n' % (address['type'], address['jid'])
173 return data 174 return data
174 175
175 try: 176 try:
176 addresses = message.elements(NS_ADDRESS, 'addresses').next() 177 addresses = message.elements(NS_ADDRESS, 'addresses').next()
177 post_treat.addCallback(post_treat_addr, addresses.children)
178 except StopIteration: 178 except StopIteration:
179 pass # no addresses 179 pass # no addresses
180 else:
181 post_treat.addCallback(post_treat_addr, addresses.children)
180 return True 182 return True
181 183
182 def getHandler(self, profile): 184 def getHandler(self, profile):
183 return XEP_0033_handler(self, profile) 185 return XEP_0033_handler(self, profile)
184 186