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)
This commit is contained in:
souliane 2013-09-05 20:48:47 +02:00
commit 9cb7071e89

View file

@ -469,21 +469,24 @@ class SAT(service.Service):
ret.append((conf_id, conf_type, data))
return ret
def _sendMessage(self, to_s, msg, subject=None, mess_type='auto', profile_key='@NONE@'):
def _sendMessage(self, to_s, msg, subject=None, mess_type='auto', options={}, profile_key='@NONE@'):
to_jid = jid.JID(to_s)
self.sendMessage(to_jid, msg, subject, mess_type, profile_key=profile_key)
def sendMessage(self, to_jid, msg, subject=None, mess_type='auto', no_trigger = False, profile_key='@NONE@'):
self.sendMessage(to_jid, msg, subject, mess_type, options=options, profile_key=profile_key)
def sendMessage(self, to_jid, msg, subject=None, mess_type='auto', options={}, 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
if options is None:
options = {}
mess_data = { # we put data in a dict, so trigger methods can change them
"to": to_jid,
"message": msg,
"subject": subject,
"type": mess_type
"type": mess_type,
"options": options,
}
if mess_data["type"] == "auto":
@ -517,12 +520,28 @@ class SAT(service.Service):
message["type"] = mess_data["type"]
if mess_data["subject"]:
message.addElement("subject", None, subject)
message.addElement("body", None, mess_data["message"])
# message without body are used to send chat states
if mess_data["message"]:
message.addElement("body", None, mess_data["message"])
if not no_trigger:
if not self.trigger.point("sendMessageXml", message,
mess_data, profile):
return
client.xmlstream.send(message)
if mess_data["type"] != "groupchat":
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
# we don't add groupchat message to history, as we get them back
# and they will be added then
self.memory.addToHistory(current_jid, mess_data['to'],
unicode(mess_data["message"]),
unicode(mess_data["type"]),
profile=profile)
# We send back the message, so all clients are aware of it
if mess_data["message"]:
self.bridge.newMessage(message['from'],
unicode(mess_data["message"]),
mess_type=mess_data["type"],
to_jid=message['to'], extra={},
profile=profile)
def setPresence(self, to="", show="", priority=0, statuses={}, profile_key='@DEFAULT@'):
"""Send our presence information"""