2 SleekXMPP: The Sleek XMPP Library
3 Copyright (C) 2012 Nathanael C. Fritz, Lance J.T. Stout
4 This file is part of SleekXMPP.
6 See the file LICENSE for copying permission.
11 from sleekxmpp
import Presence
12 from sleekxmpp
.exceptions
import XMPPError
13 from sleekxmpp
.plugins
import BasePlugin
, register_plugin
14 from sleekxmpp
.xmlstream
import register_stanza_plugin
16 from sleekxmpp
.plugins
.xep_0012
import stanza
, LastActivity
19 log
= logging
.getLogger(__name__
)
22 class XEP_0256(BasePlugin
):
25 description
= 'XEP-0256: Last Activity in Presence'
26 dependencies
= set(['xep_0012'])
29 'auto_last_activity': False
32 def plugin_init(self
):
33 register_stanza_plugin(Presence
, LastActivity
)
35 self
.xmpp
.add_filter('out', self
._initial
_presence
_activity
)
36 self
.xmpp
.add_event_handler('connected', self
._reset
_presence
_activity
)
38 self
._initial
_presence
= set()
41 self
.xmpp
.del_filter('out', self
._initial
_presence
_activity
)
42 self
.xmpp
.del_event_handler('connected', self
._reset
_presence
_activity
)
44 def _reset_presence_activity(self
, e
):
45 self
._initial
_presence
= set()
47 def _initial_presence_activity(self
, stanza
):
48 if isinstance(stanza
, Presence
):
49 use_last_activity
= False
51 if self
.auto_last_activity
and stanza
['show'] in ('xa', 'away'):
52 use_last_activity
= True
54 if stanza
['from'] not in self
._initial
_presence
:
55 self
._initial
_presence
.add(stanza
['from'])
56 use_last_activity
= True
59 plugin
= self
.xmpp
['xep_0012']
61 result
= plugin
.api
['get_last_activity'](stanza
['from'],
64 seconds
= result
['last_activity']['seconds']
68 if seconds
is not None:
69 stanza
['last_activity']['seconds'] = seconds
73 register_plugin(XEP_0256
)