Comparison

mod_mam_muc/mod_mam_muc.lua @ 2716:02a7f9fe44fa

mod_mam_muc: Rename various fields from "logging" to "archiving"
author Kim Alvefur <zash@zash.se>
date Sun, 21 May 2017 23:59:36 +0200
parent 2628:fbb26a56a667
child 2718:02d688ba7739
comparison
equal deleted inserted replaced
2715:9b43b7fc3558 2716:02a7f9fe44fa
10 10
11 local xmlns_mam = "urn:xmpp:mam:2"; 11 local xmlns_mam = "urn:xmpp:mam:2";
12 local xmlns_delay = "urn:xmpp:delay"; 12 local xmlns_delay = "urn:xmpp:delay";
13 local xmlns_forward = "urn:xmpp:forward:0"; 13 local xmlns_forward = "urn:xmpp:forward:0";
14 local xmlns_st_id = "urn:xmpp:sid:0"; 14 local xmlns_st_id = "urn:xmpp:sid:0";
15 local muc_form_enable_logging = "muc#roomconfig_enablelogging" 15 local muc_form_enable = "muc#roomconfig_enablearchiving"
16 16
17 local st = require "util.stanza"; 17 local st = require "util.stanza";
18 local rsm = require "util.rsm"; 18 local rsm = require "util.rsm";
19 local jid_bare = require "util.jid".bare; 19 local jid_bare = require "util.jid".bare;
20 local jid_split = require "util.jid".split; 20 local jid_split = require "util.jid".split;
59 end 59 end
60 module:log("info", "See https://prosody.im/doc/storage and https://prosody.im/doc/archiving for more information"); 60 module:log("info", "See https://prosody.im/doc/storage and https://prosody.im/doc/archiving for more information");
61 return false; 61 return false;
62 end 62 end
63 63
64 local function logging_enabled(room) 64 local function archiving_enabled(room)
65 if log_all_rooms then 65 if log_all_rooms then
66 return true; 66 return true;
67 end 67 end
68 local enabled = room._data.logging; 68 local enabled = room._data.archiving;
69 if enabled == nil then 69 if enabled == nil then
70 return log_by_default; 70 return log_by_default;
71 end 71 end
72 return enabled; 72 return enabled;
73 end 73 end
76 76
77 -- Override history methods for all rooms. 77 -- Override history methods for all rooms.
78 if not new_muc then -- 0.10 or older 78 if not new_muc then -- 0.10 or older
79 module:hook("muc-room-created", function (event) 79 module:hook("muc-room-created", function (event)
80 local room = event.room; 80 local room = event.room;
81 if logging_enabled(room) then 81 if archiving_enabled(room) then
82 room.send_history = send_history; 82 room.send_history = send_history;
83 room.save_to_history = save_to_history; 83 room.save_to_history = save_to_history;
84 end 84 end
85 end); 85 end);
86 86
87 function module.load() 87 function module.load()
88 for room in each_room() do 88 for room in each_room() do
89 if logging_enabled(room) then 89 if archiving_enabled(room) then
90 room.send_history = send_history; 90 room.send_history = send_history;
91 room.save_to_history = save_to_history; 91 room.save_to_history = save_to_history;
92 end 92 end
93 end 93 end
94 end 94 end
105 if not log_all_rooms then 105 if not log_all_rooms then
106 module:hook("muc-config-form", function(event) 106 module:hook("muc-config-form", function(event)
107 local room, form = event.room, event.form; 107 local room, form = event.room, event.form;
108 table.insert(form, 108 table.insert(form,
109 { 109 {
110 name = muc_form_enable_logging, 110 name = muc_form_enable,
111 type = "boolean", 111 type = "boolean",
112 label = "Enable Logging?", 112 label = "Enable archiving?",
113 value = logging_enabled(room), 113 value = archiving_enabled(room),
114 } 114 }
115 ); 115 );
116 end); 116 end);
117 117
118 module:hook("muc-config-submitted", function(event) 118 module:hook("muc-config-submitted", function(event)
119 local room, fields, changed = event.room, event.fields, event.changed; 119 local room, fields, changed = event.room, event.fields, event.changed;
120 local new = fields[muc_form_enable_logging]; 120 local new = fields[muc_form_enable];
121 if new ~= room._data.logging then 121 if new ~= room._data.archiving then
122 room._data.logging = new; 122 room._data.archiving = new;
123 if type(changed) == "table" then 123 if type(changed) == "table" then
124 changed[muc_form_enable_logging] = true; 124 changed[muc_form_enable] = true;
125 else 125 else
126 event.changed = true; 126 event.changed = true;
127 end 127 end
128 if new then 128 if new then
129 room.send_history = send_history; 129 room.send_history = send_history;
274 return true; 274 return true;
275 end); 275 end);
276 276
277 module:hook("muc-get-history", function (event) 277 module:hook("muc-get-history", function (event)
278 local room = event.room; 278 local room = event.room;
279 if not logging_enabled(room) then return end 279 if not archiving_enabled(room) then return end
280 local room_jid = room.jid; 280 local room_jid = room.jid;
281 local maxstanzas = event.maxstanzas; 281 local maxstanzas = event.maxstanzas;
282 local maxchars = event.maxchars; 282 local maxchars = event.maxchars;
283 local since = event.since; 283 local since = event.since;
284 local to = event.to; 284 local to = event.to;
364 end 364 end
365 return tag; 365 return tag;
366 end); 366 end);
367 367
368 -- Policy check 368 -- Policy check
369 if not logging_enabled(self) then return end -- Don't log 369 if not archiving_enabled(self) then return end -- Don't log
370 370
371 -- And stash it 371 -- And stash it
372 local with = stanza.name 372 local with = stanza.name
373 if stanza.attr.type then 373 if stanza.attr.type then
374 with = with .. "<" .. stanza.attr.type 374 with = with .. "<" .. stanza.attr.type