Move XEP-0085 to the new system.
Optimized handlers so that only one is needed.
This commit is contained in:
parent
6d855ec06c
commit
3fda053606
3 changed files with 22 additions and 14 deletions
|
@ -6,5 +6,14 @@
|
||||||
See the file LICENSE for copying permissio
|
See the file LICENSE for copying permissio
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
from sleekxmpp.plugins.base import register_plugin
|
||||||
|
|
||||||
from sleekxmpp.plugins.xep_0085.stanza import ChatState
|
from sleekxmpp.plugins.xep_0085.stanza import ChatState
|
||||||
from sleekxmpp.plugins.xep_0085.chat_states import xep_0085
|
from sleekxmpp.plugins.xep_0085.chat_states import XEP_0085
|
||||||
|
|
||||||
|
|
||||||
|
register_plugin(XEP_0085)
|
||||||
|
|
||||||
|
|
||||||
|
# Retain some backwards compatibility
|
||||||
|
xep_0085 = XEP_0085
|
||||||
|
|
|
@ -13,28 +13,28 @@ from sleekxmpp.stanza import Message
|
||||||
from sleekxmpp.xmlstream.handler import Callback
|
from sleekxmpp.xmlstream.handler import Callback
|
||||||
from sleekxmpp.xmlstream.matcher import StanzaPath
|
from sleekxmpp.xmlstream.matcher import StanzaPath
|
||||||
from sleekxmpp.xmlstream import register_stanza_plugin, ElementBase, ET
|
from sleekxmpp.xmlstream import register_stanza_plugin, ElementBase, ET
|
||||||
from sleekxmpp.plugins.base import base_plugin
|
from sleekxmpp.plugins import BasePlugin
|
||||||
from sleekxmpp.plugins.xep_0085 import stanza, ChatState
|
from sleekxmpp.plugins.xep_0085 import stanza, ChatState
|
||||||
|
|
||||||
|
|
||||||
log = logging.getLogger(__name__)
|
log = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
class xep_0085(base_plugin):
|
class XEP_0085(BasePlugin):
|
||||||
|
|
||||||
"""
|
"""
|
||||||
XEP-0085 Chat State Notifications
|
XEP-0085 Chat State Notifications
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def plugin_init(self):
|
name = 'xep_0085'
|
||||||
self.xep = '0085'
|
description = 'XEP-0085: Chat State Notifications'
|
||||||
self.description = 'Chat State Notifications'
|
dependencies = set(['xep_0030'])
|
||||||
self.stanza = stanza
|
stanza = stanza
|
||||||
|
|
||||||
for state in ChatState.states:
|
def plugin_init(self):
|
||||||
self.xmpp.register_handler(
|
self.xmpp.register_handler(
|
||||||
Callback('Chat State: %s' % state,
|
Callback('Chat State',
|
||||||
StanzaPath('message@chat_state=%s' % state),
|
StanzaPath('message/chat_state'),
|
||||||
self._handle_chat_state))
|
self._handle_chat_state))
|
||||||
|
|
||||||
register_stanza_plugin(Message, stanza.Active)
|
register_stanza_plugin(Message, stanza.Active)
|
||||||
|
@ -43,8 +43,6 @@ class xep_0085(base_plugin):
|
||||||
register_stanza_plugin(Message, stanza.Inactive)
|
register_stanza_plugin(Message, stanza.Inactive)
|
||||||
register_stanza_plugin(Message, stanza.Paused)
|
register_stanza_plugin(Message, stanza.Paused)
|
||||||
|
|
||||||
def post_init(self):
|
|
||||||
base_plugin.post_init(self)
|
|
||||||
self.xmpp.plugin['xep_0030'].add_feature(ChatState.namespace)
|
self.xmpp.plugin['xep_0030'].add_feature(ChatState.namespace)
|
||||||
|
|
||||||
def _handle_chat_state(self, msg):
|
def _handle_chat_state(self, msg):
|
||||||
|
|
|
@ -38,6 +38,7 @@ class ChatState(ElementBase):
|
||||||
namespace = 'http://jabber.org/protocol/chatstates'
|
namespace = 'http://jabber.org/protocol/chatstates'
|
||||||
plugin_attrib = 'chat_state'
|
plugin_attrib = 'chat_state'
|
||||||
interfaces = set(('chat_state',))
|
interfaces = set(('chat_state',))
|
||||||
|
sub_interfaces = interfaces
|
||||||
is_extension = True
|
is_extension = True
|
||||||
|
|
||||||
states = set(('active', 'composing', 'gone', 'inactive', 'paused'))
|
states = set(('active', 'composing', 'gone', 'inactive', 'paused'))
|
||||||
|
|
Loading…
Reference in a new issue