comparison src/plugins/plugin_xep_0085.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 200cd707a46d
comparison
equal deleted inserted replaced
1943:ccfe45302a5c 1955:633b5c21aefd
101 # parameter value is retrieved before each use 101 # parameter value is retrieved before each use
102 host.memory.updateParams(self.params) 102 host.memory.updateParams(self.params)
103 103
104 # triggers from core 104 # triggers from core
105 host.trigger.add("MessageReceived", self.messageReceivedTrigger) 105 host.trigger.add("MessageReceived", self.messageReceivedTrigger)
106 host.trigger.add("sendMessage", self.sendMessageTrigger) 106 host.trigger.add("messageSend", self.messageSendTrigger)
107 host.trigger.add("paramUpdateTrigger", self.paramUpdateTrigger) 107 host.trigger.add("paramUpdateTrigger", self.paramUpdateTrigger)
108 108
109 # args: to_s (jid as string), profile 109 # args: to_s (jid as string), profile
110 host.bridge.addMethod("chatStateComposing", ".plugin", in_sign='ss', 110 host.bridge.addMethod("chatStateComposing", ".plugin", in_sign='ss',
111 out_sign='', method=self.chatStateComposing) 111 out_sign='', method=self.chatStateComposing)
154 if (category, name) == (PARAM_KEY, PARAM_NAME): 154 if (category, name) == (PARAM_KEY, PARAM_NAME):
155 self.updateCache(C.ENTITY_ALL, True if C.bool(value) else DELETE_VALUE, profile=profile) 155 self.updateCache(C.ENTITY_ALL, True if C.bool(value) else DELETE_VALUE, profile=profile)
156 return False 156 return False
157 return True 157 return True
158 158
159 def messageReceivedTrigger(self, message, post_treat, profile): 159 def messageReceivedTrigger(self, client, message, post_treat):
160 """ 160 """
161 Update the entity cache when we receive a message with body. 161 Update the entity cache when we receive a message with body.
162 Check for a chat state in the message and signal frontends. 162 Check for a chat state in the message and signal frontends.
163 """ 163 """
164 profile = client.profile
164 if not self.host.memory.getParamA(PARAM_NAME, PARAM_KEY, profile_key=profile): 165 if not self.host.memory.getParamA(PARAM_NAME, PARAM_KEY, profile_key=profile):
165 return True 166 return True
166 167
167 from_jid = JID(message.getAttribute("from")) 168 from_jid = JID(message.getAttribute("from"))
168 if self._isMUC(from_jid, profile): 169 if self._isMUC(from_jid, profile):
195 if state != 'gone' or message.getAttribute('type') != 'groupchat': 196 if state != 'gone' or message.getAttribute('type') != 'groupchat':
196 self.host.bridge.chatStateReceived(message.getAttribute("from"), state, profile) 197 self.host.bridge.chatStateReceived(message.getAttribute("from"), state, profile)
197 break 198 break
198 return True 199 return True
199 200
200 def sendMessageTrigger(self, mess_data, pre_xml_treatments, post_xml_treatments, profile): 201 def messageSendTrigger(self, client, mess_data, pre_xml_treatments, post_xml_treatments):
201 """ 202 """
202 Eventually add the chat state to the message and initiate 203 Eventually add the chat state to the message and initiate
203 the state machine when sending an "active" state. 204 the state machine when sending an "active" state.
204 """ 205 """
206 profile = client.profile
205 def treatment(mess_data): 207 def treatment(mess_data):
206 message = mess_data['xml'] 208 message = mess_data['xml']
207 to_jid = JID(message.getAttribute("to")) 209 to_jid = JID(message.getAttribute("to"))
208 if not self._checkActivation(to_jid, forceEntityData=True, profile=profile): 210 if not self._checkActivation(to_jid, forceEntityData=True, profile=profile):
209 return mess_data 211 return mess_data
360 if state != self.state and state != "active": 362 if state != self.state and state != "active":
361 if state != 'gone' or self.mess_type != 'groupchat': 363 if state != 'gone' or self.mess_type != 'groupchat':
362 # send a new message without body 364 # send a new message without body
363 log.debug(u"sending state '{state}' to {jid}".format(state=state, jid=self.to_jid.full())) 365 log.debug(u"sending state '{state}' to {jid}".format(state=state, jid=self.to_jid.full()))
364 client = self.host.getClient(self.profile) 366 client = self.host.getClient(self.profile)
365 mess_data = {'message': None, 367 mess_data = {
366 'type': self.mess_type, 368 'from': client.jid,
367 'from': client.jid, 369 'to': self.to_jid,
368 'to': self.to_jid, 370 'uid': '',
369 'subject': None 371 'message': {},
370 } 372 'type': self.mess_type,
373 'subject': {},
374 'extra': {},
375 }
371 self.host.generateMessageXML(mess_data) 376 self.host.generateMessageXML(mess_data)
372 mess_data['xml'].addElement(state, NS_CHAT_STATES) 377 mess_data['xml'].addElement(state, NS_CHAT_STATES)
373 client.xmlstream.send(mess_data['xml']) 378 client.xmlstream.send(mess_data['xml'])
374 379
375 self.state = state 380 self.state = state