comparison src/core/sat_main.py @ 636:7ea6d5a86e58

plugin XEP-0085: Chat State Notifications - new "options" parameter to send chat states - plugin command export: messages without body are now delivered (since all the chat states other than "active" need them)
author souliane <souliane@mailoo.org>
date Thu, 05 Sep 2013 20:48:47 +0200
parents d207c2186519
children 49587e170f53
comparison
equal deleted inserted replaced
635:eff8772fd472 636:7ea6d5a86e58
467 for conf_id in client._waiting_conf: 467 for conf_id in client._waiting_conf:
468 conf_type, data = client._waiting_conf[conf_id][:2] 468 conf_type, data = client._waiting_conf[conf_id][:2]
469 ret.append((conf_id, conf_type, data)) 469 ret.append((conf_id, conf_type, data))
470 return ret 470 return ret
471 471
472 def _sendMessage(self, to_s, msg, subject=None, mess_type='auto', profile_key='@NONE@'): 472 def _sendMessage(self, to_s, msg, subject=None, mess_type='auto', options={}, profile_key='@NONE@'):
473 to_jid = jid.JID(to_s) 473 to_jid = jid.JID(to_s)
474 self.sendMessage(to_jid, msg, subject, mess_type, profile_key=profile_key) 474 self.sendMessage(to_jid, msg, subject, mess_type, options=options, profile_key=profile_key)
475 475
476 def sendMessage(self, to_jid, msg, subject=None, mess_type='auto', no_trigger = False, profile_key='@NONE@'): 476 def sendMessage(self, to_jid, msg, subject=None, mess_type='auto', options={}, no_trigger=False, profile_key='@NONE@'):
477 #FIXME: check validity of recipient 477 #FIXME: check validity of recipient
478 profile = self.memory.getProfileName(profile_key) 478 profile = self.memory.getProfileName(profile_key)
479 assert(profile) 479 assert(profile)
480 client = self.profiles[profile] 480 client = self.profiles[profile]
481 current_jid = client.jid 481 current_jid = client.jid
482 if options is None:
483 options = {}
482 mess_data = { # we put data in a dict, so trigger methods can change them 484 mess_data = { # we put data in a dict, so trigger methods can change them
483 "to": to_jid, 485 "to": to_jid,
484 "message": msg, 486 "message": msg,
485 "subject": subject, 487 "subject": subject,
486 "type": mess_type 488 "type": mess_type,
489 "options": options,
487 } 490 }
488 491
489 if mess_data["type"] == "auto": 492 if mess_data["type"] == "auto":
490 # we try to guess the type 493 # we try to guess the type
491 if mess_data["subject"]: 494 if mess_data["subject"]:
515 message["to"] = mess_data["to"].full() 518 message["to"] = mess_data["to"].full()
516 message["from"] = current_jid.full() 519 message["from"] = current_jid.full()
517 message["type"] = mess_data["type"] 520 message["type"] = mess_data["type"]
518 if mess_data["subject"]: 521 if mess_data["subject"]:
519 message.addElement("subject", None, subject) 522 message.addElement("subject", None, subject)
520 message.addElement("body", None, mess_data["message"]) 523 # message without body are used to send chat states
524 if mess_data["message"]:
525 message.addElement("body", None, mess_data["message"])
526 if not no_trigger:
527 if not self.trigger.point("sendMessageXml", message,
528 mess_data, profile):
529 return
521 client.xmlstream.send(message) 530 client.xmlstream.send(message)
522 if mess_data["type"] != "groupchat": 531 if mess_data["type"] != "groupchat":
523 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 532 # we don't add groupchat message to history, as we get them back
524 # and they will be added then 533 # and they will be added then
525 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 534 self.memory.addToHistory(current_jid, mess_data['to'],
535 unicode(mess_data["message"]),
536 unicode(mess_data["type"]),
537 profile=profile)
538 # We send back the message, so all clients are aware of it
539 if mess_data["message"]:
540 self.bridge.newMessage(message['from'],
541 unicode(mess_data["message"]),
542 mess_type=mess_data["type"],
543 to_jid=message['to'], extra={},
544 profile=profile)
526 545
527 def setPresence(self, to="", show="", priority=0, statuses={}, profile_key='@DEFAULT@'): 546 def setPresence(self, to="", show="", priority=0, statuses={}, profile_key='@DEFAULT@'):
528 """Send our presence information""" 547 """Send our presence information"""
529 profile = self.memory.getProfileName(profile_key) 548 profile = self.memory.getProfileName(profile_key)
530 assert(profile) 549 assert(profile)