Software /
code /
prosody
Comparison
plugins/mod_lastactivity.lua @ 9224:a84dbd2e08bc
mod_lastactivity: Simplify iq handling by hooking on iq-get/ instead of iq/.
author | Emmanuel Gil Peyrot <linkmauve@linkmauve.fr> |
---|---|
date | Fri, 24 Aug 2018 20:34:34 +0200 |
parent | 6302:76699a0ae4c4 |
child | 10750:ff087f2d4cb6 |
comparison
equal
deleted
inserted
replaced
9223:80dbb60d81e4 | 9224:a84dbd2e08bc |
---|---|
22 local s = stanza:get_child_text("status"); | 22 local s = stanza:get_child_text("status"); |
23 map[event.origin.username] = {s = s, t = t}; | 23 map[event.origin.username] = {s = s, t = t}; |
24 end | 24 end |
25 end, 10); | 25 end, 10); |
26 | 26 |
27 module:hook("iq/bare/jabber:iq:last:query", function(event) | 27 module:hook("iq-get/bare/jabber:iq:last:query", function(event) |
28 local origin, stanza = event.origin, event.stanza; | 28 local origin, stanza = event.origin, event.stanza; |
29 if stanza.attr.type == "get" then | 29 local username = jid_split(stanza.attr.to) or origin.username; |
30 local username = jid_split(stanza.attr.to) or origin.username; | 30 if not stanza.attr.to or is_contact_subscribed(username, module.host, jid_bare(stanza.attr.from)) then |
31 if not stanza.attr.to or is_contact_subscribed(username, module.host, jid_bare(stanza.attr.from)) then | 31 local seconds, text = "0", ""; |
32 local seconds, text = "0", ""; | 32 if map[username] then |
33 if map[username] then | 33 seconds = tostring(os.difftime(os.time(), map[username].t)); |
34 seconds = tostring(os.difftime(os.time(), map[username].t)); | 34 text = map[username].s; |
35 text = map[username].s; | |
36 end | |
37 origin.send(st.reply(stanza):tag('query', {xmlns='jabber:iq:last', seconds=seconds}):text(text)); | |
38 else | |
39 origin.send(st.error_reply(stanza, 'auth', 'forbidden')); | |
40 end | 35 end |
41 return true; | 36 origin.send(st.reply(stanza):tag('query', {xmlns='jabber:iq:last', seconds=seconds}):text(text)); |
37 else | |
38 origin.send(st.error_reply(stanza, 'auth', 'forbidden')); | |
42 end | 39 end |
40 return true; | |
43 end); | 41 end); |
44 | 42 |
45 module.save = function() | 43 module.save = function() |
46 return {map = map}; | 44 return {map = map}; |
47 end | 45 end |