Fix the iq.send() function, and a bunch of places where it is called
[slixmpp.git] / slixmpp / plugins / xep_0108 / user_activity.py
blob502dfae0911d6a9ebea199a0b43c489ff21f125f
1 """
2 Slixmpp: The Slick XMPP Library
3 Copyright (C) 2011 Nathanael C. Fritz, Lance J.T. Stout
4 This file is part of Slixmpp.
6 See the file LICENSE for copying permission.
7 """
9 import logging
11 from slixmpp.plugins.base import BasePlugin
12 from slixmpp.plugins.xep_0108 import stanza, UserActivity
15 log = logging.getLogger(__name__)
18 class XEP_0108(BasePlugin):
20 """
21 XEP-0108: User Activity
22 """
24 name = 'xep_0108'
25 description = 'XEP-0108: User Activity'
26 dependencies = set(['xep_0163'])
27 stanza = stanza
29 def plugin_end(self):
30 self.xmpp['xep_0030'].del_feature(feature=UserActivity.namespace)
31 self.xmpp['xep_0163'].remove_interest(UserActivity.namespace)
33 def session_bind(self, jid):
34 self.xmpp['xep_0163'].register_pep('user_activity', UserActivity)
36 def publish_activity(self, general, specific=None, text=None,
37 options=None, ifrom=None, callback=None,
38 timeout=None, timeout_callback=None):
39 """
40 Publish the user's current activity.
42 Arguments:
43 general -- The required general category of the activity.
44 specific -- Optional specific activity being done as part
45 of the general category.
46 text -- Optional natural-language description or reason
47 for the activity.
48 options -- Optional form of publish options.
49 ifrom -- Specify the sender's JID.
50 timeout -- The length of time (in seconds) to wait for a response
51 before exiting the send call if blocking is used.
52 Defaults to slixmpp.xmlstream.RESPONSE_TIMEOUT
53 callback -- Optional reference to a stream handler function. Will
54 be executed when a reply stanza is received.
55 """
56 activity = UserActivity()
57 activity['value'] = (general, specific)
58 activity['text'] = text
59 self.xmpp['xep_0163'].publish(activity, node=UserActivity.namespace,
60 options=options, ifrom=ifrom,
61 callback=callback,
62 timeout=timeout,
63 timeout_callback=timeout_callback)
65 def stop(self, ifrom=None, callback=None, timeout=None,
66 timeout_callback=None):
67 """
68 Clear existing user activity information to stop notifications.
70 Arguments:
71 ifrom -- Specify the sender's JID.
72 timeout -- The length of time (in seconds) to wait for a response
73 before exiting the send call if blocking is used.
74 Defaults to slixmpp.xmlstream.RESPONSE_TIMEOUT
75 callback -- Optional reference to a stream handler function. Will
76 be executed when a reply stanza is received.
77 """
78 activity = UserActivity()
79 self.xmpp['xep_0163'].publish(activity, node=UserActivity.namespace,
80 ifrom=ifrom, callback=callback,
81 timeout=timeout,
82 timeout_callback=timeout_callback)