annotate mod_storage_muc_log/mod_storage_muc_log.lua @ 3282:9346ed926842

mod_bookmarks: Display the bare JID instead of the username in logs.
author Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
date Sat, 25 Aug 2018 17:39:01 +0200
parents d0c4ecabf3f5
children 228e59bee8ad
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 noop = function () end;
9158882dd9a1 mod_storage_muc_log: Provides an archive API to mod_muc_log data
Kim Alvefur <zash@zash.se>
parents:
diff changeset
10 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
11
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
12 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
13 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
14
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 = {};
9158882dd9a1 mod_storage_muc_log: Provides an archive API to mod_muc_log data
Kim Alvefur <zash@zash.se>
parents:
diff changeset
16 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
17
9158882dd9a1 mod_storage_muc_log: Provides an archive API to mod_muc_log data
Kim Alvefur <zash@zash.se>
parents:
diff changeset
18 do
9158882dd9a1 mod_storage_muc_log: Provides an archive API to mod_muc_log data
Kim Alvefur <zash@zash.se>
parents:
diff changeset
19 -- Sanity check
9158882dd9a1 mod_storage_muc_log: Provides an archive API to mod_muc_log data
Kim Alvefur <zash@zash.se>
parents:
diff changeset
20 -- 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
21 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
22 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
23 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
24 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
25 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
26 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
27 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
28 end
1569
711fabfe6604 mod_storage_muc_log: Fix typo
Kim Alvefur <zash@zash.se>
parents: 1568
diff changeset
29 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
30 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
31 end
1566
9158882dd9a1 mod_storage_muc_log: Provides an archive API to mod_muc_log data
Kim Alvefur <zash@zash.se>
parents:
diff changeset
32 end
9158882dd9a1 mod_storage_muc_log: Provides an archive API to mod_muc_log data
Kim Alvefur <zash@zash.se>
parents:
diff changeset
33
9158882dd9a1 mod_storage_muc_log: Provides an archive API to mod_muc_log data
Kim Alvefur <zash@zash.se>
parents:
diff changeset
34 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
35 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
36 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
37 -- 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
38 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
39 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
40 hour = "00";
9158882dd9a1 mod_storage_muc_log: Provides an archive API to mod_muc_log data
Kim Alvefur <zash@zash.se>
parents:
diff changeset
41 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
42 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
43 end
9158882dd9a1 mod_storage_muc_log: Provides an archive API to mod_muc_log data
Kim Alvefur <zash@zash.se>
parents:
diff changeset
44 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
45 end
9158882dd9a1 mod_storage_muc_log: Provides an archive API to mod_muc_log data
Kim Alvefur <zash@zash.se>
parents:
diff changeset
46
9158882dd9a1 mod_storage_muc_log: Provides an archive API to mod_muc_log data
Kim Alvefur <zash@zash.se>
parents:
diff changeset
47 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
48 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
49 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
50 end
9158882dd9a1 mod_storage_muc_log: Provides an archive API to mod_muc_log data
Kim Alvefur <zash@zash.se>
parents:
diff changeset
51
2356
49a01b78b45f mod_storage_muc_log: Address luacheck warnings
Kim Alvefur <zash@zash.se>
parents: 1760
diff changeset
52 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
53 -- luacheck: ignore 311/with
49a01b78b45f mod_storage_muc_log: Address luacheck warnings
Kim Alvefur <zash@zash.se>
parents: 1760
diff changeset
54 -- '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
55 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
56 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
57 end
1566
9158882dd9a1 mod_storage_muc_log: Provides an archive API to mod_muc_log data
Kim Alvefur <zash@zash.se>
parents:
diff changeset
58 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
59 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
60 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
61 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
62 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
63 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
64 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
65 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
66 end
9158882dd9a1 mod_storage_muc_log: Provides an archive API to mod_muc_log data
Kim Alvefur <zash@zash.se>
parents:
diff changeset
67 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
68 end
9158882dd9a1 mod_storage_muc_log: Provides an archive API to mod_muc_log data
Kim Alvefur <zash@zash.se>
parents:
diff changeset
69
2357
093b70378fa5 mod_storage_muc_log: Separate out date collection into API method
Kim Alvefur <zash@zash.se>
parents: 2356
diff changeset
70 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
71 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
72
9158882dd9a1 mod_storage_muc_log: Provides an archive API to mod_muc_log data
Kim Alvefur <zash@zash.se>
parents:
diff changeset
73 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
74 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
75 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
76 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
77 end
9158882dd9a1 mod_storage_muc_log: Provides an archive API to mod_muc_log data
Kim Alvefur <zash@zash.se>
parents:
diff changeset
78
9158882dd9a1 mod_storage_muc_log: Provides an archive API to mod_muc_log data
Kim Alvefur <zash@zash.se>
parents:
diff changeset
79 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
80 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
81 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
82 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
83 end
9158882dd9a1 mod_storage_muc_log: Provides an archive API to mod_muc_log data
Kim Alvefur <zash@zash.se>
parents:
diff changeset
84 end
2825
d0c4ecabf3f5 mod_storage_muc_log: Signal store being empty correctly
Kim Alvefur <zash@zash.se>
parents: 2821
diff changeset
85 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
86 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
87 return dates;
093b70378fa5 mod_storage_muc_log: Separate out date collection into API method
Kim Alvefur <zash@zash.se>
parents: 2356
diff changeset
88 end
093b70378fa5 mod_storage_muc_log: Separate out date collection into API method
Kim Alvefur <zash@zash.se>
parents: 2356
diff changeset
89
093b70378fa5 mod_storage_muc_log: Separate out date collection into API method
Kim Alvefur <zash@zash.se>
parents: 2356
diff changeset
90 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
91 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
92 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
93
9158882dd9a1 mod_storage_muc_log: Provides an archive API to mod_muc_log data
Kim Alvefur <zash@zash.se>
parents:
diff changeset
94 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
95 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
96 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
97 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
98 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
99 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
100 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
101 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
102
9158882dd9a1 mod_storage_muc_log: Provides an archive API to mod_muc_log data
Kim Alvefur <zash@zash.se>
parents:
diff changeset
103 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
104 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
105 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
106 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
107 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
108 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
109 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
110 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
111 end
9158882dd9a1 mod_storage_muc_log: Provides an archive API to mod_muc_log data
Kim Alvefur <zash@zash.se>
parents:
diff changeset
112 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
113 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
114 end
9158882dd9a1 mod_storage_muc_log: Provides an archive API to mod_muc_log data
Kim Alvefur <zash@zash.se>
parents:
diff changeset
115 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
116 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
117 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
118 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
119 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
120 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
121 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
122 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
123 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
124 end
9158882dd9a1 mod_storage_muc_log: Provides an archive API to mod_muc_log data
Kim Alvefur <zash@zash.se>
parents:
diff changeset
125 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
126 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
127 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
128 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
129 end
2356
49a01b78b45f mod_storage_muc_log: Address luacheck warnings
Kim Alvefur <zash@zash.se>
parents: 1760
diff changeset
130 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
131 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
132 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
133 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
134 end
9158882dd9a1 mod_storage_muc_log: Provides an archive API to mod_muc_log data
Kim Alvefur <zash@zash.se>
parents:
diff changeset
135 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
136 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
137 item = item.tags[1];
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
9158882dd9a1 mod_storage_muc_log: Provides an archive API to mod_muc_log data
Kim Alvefur <zash@zash.se>
parents:
diff changeset
140 (not query_with or query_with == st_with(item)) and
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;
9158882dd9a1 mod_storage_muc_log: Provides an archive API to mod_muc_log data
Kim Alvefur <zash@zash.se>
parents:
diff changeset
143 coroutine.yield(today.."_"..i, item, parse_silly(today, time));
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";