Comparison

util/rsm.lua @ 11120:b2331f3dfeea

Merge 0.11->trunk
author Matthew Wild <mwild1@gmail.com>
date Wed, 30 Sep 2020 09:50:33 +0100
parent 10764:1fbfcc2f6805
child 11426:c7948491c5e4
comparison
equal deleted inserted replaced
11119:68df52bf08d5 11120:b2331f3dfeea
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