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)
This commit is contained in:
parent
dfe67edc26
commit
d339e79b1c
1 changed files with 14 additions and 9 deletions
|
|
@ -125,7 +125,7 @@ class SAT(service.Service):
|
|||
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 @@ class SAT(service.Service):
|
|||
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 @@ class SAT(service.Service):
|
|||
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 @@ class SAT(service.Service):
|
|||
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
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue