annotate mod_storage_muc_log/mod_storage_muc_log.lua @ 4318:3dd7840cb923

mod_client_proxy: Fix typo in readme Thanks, @mdosch.
author Jonas Schäfer <jonas@wielicki.name>
date Tue, 05 Jan 2021 20:51:23 +0100
parents 85b849d5ec88
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
2821
e8f0acfdccca mod_storage_muc_log: Ignore setting the global 'open', it's part of the storage API
Kim Alvefur <zash@zash.se>
parents: 2820
diff changeset
1 -- luacheck: ignore 212/self 431/err 131/open
1566
9158882dd9a1 mod_storage_muc_log: Provides an archive API to mod_muc_log data
Kim Alvefur <zash@zash.se>
parents:
diff changeset
2
9158882dd9a1 mod_storage_muc_log: Provides an archive API to mod_muc_log data
Kim Alvefur <zash@zash.se>
parents:
diff changeset
3 local datamanager = require"core.storagemanager".olddm;
9158882dd9a1 mod_storage_muc_log: Provides an archive API to mod_muc_log data
Kim Alvefur <zash@zash.se>
parents:
diff changeset
4 local xml_parse = require"util.xml".parse;
9158882dd9a1 mod_storage_muc_log: Provides an archive API to mod_muc_log data
Kim Alvefur <zash@zash.se>
parents:
diff changeset
5 local data_load, data_store = datamanager.load, datamanager.store;
9158882dd9a1 mod_storage_muc_log: Provides an archive API to mod_muc_log data
Kim Alvefur <zash@zash.se>
parents:
diff changeset
6 local datastore = "muc_log";
9158882dd9a1 mod_storage_muc_log: Provides an archive API to mod_muc_log data
Kim Alvefur <zash@zash.se>
parents:
diff changeset
7 local datetime = require"util.datetime"
9158882dd9a1 mod_storage_muc_log: Provides an archive API to mod_muc_log data
Kim Alvefur <zash@zash.se>
parents:
diff changeset
8 local lfs = require"lfs";
9158882dd9a1 mod_storage_muc_log: Provides an archive API to mod_muc_log data
Kim Alvefur <zash@zash.se>
parents:
diff changeset
9 local os_date = os.date;
9158882dd9a1 mod_storage_muc_log: Provides an archive API to mod_muc_log data
Kim Alvefur <zash@zash.se>
parents:
diff changeset
10
1568
c357039c1ab1 mod_storage_muc_log: Change to sane timestamp format and warn if it differs from legacy mod_muc_log timestamps
Kim Alvefur <zash@zash.se>
parents: 1566
diff changeset
11 local timef, datef = "!%H:%M:%S", "!%y%m%d";
1566
9158882dd9a1 mod_storage_muc_log: Provides an archive API to mod_muc_log data
Kim Alvefur <zash@zash.se>
parents:
diff changeset
12 local host = module.host;
9158882dd9a1 mod_storage_muc_log: Provides an archive API to mod_muc_log data
Kim Alvefur <zash@zash.se>
parents:
diff changeset
13
9158882dd9a1 mod_storage_muc_log: Provides an archive API to mod_muc_log data
Kim Alvefur <zash@zash.se>
parents:
diff changeset
14 local driver = {};
9158882dd9a1 mod_storage_muc_log: Provides an archive API to mod_muc_log data
Kim Alvefur <zash@zash.se>
parents:
diff changeset
15 local driver_mt = { __index = driver };
9158882dd9a1 mod_storage_muc_log: Provides an archive API to mod_muc_log data
Kim Alvefur <zash@zash.se>
parents:
diff changeset
16
9158882dd9a1 mod_storage_muc_log: Provides an archive API to mod_muc_log data
Kim Alvefur <zash@zash.se>
parents:
diff changeset
17 do
9158882dd9a1 mod_storage_muc_log: Provides an archive API to mod_muc_log data
Kim Alvefur <zash@zash.se>
parents:
diff changeset
18 -- Sanity check
9158882dd9a1 mod_storage_muc_log: Provides an archive API to mod_muc_log data
Kim Alvefur <zash@zash.se>
parents:
diff changeset
19 -- Fun fact: 09:00 and 21:00 en_HK are both "09:00:00 UTC"
9158882dd9a1 mod_storage_muc_log: Provides an archive API to mod_muc_log data
Kim Alvefur <zash@zash.se>
parents:
diff changeset
20 local t = os_date("!*t");
9158882dd9a1 mod_storage_muc_log: Provides an archive API to mod_muc_log data
Kim Alvefur <zash@zash.se>
parents:
diff changeset
21 t.hour = 9;
1568
c357039c1ab1 mod_storage_muc_log: Change to sane timestamp format and warn if it differs from legacy mod_muc_log timestamps
Kim Alvefur <zash@zash.se>
parents: 1566
diff changeset
22 local am = os_date("!%X", os.time(t));
1566
9158882dd9a1 mod_storage_muc_log: Provides an archive API to mod_muc_log data
Kim Alvefur <zash@zash.se>
parents:
diff changeset
23 t.hour = 21;
1568
c357039c1ab1 mod_storage_muc_log: Change to sane timestamp format and warn if it differs from legacy mod_muc_log timestamps
Kim Alvefur <zash@zash.se>
parents: 1566
diff changeset
24 local pm = os_date("!%X", os.time(t));
1566
9158882dd9a1 mod_storage_muc_log: Provides an archive API to mod_muc_log data
Kim Alvefur <zash@zash.se>
parents:
diff changeset
25 if am == pm then
9158882dd9a1 mod_storage_muc_log: Provides an archive API to mod_muc_log data
Kim Alvefur <zash@zash.se>
parents:
diff changeset
26 module:log("warn", "Timestamps in AM and PM are identical in your locale, expect timestamps to be wrong");
9158882dd9a1 mod_storage_muc_log: Provides an archive API to mod_muc_log data
Kim Alvefur <zash@zash.se>
parents:
diff changeset
27 end
1569
711fabfe6604 mod_storage_muc_log: Fix typo
Kim Alvefur <zash@zash.se>
parents: 1568
diff changeset
28 if os_date("!%X", os.time(t)) ~= os_date(timef, os.time(t)) then
1568
c357039c1ab1 mod_storage_muc_log: Change to sane timestamp format and warn if it differs from legacy mod_muc_log timestamps
Kim Alvefur <zash@zash.se>
parents: 1566
diff changeset
29 module:log("warn", "Timestamp format differ from what mod_muc_log used, this module may not work correctly");
c357039c1ab1 mod_storage_muc_log: Change to sane timestamp format and warn if it differs from legacy mod_muc_log timestamps
Kim Alvefur <zash@zash.se>
parents: 1566
diff changeset
30 end
1566
9158882dd9a1 mod_storage_muc_log: Provides an archive API to mod_muc_log data
Kim Alvefur <zash@zash.se>
parents:
diff changeset
31 end
9158882dd9a1 mod_storage_muc_log: Provides an archive API to mod_muc_log data
Kim Alvefur <zash@zash.se>
parents:
diff changeset
32
9158882dd9a1 mod_storage_muc_log: Provides an archive API to mod_muc_log data
Kim Alvefur <zash@zash.se>
parents:
diff changeset
33 local function parse_silly(date, time)
9158882dd9a1 mod_storage_muc_log: Provides an archive API to mod_muc_log data
Kim Alvefur <zash@zash.se>
parents:
diff changeset
34 local year, month, day = date:match("^(%d%d)(%d%d)(%d%d)");
9158882dd9a1 mod_storage_muc_log: Provides an archive API to mod_muc_log data
Kim Alvefur <zash@zash.se>
parents:
diff changeset
35 year = "20"..year;
9158882dd9a1 mod_storage_muc_log: Provides an archive API to mod_muc_log data
Kim Alvefur <zash@zash.se>
parents:
diff changeset
36 -- year = (year < "70" and "20" or "19") .. year;
9158882dd9a1 mod_storage_muc_log: Provides an archive API to mod_muc_log data
Kim Alvefur <zash@zash.se>
parents:
diff changeset
37 local hour, min, sec = time:match("(%d%d)%D+(%d%d)%D+(%d%d)");
9158882dd9a1 mod_storage_muc_log: Provides an archive API to mod_muc_log data
Kim Alvefur <zash@zash.se>
parents:
diff changeset
38 if hour == "12" and time:find("[Aa][Mm]") then
9158882dd9a1 mod_storage_muc_log: Provides an archive API to mod_muc_log data
Kim Alvefur <zash@zash.se>
parents:
diff changeset
39 hour = "00";
9158882dd9a1 mod_storage_muc_log: Provides an archive API to mod_muc_log data
Kim Alvefur <zash@zash.se>
parents:
diff changeset
40 elseif hour < "12" and time:find("[Pp][Mm]") then
9158882dd9a1 mod_storage_muc_log: Provides an archive API to mod_muc_log data
Kim Alvefur <zash@zash.se>
parents:
diff changeset
41 hour = tostring(tonumber(hour) % 12 + 12);
9158882dd9a1 mod_storage_muc_log: Provides an archive API to mod_muc_log data
Kim Alvefur <zash@zash.se>
parents:
diff changeset
42 end
9158882dd9a1 mod_storage_muc_log: Provides an archive API to mod_muc_log data
Kim Alvefur <zash@zash.se>
parents:
diff changeset
43 return datetime.parse(("%s-%s-%sT%s:%s:%sZ"):format(year, month, day, hour or "00", min or "00", sec or "00"));
9158882dd9a1 mod_storage_muc_log: Provides an archive API to mod_muc_log data
Kim Alvefur <zash@zash.se>
parents:
diff changeset
44 end
9158882dd9a1 mod_storage_muc_log: Provides an archive API to mod_muc_log data
Kim Alvefur <zash@zash.se>
parents:
diff changeset
45
9158882dd9a1 mod_storage_muc_log: Provides an archive API to mod_muc_log data
Kim Alvefur <zash@zash.se>
parents:
diff changeset
46 local function st_with(tag)
9158882dd9a1 mod_storage_muc_log: Provides an archive API to mod_muc_log data
Kim Alvefur <zash@zash.se>
parents:
diff changeset
47 local with = tag.attr.type;
9158882dd9a1 mod_storage_muc_log: Provides an archive API to mod_muc_log data
Kim Alvefur <zash@zash.se>
parents:
diff changeset
48 return with and tag.name .. "<" .. with or tag.name;
9158882dd9a1 mod_storage_muc_log: Provides an archive API to mod_muc_log data
Kim Alvefur <zash@zash.se>
parents:
diff changeset
49 end
9158882dd9a1 mod_storage_muc_log: Provides an archive API to mod_muc_log data
Kim Alvefur <zash@zash.se>
parents:
diff changeset
50
2356
49a01b78b45f mod_storage_muc_log: Address luacheck warnings
Kim Alvefur <zash@zash.se>
parents: 1760
diff changeset
51 function driver:append(node, key, stanza, when, with) -- luacheck: ignore 212/key
49a01b78b45f mod_storage_muc_log: Address luacheck warnings
Kim Alvefur <zash@zash.se>
parents: 1760
diff changeset
52 -- luacheck: ignore 311/with
49a01b78b45f mod_storage_muc_log: Address luacheck warnings
Kim Alvefur <zash@zash.se>
parents: 1760
diff changeset
53 -- 'with' doesn't exist in the original mod_muc_log, so gets derived here
1753
54c8a0cb2996 mod_storage_(archive-capable): Change order of arguments to :append to be the same as return values from :find iterator (see prosody 41725f3df3cc)
Kim Alvefur <zash@zash.se>
parents: 1569
diff changeset
54 if type(when) ~= "number" then
1760
e72f9eac51c8 mod_storage_(various): Order swapping in 54c8a0cb2996 was backwards
Kim Alvefur <zash@zash.se>
parents: 1759
diff changeset
55 when, with, stanza = stanza, when, with;
1753
54c8a0cb2996 mod_storage_(archive-capable): Change order of arguments to :append to be the same as return values from :find iterator (see prosody 41725f3df3cc)
Kim Alvefur <zash@zash.se>
parents: 1569
diff changeset
56 end
1566
9158882dd9a1 mod_storage_muc_log: Provides an archive API to mod_muc_log data
Kim Alvefur <zash@zash.se>
parents:
diff changeset
57 local today = os_date(datef, when);
9158882dd9a1 mod_storage_muc_log: Provides an archive API to mod_muc_log data
Kim Alvefur <zash@zash.se>
parents:
diff changeset
58 local now = os_date(timef, when);
9158882dd9a1 mod_storage_muc_log: Provides an archive API to mod_muc_log data
Kim Alvefur <zash@zash.se>
parents:
diff changeset
59 local data = data_load(node, host, datastore .. "/" .. today) or {};
9158882dd9a1 mod_storage_muc_log: Provides an archive API to mod_muc_log data
Kim Alvefur <zash@zash.se>
parents:
diff changeset
60 data[#data + 1] = "<stanza time=\"".. now .. "\">" .. tostring(stanza) .. "</stanza>\n";
9158882dd9a1 mod_storage_muc_log: Provides an archive API to mod_muc_log data
Kim Alvefur <zash@zash.se>
parents:
diff changeset
61 datamanager.getpath(node, host, datastore, nil, true); -- create the datastore dir
9158882dd9a1 mod_storage_muc_log: Provides an archive API to mod_muc_log data
Kim Alvefur <zash@zash.se>
parents:
diff changeset
62 local ok, err = data_store(node, host, datastore .. "/" .. today, data);
9158882dd9a1 mod_storage_muc_log: Provides an archive API to mod_muc_log data
Kim Alvefur <zash@zash.se>
parents:
diff changeset
63 if not ok then
9158882dd9a1 mod_storage_muc_log: Provides an archive API to mod_muc_log data
Kim Alvefur <zash@zash.se>
parents:
diff changeset
64 return ok, err;
9158882dd9a1 mod_storage_muc_log: Provides an archive API to mod_muc_log data
Kim Alvefur <zash@zash.se>
parents:
diff changeset
65 end
9158882dd9a1 mod_storage_muc_log: Provides an archive API to mod_muc_log data
Kim Alvefur <zash@zash.se>
parents:
diff changeset
66 return today .. "_" .. #data;
9158882dd9a1 mod_storage_muc_log: Provides an archive API to mod_muc_log data
Kim Alvefur <zash@zash.se>
parents:
diff changeset
67 end
9158882dd9a1 mod_storage_muc_log: Provides an archive API to mod_muc_log data
Kim Alvefur <zash@zash.se>
parents:
diff changeset
68
2357
093b70378fa5 mod_storage_muc_log: Separate out date collection into API method
Kim Alvefur <zash@zash.se>
parents: 2356
diff changeset
69 function driver:dates(node)
1566
9158882dd9a1 mod_storage_muc_log: Provides an archive API to mod_muc_log data
Kim Alvefur <zash@zash.se>
parents:
diff changeset
70 local path = datamanager.getpath(node, host, datastore):match("(.*)/");
9158882dd9a1 mod_storage_muc_log: Provides an archive API to mod_muc_log data
Kim Alvefur <zash@zash.se>
parents:
diff changeset
71
9158882dd9a1 mod_storage_muc_log: Provides an archive API to mod_muc_log data
Kim Alvefur <zash@zash.se>
parents:
diff changeset
72 local ok, iter, state, var = pcall(lfs.dir, path);
9158882dd9a1 mod_storage_muc_log: Provides an archive API to mod_muc_log data
Kim Alvefur <zash@zash.se>
parents:
diff changeset
73 if not ok then
9158882dd9a1 mod_storage_muc_log: Provides an archive API to mod_muc_log data
Kim Alvefur <zash@zash.se>
parents:
diff changeset
74 module:log("warn", iter);
9158882dd9a1 mod_storage_muc_log: Provides an archive API to mod_muc_log data
Kim Alvefur <zash@zash.se>
parents:
diff changeset
75 return nil, iter;
9158882dd9a1 mod_storage_muc_log: Provides an archive API to mod_muc_log data
Kim Alvefur <zash@zash.se>
parents:
diff changeset
76 end
9158882dd9a1 mod_storage_muc_log: Provides an archive API to mod_muc_log data
Kim Alvefur <zash@zash.se>
parents:
diff changeset
77
9158882dd9a1 mod_storage_muc_log: Provides an archive API to mod_muc_log data
Kim Alvefur <zash@zash.se>
parents:
diff changeset
78 local dates, i = {}, 1;
9158882dd9a1 mod_storage_muc_log: Provides an archive API to mod_muc_log data
Kim Alvefur <zash@zash.se>
parents:
diff changeset
79 for dir in iter, state, var do
9158882dd9a1 mod_storage_muc_log: Provides an archive API to mod_muc_log data
Kim Alvefur <zash@zash.se>
parents:
diff changeset
80 if lfs.attributes(datamanager.getpath(node, host, datastore .. "/" .. dir), "mode") == "file" then
9158882dd9a1 mod_storage_muc_log: Provides an archive API to mod_muc_log data
Kim Alvefur <zash@zash.se>
parents:
diff changeset
81 dates[i], i = dir, i+1;
9158882dd9a1 mod_storage_muc_log: Provides an archive API to mod_muc_log data
Kim Alvefur <zash@zash.se>
parents:
diff changeset
82 end
9158882dd9a1 mod_storage_muc_log: Provides an archive API to mod_muc_log data
Kim Alvefur <zash@zash.se>
parents:
diff changeset
83 end
2825
d0c4ecabf3f5 mod_storage_muc_log: Signal store being empty correctly
Kim Alvefur <zash@zash.se>
parents: 2821
diff changeset
84 if dates[1] == nil then return nil end
1566
9158882dd9a1 mod_storage_muc_log: Provides an archive API to mod_muc_log data
Kim Alvefur <zash@zash.se>
parents:
diff changeset
85 table.sort(dates);
2357
093b70378fa5 mod_storage_muc_log: Separate out date collection into API method
Kim Alvefur <zash@zash.se>
parents: 2356
diff changeset
86 return dates;
093b70378fa5 mod_storage_muc_log: Separate out date collection into API method
Kim Alvefur <zash@zash.se>
parents: 2356
diff changeset
87 end
093b70378fa5 mod_storage_muc_log: Separate out date collection into API method
Kim Alvefur <zash@zash.se>
parents: 2356
diff changeset
88
093b70378fa5 mod_storage_muc_log: Separate out date collection into API method
Kim Alvefur <zash@zash.se>
parents: 2356
diff changeset
89 function driver:find(node, query)
093b70378fa5 mod_storage_muc_log: Separate out date collection into API method
Kim Alvefur <zash@zash.se>
parents: 2356
diff changeset
90 local dates, err = self:dates(node);
093b70378fa5 mod_storage_muc_log: Separate out date collection into API method
Kim Alvefur <zash@zash.se>
parents: 2356
diff changeset
91 if not dates then return dates, err; end
1566
9158882dd9a1 mod_storage_muc_log: Provides an archive API to mod_muc_log data
Kim Alvefur <zash@zash.se>
parents:
diff changeset
92
9158882dd9a1 mod_storage_muc_log: Provides an archive API to mod_muc_log data
Kim Alvefur <zash@zash.se>
parents:
diff changeset
93 return coroutine.wrap(function ()
9158882dd9a1 mod_storage_muc_log: Provides an archive API to mod_muc_log data
Kim Alvefur <zash@zash.se>
parents:
diff changeset
94 local start_date = query and query.start and os_date(datef, query.start) or dates[1];
9158882dd9a1 mod_storage_muc_log: Provides an archive API to mod_muc_log data
Kim Alvefur <zash@zash.se>
parents:
diff changeset
95 local end_date = query and query["end"] and os_date(datef, query["end"]) or dates[#dates];
9158882dd9a1 mod_storage_muc_log: Provides an archive API to mod_muc_log data
Kim Alvefur <zash@zash.se>
parents:
diff changeset
96 local start_time = query and query.start and os_date(timef, query.start) or dates[1];
9158882dd9a1 mod_storage_muc_log: Provides an archive API to mod_muc_log data
Kim Alvefur <zash@zash.se>
parents:
diff changeset
97 local end_time = query and query["end"] and os_date(timef, query["end"]) or dates[#dates];
9158882dd9a1 mod_storage_muc_log: Provides an archive API to mod_muc_log data
Kim Alvefur <zash@zash.se>
parents:
diff changeset
98 local query_with = query and query.with;
9158882dd9a1 mod_storage_muc_log: Provides an archive API to mod_muc_log data
Kim Alvefur <zash@zash.se>
parents:
diff changeset
99 local query_limit = query and query.limit;
9158882dd9a1 mod_storage_muc_log: Provides an archive API to mod_muc_log data
Kim Alvefur <zash@zash.se>
parents:
diff changeset
100 local seek_once = query and query.after;
9158882dd9a1 mod_storage_muc_log: Provides an archive API to mod_muc_log data
Kim Alvefur <zash@zash.se>
parents:
diff changeset
101
9158882dd9a1 mod_storage_muc_log: Provides an archive API to mod_muc_log data
Kim Alvefur <zash@zash.se>
parents:
diff changeset
102 local today, time, data, err, item;
9158882dd9a1 mod_storage_muc_log: Provides an archive API to mod_muc_log data
Kim Alvefur <zash@zash.se>
parents:
diff changeset
103 local inner_start, inner_stop, inner_step;
9158882dd9a1 mod_storage_muc_log: Provides an archive API to mod_muc_log data
Kim Alvefur <zash@zash.se>
parents:
diff changeset
104 local outer_start, outer_stop, outer_step = 1, #dates, 1;
2820
f3a09a559201 mod_storage_muc_log: Trim trailing whitespace [luacheck]
Kim Alvefur <zash@zash.se>
parents: 2357
diff changeset
105 if query and query.reverse then
1566
9158882dd9a1 mod_storage_muc_log: Provides an archive API to mod_muc_log data
Kim Alvefur <zash@zash.se>
parents:
diff changeset
106 outer_start, outer_stop, outer_step = outer_stop, outer_start, -outer_step;
9158882dd9a1 mod_storage_muc_log: Provides an archive API to mod_muc_log data
Kim Alvefur <zash@zash.se>
parents:
diff changeset
107 seek_once = query.before;
9158882dd9a1 mod_storage_muc_log: Provides an archive API to mod_muc_log data
Kim Alvefur <zash@zash.se>
parents:
diff changeset
108 if seek_once then
9158882dd9a1 mod_storage_muc_log: Provides an archive API to mod_muc_log data
Kim Alvefur <zash@zash.se>
parents:
diff changeset
109 end_date = seek_once:match"^(%d+)_%d";
9158882dd9a1 mod_storage_muc_log: Provides an archive API to mod_muc_log data
Kim Alvefur <zash@zash.se>
parents:
diff changeset
110 end
9158882dd9a1 mod_storage_muc_log: Provides an archive API to mod_muc_log data
Kim Alvefur <zash@zash.se>
parents:
diff changeset
111 elseif seek_once then
9158882dd9a1 mod_storage_muc_log: Provides an archive API to mod_muc_log data
Kim Alvefur <zash@zash.se>
parents:
diff changeset
112 start_date = seek_once:match"^(%d+)_%d";
9158882dd9a1 mod_storage_muc_log: Provides an archive API to mod_muc_log data
Kim Alvefur <zash@zash.se>
parents:
diff changeset
113 end
9158882dd9a1 mod_storage_muc_log: Provides an archive API to mod_muc_log data
Kim Alvefur <zash@zash.se>
parents:
diff changeset
114 local matches = 0;
9158882dd9a1 mod_storage_muc_log: Provides an archive API to mod_muc_log data
Kim Alvefur <zash@zash.se>
parents:
diff changeset
115 for i = outer_start, outer_stop, outer_step do
9158882dd9a1 mod_storage_muc_log: Provides an archive API to mod_muc_log data
Kim Alvefur <zash@zash.se>
parents:
diff changeset
116 today = dates[i];
9158882dd9a1 mod_storage_muc_log: Provides an archive API to mod_muc_log data
Kim Alvefur <zash@zash.se>
parents:
diff changeset
117 if today >= start_date and today <= end_date then
9158882dd9a1 mod_storage_muc_log: Provides an archive API to mod_muc_log data
Kim Alvefur <zash@zash.se>
parents:
diff changeset
118 data, err = data_load(node, host, datastore .. "/" .. today);
9158882dd9a1 mod_storage_muc_log: Provides an archive API to mod_muc_log data
Kim Alvefur <zash@zash.se>
parents:
diff changeset
119 if data then
9158882dd9a1 mod_storage_muc_log: Provides an archive API to mod_muc_log data
Kim Alvefur <zash@zash.se>
parents:
diff changeset
120 inner_start, inner_stop, inner_step = 1, #data, 1;
2820
f3a09a559201 mod_storage_muc_log: Trim trailing whitespace [luacheck]
Kim Alvefur <zash@zash.se>
parents: 2357
diff changeset
121 if query and query.reverse then
1566
9158882dd9a1 mod_storage_muc_log: Provides an archive API to mod_muc_log data
Kim Alvefur <zash@zash.se>
parents:
diff changeset
122 inner_start, inner_stop, inner_step = inner_stop, inner_start, -inner_step;
9158882dd9a1 mod_storage_muc_log: Provides an archive API to mod_muc_log data
Kim Alvefur <zash@zash.se>
parents:
diff changeset
123 end
9158882dd9a1 mod_storage_muc_log: Provides an archive API to mod_muc_log data
Kim Alvefur <zash@zash.se>
parents:
diff changeset
124 if seek_once then
9158882dd9a1 mod_storage_muc_log: Provides an archive API to mod_muc_log data
Kim Alvefur <zash@zash.se>
parents:
diff changeset
125 inner_start = tonumber(seek_once:match("_(%d+)$"));
9158882dd9a1 mod_storage_muc_log: Provides an archive API to mod_muc_log data
Kim Alvefur <zash@zash.se>
parents:
diff changeset
126 inner_start = inner_start + (query and query.reverse and -1 or 1);
9158882dd9a1 mod_storage_muc_log: Provides an archive API to mod_muc_log data
Kim Alvefur <zash@zash.se>
parents:
diff changeset
127 seek_once = nil;
9158882dd9a1 mod_storage_muc_log: Provides an archive API to mod_muc_log data
Kim Alvefur <zash@zash.se>
parents:
diff changeset
128 end
2356
49a01b78b45f mod_storage_muc_log: Address luacheck warnings
Kim Alvefur <zash@zash.se>
parents: 1760
diff changeset
129 for i = inner_start, inner_stop, inner_step do -- luacheck: ignore 423/i
49a01b78b45f mod_storage_muc_log: Address luacheck warnings
Kim Alvefur <zash@zash.se>
parents: 1760
diff changeset
130 item, err = data[i], nil;
1566
9158882dd9a1 mod_storage_muc_log: Provides an archive API to mod_muc_log data
Kim Alvefur <zash@zash.se>
parents:
diff changeset
131 if item then
9158882dd9a1 mod_storage_muc_log: Provides an archive API to mod_muc_log data
Kim Alvefur <zash@zash.se>
parents:
diff changeset
132 item, err = xml_parse(item);
9158882dd9a1 mod_storage_muc_log: Provides an archive API to mod_muc_log data
Kim Alvefur <zash@zash.se>
parents:
diff changeset
133 end
9158882dd9a1 mod_storage_muc_log: Provides an archive API to mod_muc_log data
Kim Alvefur <zash@zash.se>
parents:
diff changeset
134 if item then
9158882dd9a1 mod_storage_muc_log: Provides an archive API to mod_muc_log data
Kim Alvefur <zash@zash.se>
parents:
diff changeset
135 time = item.attr.time;
9158882dd9a1 mod_storage_muc_log: Provides an archive API to mod_muc_log data
Kim Alvefur <zash@zash.se>
parents:
diff changeset
136 item = item.tags[1];
3468
228e59bee8ad mod_storage_muc_log: Return 'with' property for items (API conformance)
Kim Alvefur <zash@zash.se>
parents: 2825
diff changeset
137 local with = st_with(item);
1566
9158882dd9a1 mod_storage_muc_log: Provides an archive API to mod_muc_log data
Kim Alvefur <zash@zash.se>
parents:
diff changeset
138 if (today >= start_date or time >= start_time) and
9158882dd9a1 mod_storage_muc_log: Provides an archive API to mod_muc_log data
Kim Alvefur <zash@zash.se>
parents:
diff changeset
139 (today <= end_date or time <= end_time) and
3468
228e59bee8ad mod_storage_muc_log: Return 'with' property for items (API conformance)
Kim Alvefur <zash@zash.se>
parents: 2825
diff changeset
140 (not query_with or query_with == with) and
1566
9158882dd9a1 mod_storage_muc_log: Provides an archive API to mod_muc_log data
Kim Alvefur <zash@zash.se>
parents:
diff changeset
141 item:get_child_text("alreadyJoined") ~= "true" then
9158882dd9a1 mod_storage_muc_log: Provides an archive API to mod_muc_log data
Kim Alvefur <zash@zash.se>
parents:
diff changeset
142 matches = matches + 1;
3468
228e59bee8ad mod_storage_muc_log: Return 'with' property for items (API conformance)
Kim Alvefur <zash@zash.se>
parents: 2825
diff changeset
143 coroutine.yield(today.."_"..i, item, parse_silly(today, time), with);
1566
9158882dd9a1 mod_storage_muc_log: Provides an archive API to mod_muc_log data
Kim Alvefur <zash@zash.se>
parents:
diff changeset
144 if query_limit and matches >= query_limit then
9158882dd9a1 mod_storage_muc_log: Provides an archive API to mod_muc_log data
Kim Alvefur <zash@zash.se>
parents:
diff changeset
145 return;
9158882dd9a1 mod_storage_muc_log: Provides an archive API to mod_muc_log data
Kim Alvefur <zash@zash.se>
parents:
diff changeset
146 end
9158882dd9a1 mod_storage_muc_log: Provides an archive API to mod_muc_log data
Kim Alvefur <zash@zash.se>
parents:
diff changeset
147 end
9158882dd9a1 mod_storage_muc_log: Provides an archive API to mod_muc_log data
Kim Alvefur <zash@zash.se>
parents:
diff changeset
148 elseif err then
9158882dd9a1 mod_storage_muc_log: Provides an archive API to mod_muc_log data
Kim Alvefur <zash@zash.se>
parents:
diff changeset
149 module:log("warn", err);
9158882dd9a1 mod_storage_muc_log: Provides an archive API to mod_muc_log data
Kim Alvefur <zash@zash.se>
parents:
diff changeset
150 end
9158882dd9a1 mod_storage_muc_log: Provides an archive API to mod_muc_log data
Kim Alvefur <zash@zash.se>
parents:
diff changeset
151 end
9158882dd9a1 mod_storage_muc_log: Provides an archive API to mod_muc_log data
Kim Alvefur <zash@zash.se>
parents:
diff changeset
152 elseif err then
9158882dd9a1 mod_storage_muc_log: Provides an archive API to mod_muc_log data
Kim Alvefur <zash@zash.se>
parents:
diff changeset
153 module:log("warn", err);
9158882dd9a1 mod_storage_muc_log: Provides an archive API to mod_muc_log data
Kim Alvefur <zash@zash.se>
parents:
diff changeset
154 end
9158882dd9a1 mod_storage_muc_log: Provides an archive API to mod_muc_log data
Kim Alvefur <zash@zash.se>
parents:
diff changeset
155 end
9158882dd9a1 mod_storage_muc_log: Provides an archive API to mod_muc_log data
Kim Alvefur <zash@zash.se>
parents:
diff changeset
156 end
9158882dd9a1 mod_storage_muc_log: Provides an archive API to mod_muc_log data
Kim Alvefur <zash@zash.se>
parents:
diff changeset
157 end);
9158882dd9a1 mod_storage_muc_log: Provides an archive API to mod_muc_log data
Kim Alvefur <zash@zash.se>
parents:
diff changeset
158 end
9158882dd9a1 mod_storage_muc_log: Provides an archive API to mod_muc_log data
Kim Alvefur <zash@zash.se>
parents:
diff changeset
159
9158882dd9a1 mod_storage_muc_log: Provides an archive API to mod_muc_log data
Kim Alvefur <zash@zash.se>
parents:
diff changeset
160 function open(_, store, typ)
9158882dd9a1 mod_storage_muc_log: Provides an archive API to mod_muc_log data
Kim Alvefur <zash@zash.se>
parents:
diff changeset
161 if typ ~= "archive" then
9158882dd9a1 mod_storage_muc_log: Provides an archive API to mod_muc_log data
Kim Alvefur <zash@zash.se>
parents:
diff changeset
162 return nil, "unsupported-store";
9158882dd9a1 mod_storage_muc_log: Provides an archive API to mod_muc_log data
Kim Alvefur <zash@zash.se>
parents:
diff changeset
163 end
9158882dd9a1 mod_storage_muc_log: Provides an archive API to mod_muc_log data
Kim Alvefur <zash@zash.se>
parents:
diff changeset
164 return setmetatable({ store = store, type = typ }, driver_mt);
9158882dd9a1 mod_storage_muc_log: Provides an archive API to mod_muc_log data
Kim Alvefur <zash@zash.se>
parents:
diff changeset
165 end
9158882dd9a1 mod_storage_muc_log: Provides an archive API to mod_muc_log data
Kim Alvefur <zash@zash.se>
parents:
diff changeset
166
9158882dd9a1 mod_storage_muc_log: Provides an archive API to mod_muc_log data
Kim Alvefur <zash@zash.se>
parents:
diff changeset
167 module:provides "storage";