2 Slixmpp: The Slick XMPP Library
3 Copyright (C) 2012 Nathanael C. Fritz, Lance J.T. Stout
4 This file is part of Slixmpp.
6 See the file LICENSE for copying permissio
12 from slixmpp
.stanza
import Message
, Iq
13 from slixmpp
.xmlstream
.handler
import Callback
14 from slixmpp
.xmlstream
.matcher
import StanzaPath
15 from slixmpp
.xmlstream
import register_stanza_plugin
16 from slixmpp
.plugins
import BasePlugin
17 from slixmpp
.plugins
.xep_0280
import stanza
20 log
= logging
.getLogger(__name__
)
23 class XEP_0280(BasePlugin
):
26 XEP-0280 Message Carbons
30 description
= 'XEP-0280: Message Carbons'
31 dependencies
= set(['xep_0030', 'xep_0297'])
34 def plugin_init(self
):
35 self
.xmpp
.register_handler(
36 Callback('Carbon Received',
37 StanzaPath('message/carbon_received'),
38 self
._handle
_carbon
_received
))
39 self
.xmpp
.register_handler(
40 Callback('Carbon Sent',
41 StanzaPath('message/carbon_sent'),
42 self
._handle
_carbon
_sent
))
44 register_stanza_plugin(Message
, stanza
.ReceivedCarbon
)
45 register_stanza_plugin(Message
, stanza
.SentCarbon
)
46 register_stanza_plugin(Message
, stanza
.PrivateCarbon
)
47 register_stanza_plugin(Iq
, stanza
.CarbonEnable
)
48 register_stanza_plugin(Iq
, stanza
.CarbonDisable
)
50 register_stanza_plugin(stanza
.ReceivedCarbon
,
51 self
.xmpp
['xep_0297'].stanza
.Forwarded
)
52 register_stanza_plugin(stanza
.SentCarbon
,
53 self
.xmpp
['xep_0297'].stanza
.Forwarded
)
56 self
.xmpp
.remove_handler('Carbon Received')
57 self
.xmpp
.remove_handler('Carbon Sent')
58 self
.xmpp
.plugin
['xep_0030'].del_feature(feature
='urn:xmpp:carbons:2')
60 def session_bind(self
, jid
):
61 self
.xmpp
.plugin
['xep_0030'].add_feature('urn:xmpp:carbons:2')
63 def _handle_carbon_received(self
, msg
):
64 self
.xmpp
.event('carbon_received', msg
)
66 def _handle_carbon_sent(self
, msg
):
67 self
.xmpp
.event('carbon_sent', msg
)
69 def enable(self
, ifrom
=None, block
=True, timeout
=None, callback
=None):
73 iq
.enable('carbon_enable')
74 return iq
.send(block
=block
, timeout
=timeout
, callback
=callback
)
76 def disable(self
, ifrom
=None, block
=True, timeout
=None, callback
=None):
80 iq
.enable('carbon_disable')
81 return iq
.send(block
=block
, timeout
=timeout
, callback
=callback
)