Mercurial > libervia-backend
diff src/core/sat_main.py @ 602:6fd1095b2b7b
core: sendMessage refactoring:
- sendMessage now use JID instead of unicode, bridge method using unicode is now _sendMessage
- added no_trigger argument, so it's now possible to forbid trigger execution (to avoid any plugin when we send a message)
author | Goffi <goffi@goffi.org> |
---|---|
date | Fri, 22 Feb 2013 00:15:50 +0100 |
parents | d1b4805124a1 |
children | c8b129a3c209 |
line wrap: on
line diff
--- a/src/core/sat_main.py Fri Feb 22 00:11:47 2013 +0100 +++ b/src/core/sat_main.py Fri Feb 22 00:15:50 2013 +0100 @@ -125,7 +125,7 @@ self.bridge.register("getPresenceStatus", self.memory.getPresenceStatus) self.bridge.register("getWaitingSub", self.memory.getWaitingSub) self.bridge.register("getWaitingConf", self.getWaitingConf) - self.bridge.register("sendMessage", self.sendMessage) + self.bridge.register("sendMessage", self._sendMessage) self.bridge.register("getConfig", self.memory.getConfig) self.bridge.register("setParam", self.setParam) self.bridge.register("getParamA", self.memory.getStringParamA) @@ -467,14 +467,18 @@ ret.append((conf_id, conf_type, data)) return ret - def sendMessage(self, to, msg, subject=None, mess_type='auto', profile_key='@DEFAULT@'): + def _sendMessage(self, to_s, msg, subject=None, mess_type='auto', profile_key='@NONE@'): + to_jid = jid.JID(to_s) + self.sendMessage(to_jid, msg, subject, mess_type, profile_key) + + def sendMessage(self, to_jid, msg, subject=None, mess_type='auto', no_trigger = False, profile_key='@NONE@'): #FIXME: check validity of recipient profile = self.memory.getProfileName(profile_key) assert(profile) client = self.profiles[profile] current_jid = client.jid mess_data = { # we put data in a dict, so trigger methods can change them - "to": jid.JID(to), + "to": to_jid, "message": msg, "subject": subject, "type": mess_type @@ -500,10 +504,11 @@ mess_data["type"] == 'chat' mess_data["type"] == "chat" if mess_data["subject"] else "normal" - if not self.trigger.point("sendMessage", mess_data, profile): - return + if not no_trigger: + if not self.trigger.point("sendMessage", mess_data, profile): + return - debug(_("Sending jabber message of type [%(type)s] to %(to)s...") % {"type": mess_data["type"], "to": to}) + debug(_("Sending jabber message of type [%(type)s] to %(to)s...") % {"type": mess_data["type"], "to": to_jid.full()}) message = domish.Element((None, 'message')) message["to"] = mess_data["to"].full() message["from"] = current_jid.full() @@ -513,7 +518,7 @@ message.addElement("body", None, mess_data["message"]) client.xmlstream.send(message) if mess_data["type"] != "groupchat": - self.memory.addToHistory(current_jid, jid.JID(to), unicode(mess_data["message"]), unicode(mess_data["type"]), profile=profile) # we don't add groupchat message to history, as we get them back + self.memory.addToHistory(current_jid, mess_data['to'], unicode(mess_data["message"]), unicode(mess_data["type"]), profile=profile) # we don't add groupchat message to history, as we get them back # and they will be added then self.bridge.newMessage(message['from'], unicode(mess_data["message"]), mess_type=mess_data["type"], to_jid=message['to'], extra={}, profile=profile) # We send back the message, so all clients are aware of it