summaryrefslogtreecommitdiff
path: root/src/core.py
diff options
context:
space:
mode:
authormathieui <mathieui@mathieui.net>2012-08-02 16:24:10 +0200
committermathieui <mathieui@mathieui.net>2012-08-02 16:24:10 +0200
commit3897d131c1cf971a6ceb6c3d86cf83813bc26dcd (patch)
treeef56b17f851e24f879e22c87e27a80d8f69b023d /src/core.py
parent1d908702b170e5edb8ca576f54f49a69bd3e2deb (diff)
downloadpoezio-3897d131c1cf971a6ceb6c3d86cf83813bc26dcd.tar.gz
poezio-3897d131c1cf971a6ceb6c3d86cf83813bc26dcd.tar.bz2
poezio-3897d131c1cf971a6ceb6c3d86cf83813bc26dcd.tar.xz
poezio-3897d131c1cf971a6ceb6c3d86cf83813bc26dcd.zip
Implement XEP-0012 (last activity) ; Fixes #1870
- Add a /activity command - Load xep_0012 on start - Add a 'l' shortcut in the roster to get the last activity - Using "/activity" in a direct conversation will add a message in the conversation, and not in the info buffer.
Diffstat (limited to 'src/core.py')
-rw-r--r--src/core.py38
1 files changed, 37 insertions, 1 deletions
diff --git a/src/core.py b/src/core.py
index e7897c59..b2906f10 100644
--- a/src/core.py
+++ b/src/core.py
@@ -24,7 +24,7 @@ import logging
import singleton
import collections
-from sleekxmpp.xmlstream.stanzabase import JID
+from sleekxmpp import JID, InvalidJID
from sleekxmpp.xmlstream.stanzabase import StanzaBase
from sleekxmpp.xmlstream.handler import Callback
@@ -179,6 +179,7 @@ class Core(object):
'xml_tab': (self.command_xml_tab, _("Usage: /xml_tab\nXML Tab: Open an XML tab."), None),
'runkey': (self.command_runkey, _("Usage: /runkey <key>\nRunkey: Execute the action defined for <key>."), self.completion_runkey),
'self': (self.command_self, _("Usage: /self\nSelf: Remind you of who you are."), None),
+ 'activity': (self.command_activity, _("Usage: /activity <jid>\nActivity: Informs you of the last activity of a JID."), self.completion_activity),
}
# We are invisible
@@ -1866,6 +1867,40 @@ class Core(object):
serv_list.append(serv)
return the_input.auto_completion(serv_list, ' ')
+ def command_activity(self, arg):
+ """
+ /activity <jid>
+ """
+ def callback(iq):
+ if iq['type'] != 'result':
+ if iq['error']['type'] == 'auth':
+ self.information('You are not allowed to see the activity of this contact.', 'Error')
+ else:
+ self.information('Error retrieving the activity', 'Error')
+ return
+ seconds = iq['last_activity']['seconds']
+ status = iq['last_activity']['status']
+ from_ = iq['from']
+ if not JID(from_).user:
+ msg = 'The uptime of %s is %s.' % (
+ from_,
+ common.parse_secs_to_str(seconds))
+ else:
+ msg = 'The last activity of %s was %s ago%s' % (
+ from_,
+ common.parse_secs_to_str(seconds),
+ (' and his/her last status was %s' % status) if status else '',)
+ self.information(msg, 'Info')
+ try:
+ jid = JID(arg)
+ except InvalidJID:
+ self.information('No valid JID given', 'Error')
+ return
+ self.xmpp.plugin['xep_0012'].get_last_activity(jid, block=False, callback=callback)
+
+ def completion_activity(self, the_input):
+ return the_input.auto_completion([jid for jid in roster.jids()], '', quotify=False)
+
def command_invite(self, arg):
"""/invite <to> <room> [reason]"""
args = common.shell_split(arg)
@@ -2607,6 +2642,7 @@ class Core(object):
"""
We are sending a new stanza, write it in the xml buffer if needed.
"""
+ self.xmpp.plugin['xep_0012'].set_last_activity()
if self.xml_tabs:
self.add_message_to_text_buffer(self.xml_buffer, '\x191}<--\x19o %s' % stanza)
if isinstance(self.current_tab(), tabs.XMLTab):