# HG changeset patch # User Goffi # Date 1361488550 -3600 # Node ID 6fd1095b2b7b23527f3babe86ba5d63c0424cc65 # Parent a4f6f78f06203e3fb29ea6cde55df2c597aaa5c3 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) diff -r a4f6f78f0620 -r 6fd1095b2b7b src/core/sat_main.py --- 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 diff -r a4f6f78f0620 -r 6fd1095b2b7b src/plugins/plugin_exp_parrot.py --- a/src/plugins/plugin_exp_parrot.py Fri Feb 22 00:11:47 2013 +0100 +++ b/src/plugins/plugin_exp_parrot.py Fri Feb 22 00:15:50 2013 +0100 @@ -94,7 +94,7 @@ linked = _links[from_jid.userhostJID()] - self.host.sendMessage(unicode(linked), msg, None, "auto", profile_key=profile) + self.host._sendMessage(unicode(linked), msg, None, "auto", profile_key=profile) else: warning("No body element found in message, following normal behaviour") diff -r a4f6f78f0620 -r 6fd1095b2b7b src/plugins/plugin_misc_smtp.py --- a/src/plugins/plugin_misc_smtp.py Fri Feb 22 00:11:47 2013 +0100 +++ b/src/plugins/plugin_misc_smtp.py Fri Feb 22 00:15:50 2013 +0100 @@ -90,7 +90,7 @@ """handle end of message""" mail = Parser().parsestr("\n".join(self.message)) try: - self.host.sendMessage(parseaddr(mail['to'].decode('utf-8', 'replace'))[1], mail.get_payload().decode('utf-8', 'replace'), # TODO: manage other charsets + self.host._sendMessage(parseaddr(mail['to'].decode('utf-8', 'replace'))[1], mail.get_payload().decode('utf-8', 'replace'), # TODO: manage other charsets subject=mail['subject'].decode('utf-8', 'replace'), mess_type='normal', profile_key=self.profile) except: exc_type, exc_value, exc_traceback = sys.exc_info()