comparison 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
comparison
equal deleted inserted replaced
601:a4f6f78f0620 602:6fd1095b2b7b
123 self.bridge.register("getContactsFromGroup", self.getContactsFromGroup) 123 self.bridge.register("getContactsFromGroup", self.getContactsFromGroup)
124 self.bridge.register("getLastResource", self.memory.getLastResource) 124 self.bridge.register("getLastResource", self.memory.getLastResource)
125 self.bridge.register("getPresenceStatus", self.memory.getPresenceStatus) 125 self.bridge.register("getPresenceStatus", self.memory.getPresenceStatus)
126 self.bridge.register("getWaitingSub", self.memory.getWaitingSub) 126 self.bridge.register("getWaitingSub", self.memory.getWaitingSub)
127 self.bridge.register("getWaitingConf", self.getWaitingConf) 127 self.bridge.register("getWaitingConf", self.getWaitingConf)
128 self.bridge.register("sendMessage", self.sendMessage) 128 self.bridge.register("sendMessage", self._sendMessage)
129 self.bridge.register("getConfig", self.memory.getConfig) 129 self.bridge.register("getConfig", self.memory.getConfig)
130 self.bridge.register("setParam", self.setParam) 130 self.bridge.register("setParam", self.setParam)
131 self.bridge.register("getParamA", self.memory.getStringParamA) 131 self.bridge.register("getParamA", self.memory.getStringParamA)
132 self.bridge.register("asyncGetParamA", self.memory.asyncGetStringParamA) 132 self.bridge.register("asyncGetParamA", self.memory.asyncGetStringParamA)
133 self.bridge.register("getParamsUI", self.memory.getParamsUI) 133 self.bridge.register("getParamsUI", self.memory.getParamsUI)
465 for conf_id in client._waiting_conf: 465 for conf_id in client._waiting_conf:
466 conf_type, data = client._waiting_conf[conf_id][:2] 466 conf_type, data = client._waiting_conf[conf_id][:2]
467 ret.append((conf_id, conf_type, data)) 467 ret.append((conf_id, conf_type, data))
468 return ret 468 return ret
469 469
470 def sendMessage(self, to, msg, subject=None, mess_type='auto', profile_key='@DEFAULT@'): 470 def _sendMessage(self, to_s, msg, subject=None, mess_type='auto', profile_key='@NONE@'):
471 to_jid = jid.JID(to_s)
472 self.sendMessage(to_jid, msg, subject, mess_type, profile_key)
473
474 def sendMessage(self, to_jid, msg, subject=None, mess_type='auto', no_trigger = False, profile_key='@NONE@'):
471 #FIXME: check validity of recipient 475 #FIXME: check validity of recipient
472 profile = self.memory.getProfileName(profile_key) 476 profile = self.memory.getProfileName(profile_key)
473 assert(profile) 477 assert(profile)
474 client = self.profiles[profile] 478 client = self.profiles[profile]
475 current_jid = client.jid 479 current_jid = client.jid
476 mess_data = { # we put data in a dict, so trigger methods can change them 480 mess_data = { # we put data in a dict, so trigger methods can change them
477 "to": jid.JID(to), 481 "to": to_jid,
478 "message": msg, 482 "message": msg,
479 "subject": subject, 483 "subject": subject,
480 "type": mess_type 484 "type": mess_type
481 } 485 }
482 486
498 mess_data["type"] = 'chat' 502 mess_data["type"] = 'chat'
499 else: 503 else:
500 mess_data["type"] == 'chat' 504 mess_data["type"] == 'chat'
501 mess_data["type"] == "chat" if mess_data["subject"] else "normal" 505 mess_data["type"] == "chat" if mess_data["subject"] else "normal"
502 506
503 if not self.trigger.point("sendMessage", mess_data, profile): 507 if not no_trigger:
504 return 508 if not self.trigger.point("sendMessage", mess_data, profile):
505 509 return
506 debug(_("Sending jabber message of type [%(type)s] to %(to)s...") % {"type": mess_data["type"], "to": to}) 510
511 debug(_("Sending jabber message of type [%(type)s] to %(to)s...") % {"type": mess_data["type"], "to": to_jid.full()})
507 message = domish.Element((None, 'message')) 512 message = domish.Element((None, 'message'))
508 message["to"] = mess_data["to"].full() 513 message["to"] = mess_data["to"].full()
509 message["from"] = current_jid.full() 514 message["from"] = current_jid.full()
510 message["type"] = mess_data["type"] 515 message["type"] = mess_data["type"]
511 if mess_data["subject"]: 516 if mess_data["subject"]:
512 message.addElement("subject", None, subject) 517 message.addElement("subject", None, subject)
513 message.addElement("body", None, mess_data["message"]) 518 message.addElement("body", None, mess_data["message"])
514 client.xmlstream.send(message) 519 client.xmlstream.send(message)
515 if mess_data["type"] != "groupchat": 520 if mess_data["type"] != "groupchat":
516 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 521 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
517 # and they will be added then 522 # and they will be added then
518 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 523 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
519 524
520 def setPresence(self, to="", show="", priority=0, statuses={}, profile_key='@DEFAULT@'): 525 def setPresence(self, to="", show="", priority=0, statuses={}, profile_key='@DEFAULT@'):
521 """Send our presence information""" 526 """Send our presence information"""