Mercurial > prosody-hg
comparison plugins/mod_lastactivity.lua @ 10750:ff087f2d4cb6
mod_lastactivity: Encode seconds as decimal, not float
In Lua 5.3 difftime() takes integers as argument but returns a float,
and then tostring() serializes it with a decimal point. This violates
XEP-0012.
Like #1536
| author | Kim Alvefur <zash@zash.se> |
|---|---|
| date | Wed, 22 Apr 2020 23:36:25 +0200 |
| parents | a84dbd2e08bc |
| children | 74b9e05af71e |
comparison
equal
deleted
inserted
replaced
| 10749:abbdf72b0710 | 10750:ff087f2d4cb6 |
|---|---|
| 28 local origin, stanza = event.origin, event.stanza; | 28 local origin, stanza = event.origin, event.stanza; |
| 29 local username = jid_split(stanza.attr.to) or origin.username; | 29 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 | 30 if not stanza.attr.to or is_contact_subscribed(username, module.host, jid_bare(stanza.attr.from)) then |
| 31 local seconds, text = "0", ""; | 31 local seconds, text = "0", ""; |
| 32 if map[username] then | 32 if map[username] then |
| 33 seconds = tostring(os.difftime(os.time(), map[username].t)); | 33 seconds = string.format("%d", os.difftime(os.time(), map[username].t)); |
| 34 text = map[username].s; | 34 text = map[username].s; |
| 35 end | 35 end |
| 36 origin.send(st.reply(stanza):tag('query', {xmlns='jabber:iq:last', seconds=seconds}):text(text)); | 36 origin.send(st.reply(stanza):tag('query', {xmlns='jabber:iq:last', seconds=seconds}):text(text)); |
| 37 else | 37 else |
| 38 origin.send(st.error_reply(stanza, 'auth', 'forbidden')); | 38 origin.send(st.error_reply(stanza, 'auth', 'forbidden')); |
