Mercurial > prosody-hg
comparison util/rsm.lua @ 11200:bf8f2da84007
Merge 0.11->trunk
| author | Kim Alvefur <zash@zash.se> |
|---|---|
| date | Thu, 05 Nov 2020 22:31:25 +0100 |
| parents | 1fbfcc2f6805 |
| children | c7948491c5e4 |
comparison
equal
deleted
inserted
replaced
| 11199:6c7c50a4de32 | 11200:bf8f2da84007 |
|---|---|
| 8 -- | 8 -- |
| 9 -- XEP-0313: Message Archive Management for Prosody | 9 -- XEP-0313: Message Archive Management for Prosody |
| 10 -- | 10 -- |
| 11 | 11 |
| 12 local stanza = require"util.stanza".stanza; | 12 local stanza = require"util.stanza".stanza; |
| 13 local tostring, tonumber = tostring, tonumber; | 13 local tonumber = tonumber; |
| 14 local s_format = string.format; | |
| 14 local type = type; | 15 local type = type; |
| 15 local pairs = pairs; | 16 local pairs = pairs; |
| 17 | |
| 18 local function inttostr(n) | |
| 19 return s_format("%d", n); | |
| 20 end | |
| 16 | 21 |
| 17 local xmlns_rsm = 'http://jabber.org/protocol/rsm'; | 22 local xmlns_rsm = 'http://jabber.org/protocol/rsm'; |
| 18 | 23 |
| 19 local element_parsers = {}; | 24 local element_parsers = {}; |
| 20 | 25 |
| 43 end | 48 end |
| 44 | 49 |
| 45 local element_generators = setmetatable({ | 50 local element_generators = setmetatable({ |
| 46 first = function(st, data) | 51 first = function(st, data) |
| 47 if type(data) == "table" then | 52 if type(data) == "table" then |
| 48 st:tag("first", { index = data.index }):text(data[1]):up(); | 53 st:tag("first", { index = inttostr(data.index) }):text(data[1]):up(); |
| 49 else | 54 else |
| 50 st:tag("first"):text(tostring(data)):up(); | 55 st:tag("first"):text(data):up(); |
| 51 end | 56 end |
| 52 end; | 57 end; |
| 53 before = function(st, data) | 58 before = function(st, data) |
| 54 if data == true then | 59 if data == true then |
| 55 st:tag("before"):up(); | 60 st:tag("before"):up(); |
| 56 else | 61 else |
| 57 st:tag("before"):text(tostring(data)):up(); | 62 st:tag("before"):text(data):up(); |
| 58 end | 63 end |
| 59 end | 64 end; |
| 65 max = function (st, data) | |
| 66 st:tag("max"):text(inttostr(data)):up(); | |
| 67 end; | |
| 68 count = function (st, data) | |
| 69 st:tag("count"):text(inttostr(data)):up(); | |
| 70 end; | |
| 60 }, { | 71 }, { |
| 61 __index = function(_, name) | 72 __index = function(_, name) |
| 62 return function(st, data) | 73 return function(st, data) |
| 63 st:tag(name):text(tostring(data)):up(); | 74 st:tag(name):text(data):up(); |
| 64 end | 75 end |
| 65 end; | 76 end; |
| 66 }); | 77 }); |
| 67 | 78 |
| 68 | 79 |
