annotate mod_muc_archive/mod_muc_archive.lua @ 4876:0f5f2d4475b9

mod_http_xep227: Add support for import via APIs rather than direct store manipulation In particular this transitions PEP nodes and data to be imported via mod_pep's APIs, fixing issues with importing at runtime while PEP data may already be live in RAM. Next obvious candidate for this approach is rosters, so clients get immediate roster pushes and other special handling (such as emitting subscribes to reach the desired subscription state).
author Matthew Wild <mwild1@gmail.com>
date Tue, 18 Jan 2022 17:01:18 +0000
parents 7e96b95924bd
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
3957
7e96b95924bd mod_muc_archive: Add fork of mod_muc_log that uses newer storage API
JC Brand <jc@opkode.com>
parents:
diff changeset
1 -- The MIT License (MIT)
7e96b95924bd mod_muc_archive: Add fork of mod_muc_log that uses newer storage API
JC Brand <jc@opkode.com>
parents:
diff changeset
2 --
7e96b95924bd mod_muc_archive: Add fork of mod_muc_log that uses newer storage API
JC Brand <jc@opkode.com>
parents:
diff changeset
3 -- Copyright (C) 2009 Thilo Cestonaro
7e96b95924bd mod_muc_archive: Add fork of mod_muc_log that uses newer storage API
JC Brand <jc@opkode.com>
parents:
diff changeset
4 -- Copyright (C) 2009 Waqas Hussain
7e96b95924bd mod_muc_archive: Add fork of mod_muc_log that uses newer storage API
JC Brand <jc@opkode.com>
parents:
diff changeset
5 -- Copyright (C) 2009-2013 Matthew Wild
7e96b95924bd mod_muc_archive: Add fork of mod_muc_log that uses newer storage API
JC Brand <jc@opkode.com>
parents:
diff changeset
6 -- Copyright (C) 2013 Kim Alvefur
7e96b95924bd mod_muc_archive: Add fork of mod_muc_log that uses newer storage API
JC Brand <jc@opkode.com>
parents:
diff changeset
7 -- Copyright (C) 2013 Marco Cirillo
7e96b95924bd mod_muc_archive: Add fork of mod_muc_log that uses newer storage API
JC Brand <jc@opkode.com>
parents:
diff changeset
8 -- Copyright (c) 2020 JC Brand
7e96b95924bd mod_muc_archive: Add fork of mod_muc_log that uses newer storage API
JC Brand <jc@opkode.com>
parents:
diff changeset
9 --
7e96b95924bd mod_muc_archive: Add fork of mod_muc_log that uses newer storage API
JC Brand <jc@opkode.com>
parents:
diff changeset
10 -- Permission is hereby granted, free of charge, to any person obtaining a copy of
7e96b95924bd mod_muc_archive: Add fork of mod_muc_log that uses newer storage API
JC Brand <jc@opkode.com>
parents:
diff changeset
11 -- this software and associated documentation files (the "Software"), to deal in
7e96b95924bd mod_muc_archive: Add fork of mod_muc_log that uses newer storage API
JC Brand <jc@opkode.com>
parents:
diff changeset
12 -- the Software without restriction, including without limitation the rights to
7e96b95924bd mod_muc_archive: Add fork of mod_muc_log that uses newer storage API
JC Brand <jc@opkode.com>
parents:
diff changeset
13 -- use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
7e96b95924bd mod_muc_archive: Add fork of mod_muc_log that uses newer storage API
JC Brand <jc@opkode.com>
parents:
diff changeset
14 -- the Software, and to permit persons to whom the Software is furnished to do so,
7e96b95924bd mod_muc_archive: Add fork of mod_muc_log that uses newer storage API
JC Brand <jc@opkode.com>
parents:
diff changeset
15 -- subject to the following conditions:
7e96b95924bd mod_muc_archive: Add fork of mod_muc_log that uses newer storage API
JC Brand <jc@opkode.com>
parents:
diff changeset
16 --
7e96b95924bd mod_muc_archive: Add fork of mod_muc_log that uses newer storage API
JC Brand <jc@opkode.com>
parents:
diff changeset
17 -- The above copyright notice and this permission notice shall be included in all
7e96b95924bd mod_muc_archive: Add fork of mod_muc_log that uses newer storage API
JC Brand <jc@opkode.com>
parents:
diff changeset
18 -- copies or substantial portions of the Software.
7e96b95924bd mod_muc_archive: Add fork of mod_muc_log that uses newer storage API
JC Brand <jc@opkode.com>
parents:
diff changeset
19 --
7e96b95924bd mod_muc_archive: Add fork of mod_muc_log that uses newer storage API
JC Brand <jc@opkode.com>
parents:
diff changeset
20 -- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
7e96b95924bd mod_muc_archive: Add fork of mod_muc_log that uses newer storage API
JC Brand <jc@opkode.com>
parents:
diff changeset
21 -- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
7e96b95924bd mod_muc_archive: Add fork of mod_muc_log that uses newer storage API
JC Brand <jc@opkode.com>
parents:
diff changeset
22 -- FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
7e96b95924bd mod_muc_archive: Add fork of mod_muc_log that uses newer storage API
JC Brand <jc@opkode.com>
parents:
diff changeset
23 -- COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
7e96b95924bd mod_muc_archive: Add fork of mod_muc_log that uses newer storage API
JC Brand <jc@opkode.com>
parents:
diff changeset
24 -- IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
7e96b95924bd mod_muc_archive: Add fork of mod_muc_log that uses newer storage API
JC Brand <jc@opkode.com>
parents:
diff changeset
25 -- CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
7e96b95924bd mod_muc_archive: Add fork of mod_muc_log that uses newer storage API
JC Brand <jc@opkode.com>
parents:
diff changeset
26 --
7e96b95924bd mod_muc_archive: Add fork of mod_muc_log that uses newer storage API
JC Brand <jc@opkode.com>
parents:
diff changeset
27 local hosts = prosody.hosts;
7e96b95924bd mod_muc_archive: Add fork of mod_muc_log that uses newer storage API
JC Brand <jc@opkode.com>
parents:
diff changeset
28 local tostring = tostring;
7e96b95924bd mod_muc_archive: Add fork of mod_muc_log that uses newer storage API
JC Brand <jc@opkode.com>
parents:
diff changeset
29 local st = require "util.stanza";
7e96b95924bd mod_muc_archive: Add fork of mod_muc_log that uses newer storage API
JC Brand <jc@opkode.com>
parents:
diff changeset
30 local split_jid = require "util.jid".split;
7e96b95924bd mod_muc_archive: Add fork of mod_muc_log that uses newer storage API
JC Brand <jc@opkode.com>
parents:
diff changeset
31 local jid_bare = require "util.jid".bare;
7e96b95924bd mod_muc_archive: Add fork of mod_muc_log that uses newer storage API
JC Brand <jc@opkode.com>
parents:
diff changeset
32 local time_now = os.time;
7e96b95924bd mod_muc_archive: Add fork of mod_muc_log that uses newer storage API
JC Brand <jc@opkode.com>
parents:
diff changeset
33
7e96b95924bd mod_muc_archive: Add fork of mod_muc_log that uses newer storage API
JC Brand <jc@opkode.com>
parents:
diff changeset
34 local muc_form_config_option = "muc#roomconfig_enablelogging"
7e96b95924bd mod_muc_archive: Add fork of mod_muc_log that uses newer storage API
JC Brand <jc@opkode.com>
parents:
diff changeset
35
7e96b95924bd mod_muc_archive: Add fork of mod_muc_log that uses newer storage API
JC Brand <jc@opkode.com>
parents:
diff changeset
36 local log_all_rooms = module:get_option_boolean("muc_log_all_rooms", false);
7e96b95924bd mod_muc_archive: Add fork of mod_muc_log that uses newer storage API
JC Brand <jc@opkode.com>
parents:
diff changeset
37 local log_by_default = module:get_option_boolean("muc_log_by_default", false);
7e96b95924bd mod_muc_archive: Add fork of mod_muc_log that uses newer storage API
JC Brand <jc@opkode.com>
parents:
diff changeset
38 local log_presences = module:get_option_boolean("muc_log_presences", true);
7e96b95924bd mod_muc_archive: Add fork of mod_muc_log that uses newer storage API
JC Brand <jc@opkode.com>
parents:
diff changeset
39
7e96b95924bd mod_muc_archive: Add fork of mod_muc_log that uses newer storage API
JC Brand <jc@opkode.com>
parents:
diff changeset
40 local archive_store = "muc_logging_archive";
7e96b95924bd mod_muc_archive: Add fork of mod_muc_log that uses newer storage API
JC Brand <jc@opkode.com>
parents:
diff changeset
41 local archive = module:open_store(archive_store, "archive");
7e96b95924bd mod_muc_archive: Add fork of mod_muc_log that uses newer storage API
JC Brand <jc@opkode.com>
parents:
diff changeset
42
7e96b95924bd mod_muc_archive: Add fork of mod_muc_log that uses newer storage API
JC Brand <jc@opkode.com>
parents:
diff changeset
43 local xmlns_muc_user = "http://jabber.org/protocol/muc#user";
7e96b95924bd mod_muc_archive: Add fork of mod_muc_log that uses newer storage API
JC Brand <jc@opkode.com>
parents:
diff changeset
44
7e96b95924bd mod_muc_archive: Add fork of mod_muc_log that uses newer storage API
JC Brand <jc@opkode.com>
parents:
diff changeset
45 if archive.name == "null" or not archive.find then
7e96b95924bd mod_muc_archive: Add fork of mod_muc_log that uses newer storage API
JC Brand <jc@opkode.com>
parents:
diff changeset
46 if not archive.find then
7e96b95924bd mod_muc_archive: Add fork of mod_muc_log that uses newer storage API
JC Brand <jc@opkode.com>
parents:
diff changeset
47 module:log("error", "Attempt to open archive storage returned a driver without archive API support");
7e96b95924bd mod_muc_archive: Add fork of mod_muc_log that uses newer storage API
JC Brand <jc@opkode.com>
parents:
diff changeset
48 module:log("error", "mod_%s does not support archiving",
7e96b95924bd mod_muc_archive: Add fork of mod_muc_log that uses newer storage API
JC Brand <jc@opkode.com>
parents:
diff changeset
49 archive._provided_by or archive.name and "storage_"..archive.name.."(?)" or "<unknown>");
7e96b95924bd mod_muc_archive: Add fork of mod_muc_log that uses newer storage API
JC Brand <jc@opkode.com>
parents:
diff changeset
50 else
7e96b95924bd mod_muc_archive: Add fork of mod_muc_log that uses newer storage API
JC Brand <jc@opkode.com>
parents:
diff changeset
51 module:log("error", "Attempt to open archive storage returned null driver");
7e96b95924bd mod_muc_archive: Add fork of mod_muc_log that uses newer storage API
JC Brand <jc@opkode.com>
parents:
diff changeset
52 end
7e96b95924bd mod_muc_archive: Add fork of mod_muc_log that uses newer storage API
JC Brand <jc@opkode.com>
parents:
diff changeset
53 module:log("info", "See https://prosody.im/doc/storage and https://prosody.im/doc/archiving for more information");
7e96b95924bd mod_muc_archive: Add fork of mod_muc_log that uses newer storage API
JC Brand <jc@opkode.com>
parents:
diff changeset
54 return false;
7e96b95924bd mod_muc_archive: Add fork of mod_muc_log that uses newer storage API
JC Brand <jc@opkode.com>
parents:
diff changeset
55 end
7e96b95924bd mod_muc_archive: Add fork of mod_muc_log that uses newer storage API
JC Brand <jc@opkode.com>
parents:
diff changeset
56
7e96b95924bd mod_muc_archive: Add fork of mod_muc_log that uses newer storage API
JC Brand <jc@opkode.com>
parents:
diff changeset
57
7e96b95924bd mod_muc_archive: Add fork of mod_muc_log that uses newer storage API
JC Brand <jc@opkode.com>
parents:
diff changeset
58 -- Module Definitions
7e96b95924bd mod_muc_archive: Add fork of mod_muc_log that uses newer storage API
JC Brand <jc@opkode.com>
parents:
diff changeset
59
7e96b95924bd mod_muc_archive: Add fork of mod_muc_log that uses newer storage API
JC Brand <jc@opkode.com>
parents:
diff changeset
60 local function get_room_from_jid(jid)
7e96b95924bd mod_muc_archive: Add fork of mod_muc_log that uses newer storage API
JC Brand <jc@opkode.com>
parents:
diff changeset
61 local node, host = split_jid(jid);
7e96b95924bd mod_muc_archive: Add fork of mod_muc_log that uses newer storage API
JC Brand <jc@opkode.com>
parents:
diff changeset
62 local component = hosts[host];
7e96b95924bd mod_muc_archive: Add fork of mod_muc_log that uses newer storage API
JC Brand <jc@opkode.com>
parents:
diff changeset
63 if component then
7e96b95924bd mod_muc_archive: Add fork of mod_muc_log that uses newer storage API
JC Brand <jc@opkode.com>
parents:
diff changeset
64 local muc = component.modules.muc
7e96b95924bd mod_muc_archive: Add fork of mod_muc_log that uses newer storage API
JC Brand <jc@opkode.com>
parents:
diff changeset
65 if muc and rawget(muc,"rooms") then
7e96b95924bd mod_muc_archive: Add fork of mod_muc_log that uses newer storage API
JC Brand <jc@opkode.com>
parents:
diff changeset
66 -- We're running 0.9.x or 0.10 (old MUC API)
7e96b95924bd mod_muc_archive: Add fork of mod_muc_log that uses newer storage API
JC Brand <jc@opkode.com>
parents:
diff changeset
67 return muc.rooms[jid];
7e96b95924bd mod_muc_archive: Add fork of mod_muc_log that uses newer storage API
JC Brand <jc@opkode.com>
parents:
diff changeset
68 elseif muc and rawget(muc,"get_room_from_jid") then
7e96b95924bd mod_muc_archive: Add fork of mod_muc_log that uses newer storage API
JC Brand <jc@opkode.com>
parents:
diff changeset
69 -- We're running >0.10 (new MUC API)
7e96b95924bd mod_muc_archive: Add fork of mod_muc_log that uses newer storage API
JC Brand <jc@opkode.com>
parents:
diff changeset
70 return muc.get_room_from_jid(jid);
7e96b95924bd mod_muc_archive: Add fork of mod_muc_log that uses newer storage API
JC Brand <jc@opkode.com>
parents:
diff changeset
71 else
7e96b95924bd mod_muc_archive: Add fork of mod_muc_log that uses newer storage API
JC Brand <jc@opkode.com>
parents:
diff changeset
72 return
7e96b95924bd mod_muc_archive: Add fork of mod_muc_log that uses newer storage API
JC Brand <jc@opkode.com>
parents:
diff changeset
73 end
7e96b95924bd mod_muc_archive: Add fork of mod_muc_log that uses newer storage API
JC Brand <jc@opkode.com>
parents:
diff changeset
74 end
7e96b95924bd mod_muc_archive: Add fork of mod_muc_log that uses newer storage API
JC Brand <jc@opkode.com>
parents:
diff changeset
75 end
7e96b95924bd mod_muc_archive: Add fork of mod_muc_log that uses newer storage API
JC Brand <jc@opkode.com>
parents:
diff changeset
76
7e96b95924bd mod_muc_archive: Add fork of mod_muc_log that uses newer storage API
JC Brand <jc@opkode.com>
parents:
diff changeset
77 local function logging_enabled(room)
7e96b95924bd mod_muc_archive: Add fork of mod_muc_log that uses newer storage API
JC Brand <jc@opkode.com>
parents:
diff changeset
78 if log_all_rooms then
7e96b95924bd mod_muc_archive: Add fork of mod_muc_log that uses newer storage API
JC Brand <jc@opkode.com>
parents:
diff changeset
79 return true;
7e96b95924bd mod_muc_archive: Add fork of mod_muc_log that uses newer storage API
JC Brand <jc@opkode.com>
parents:
diff changeset
80 end
7e96b95924bd mod_muc_archive: Add fork of mod_muc_log that uses newer storage API
JC Brand <jc@opkode.com>
parents:
diff changeset
81 if room._data.hidden then -- do not log data of private rooms
7e96b95924bd mod_muc_archive: Add fork of mod_muc_log that uses newer storage API
JC Brand <jc@opkode.com>
parents:
diff changeset
82 return false;
7e96b95924bd mod_muc_archive: Add fork of mod_muc_log that uses newer storage API
JC Brand <jc@opkode.com>
parents:
diff changeset
83 end
7e96b95924bd mod_muc_archive: Add fork of mod_muc_log that uses newer storage API
JC Brand <jc@opkode.com>
parents:
diff changeset
84 local enabled = room._data.logging;
7e96b95924bd mod_muc_archive: Add fork of mod_muc_log that uses newer storage API
JC Brand <jc@opkode.com>
parents:
diff changeset
85 if enabled == nil then
7e96b95924bd mod_muc_archive: Add fork of mod_muc_log that uses newer storage API
JC Brand <jc@opkode.com>
parents:
diff changeset
86 return log_by_default;
7e96b95924bd mod_muc_archive: Add fork of mod_muc_log that uses newer storage API
JC Brand <jc@opkode.com>
parents:
diff changeset
87 end
7e96b95924bd mod_muc_archive: Add fork of mod_muc_log that uses newer storage API
JC Brand <jc@opkode.com>
parents:
diff changeset
88 return enabled;
7e96b95924bd mod_muc_archive: Add fork of mod_muc_log that uses newer storage API
JC Brand <jc@opkode.com>
parents:
diff changeset
89 end
7e96b95924bd mod_muc_archive: Add fork of mod_muc_log that uses newer storage API
JC Brand <jc@opkode.com>
parents:
diff changeset
90
7e96b95924bd mod_muc_archive: Add fork of mod_muc_log that uses newer storage API
JC Brand <jc@opkode.com>
parents:
diff changeset
91
7e96b95924bd mod_muc_archive: Add fork of mod_muc_log that uses newer storage API
JC Brand <jc@opkode.com>
parents:
diff changeset
92 local function log_if_needed(event)
7e96b95924bd mod_muc_archive: Add fork of mod_muc_log that uses newer storage API
JC Brand <jc@opkode.com>
parents:
diff changeset
93 local stanza = event.stanza;
7e96b95924bd mod_muc_archive: Add fork of mod_muc_log that uses newer storage API
JC Brand <jc@opkode.com>
parents:
diff changeset
94
7e96b95924bd mod_muc_archive: Add fork of mod_muc_log that uses newer storage API
JC Brand <jc@opkode.com>
parents:
diff changeset
95 if (stanza.name == "presence") or
7e96b95924bd mod_muc_archive: Add fork of mod_muc_log that uses newer storage API
JC Brand <jc@opkode.com>
parents:
diff changeset
96 (stanza.name == "iq") or
7e96b95924bd mod_muc_archive: Add fork of mod_muc_log that uses newer storage API
JC Brand <jc@opkode.com>
parents:
diff changeset
97 (stanza.name == "message" and tostring(stanza.attr.type) == "groupchat")
7e96b95924bd mod_muc_archive: Add fork of mod_muc_log that uses newer storage API
JC Brand <jc@opkode.com>
parents:
diff changeset
98 then
7e96b95924bd mod_muc_archive: Add fork of mod_muc_log that uses newer storage API
JC Brand <jc@opkode.com>
parents:
diff changeset
99 local node, host = split_jid(stanza.attr.to);
7e96b95924bd mod_muc_archive: Add fork of mod_muc_log that uses newer storage API
JC Brand <jc@opkode.com>
parents:
diff changeset
100 if node and host then
7e96b95924bd mod_muc_archive: Add fork of mod_muc_log that uses newer storage API
JC Brand <jc@opkode.com>
parents:
diff changeset
101 local room = get_room_from_jid(node.."@"..host)
7e96b95924bd mod_muc_archive: Add fork of mod_muc_log that uses newer storage API
JC Brand <jc@opkode.com>
parents:
diff changeset
102 if not room then return end
7e96b95924bd mod_muc_archive: Add fork of mod_muc_log that uses newer storage API
JC Brand <jc@opkode.com>
parents:
diff changeset
103 -- Policy check
7e96b95924bd mod_muc_archive: Add fork of mod_muc_log that uses newer storage API
JC Brand <jc@opkode.com>
parents:
diff changeset
104 if not logging_enabled(room) then return end
7e96b95924bd mod_muc_archive: Add fork of mod_muc_log that uses newer storage API
JC Brand <jc@opkode.com>
parents:
diff changeset
105
7e96b95924bd mod_muc_archive: Add fork of mod_muc_log that uses newer storage API
JC Brand <jc@opkode.com>
parents:
diff changeset
106 local muc_to = nil
7e96b95924bd mod_muc_archive: Add fork of mod_muc_log that uses newer storage API
JC Brand <jc@opkode.com>
parents:
diff changeset
107 local muc_from = nil;
7e96b95924bd mod_muc_archive: Add fork of mod_muc_log that uses newer storage API
JC Brand <jc@opkode.com>
parents:
diff changeset
108
7e96b95924bd mod_muc_archive: Add fork of mod_muc_log that uses newer storage API
JC Brand <jc@opkode.com>
parents:
diff changeset
109 if stanza.name == "presence" and stanza.attr.type == nil then
7e96b95924bd mod_muc_archive: Add fork of mod_muc_log that uses newer storage API
JC Brand <jc@opkode.com>
parents:
diff changeset
110 muc_from = stanza.attr.to;
7e96b95924bd mod_muc_archive: Add fork of mod_muc_log that uses newer storage API
JC Brand <jc@opkode.com>
parents:
diff changeset
111 elseif stanza.name == "iq" and stanza.attr.type == "set" then
7e96b95924bd mod_muc_archive: Add fork of mod_muc_log that uses newer storage API
JC Brand <jc@opkode.com>
parents:
diff changeset
112 -- kick, to is the room, from is the admin, nick who is kicked is attr of iq->query->item
7e96b95924bd mod_muc_archive: Add fork of mod_muc_log that uses newer storage API
JC Brand <jc@opkode.com>
parents:
diff changeset
113 if stanza.tags[1] and stanza.tags[1].name == "query" then
7e96b95924bd mod_muc_archive: Add fork of mod_muc_log that uses newer storage API
JC Brand <jc@opkode.com>
parents:
diff changeset
114 local tmp = stanza.tags[1];
7e96b95924bd mod_muc_archive: Add fork of mod_muc_log that uses newer storage API
JC Brand <jc@opkode.com>
parents:
diff changeset
115 if tmp.tags[1] ~= nil and tmp.tags[1].name == "item" and tmp.tags[1].attr.nick then
7e96b95924bd mod_muc_archive: Add fork of mod_muc_log that uses newer storage API
JC Brand <jc@opkode.com>
parents:
diff changeset
116 tmp = tmp.tags[1];
7e96b95924bd mod_muc_archive: Add fork of mod_muc_log that uses newer storage API
JC Brand <jc@opkode.com>
parents:
diff changeset
117 for jid, nick in pairs(room._jid_nick) do
7e96b95924bd mod_muc_archive: Add fork of mod_muc_log that uses newer storage API
JC Brand <jc@opkode.com>
parents:
diff changeset
118 if nick == stanza.attr.to .. "/" .. tmp.attr.nick then
7e96b95924bd mod_muc_archive: Add fork of mod_muc_log that uses newer storage API
JC Brand <jc@opkode.com>
parents:
diff changeset
119 muc_to = nick;
7e96b95924bd mod_muc_archive: Add fork of mod_muc_log that uses newer storage API
JC Brand <jc@opkode.com>
parents:
diff changeset
120 break;
7e96b95924bd mod_muc_archive: Add fork of mod_muc_log that uses newer storage API
JC Brand <jc@opkode.com>
parents:
diff changeset
121 end
7e96b95924bd mod_muc_archive: Add fork of mod_muc_log that uses newer storage API
JC Brand <jc@opkode.com>
parents:
diff changeset
122 end
7e96b95924bd mod_muc_archive: Add fork of mod_muc_log that uses newer storage API
JC Brand <jc@opkode.com>
parents:
diff changeset
123 end
7e96b95924bd mod_muc_archive: Add fork of mod_muc_log that uses newer storage API
JC Brand <jc@opkode.com>
parents:
diff changeset
124 end
7e96b95924bd mod_muc_archive: Add fork of mod_muc_log that uses newer storage API
JC Brand <jc@opkode.com>
parents:
diff changeset
125 else
7e96b95924bd mod_muc_archive: Add fork of mod_muc_log that uses newer storage API
JC Brand <jc@opkode.com>
parents:
diff changeset
126 for jid, nick in pairs(room._jid_nick) do
7e96b95924bd mod_muc_archive: Add fork of mod_muc_log that uses newer storage API
JC Brand <jc@opkode.com>
parents:
diff changeset
127 if jid == stanza.attr.from then
7e96b95924bd mod_muc_archive: Add fork of mod_muc_log that uses newer storage API
JC Brand <jc@opkode.com>
parents:
diff changeset
128 muc_from = nick;
7e96b95924bd mod_muc_archive: Add fork of mod_muc_log that uses newer storage API
JC Brand <jc@opkode.com>
parents:
diff changeset
129 break;
7e96b95924bd mod_muc_archive: Add fork of mod_muc_log that uses newer storage API
JC Brand <jc@opkode.com>
parents:
diff changeset
130 end
7e96b95924bd mod_muc_archive: Add fork of mod_muc_log that uses newer storage API
JC Brand <jc@opkode.com>
parents:
diff changeset
131 end
7e96b95924bd mod_muc_archive: Add fork of mod_muc_log that uses newer storage API
JC Brand <jc@opkode.com>
parents:
diff changeset
132 end
7e96b95924bd mod_muc_archive: Add fork of mod_muc_log that uses newer storage API
JC Brand <jc@opkode.com>
parents:
diff changeset
133
7e96b95924bd mod_muc_archive: Add fork of mod_muc_log that uses newer storage API
JC Brand <jc@opkode.com>
parents:
diff changeset
134 if (muc_from or muc_to) then
7e96b95924bd mod_muc_archive: Add fork of mod_muc_log that uses newer storage API
JC Brand <jc@opkode.com>
parents:
diff changeset
135 local stored_stanza = st.clone(stanza);
7e96b95924bd mod_muc_archive: Add fork of mod_muc_log that uses newer storage API
JC Brand <jc@opkode.com>
parents:
diff changeset
136 stored_stanza.attr.from = muc_from;
7e96b95924bd mod_muc_archive: Add fork of mod_muc_log that uses newer storage API
JC Brand <jc@opkode.com>
parents:
diff changeset
137 stored_stanza.attr.to = muc_to;
7e96b95924bd mod_muc_archive: Add fork of mod_muc_log that uses newer storage API
JC Brand <jc@opkode.com>
parents:
diff changeset
138
7e96b95924bd mod_muc_archive: Add fork of mod_muc_log that uses newer storage API
JC Brand <jc@opkode.com>
parents:
diff changeset
139 if stanza.name == "message" then
7e96b95924bd mod_muc_archive: Add fork of mod_muc_log that uses newer storage API
JC Brand <jc@opkode.com>
parents:
diff changeset
140 local actor = jid_bare(room._occupants[muc_from].jid);
7e96b95924bd mod_muc_archive: Add fork of mod_muc_log that uses newer storage API
JC Brand <jc@opkode.com>
parents:
diff changeset
141 local affiliation = room:get_affiliation(actor) or "none";
7e96b95924bd mod_muc_archive: Add fork of mod_muc_log that uses newer storage API
JC Brand <jc@opkode.com>
parents:
diff changeset
142 local role = room:get_role(actor) or room:get_default_role(affiliation);
7e96b95924bd mod_muc_archive: Add fork of mod_muc_log that uses newer storage API
JC Brand <jc@opkode.com>
parents:
diff changeset
143 stored_stanza:add_direct_child(st.stanza("x", { xmlns = xmlns_muc_user })
7e96b95924bd mod_muc_archive: Add fork of mod_muc_log that uses newer storage API
JC Brand <jc@opkode.com>
parents:
diff changeset
144 :tag("item", { affiliation = affiliation; role = role; jid = actor }));
7e96b95924bd mod_muc_archive: Add fork of mod_muc_log that uses newer storage API
JC Brand <jc@opkode.com>
parents:
diff changeset
145 end
7e96b95924bd mod_muc_archive: Add fork of mod_muc_log that uses newer storage API
JC Brand <jc@opkode.com>
parents:
diff changeset
146
7e96b95924bd mod_muc_archive: Add fork of mod_muc_log that uses newer storage API
JC Brand <jc@opkode.com>
parents:
diff changeset
147 local with = stanza.name
7e96b95924bd mod_muc_archive: Add fork of mod_muc_log that uses newer storage API
JC Brand <jc@opkode.com>
parents:
diff changeset
148 if stanza.attr.type then
7e96b95924bd mod_muc_archive: Add fork of mod_muc_log that uses newer storage API
JC Brand <jc@opkode.com>
parents:
diff changeset
149 with = with .. "<" .. stanza.attr.type
7e96b95924bd mod_muc_archive: Add fork of mod_muc_log that uses newer storage API
JC Brand <jc@opkode.com>
parents:
diff changeset
150 end
7e96b95924bd mod_muc_archive: Add fork of mod_muc_log that uses newer storage API
JC Brand <jc@opkode.com>
parents:
diff changeset
151 archive:append(node, nil, stored_stanza, time_now(), with);
7e96b95924bd mod_muc_archive: Add fork of mod_muc_log that uses newer storage API
JC Brand <jc@opkode.com>
parents:
diff changeset
152 end
7e96b95924bd mod_muc_archive: Add fork of mod_muc_log that uses newer storage API
JC Brand <jc@opkode.com>
parents:
diff changeset
153 end
7e96b95924bd mod_muc_archive: Add fork of mod_muc_log that uses newer storage API
JC Brand <jc@opkode.com>
parents:
diff changeset
154 end
7e96b95924bd mod_muc_archive: Add fork of mod_muc_log that uses newer storage API
JC Brand <jc@opkode.com>
parents:
diff changeset
155 end
7e96b95924bd mod_muc_archive: Add fork of mod_muc_log that uses newer storage API
JC Brand <jc@opkode.com>
parents:
diff changeset
156
7e96b95924bd mod_muc_archive: Add fork of mod_muc_log that uses newer storage API
JC Brand <jc@opkode.com>
parents:
diff changeset
157 if not log_all_rooms then
7e96b95924bd mod_muc_archive: Add fork of mod_muc_log that uses newer storage API
JC Brand <jc@opkode.com>
parents:
diff changeset
158 module:hook("muc-config-form", function(event)
7e96b95924bd mod_muc_archive: Add fork of mod_muc_log that uses newer storage API
JC Brand <jc@opkode.com>
parents:
diff changeset
159 local room, form = event.room, event.form;
7e96b95924bd mod_muc_archive: Add fork of mod_muc_log that uses newer storage API
JC Brand <jc@opkode.com>
parents:
diff changeset
160 table.insert(form,
7e96b95924bd mod_muc_archive: Add fork of mod_muc_log that uses newer storage API
JC Brand <jc@opkode.com>
parents:
diff changeset
161 {
7e96b95924bd mod_muc_archive: Add fork of mod_muc_log that uses newer storage API
JC Brand <jc@opkode.com>
parents:
diff changeset
162 name = muc_form_config_option,
7e96b95924bd mod_muc_archive: Add fork of mod_muc_log that uses newer storage API
JC Brand <jc@opkode.com>
parents:
diff changeset
163 type = "boolean",
7e96b95924bd mod_muc_archive: Add fork of mod_muc_log that uses newer storage API
JC Brand <jc@opkode.com>
parents:
diff changeset
164 label = "Enable Logging?",
7e96b95924bd mod_muc_archive: Add fork of mod_muc_log that uses newer storage API
JC Brand <jc@opkode.com>
parents:
diff changeset
165 value = logging_enabled(room),
7e96b95924bd mod_muc_archive: Add fork of mod_muc_log that uses newer storage API
JC Brand <jc@opkode.com>
parents:
diff changeset
166 }
7e96b95924bd mod_muc_archive: Add fork of mod_muc_log that uses newer storage API
JC Brand <jc@opkode.com>
parents:
diff changeset
167 );
7e96b95924bd mod_muc_archive: Add fork of mod_muc_log that uses newer storage API
JC Brand <jc@opkode.com>
parents:
diff changeset
168 end);
7e96b95924bd mod_muc_archive: Add fork of mod_muc_log that uses newer storage API
JC Brand <jc@opkode.com>
parents:
diff changeset
169
7e96b95924bd mod_muc_archive: Add fork of mod_muc_log that uses newer storage API
JC Brand <jc@opkode.com>
parents:
diff changeset
170 module:hook("muc-config-submitted", function(event)
7e96b95924bd mod_muc_archive: Add fork of mod_muc_log that uses newer storage API
JC Brand <jc@opkode.com>
parents:
diff changeset
171 local room, fields, changed = event.room, event.fields, event.changed;
7e96b95924bd mod_muc_archive: Add fork of mod_muc_log that uses newer storage API
JC Brand <jc@opkode.com>
parents:
diff changeset
172 local new = fields[muc_form_config_option];
7e96b95924bd mod_muc_archive: Add fork of mod_muc_log that uses newer storage API
JC Brand <jc@opkode.com>
parents:
diff changeset
173 if new ~= room._data.logging then
7e96b95924bd mod_muc_archive: Add fork of mod_muc_log that uses newer storage API
JC Brand <jc@opkode.com>
parents:
diff changeset
174 room._data.logging = new;
7e96b95924bd mod_muc_archive: Add fork of mod_muc_log that uses newer storage API
JC Brand <jc@opkode.com>
parents:
diff changeset
175 if type(changed) == "table" then
7e96b95924bd mod_muc_archive: Add fork of mod_muc_log that uses newer storage API
JC Brand <jc@opkode.com>
parents:
diff changeset
176 changed[muc_form_config_option] = true;
7e96b95924bd mod_muc_archive: Add fork of mod_muc_log that uses newer storage API
JC Brand <jc@opkode.com>
parents:
diff changeset
177 else
7e96b95924bd mod_muc_archive: Add fork of mod_muc_log that uses newer storage API
JC Brand <jc@opkode.com>
parents:
diff changeset
178 event.changed = true;
7e96b95924bd mod_muc_archive: Add fork of mod_muc_log that uses newer storage API
JC Brand <jc@opkode.com>
parents:
diff changeset
179 end
7e96b95924bd mod_muc_archive: Add fork of mod_muc_log that uses newer storage API
JC Brand <jc@opkode.com>
parents:
diff changeset
180 end
7e96b95924bd mod_muc_archive: Add fork of mod_muc_log that uses newer storage API
JC Brand <jc@opkode.com>
parents:
diff changeset
181 end);
7e96b95924bd mod_muc_archive: Add fork of mod_muc_log that uses newer storage API
JC Brand <jc@opkode.com>
parents:
diff changeset
182 end
7e96b95924bd mod_muc_archive: Add fork of mod_muc_log that uses newer storage API
JC Brand <jc@opkode.com>
parents:
diff changeset
183
7e96b95924bd mod_muc_archive: Add fork of mod_muc_log that uses newer storage API
JC Brand <jc@opkode.com>
parents:
diff changeset
184 module:hook("message/bare", log_if_needed, 1);
7e96b95924bd mod_muc_archive: Add fork of mod_muc_log that uses newer storage API
JC Brand <jc@opkode.com>
parents:
diff changeset
185
7e96b95924bd mod_muc_archive: Add fork of mod_muc_log that uses newer storage API
JC Brand <jc@opkode.com>
parents:
diff changeset
186 if log_presences then
7e96b95924bd mod_muc_archive: Add fork of mod_muc_log that uses newer storage API
JC Brand <jc@opkode.com>
parents:
diff changeset
187 module:hook("iq/bare", log_if_needed, 1);
7e96b95924bd mod_muc_archive: Add fork of mod_muc_log that uses newer storage API
JC Brand <jc@opkode.com>
parents:
diff changeset
188 module:hook("presence/full", log_if_needed, 1);
7e96b95924bd mod_muc_archive: Add fork of mod_muc_log that uses newer storage API
JC Brand <jc@opkode.com>
parents:
diff changeset
189 end
7e96b95924bd mod_muc_archive: Add fork of mod_muc_log that uses newer storage API
JC Brand <jc@opkode.com>
parents:
diff changeset
190
7e96b95924bd mod_muc_archive: Add fork of mod_muc_log that uses newer storage API
JC Brand <jc@opkode.com>
parents:
diff changeset
191 module:log("debug", "module mod_muc_archive loaded!");