annotate src/plugins/plugin_xep_0085.py @ 637:3b02554d4c8b

primitivus: chat state implementation for now chat states are displayed in primitivus surrended text (after the contact's name)
author souliane <souliane@mailoo.org>
date Sun, 08 Sep 2013 19:13:02 +0200
parents 7ea6d5a86e58
children 262d9d9ad27a
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
636
7ea6d5a86e58 plugin XEP-0085: Chat State Notifications
souliane <souliane@mailoo.org>
parents:
diff changeset
1 #!/usr/bin/python
7ea6d5a86e58 plugin XEP-0085: Chat State Notifications
souliane <souliane@mailoo.org>
parents:
diff changeset
2 # -*- coding: utf-8 -*-
7ea6d5a86e58 plugin XEP-0085: Chat State Notifications
souliane <souliane@mailoo.org>
parents:
diff changeset
3
7ea6d5a86e58 plugin XEP-0085: Chat State Notifications
souliane <souliane@mailoo.org>
parents:
diff changeset
4 # SAT plugin for Chat State Notifications Protocol (xep-0085)
7ea6d5a86e58 plugin XEP-0085: Chat State Notifications
souliane <souliane@mailoo.org>
parents:
diff changeset
5 # Copyright (C) 2009, 2010, 2011, 2012, 2013 Adrien Cossa (souliane@mailoo.org)
7ea6d5a86e58 plugin XEP-0085: Chat State Notifications
souliane <souliane@mailoo.org>
parents:
diff changeset
6
7ea6d5a86e58 plugin XEP-0085: Chat State Notifications
souliane <souliane@mailoo.org>
parents:
diff changeset
7 # This program is free software: you can redistribute it and/or modify
7ea6d5a86e58 plugin XEP-0085: Chat State Notifications
souliane <souliane@mailoo.org>
parents:
diff changeset
8 # it under the terms of the GNU Affero General Public License as published by
7ea6d5a86e58 plugin XEP-0085: Chat State Notifications
souliane <souliane@mailoo.org>
parents:
diff changeset
9 # the Free Software Foundation, either version 3 of the License, or
7ea6d5a86e58 plugin XEP-0085: Chat State Notifications
souliane <souliane@mailoo.org>
parents:
diff changeset
10 # (at your option) any later version.
7ea6d5a86e58 plugin XEP-0085: Chat State Notifications
souliane <souliane@mailoo.org>
parents:
diff changeset
11
7ea6d5a86e58 plugin XEP-0085: Chat State Notifications
souliane <souliane@mailoo.org>
parents:
diff changeset
12 # This program is distributed in the hope that it will be useful,
7ea6d5a86e58 plugin XEP-0085: Chat State Notifications
souliane <souliane@mailoo.org>
parents:
diff changeset
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
7ea6d5a86e58 plugin XEP-0085: Chat State Notifications
souliane <souliane@mailoo.org>
parents:
diff changeset
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
7ea6d5a86e58 plugin XEP-0085: Chat State Notifications
souliane <souliane@mailoo.org>
parents:
diff changeset
15 # GNU Affero General Public License for more details.
7ea6d5a86e58 plugin XEP-0085: Chat State Notifications
souliane <souliane@mailoo.org>
parents:
diff changeset
16
7ea6d5a86e58 plugin XEP-0085: Chat State Notifications
souliane <souliane@mailoo.org>
parents:
diff changeset
17 # You should have received a copy of the GNU Affero General Public License
7ea6d5a86e58 plugin XEP-0085: Chat State Notifications
souliane <souliane@mailoo.org>
parents:
diff changeset
18 # along with this program. If not, see <http://www.gnu.org/licenses/>.
7ea6d5a86e58 plugin XEP-0085: Chat State Notifications
souliane <souliane@mailoo.org>
parents:
diff changeset
19
7ea6d5a86e58 plugin XEP-0085: Chat State Notifications
souliane <souliane@mailoo.org>
parents:
diff changeset
20 from sat.core import exceptions
7ea6d5a86e58 plugin XEP-0085: Chat State Notifications
souliane <souliane@mailoo.org>
parents:
diff changeset
21 from logging import debug, info, error
7ea6d5a86e58 plugin XEP-0085: Chat State Notifications
souliane <souliane@mailoo.org>
parents:
diff changeset
22 from wokkel import disco, iwokkel
7ea6d5a86e58 plugin XEP-0085: Chat State Notifications
souliane <souliane@mailoo.org>
parents:
diff changeset
23 from zope.interface import implements
7ea6d5a86e58 plugin XEP-0085: Chat State Notifications
souliane <souliane@mailoo.org>
parents:
diff changeset
24 from twisted.words.protocols.jabber.jid import JID
7ea6d5a86e58 plugin XEP-0085: Chat State Notifications
souliane <souliane@mailoo.org>
parents:
diff changeset
25 try:
7ea6d5a86e58 plugin XEP-0085: Chat State Notifications
souliane <souliane@mailoo.org>
parents:
diff changeset
26 from twisted.words.protocols.xmlstream import XMPPHandler
7ea6d5a86e58 plugin XEP-0085: Chat State Notifications
souliane <souliane@mailoo.org>
parents:
diff changeset
27 except ImportError:
7ea6d5a86e58 plugin XEP-0085: Chat State Notifications
souliane <souliane@mailoo.org>
parents:
diff changeset
28 from wokkel.subprotocols import XMPPHandler
7ea6d5a86e58 plugin XEP-0085: Chat State Notifications
souliane <souliane@mailoo.org>
parents:
diff changeset
29 from threading import Timer
7ea6d5a86e58 plugin XEP-0085: Chat State Notifications
souliane <souliane@mailoo.org>
parents:
diff changeset
30 from twisted.words.xish.domish import generateElementsNamed
7ea6d5a86e58 plugin XEP-0085: Chat State Notifications
souliane <souliane@mailoo.org>
parents:
diff changeset
31
7ea6d5a86e58 plugin XEP-0085: Chat State Notifications
souliane <souliane@mailoo.org>
parents:
diff changeset
32 NS_XMPP_CLIENT = "jabber:client"
7ea6d5a86e58 plugin XEP-0085: Chat State Notifications
souliane <souliane@mailoo.org>
parents:
diff changeset
33 NS_CHAT_STATES = "http://jabber.org/protocol/chatstates"
7ea6d5a86e58 plugin XEP-0085: Chat State Notifications
souliane <souliane@mailoo.org>
parents:
diff changeset
34 CHAT_STATES = ["active", "inactive", "gone", "composing", "paused"]
7ea6d5a86e58 plugin XEP-0085: Chat State Notifications
souliane <souliane@mailoo.org>
parents:
diff changeset
35 MESSAGE_TYPES = ["chat", "groupchat"]
7ea6d5a86e58 plugin XEP-0085: Chat State Notifications
souliane <souliane@mailoo.org>
parents:
diff changeset
36 PARAM_KEY = "Chat State Notifications"
7ea6d5a86e58 plugin XEP-0085: Chat State Notifications
souliane <souliane@mailoo.org>
parents:
diff changeset
37 PARAM_NAME = "Enabled"
7ea6d5a86e58 plugin XEP-0085: Chat State Notifications
souliane <souliane@mailoo.org>
parents:
diff changeset
38
7ea6d5a86e58 plugin XEP-0085: Chat State Notifications
souliane <souliane@mailoo.org>
parents:
diff changeset
39 PLUGIN_INFO = {
7ea6d5a86e58 plugin XEP-0085: Chat State Notifications
souliane <souliane@mailoo.org>
parents:
diff changeset
40 "name": "Chat State Notifications Protocol Plugin",
7ea6d5a86e58 plugin XEP-0085: Chat State Notifications
souliane <souliane@mailoo.org>
parents:
diff changeset
41 "import_name": "XEP-0085",
7ea6d5a86e58 plugin XEP-0085: Chat State Notifications
souliane <souliane@mailoo.org>
parents:
diff changeset
42 "type": "XEP",
7ea6d5a86e58 plugin XEP-0085: Chat State Notifications
souliane <souliane@mailoo.org>
parents:
diff changeset
43 "protocols": ["XEP-0085"],
7ea6d5a86e58 plugin XEP-0085: Chat State Notifications
souliane <souliane@mailoo.org>
parents:
diff changeset
44 "dependencies": [],
7ea6d5a86e58 plugin XEP-0085: Chat State Notifications
souliane <souliane@mailoo.org>
parents:
diff changeset
45 "main": "XEP_0085",
7ea6d5a86e58 plugin XEP-0085: Chat State Notifications
souliane <souliane@mailoo.org>
parents:
diff changeset
46 "handler": "yes",
7ea6d5a86e58 plugin XEP-0085: Chat State Notifications
souliane <souliane@mailoo.org>
parents:
diff changeset
47 "description": _("""Implementation of Chat State Notifications Protocol""")
7ea6d5a86e58 plugin XEP-0085: Chat State Notifications
souliane <souliane@mailoo.org>
parents:
diff changeset
48 }
7ea6d5a86e58 plugin XEP-0085: Chat State Notifications
souliane <souliane@mailoo.org>
parents:
diff changeset
49
7ea6d5a86e58 plugin XEP-0085: Chat State Notifications
souliane <souliane@mailoo.org>
parents:
diff changeset
50
7ea6d5a86e58 plugin XEP-0085: Chat State Notifications
souliane <souliane@mailoo.org>
parents:
diff changeset
51 # Describe the internal transitions that are triggered
7ea6d5a86e58 plugin XEP-0085: Chat State Notifications
souliane <souliane@mailoo.org>
parents:
diff changeset
52 # by a timer. Beside that, external transitions can be
7ea6d5a86e58 plugin XEP-0085: Chat State Notifications
souliane <souliane@mailoo.org>
parents:
diff changeset
53 # runned to target the states "active" or "composing".
7ea6d5a86e58 plugin XEP-0085: Chat State Notifications
souliane <souliane@mailoo.org>
parents:
diff changeset
54 # Delay is specified here in seconds.
7ea6d5a86e58 plugin XEP-0085: Chat State Notifications
souliane <souliane@mailoo.org>
parents:
diff changeset
55 TRANSITIONS = {
7ea6d5a86e58 plugin XEP-0085: Chat State Notifications
souliane <souliane@mailoo.org>
parents:
diff changeset
56 "active": {"next_state": "inactive", "delay": 120},
7ea6d5a86e58 plugin XEP-0085: Chat State Notifications
souliane <souliane@mailoo.org>
parents:
diff changeset
57 "inactive": {"next_state": "gone", "delay": 480},
7ea6d5a86e58 plugin XEP-0085: Chat State Notifications
souliane <souliane@mailoo.org>
parents:
diff changeset
58 "gone": {"next_state": "", "delay": 0},
7ea6d5a86e58 plugin XEP-0085: Chat State Notifications
souliane <souliane@mailoo.org>
parents:
diff changeset
59 "composing": {"next_state": "paused", "delay": 30},
7ea6d5a86e58 plugin XEP-0085: Chat State Notifications
souliane <souliane@mailoo.org>
parents:
diff changeset
60 "paused": {"next_state": "inactive", "delay": 450}
7ea6d5a86e58 plugin XEP-0085: Chat State Notifications
souliane <souliane@mailoo.org>
parents:
diff changeset
61 }
7ea6d5a86e58 plugin XEP-0085: Chat State Notifications
souliane <souliane@mailoo.org>
parents:
diff changeset
62
7ea6d5a86e58 plugin XEP-0085: Chat State Notifications
souliane <souliane@mailoo.org>
parents:
diff changeset
63
7ea6d5a86e58 plugin XEP-0085: Chat State Notifications
souliane <souliane@mailoo.org>
parents:
diff changeset
64 class UnknownChatStateException(Exception):
7ea6d5a86e58 plugin XEP-0085: Chat State Notifications
souliane <souliane@mailoo.org>
parents:
diff changeset
65 """
7ea6d5a86e58 plugin XEP-0085: Chat State Notifications
souliane <souliane@mailoo.org>
parents:
diff changeset
66 This error is raised when an unknown chat state is used.
7ea6d5a86e58 plugin XEP-0085: Chat State Notifications
souliane <souliane@mailoo.org>
parents:
diff changeset
67 """
7ea6d5a86e58 plugin XEP-0085: Chat State Notifications
souliane <souliane@mailoo.org>
parents:
diff changeset
68 pass
7ea6d5a86e58 plugin XEP-0085: Chat State Notifications
souliane <souliane@mailoo.org>
parents:
diff changeset
69
7ea6d5a86e58 plugin XEP-0085: Chat State Notifications
souliane <souliane@mailoo.org>
parents:
diff changeset
70
7ea6d5a86e58 plugin XEP-0085: Chat State Notifications
souliane <souliane@mailoo.org>
parents:
diff changeset
71 class XEP_0085(object):
7ea6d5a86e58 plugin XEP-0085: Chat State Notifications
souliane <souliane@mailoo.org>
parents:
diff changeset
72 """
7ea6d5a86e58 plugin XEP-0085: Chat State Notifications
souliane <souliane@mailoo.org>
parents:
diff changeset
73 Implementation for XEP 0085
7ea6d5a86e58 plugin XEP-0085: Chat State Notifications
souliane <souliane@mailoo.org>
parents:
diff changeset
74 """
7ea6d5a86e58 plugin XEP-0085: Chat State Notifications
souliane <souliane@mailoo.org>
parents:
diff changeset
75 params = """
7ea6d5a86e58 plugin XEP-0085: Chat State Notifications
souliane <souliane@mailoo.org>
parents:
diff changeset
76 <params>
7ea6d5a86e58 plugin XEP-0085: Chat State Notifications
souliane <souliane@mailoo.org>
parents:
diff changeset
77 <individual>
7ea6d5a86e58 plugin XEP-0085: Chat State Notifications
souliane <souliane@mailoo.org>
parents:
diff changeset
78 <category name="%(category_name)s" label="%(category_label)s">
7ea6d5a86e58 plugin XEP-0085: Chat State Notifications
souliane <souliane@mailoo.org>
parents:
diff changeset
79 <param name="%(param_name)s" label="%(param_label)s" value="true" type="bool" security="0"/>
7ea6d5a86e58 plugin XEP-0085: Chat State Notifications
souliane <souliane@mailoo.org>
parents:
diff changeset
80 </category>
7ea6d5a86e58 plugin XEP-0085: Chat State Notifications
souliane <souliane@mailoo.org>
parents:
diff changeset
81 </individual>
7ea6d5a86e58 plugin XEP-0085: Chat State Notifications
souliane <souliane@mailoo.org>
parents:
diff changeset
82 </params>
7ea6d5a86e58 plugin XEP-0085: Chat State Notifications
souliane <souliane@mailoo.org>
parents:
diff changeset
83 """ % {
7ea6d5a86e58 plugin XEP-0085: Chat State Notifications
souliane <souliane@mailoo.org>
parents:
diff changeset
84 'category_name': PARAM_KEY,
7ea6d5a86e58 plugin XEP-0085: Chat State Notifications
souliane <souliane@mailoo.org>
parents:
diff changeset
85 'category_label': _(PARAM_KEY),
7ea6d5a86e58 plugin XEP-0085: Chat State Notifications
souliane <souliane@mailoo.org>
parents:
diff changeset
86 'param_name': PARAM_NAME,
7ea6d5a86e58 plugin XEP-0085: Chat State Notifications
souliane <souliane@mailoo.org>
parents:
diff changeset
87 'param_label': _('Enable chat state notifications')
7ea6d5a86e58 plugin XEP-0085: Chat State Notifications
souliane <souliane@mailoo.org>
parents:
diff changeset
88 }
7ea6d5a86e58 plugin XEP-0085: Chat State Notifications
souliane <souliane@mailoo.org>
parents:
diff changeset
89
7ea6d5a86e58 plugin XEP-0085: Chat State Notifications
souliane <souliane@mailoo.org>
parents:
diff changeset
90 def __init__(self, host):
7ea6d5a86e58 plugin XEP-0085: Chat State Notifications
souliane <souliane@mailoo.org>
parents:
diff changeset
91 info(_("CSN plugin initialization"))
7ea6d5a86e58 plugin XEP-0085: Chat State Notifications
souliane <souliane@mailoo.org>
parents:
diff changeset
92 self.host = host
7ea6d5a86e58 plugin XEP-0085: Chat State Notifications
souliane <souliane@mailoo.org>
parents:
diff changeset
93
7ea6d5a86e58 plugin XEP-0085: Chat State Notifications
souliane <souliane@mailoo.org>
parents:
diff changeset
94 # parameter value is retrieved before each use
7ea6d5a86e58 plugin XEP-0085: Chat State Notifications
souliane <souliane@mailoo.org>
parents:
diff changeset
95 host.memory.importParams(self.params)
7ea6d5a86e58 plugin XEP-0085: Chat State Notifications
souliane <souliane@mailoo.org>
parents:
diff changeset
96
7ea6d5a86e58 plugin XEP-0085: Chat State Notifications
souliane <souliane@mailoo.org>
parents:
diff changeset
97 # triggers from core
7ea6d5a86e58 plugin XEP-0085: Chat State Notifications
souliane <souliane@mailoo.org>
parents:
diff changeset
98 host.trigger.add("MessageReceived", self.messageReceivedTrigger)
7ea6d5a86e58 plugin XEP-0085: Chat State Notifications
souliane <souliane@mailoo.org>
parents:
diff changeset
99 host.trigger.add("sendMessageXml", self.sendMessageXmlTrigger)
7ea6d5a86e58 plugin XEP-0085: Chat State Notifications
souliane <souliane@mailoo.org>
parents:
diff changeset
100 host.trigger.add("paramUpdateTrigger", self.paramUpdateTrigger)
7ea6d5a86e58 plugin XEP-0085: Chat State Notifications
souliane <souliane@mailoo.org>
parents:
diff changeset
101 #TODO: handle profile disconnexion (free memory in entity data)
7ea6d5a86e58 plugin XEP-0085: Chat State Notifications
souliane <souliane@mailoo.org>
parents:
diff changeset
102
7ea6d5a86e58 plugin XEP-0085: Chat State Notifications
souliane <souliane@mailoo.org>
parents:
diff changeset
103 # args: to_s (jid as string), profile
7ea6d5a86e58 plugin XEP-0085: Chat State Notifications
souliane <souliane@mailoo.org>
parents:
diff changeset
104 host.bridge.addMethod("chatStateComposing", ".plugin", in_sign='ss',
7ea6d5a86e58 plugin XEP-0085: Chat State Notifications
souliane <souliane@mailoo.org>
parents:
diff changeset
105 out_sign='', method=self.chatStateComposing)
7ea6d5a86e58 plugin XEP-0085: Chat State Notifications
souliane <souliane@mailoo.org>
parents:
diff changeset
106
7ea6d5a86e58 plugin XEP-0085: Chat State Notifications
souliane <souliane@mailoo.org>
parents:
diff changeset
107 # args: from (jid as string), state in CHAT_STATES, profile
7ea6d5a86e58 plugin XEP-0085: Chat State Notifications
souliane <souliane@mailoo.org>
parents:
diff changeset
108 host.bridge.addSignal("chatStateReceived", ".plugin", signature='sss')
7ea6d5a86e58 plugin XEP-0085: Chat State Notifications
souliane <souliane@mailoo.org>
parents:
diff changeset
109
7ea6d5a86e58 plugin XEP-0085: Chat State Notifications
souliane <souliane@mailoo.org>
parents:
diff changeset
110 def getHandler(self, profile):
7ea6d5a86e58 plugin XEP-0085: Chat State Notifications
souliane <souliane@mailoo.org>
parents:
diff changeset
111 return XEP_0085_handler(self, profile)
7ea6d5a86e58 plugin XEP-0085: Chat State Notifications
souliane <souliane@mailoo.org>
parents:
diff changeset
112
7ea6d5a86e58 plugin XEP-0085: Chat State Notifications
souliane <souliane@mailoo.org>
parents:
diff changeset
113 def updateEntityData(self, entity_jid, value, profile):
7ea6d5a86e58 plugin XEP-0085: Chat State Notifications
souliane <souliane@mailoo.org>
parents:
diff changeset
114 """
7ea6d5a86e58 plugin XEP-0085: Chat State Notifications
souliane <souliane@mailoo.org>
parents:
diff changeset
115 Update the entity data and reset the chat state display
7ea6d5a86e58 plugin XEP-0085: Chat State Notifications
souliane <souliane@mailoo.org>
parents:
diff changeset
116 if the notification has been disabled. Parameter "entity_jid"
7ea6d5a86e58 plugin XEP-0085: Chat State Notifications
souliane <souliane@mailoo.org>
parents:
diff changeset
117 could be @ALL@ to update all entities.
7ea6d5a86e58 plugin XEP-0085: Chat State Notifications
souliane <souliane@mailoo.org>
parents:
diff changeset
118 """
7ea6d5a86e58 plugin XEP-0085: Chat State Notifications
souliane <souliane@mailoo.org>
parents:
diff changeset
119 self.host.memory.updateEntityData(entity_jid, PARAM_KEY, value, profile)
7ea6d5a86e58 plugin XEP-0085: Chat State Notifications
souliane <souliane@mailoo.org>
parents:
diff changeset
120 if not value or value == "@NONE@":
7ea6d5a86e58 plugin XEP-0085: Chat State Notifications
souliane <souliane@mailoo.org>
parents:
diff changeset
121 # disable chat state for this or these contact(s)
7ea6d5a86e58 plugin XEP-0085: Chat State Notifications
souliane <souliane@mailoo.org>
parents:
diff changeset
122 self.host.bridge.chatStateReceived(unicode(entity_jid), "", profile)
7ea6d5a86e58 plugin XEP-0085: Chat State Notifications
souliane <souliane@mailoo.org>
parents:
diff changeset
123
7ea6d5a86e58 plugin XEP-0085: Chat State Notifications
souliane <souliane@mailoo.org>
parents:
diff changeset
124 def paramUpdateTrigger(self, name, value, category, type, profile):
7ea6d5a86e58 plugin XEP-0085: Chat State Notifications
souliane <souliane@mailoo.org>
parents:
diff changeset
125 """
7ea6d5a86e58 plugin XEP-0085: Chat State Notifications
souliane <souliane@mailoo.org>
parents:
diff changeset
126 Reset all the existing chat state entity data associated
7ea6d5a86e58 plugin XEP-0085: Chat State Notifications
souliane <souliane@mailoo.org>
parents:
diff changeset
127 with this profile after a parameter modification (value
7ea6d5a86e58 plugin XEP-0085: Chat State Notifications
souliane <souliane@mailoo.org>
parents:
diff changeset
128 different then "true" would delete the entity data).
7ea6d5a86e58 plugin XEP-0085: Chat State Notifications
souliane <souliane@mailoo.org>
parents:
diff changeset
129 """
7ea6d5a86e58 plugin XEP-0085: Chat State Notifications
souliane <souliane@mailoo.org>
parents:
diff changeset
130 if (category, name) == (PARAM_KEY, PARAM_NAME):
7ea6d5a86e58 plugin XEP-0085: Chat State Notifications
souliane <souliane@mailoo.org>
parents:
diff changeset
131 self.updateEntityData("@ALL@", True if value == "true" else "@NONE@", profile)
7ea6d5a86e58 plugin XEP-0085: Chat State Notifications
souliane <souliane@mailoo.org>
parents:
diff changeset
132
7ea6d5a86e58 plugin XEP-0085: Chat State Notifications
souliane <souliane@mailoo.org>
parents:
diff changeset
133 def messageReceivedTrigger(self, message, profile):
7ea6d5a86e58 plugin XEP-0085: Chat State Notifications
souliane <souliane@mailoo.org>
parents:
diff changeset
134 """
7ea6d5a86e58 plugin XEP-0085: Chat State Notifications
souliane <souliane@mailoo.org>
parents:
diff changeset
135 Update the entity cache when we receive a message with body.
7ea6d5a86e58 plugin XEP-0085: Chat State Notifications
souliane <souliane@mailoo.org>
parents:
diff changeset
136 Check for a check state in the incoming message and broadcast signal.
7ea6d5a86e58 plugin XEP-0085: Chat State Notifications
souliane <souliane@mailoo.org>
parents:
diff changeset
137 """
7ea6d5a86e58 plugin XEP-0085: Chat State Notifications
souliane <souliane@mailoo.org>
parents:
diff changeset
138 if not self.host.memory.getParamA(PARAM_NAME, PARAM_KEY, profile_key=profile):
7ea6d5a86e58 plugin XEP-0085: Chat State Notifications
souliane <souliane@mailoo.org>
parents:
diff changeset
139 return True
7ea6d5a86e58 plugin XEP-0085: Chat State Notifications
souliane <souliane@mailoo.org>
parents:
diff changeset
140
7ea6d5a86e58 plugin XEP-0085: Chat State Notifications
souliane <souliane@mailoo.org>
parents:
diff changeset
141 try:
7ea6d5a86e58 plugin XEP-0085: Chat State Notifications
souliane <souliane@mailoo.org>
parents:
diff changeset
142 generateElementsNamed(message.children, name="body").next()
7ea6d5a86e58 plugin XEP-0085: Chat State Notifications
souliane <souliane@mailoo.org>
parents:
diff changeset
143 from_jid = JID(message.getAttribute("from"))
7ea6d5a86e58 plugin XEP-0085: Chat State Notifications
souliane <souliane@mailoo.org>
parents:
diff changeset
144 try:
7ea6d5a86e58 plugin XEP-0085: Chat State Notifications
souliane <souliane@mailoo.org>
parents:
diff changeset
145 generateElementsNamed(message.children, name="active").next()
7ea6d5a86e58 plugin XEP-0085: Chat State Notifications
souliane <souliane@mailoo.org>
parents:
diff changeset
146 # contact enabled Chat State Notifications
7ea6d5a86e58 plugin XEP-0085: Chat State Notifications
souliane <souliane@mailoo.org>
parents:
diff changeset
147 self.updateEntityData(from_jid, True, profile)
7ea6d5a86e58 plugin XEP-0085: Chat State Notifications
souliane <souliane@mailoo.org>
parents:
diff changeset
148 # init to send following "composing" state
7ea6d5a86e58 plugin XEP-0085: Chat State Notifications
souliane <souliane@mailoo.org>
parents:
diff changeset
149 self.__chatStateInit(from_jid, message.getAttribute("type"), profile)
7ea6d5a86e58 plugin XEP-0085: Chat State Notifications
souliane <souliane@mailoo.org>
parents:
diff changeset
150 except StopIteration:
7ea6d5a86e58 plugin XEP-0085: Chat State Notifications
souliane <souliane@mailoo.org>
parents:
diff changeset
151 # contact didn't enable Chat State Notifications
7ea6d5a86e58 plugin XEP-0085: Chat State Notifications
souliane <souliane@mailoo.org>
parents:
diff changeset
152 self.updateEntityData(from_jid, False, profile)
7ea6d5a86e58 plugin XEP-0085: Chat State Notifications
souliane <souliane@mailoo.org>
parents:
diff changeset
153 except StopIteration:
7ea6d5a86e58 plugin XEP-0085: Chat State Notifications
souliane <souliane@mailoo.org>
parents:
diff changeset
154 pass
7ea6d5a86e58 plugin XEP-0085: Chat State Notifications
souliane <souliane@mailoo.org>
parents:
diff changeset
155
7ea6d5a86e58 plugin XEP-0085: Chat State Notifications
souliane <souliane@mailoo.org>
parents:
diff changeset
156 state_list = [child.name for child in message.children if
7ea6d5a86e58 plugin XEP-0085: Chat State Notifications
souliane <souliane@mailoo.org>
parents:
diff changeset
157 message.getAttribute("type") in MESSAGE_TYPES
7ea6d5a86e58 plugin XEP-0085: Chat State Notifications
souliane <souliane@mailoo.org>
parents:
diff changeset
158 and child.name in CHAT_STATES
7ea6d5a86e58 plugin XEP-0085: Chat State Notifications
souliane <souliane@mailoo.org>
parents:
diff changeset
159 and child.defaultUri == NS_CHAT_STATES]
7ea6d5a86e58 plugin XEP-0085: Chat State Notifications
souliane <souliane@mailoo.org>
parents:
diff changeset
160 for state in state_list:
7ea6d5a86e58 plugin XEP-0085: Chat State Notifications
souliane <souliane@mailoo.org>
parents:
diff changeset
161 # there must be only one state according to the XEP
7ea6d5a86e58 plugin XEP-0085: Chat State Notifications
souliane <souliane@mailoo.org>
parents:
diff changeset
162 self.host.bridge.chatStateReceived(message.getAttribute("from"),
7ea6d5a86e58 plugin XEP-0085: Chat State Notifications
souliane <souliane@mailoo.org>
parents:
diff changeset
163 state, profile)
7ea6d5a86e58 plugin XEP-0085: Chat State Notifications
souliane <souliane@mailoo.org>
parents:
diff changeset
164 break
7ea6d5a86e58 plugin XEP-0085: Chat State Notifications
souliane <souliane@mailoo.org>
parents:
diff changeset
165 return True
7ea6d5a86e58 plugin XEP-0085: Chat State Notifications
souliane <souliane@mailoo.org>
parents:
diff changeset
166
7ea6d5a86e58 plugin XEP-0085: Chat State Notifications
souliane <souliane@mailoo.org>
parents:
diff changeset
167 def sendMessageXmlTrigger(self, message, mess_data, profile):
7ea6d5a86e58 plugin XEP-0085: Chat State Notifications
souliane <souliane@mailoo.org>
parents:
diff changeset
168 """
7ea6d5a86e58 plugin XEP-0085: Chat State Notifications
souliane <souliane@mailoo.org>
parents:
diff changeset
169 Eventually add the chat state to the message and initiate
7ea6d5a86e58 plugin XEP-0085: Chat State Notifications
souliane <souliane@mailoo.org>
parents:
diff changeset
170 the state machine when sending an "active" state.
7ea6d5a86e58 plugin XEP-0085: Chat State Notifications
souliane <souliane@mailoo.org>
parents:
diff changeset
171 """
7ea6d5a86e58 plugin XEP-0085: Chat State Notifications
souliane <souliane@mailoo.org>
parents:
diff changeset
172 if not self.host.memory.getParamA(PARAM_NAME, PARAM_KEY, profile_key=profile):
7ea6d5a86e58 plugin XEP-0085: Chat State Notifications
souliane <souliane@mailoo.org>
parents:
diff changeset
173 return True
7ea6d5a86e58 plugin XEP-0085: Chat State Notifications
souliane <souliane@mailoo.org>
parents:
diff changeset
174
7ea6d5a86e58 plugin XEP-0085: Chat State Notifications
souliane <souliane@mailoo.org>
parents:
diff changeset
175 # check if notifications should be sent to this contact
7ea6d5a86e58 plugin XEP-0085: Chat State Notifications
souliane <souliane@mailoo.org>
parents:
diff changeset
176 contact_enabled = True
7ea6d5a86e58 plugin XEP-0085: Chat State Notifications
souliane <souliane@mailoo.org>
parents:
diff changeset
177 to_jid = JID(message.getAttribute("to"))
7ea6d5a86e58 plugin XEP-0085: Chat State Notifications
souliane <souliane@mailoo.org>
parents:
diff changeset
178 try:
7ea6d5a86e58 plugin XEP-0085: Chat State Notifications
souliane <souliane@mailoo.org>
parents:
diff changeset
179 contact_enabled = self.host.memory.getEntityData(
7ea6d5a86e58 plugin XEP-0085: Chat State Notifications
souliane <souliane@mailoo.org>
parents:
diff changeset
180 to_jid, [PARAM_KEY], profile)[PARAM_KEY]
7ea6d5a86e58 plugin XEP-0085: Chat State Notifications
souliane <souliane@mailoo.org>
parents:
diff changeset
181 except (exceptions.UnknownEntityError, KeyError):
7ea6d5a86e58 plugin XEP-0085: Chat State Notifications
souliane <souliane@mailoo.org>
parents:
diff changeset
182 # enable it for the first time
7ea6d5a86e58 plugin XEP-0085: Chat State Notifications
souliane <souliane@mailoo.org>
parents:
diff changeset
183 self.updateEntityData(to_jid, True, profile)
7ea6d5a86e58 plugin XEP-0085: Chat State Notifications
souliane <souliane@mailoo.org>
parents:
diff changeset
184 if not contact_enabled:
7ea6d5a86e58 plugin XEP-0085: Chat State Notifications
souliane <souliane@mailoo.org>
parents:
diff changeset
185 return True
7ea6d5a86e58 plugin XEP-0085: Chat State Notifications
souliane <souliane@mailoo.org>
parents:
diff changeset
186 try:
7ea6d5a86e58 plugin XEP-0085: Chat State Notifications
souliane <souliane@mailoo.org>
parents:
diff changeset
187 # message with a body always mean active state
7ea6d5a86e58 plugin XEP-0085: Chat State Notifications
souliane <souliane@mailoo.org>
parents:
diff changeset
188 generateElementsNamed(message.children, name="body").next()
7ea6d5a86e58 plugin XEP-0085: Chat State Notifications
souliane <souliane@mailoo.org>
parents:
diff changeset
189 message.addElement('active', NS_CHAT_STATES)
7ea6d5a86e58 plugin XEP-0085: Chat State Notifications
souliane <souliane@mailoo.org>
parents:
diff changeset
190 # launch the chat state machine (init the timer)
7ea6d5a86e58 plugin XEP-0085: Chat State Notifications
souliane <souliane@mailoo.org>
parents:
diff changeset
191 self.__chatStateActive(to_jid, mess_data["type"], profile)
7ea6d5a86e58 plugin XEP-0085: Chat State Notifications
souliane <souliane@mailoo.org>
parents:
diff changeset
192 except StopIteration:
7ea6d5a86e58 plugin XEP-0085: Chat State Notifications
souliane <souliane@mailoo.org>
parents:
diff changeset
193 if "chat_state" in mess_data["options"]:
7ea6d5a86e58 plugin XEP-0085: Chat State Notifications
souliane <souliane@mailoo.org>
parents:
diff changeset
194 state = mess_data["options"]["chat_state"]
7ea6d5a86e58 plugin XEP-0085: Chat State Notifications
souliane <souliane@mailoo.org>
parents:
diff changeset
195 assert(state in CHAT_STATES)
7ea6d5a86e58 plugin XEP-0085: Chat State Notifications
souliane <souliane@mailoo.org>
parents:
diff changeset
196 message.addElement(state, NS_CHAT_STATES)
7ea6d5a86e58 plugin XEP-0085: Chat State Notifications
souliane <souliane@mailoo.org>
parents:
diff changeset
197 return True
7ea6d5a86e58 plugin XEP-0085: Chat State Notifications
souliane <souliane@mailoo.org>
parents:
diff changeset
198
7ea6d5a86e58 plugin XEP-0085: Chat State Notifications
souliane <souliane@mailoo.org>
parents:
diff changeset
199 def __chatStateInit(self, to_jid, mess_type, profile):
7ea6d5a86e58 plugin XEP-0085: Chat State Notifications
souliane <souliane@mailoo.org>
parents:
diff changeset
200 """
7ea6d5a86e58 plugin XEP-0085: Chat State Notifications
souliane <souliane@mailoo.org>
parents:
diff changeset
201 Data initialization for the chat state machine.
7ea6d5a86e58 plugin XEP-0085: Chat State Notifications
souliane <souliane@mailoo.org>
parents:
diff changeset
202 """
7ea6d5a86e58 plugin XEP-0085: Chat State Notifications
souliane <souliane@mailoo.org>
parents:
diff changeset
203 # TODO: use also the resource in map key
7ea6d5a86e58 plugin XEP-0085: Chat State Notifications
souliane <souliane@mailoo.org>
parents:
diff changeset
204 to_jid = to_jid.userhostJID()
7ea6d5a86e58 plugin XEP-0085: Chat State Notifications
souliane <souliane@mailoo.org>
parents:
diff changeset
205 if mess_type is None:
7ea6d5a86e58 plugin XEP-0085: Chat State Notifications
souliane <souliane@mailoo.org>
parents:
diff changeset
206 return
7ea6d5a86e58 plugin XEP-0085: Chat State Notifications
souliane <souliane@mailoo.org>
parents:
diff changeset
207 if not hasattr(self, "map"):
7ea6d5a86e58 plugin XEP-0085: Chat State Notifications
souliane <souliane@mailoo.org>
parents:
diff changeset
208 self.map = {}
7ea6d5a86e58 plugin XEP-0085: Chat State Notifications
souliane <souliane@mailoo.org>
parents:
diff changeset
209 profile_map = self.map.setdefault(profile, {})
7ea6d5a86e58 plugin XEP-0085: Chat State Notifications
souliane <souliane@mailoo.org>
parents:
diff changeset
210 if not to_jid in profile_map:
7ea6d5a86e58 plugin XEP-0085: Chat State Notifications
souliane <souliane@mailoo.org>
parents:
diff changeset
211 machine = ChatStateMachine(self.host, to_jid,
7ea6d5a86e58 plugin XEP-0085: Chat State Notifications
souliane <souliane@mailoo.org>
parents:
diff changeset
212 mess_type, profile)
7ea6d5a86e58 plugin XEP-0085: Chat State Notifications
souliane <souliane@mailoo.org>
parents:
diff changeset
213 self.map[profile][to_jid] = machine
7ea6d5a86e58 plugin XEP-0085: Chat State Notifications
souliane <souliane@mailoo.org>
parents:
diff changeset
214
7ea6d5a86e58 plugin XEP-0085: Chat State Notifications
souliane <souliane@mailoo.org>
parents:
diff changeset
215 def __chatStateActive(self, to_jid, mess_type, profile_key):
7ea6d5a86e58 plugin XEP-0085: Chat State Notifications
souliane <souliane@mailoo.org>
parents:
diff changeset
216 """
7ea6d5a86e58 plugin XEP-0085: Chat State Notifications
souliane <souliane@mailoo.org>
parents:
diff changeset
217 Launch the chat state machine on "active" state.
7ea6d5a86e58 plugin XEP-0085: Chat State Notifications
souliane <souliane@mailoo.org>
parents:
diff changeset
218 """
7ea6d5a86e58 plugin XEP-0085: Chat State Notifications
souliane <souliane@mailoo.org>
parents:
diff changeset
219 # TODO: use also the resource in map key
7ea6d5a86e58 plugin XEP-0085: Chat State Notifications
souliane <souliane@mailoo.org>
parents:
diff changeset
220 to_jid = to_jid.userhostJID()
7ea6d5a86e58 plugin XEP-0085: Chat State Notifications
souliane <souliane@mailoo.org>
parents:
diff changeset
221 profile = self.host.memory.getProfileName(profile_key)
7ea6d5a86e58 plugin XEP-0085: Chat State Notifications
souliane <souliane@mailoo.org>
parents:
diff changeset
222 if profile is None:
7ea6d5a86e58 plugin XEP-0085: Chat State Notifications
souliane <souliane@mailoo.org>
parents:
diff changeset
223 raise exceptions.ProfileUnknownError
7ea6d5a86e58 plugin XEP-0085: Chat State Notifications
souliane <souliane@mailoo.org>
parents:
diff changeset
224 self.__chatStateInit(to_jid, mess_type, profile)
7ea6d5a86e58 plugin XEP-0085: Chat State Notifications
souliane <souliane@mailoo.org>
parents:
diff changeset
225 self.map[profile][to_jid]._onEvent("active")
7ea6d5a86e58 plugin XEP-0085: Chat State Notifications
souliane <souliane@mailoo.org>
parents:
diff changeset
226
7ea6d5a86e58 plugin XEP-0085: Chat State Notifications
souliane <souliane@mailoo.org>
parents:
diff changeset
227 def chatStateComposing(self, to_jid_s, profile_key):
7ea6d5a86e58 plugin XEP-0085: Chat State Notifications
souliane <souliane@mailoo.org>
parents:
diff changeset
228 """
7ea6d5a86e58 plugin XEP-0085: Chat State Notifications
souliane <souliane@mailoo.org>
parents:
diff changeset
229 Move to the "composing" state.
7ea6d5a86e58 plugin XEP-0085: Chat State Notifications
souliane <souliane@mailoo.org>
parents:
diff changeset
230 """
7ea6d5a86e58 plugin XEP-0085: Chat State Notifications
souliane <souliane@mailoo.org>
parents:
diff changeset
231 # TODO: use also the resource in map key
7ea6d5a86e58 plugin XEP-0085: Chat State Notifications
souliane <souliane@mailoo.org>
parents:
diff changeset
232 to_jid = JID(to_jid_s).userhostJID()
7ea6d5a86e58 plugin XEP-0085: Chat State Notifications
souliane <souliane@mailoo.org>
parents:
diff changeset
233 profile = self.host.memory.getProfileName(profile_key)
7ea6d5a86e58 plugin XEP-0085: Chat State Notifications
souliane <souliane@mailoo.org>
parents:
diff changeset
234 if profile is None:
7ea6d5a86e58 plugin XEP-0085: Chat State Notifications
souliane <souliane@mailoo.org>
parents:
diff changeset
235 raise exceptions.ProfileUnknownError
7ea6d5a86e58 plugin XEP-0085: Chat State Notifications
souliane <souliane@mailoo.org>
parents:
diff changeset
236 try:
7ea6d5a86e58 plugin XEP-0085: Chat State Notifications
souliane <souliane@mailoo.org>
parents:
diff changeset
237 self.map[profile][to_jid]._onEvent("composing")
7ea6d5a86e58 plugin XEP-0085: Chat State Notifications
souliane <souliane@mailoo.org>
parents:
diff changeset
238 except:
7ea6d5a86e58 plugin XEP-0085: Chat State Notifications
souliane <souliane@mailoo.org>
parents:
diff changeset
239 return
7ea6d5a86e58 plugin XEP-0085: Chat State Notifications
souliane <souliane@mailoo.org>
parents:
diff changeset
240
7ea6d5a86e58 plugin XEP-0085: Chat State Notifications
souliane <souliane@mailoo.org>
parents:
diff changeset
241
7ea6d5a86e58 plugin XEP-0085: Chat State Notifications
souliane <souliane@mailoo.org>
parents:
diff changeset
242 class ChatStateMachine:
7ea6d5a86e58 plugin XEP-0085: Chat State Notifications
souliane <souliane@mailoo.org>
parents:
diff changeset
243 """
7ea6d5a86e58 plugin XEP-0085: Chat State Notifications
souliane <souliane@mailoo.org>
parents:
diff changeset
244 This class represents a chat state, between one profile and
7ea6d5a86e58 plugin XEP-0085: Chat State Notifications
souliane <souliane@mailoo.org>
parents:
diff changeset
245 one target contact. A timer is used to move from one state
7ea6d5a86e58 plugin XEP-0085: Chat State Notifications
souliane <souliane@mailoo.org>
parents:
diff changeset
246 to the other. The initialization is done through the "active"
7ea6d5a86e58 plugin XEP-0085: Chat State Notifications
souliane <souliane@mailoo.org>
parents:
diff changeset
247 state which is internally set when a message is sent. The state
7ea6d5a86e58 plugin XEP-0085: Chat State Notifications
souliane <souliane@mailoo.org>
parents:
diff changeset
248 "composing" can be set externally (through the bridge by a
7ea6d5a86e58 plugin XEP-0085: Chat State Notifications
souliane <souliane@mailoo.org>
parents:
diff changeset
249 frontend). Other states are automatically set with the timer.
7ea6d5a86e58 plugin XEP-0085: Chat State Notifications
souliane <souliane@mailoo.org>
parents:
diff changeset
250 """
7ea6d5a86e58 plugin XEP-0085: Chat State Notifications
souliane <souliane@mailoo.org>
parents:
diff changeset
251
7ea6d5a86e58 plugin XEP-0085: Chat State Notifications
souliane <souliane@mailoo.org>
parents:
diff changeset
252 def __init__(self, host, to_jid, mess_type, profile):
7ea6d5a86e58 plugin XEP-0085: Chat State Notifications
souliane <souliane@mailoo.org>
parents:
diff changeset
253 """
7ea6d5a86e58 plugin XEP-0085: Chat State Notifications
souliane <souliane@mailoo.org>
parents:
diff changeset
254 Initialization need to store the target, message type
7ea6d5a86e58 plugin XEP-0085: Chat State Notifications
souliane <souliane@mailoo.org>
parents:
diff changeset
255 and a profile for sending later messages.
7ea6d5a86e58 plugin XEP-0085: Chat State Notifications
souliane <souliane@mailoo.org>
parents:
diff changeset
256 """
7ea6d5a86e58 plugin XEP-0085: Chat State Notifications
souliane <souliane@mailoo.org>
parents:
diff changeset
257 self.host = host
7ea6d5a86e58 plugin XEP-0085: Chat State Notifications
souliane <souliane@mailoo.org>
parents:
diff changeset
258 self.to_jid = to_jid
7ea6d5a86e58 plugin XEP-0085: Chat State Notifications
souliane <souliane@mailoo.org>
parents:
diff changeset
259 self.mess_type = mess_type
7ea6d5a86e58 plugin XEP-0085: Chat State Notifications
souliane <souliane@mailoo.org>
parents:
diff changeset
260 self.profile = profile
7ea6d5a86e58 plugin XEP-0085: Chat State Notifications
souliane <souliane@mailoo.org>
parents:
diff changeset
261 self.state = None
7ea6d5a86e58 plugin XEP-0085: Chat State Notifications
souliane <souliane@mailoo.org>
parents:
diff changeset
262 self.timer = None
7ea6d5a86e58 plugin XEP-0085: Chat State Notifications
souliane <souliane@mailoo.org>
parents:
diff changeset
263
7ea6d5a86e58 plugin XEP-0085: Chat State Notifications
souliane <souliane@mailoo.org>
parents:
diff changeset
264 def _onEvent(self, state):
7ea6d5a86e58 plugin XEP-0085: Chat State Notifications
souliane <souliane@mailoo.org>
parents:
diff changeset
265 """
7ea6d5a86e58 plugin XEP-0085: Chat State Notifications
souliane <souliane@mailoo.org>
parents:
diff changeset
266 Move to the specified state, eventually send the
7ea6d5a86e58 plugin XEP-0085: Chat State Notifications
souliane <souliane@mailoo.org>
parents:
diff changeset
267 notification to the contact (the "active" state is
7ea6d5a86e58 plugin XEP-0085: Chat State Notifications
souliane <souliane@mailoo.org>
parents:
diff changeset
268 automatically sent with each message) and set the timer.
7ea6d5a86e58 plugin XEP-0085: Chat State Notifications
souliane <souliane@mailoo.org>
parents:
diff changeset
269 """
7ea6d5a86e58 plugin XEP-0085: Chat State Notifications
souliane <souliane@mailoo.org>
parents:
diff changeset
270 if state != self.state and state != "active":
7ea6d5a86e58 plugin XEP-0085: Chat State Notifications
souliane <souliane@mailoo.org>
parents:
diff changeset
271 # send a new message without body
7ea6d5a86e58 plugin XEP-0085: Chat State Notifications
souliane <souliane@mailoo.org>
parents:
diff changeset
272 self.host.sendMessage(self.to_jid,
7ea6d5a86e58 plugin XEP-0085: Chat State Notifications
souliane <souliane@mailoo.org>
parents:
diff changeset
273 '',
7ea6d5a86e58 plugin XEP-0085: Chat State Notifications
souliane <souliane@mailoo.org>
parents:
diff changeset
274 '',
7ea6d5a86e58 plugin XEP-0085: Chat State Notifications
souliane <souliane@mailoo.org>
parents:
diff changeset
275 self.mess_type,
7ea6d5a86e58 plugin XEP-0085: Chat State Notifications
souliane <souliane@mailoo.org>
parents:
diff changeset
276 options={"chat_state": state},
7ea6d5a86e58 plugin XEP-0085: Chat State Notifications
souliane <souliane@mailoo.org>
parents:
diff changeset
277 profile_key=self.profile)
7ea6d5a86e58 plugin XEP-0085: Chat State Notifications
souliane <souliane@mailoo.org>
parents:
diff changeset
278 self.state = state
7ea6d5a86e58 plugin XEP-0085: Chat State Notifications
souliane <souliane@mailoo.org>
parents:
diff changeset
279 if not self.timer is None:
7ea6d5a86e58 plugin XEP-0085: Chat State Notifications
souliane <souliane@mailoo.org>
parents:
diff changeset
280 self.timer.cancel()
7ea6d5a86e58 plugin XEP-0085: Chat State Notifications
souliane <souliane@mailoo.org>
parents:
diff changeset
281
7ea6d5a86e58 plugin XEP-0085: Chat State Notifications
souliane <souliane@mailoo.org>
parents:
diff changeset
282 if not state in TRANSITIONS:
7ea6d5a86e58 plugin XEP-0085: Chat State Notifications
souliane <souliane@mailoo.org>
parents:
diff changeset
283 return
7ea6d5a86e58 plugin XEP-0085: Chat State Notifications
souliane <souliane@mailoo.org>
parents:
diff changeset
284 if not "next_state" in TRANSITIONS[state]:
7ea6d5a86e58 plugin XEP-0085: Chat State Notifications
souliane <souliane@mailoo.org>
parents:
diff changeset
285 return
7ea6d5a86e58 plugin XEP-0085: Chat State Notifications
souliane <souliane@mailoo.org>
parents:
diff changeset
286 if not "delay" in TRANSITIONS[state]:
7ea6d5a86e58 plugin XEP-0085: Chat State Notifications
souliane <souliane@mailoo.org>
parents:
diff changeset
287 return
7ea6d5a86e58 plugin XEP-0085: Chat State Notifications
souliane <souliane@mailoo.org>
parents:
diff changeset
288 next_state = TRANSITIONS[state]["next_state"]
7ea6d5a86e58 plugin XEP-0085: Chat State Notifications
souliane <souliane@mailoo.org>
parents:
diff changeset
289 delay = TRANSITIONS[state]["delay"]
7ea6d5a86e58 plugin XEP-0085: Chat State Notifications
souliane <souliane@mailoo.org>
parents:
diff changeset
290 if next_state == "" or delay < 0:
7ea6d5a86e58 plugin XEP-0085: Chat State Notifications
souliane <souliane@mailoo.org>
parents:
diff changeset
291 return
7ea6d5a86e58 plugin XEP-0085: Chat State Notifications
souliane <souliane@mailoo.org>
parents:
diff changeset
292 self.timer = Timer(delay, self._onEvent, [next_state])
7ea6d5a86e58 plugin XEP-0085: Chat State Notifications
souliane <souliane@mailoo.org>
parents:
diff changeset
293 self.timer.start()
7ea6d5a86e58 plugin XEP-0085: Chat State Notifications
souliane <souliane@mailoo.org>
parents:
diff changeset
294
7ea6d5a86e58 plugin XEP-0085: Chat State Notifications
souliane <souliane@mailoo.org>
parents:
diff changeset
295
7ea6d5a86e58 plugin XEP-0085: Chat State Notifications
souliane <souliane@mailoo.org>
parents:
diff changeset
296 class XEP_0085_handler(XMPPHandler):
7ea6d5a86e58 plugin XEP-0085: Chat State Notifications
souliane <souliane@mailoo.org>
parents:
diff changeset
297 implements(iwokkel.IDisco)
7ea6d5a86e58 plugin XEP-0085: Chat State Notifications
souliane <souliane@mailoo.org>
parents:
diff changeset
298
7ea6d5a86e58 plugin XEP-0085: Chat State Notifications
souliane <souliane@mailoo.org>
parents:
diff changeset
299 def __init__(self, plugin_parent, profile):
7ea6d5a86e58 plugin XEP-0085: Chat State Notifications
souliane <souliane@mailoo.org>
parents:
diff changeset
300 self.plugin_parent = plugin_parent
7ea6d5a86e58 plugin XEP-0085: Chat State Notifications
souliane <souliane@mailoo.org>
parents:
diff changeset
301 self.host = plugin_parent.host
7ea6d5a86e58 plugin XEP-0085: Chat State Notifications
souliane <souliane@mailoo.org>
parents:
diff changeset
302 self.profile = profile
7ea6d5a86e58 plugin XEP-0085: Chat State Notifications
souliane <souliane@mailoo.org>
parents:
diff changeset
303
7ea6d5a86e58 plugin XEP-0085: Chat State Notifications
souliane <souliane@mailoo.org>
parents:
diff changeset
304 def getDiscoInfo(self, requestor, target, nodeIdentifier=''):
7ea6d5a86e58 plugin XEP-0085: Chat State Notifications
souliane <souliane@mailoo.org>
parents:
diff changeset
305 return [disco.DiscoFeature(NS_CHAT_STATES)]
7ea6d5a86e58 plugin XEP-0085: Chat State Notifications
souliane <souliane@mailoo.org>
parents:
diff changeset
306
7ea6d5a86e58 plugin XEP-0085: Chat State Notifications
souliane <souliane@mailoo.org>
parents:
diff changeset
307 def getDiscoItems(self, requestor, target, nodeIdentifier=''):
7ea6d5a86e58 plugin XEP-0085: Chat State Notifications
souliane <souliane@mailoo.org>
parents:
diff changeset
308 return []