comparison src/plugins/plugin_exp_command_export.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
16 16
17 # You should have received a copy of the GNU Affero General Public License 17 # You should have received a copy of the GNU Affero General Public License
18 # along with this program. If not, see <http://www.gnu.org/licenses/>. 18 # along with this program. If not, see <http://www.gnu.org/licenses/>.
19 19
20 from sat.core.i18n import _ 20 from sat.core.i18n import _
21 from sat.core.constants import Const as C
21 from sat.core.log import getLogger 22 from sat.core.log import getLogger
22 log = getLogger(__name__) 23 log = getLogger(__name__)
23 from twisted.words.protocols.jabber import jid 24 from twisted.words.protocols.jabber import jid
24 from twisted.internet import reactor, protocol 25 from twisted.internet import reactor, protocol
25 26
55 56
56 def connectionMade(self): 57 def connectionMade(self):
57 log.info("connectionMade :)") 58 log.info("connectionMade :)")
58 59
59 def outReceived(self, data): 60 def outReceived(self, data):
60 self.parent.host.sendMessage(self.target, self._clean(data), no_trigger=True, profile_key=self.profile) 61 self.parent.host.messageSend(self.target, {'': self._clean(data)}, no_trigger=True, profile_key=self.profile)
61 62
62 def errReceived(self, data): 63 def errReceived(self, data):
63 self.parent.host.sendMessage(self.target, self._clean(data), no_trigger=True, profile_key=self.profile) 64 self.parent.host.messageSend(self.target, {'': self._clean(data)}, no_trigger=True, profile_key=self.profile)
64 65
65 def processEnded(self, reason): 66 def processEnded(self, reason):
66 log.info (u"process finished: %d" % (reason.value.exitCode,)) 67 log.info (u"process finished: %d" % (reason.value.exitCode,))
67 self.parent.removeProcess(self.target, self) 68 self.parent.removeProcess(self.target, self)
68 69
100 if not processes_set: 101 if not processes_set:
101 del(self.spawned[(entity, process.profile)]) 102 del(self.spawned[(entity, process.profile)])
102 except ValueError: 103 except ValueError:
103 pass 104 pass
104 105
105 def MessageReceivedTrigger(self, message, post_treat, profile): 106 def MessageReceivedTrigger(self, client, message, post_treat):
106 """ Check if source is linked and repeat message, else do nothing """ 107 """ Check if source is linked and repeat message, else do nothing """
107 from_jid = jid.JID(message["from"]) 108 from_jid = jid.JID(message["from"])
108 spawned_key = (from_jid.userhostJID(), profile) 109 spawned_key = (from_jid.userhostJID(), client.profile)
109 try:
110 body = [e for e in message.elements() if e.name == 'body'][0]
111 except IndexError:
112 # do not block message without body (chat state notification...)
113 log.debug("No body element found in message, following normal behaviour")
114 return True
115
116 mess_data = unicode(body) + '\n'
117 110
118 if spawned_key in self.spawned: 111 if spawned_key in self.spawned:
112 try:
113 body = message.elements(C.NS_CLIENT, 'body').next()
114 except StopIteration:
115 # do not block message without body (chat state notification...)
116 return True
117
118 mess_data = unicode(body) + '\n'
119 processes_set = self.spawned[spawned_key] 119 processes_set = self.spawned[spawned_key]
120 _continue = False 120 _continue = False
121 exclusive = False 121 exclusive = False
122 for process in processes_set: 122 for process in processes_set:
123 process.write(mess_data) 123 process.write(mess_data)