annotate mod_mam_muc/mod_mam_muc.lua @ 1534:4dd6eebc8fbd

mod_mam_muc: Minor moving about of variables
author Kim Alvefur <zash@zash.se>
date Wed, 22 Oct 2014 19:32:52 +0200
parents 915bdcb35e79
children efbb047c01e7
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1313
440d7276ca62 mod_mam_muc: Rename variable
Kim Alvefur <zash@zash.se>
parents: 1312
diff changeset
1 -- XEP-0313: Message Archive Management for Prosody MUC
1519
67c80abe742e mod_mam_muc: Fix add/removal of room method overrides
Kim Alvefur <zash@zash.se>
parents: 1430
diff changeset
2 -- Copyright (C) 2011-2014 Kim Alvefur
820
005037032d65 mod_mam_muc: MUC version of mod_mam
Kim Alvefur <zash@zash.se>
parents:
diff changeset
3 --
005037032d65 mod_mam_muc: MUC version of mod_mam
Kim Alvefur <zash@zash.se>
parents:
diff changeset
4 -- This file is MIT/X11 licensed.
005037032d65 mod_mam_muc: MUC version of mod_mam
Kim Alvefur <zash@zash.se>
parents:
diff changeset
5
005037032d65 mod_mam_muc: MUC version of mod_mam
Kim Alvefur <zash@zash.se>
parents:
diff changeset
6 local xmlns_mam = "urn:xmpp:mam:tmp";
005037032d65 mod_mam_muc: MUC version of mod_mam
Kim Alvefur <zash@zash.se>
parents:
diff changeset
7 local xmlns_delay = "urn:xmpp:delay";
005037032d65 mod_mam_muc: MUC version of mod_mam
Kim Alvefur <zash@zash.se>
parents:
diff changeset
8 local xmlns_forward = "urn:xmpp:forward:0";
1313
440d7276ca62 mod_mam_muc: Rename variable
Kim Alvefur <zash@zash.se>
parents: 1312
diff changeset
9 local muc_form_enable_logging = "muc#roomconfig_enablelogging"
820
005037032d65 mod_mam_muc: MUC version of mod_mam
Kim Alvefur <zash@zash.se>
parents:
diff changeset
10
005037032d65 mod_mam_muc: MUC version of mod_mam
Kim Alvefur <zash@zash.se>
parents:
diff changeset
11 local st = require "util.stanza";
005037032d65 mod_mam_muc: MUC version of mod_mam
Kim Alvefur <zash@zash.se>
parents:
diff changeset
12 local rsm = module:require "mod_mam/rsm";
005037032d65 mod_mam_muc: MUC version of mod_mam
Kim Alvefur <zash@zash.se>
parents:
diff changeset
13 local jid_bare = require "util.jid".bare;
005037032d65 mod_mam_muc: MUC version of mod_mam
Kim Alvefur <zash@zash.se>
parents:
diff changeset
14 local jid_split = require "util.jid".split;
1534
4dd6eebc8fbd mod_mam_muc: Minor moving about of variables
Kim Alvefur <zash@zash.se>
parents: 1533
diff changeset
15
4dd6eebc8fbd mod_mam_muc: Minor moving about of variables
Kim Alvefur <zash@zash.se>
parents: 1533
diff changeset
16 local mod_muc = module:depends"muc";
4dd6eebc8fbd mod_mam_muc: Minor moving about of variables
Kim Alvefur <zash@zash.se>
parents: 1533
diff changeset
17 local room_mt = mod_muc.room_mt;
4dd6eebc8fbd mod_mam_muc: Minor moving about of variables
Kim Alvefur <zash@zash.se>
parents: 1533
diff changeset
18 local rooms = mod_muc.rooms;
820
005037032d65 mod_mam_muc: MUC version of mod_mam
Kim Alvefur <zash@zash.se>
parents:
diff changeset
19
1141
1091be1c3aba mod_mam_muc: Switch to new stanza storage API
Kim Alvefur <zash@zash.se>
parents: 1140
diff changeset
20 local getmetatable = getmetatable;
1091be1c3aba mod_mam_muc: Switch to new stanza storage API
Kim Alvefur <zash@zash.se>
parents: 1140
diff changeset
21 local function is_stanza(x)
1091be1c3aba mod_mam_muc: Switch to new stanza storage API
Kim Alvefur <zash@zash.se>
parents: 1140
diff changeset
22 return getmetatable(x) == st.stanza_mt;
1091be1c3aba mod_mam_muc: Switch to new stanza storage API
Kim Alvefur <zash@zash.se>
parents: 1140
diff changeset
23 end
820
005037032d65 mod_mam_muc: MUC version of mod_mam
Kim Alvefur <zash@zash.se>
parents:
diff changeset
24
005037032d65 mod_mam_muc: MUC version of mod_mam
Kim Alvefur <zash@zash.se>
parents:
diff changeset
25 local tostring = tostring;
005037032d65 mod_mam_muc: MUC version of mod_mam
Kim Alvefur <zash@zash.se>
parents:
diff changeset
26 local time_now = os.time;
005037032d65 mod_mam_muc: MUC version of mod_mam
Kim Alvefur <zash@zash.se>
parents:
diff changeset
27 local m_min = math.min;
005037032d65 mod_mam_muc: MUC version of mod_mam
Kim Alvefur <zash@zash.se>
parents:
diff changeset
28 local timestamp, timestamp_parse = require "util.datetime".datetime, require "util.datetime".parse;
1278
40f077b18dfe mod_mam_muc: Override sending of room history and use archives
Kim Alvefur <zash@zash.se>
parents: 1277
diff changeset
29 local max_history_length = module:get_option_number("max_history_messages", 1000);
1430
18f5f1b13353 mod_mam_muc: Use max_history_length as default for "max_archive_query_results"
daurnimator <quae@daurnimator.com>
parents: 1385
diff changeset
30 local default_max_items, max_max_items = 20, module:get_option_number("max_archive_query_results", max_history_length);
820
005037032d65 mod_mam_muc: MUC version of mod_mam
Kim Alvefur <zash@zash.se>
parents:
diff changeset
31
1143
8098683b6d6f mod_mam_muc: Allow archiving to be enabled trough in the room configuration
Kim Alvefur <zash@zash.se>
parents: 1142
diff changeset
32 local log_all_rooms = module:get_option_boolean("muc_log_all_rooms", false);
8098683b6d6f mod_mam_muc: Allow archiving to be enabled trough in the room configuration
Kim Alvefur <zash@zash.se>
parents: 1142
diff changeset
33 local log_by_default = module:get_option_boolean("muc_log_by_default", true);
1142
fabdaa0d99e3 mod_mam_muc: Stap archived messages
Kim Alvefur <zash@zash.se>
parents: 1141
diff changeset
34 local advertise_archive = module:get_option_boolean("muc_log_advertise", true);
fabdaa0d99e3 mod_mam_muc: Stap archived messages
Kim Alvefur <zash@zash.se>
parents: 1141
diff changeset
35
1311
27b2a357c73c mod_mam_muc: porting archive checks from mod_mam (to avoid tracebacks about calling null functions)
Vadim Misbakh-Soloviov <mva@mva.name>
parents: 1279
diff changeset
36 local archive_store = "archive2";
27b2a357c73c mod_mam_muc: porting archive checks from mod_mam (to avoid tracebacks about calling null functions)
Vadim Misbakh-Soloviov <mva@mva.name>
parents: 1279
diff changeset
37 local archive = module:open_store(archive_store, "archive");
1369
8be609f5610e mod_mam, mod_mam_muc: Check that storagemanager didn't return an instance of the null storage method (Thanks Jonathan)
Kim Alvefur <zash@zash.se>
parents: 1325
diff changeset
38 if not archive or archive.name == "null" then
1311
27b2a357c73c mod_mam_muc: porting archive checks from mod_mam (to avoid tracebacks about calling null functions)
Vadim Misbakh-Soloviov <mva@mva.name>
parents: 1279
diff changeset
39 module:log("error", "Could not open archive storage");
27b2a357c73c mod_mam_muc: porting archive checks from mod_mam (to avoid tracebacks about calling null functions)
Vadim Misbakh-Soloviov <mva@mva.name>
parents: 1279
diff changeset
40 return
27b2a357c73c mod_mam_muc: porting archive checks from mod_mam (to avoid tracebacks about calling null functions)
Vadim Misbakh-Soloviov <mva@mva.name>
parents: 1279
diff changeset
41 elseif not archive.find then
27b2a357c73c mod_mam_muc: porting archive checks from mod_mam (to avoid tracebacks about calling null functions)
Vadim Misbakh-Soloviov <mva@mva.name>
parents: 1279
diff changeset
42 module:log("error", "mod_%s does not support archiving, switch to mod_storage_sql2", archive._provided_by);
27b2a357c73c mod_mam_muc: porting archive checks from mod_mam (to avoid tracebacks about calling null functions)
Vadim Misbakh-Soloviov <mva@mva.name>
parents: 1279
diff changeset
43 return
27b2a357c73c mod_mam_muc: porting archive checks from mod_mam (to avoid tracebacks about calling null functions)
Vadim Misbakh-Soloviov <mva@mva.name>
parents: 1279
diff changeset
44 end
27b2a357c73c mod_mam_muc: porting archive checks from mod_mam (to avoid tracebacks about calling null functions)
Vadim Misbakh-Soloviov <mva@mva.name>
parents: 1279
diff changeset
45
1314
cc9831033f5d mod_mam_muc: Add and remove method overrides based on configuration instead of modifying room metatable
Kim Alvefur <zash@zash.se>
parents: 1313
diff changeset
46 local send_history, save_to_history;
cc9831033f5d mod_mam_muc: Add and remove method overrides based on configuration instead of modifying room metatable
Kim Alvefur <zash@zash.se>
parents: 1313
diff changeset
47
cc9831033f5d mod_mam_muc: Add and remove method overrides based on configuration instead of modifying room metatable
Kim Alvefur <zash@zash.se>
parents: 1313
diff changeset
48 -- Override history methods for all rooms.
1533
915bdcb35e79 mod_mam_muc: Restructure initialization
Kim Alvefur <zash@zash.se>
parents: 1532
diff changeset
49 module:hook("muc-room-created", function (event)
915bdcb35e79 mod_mam_muc: Restructure initialization
Kim Alvefur <zash@zash.se>
parents: 1532
diff changeset
50 local room = event.room;
915bdcb35e79 mod_mam_muc: Restructure initialization
Kim Alvefur <zash@zash.se>
parents: 1532
diff changeset
51 if log_all_rooms or room._data.logging then
915bdcb35e79 mod_mam_muc: Restructure initialization
Kim Alvefur <zash@zash.se>
parents: 1532
diff changeset
52 room.send_history = send_history;
915bdcb35e79 mod_mam_muc: Restructure initialization
Kim Alvefur <zash@zash.se>
parents: 1532
diff changeset
53 room.save_to_history = save_to_history;
1314
cc9831033f5d mod_mam_muc: Add and remove method overrides based on configuration instead of modifying room metatable
Kim Alvefur <zash@zash.se>
parents: 1313
diff changeset
54 end
1533
915bdcb35e79 mod_mam_muc: Restructure initialization
Kim Alvefur <zash@zash.se>
parents: 1532
diff changeset
55 end);
915bdcb35e79 mod_mam_muc: Restructure initialization
Kim Alvefur <zash@zash.se>
parents: 1532
diff changeset
56
915bdcb35e79 mod_mam_muc: Restructure initialization
Kim Alvefur <zash@zash.se>
parents: 1532
diff changeset
57 function module.load()
915bdcb35e79 mod_mam_muc: Restructure initialization
Kim Alvefur <zash@zash.se>
parents: 1532
diff changeset
58 for _, room in pairs(rooms) do
915bdcb35e79 mod_mam_muc: Restructure initialization
Kim Alvefur <zash@zash.se>
parents: 1532
diff changeset
59 if log_all_rooms or room._data.logging then
915bdcb35e79 mod_mam_muc: Restructure initialization
Kim Alvefur <zash@zash.se>
parents: 1532
diff changeset
60 room.send_history = send_history;
915bdcb35e79 mod_mam_muc: Restructure initialization
Kim Alvefur <zash@zash.se>
parents: 1532
diff changeset
61 room.save_to_history = save_to_history;
1314
cc9831033f5d mod_mam_muc: Add and remove method overrides based on configuration instead of modifying room metatable
Kim Alvefur <zash@zash.se>
parents: 1313
diff changeset
62 end
cc9831033f5d mod_mam_muc: Add and remove method overrides based on configuration instead of modifying room metatable
Kim Alvefur <zash@zash.se>
parents: 1313
diff changeset
63 end
1533
915bdcb35e79 mod_mam_muc: Restructure initialization
Kim Alvefur <zash@zash.se>
parents: 1532
diff changeset
64 end
915bdcb35e79 mod_mam_muc: Restructure initialization
Kim Alvefur <zash@zash.se>
parents: 1532
diff changeset
65 function module.unload()
915bdcb35e79 mod_mam_muc: Restructure initialization
Kim Alvefur <zash@zash.se>
parents: 1532
diff changeset
66 for _, room in pairs(rooms) do
915bdcb35e79 mod_mam_muc: Restructure initialization
Kim Alvefur <zash@zash.se>
parents: 1532
diff changeset
67 if room.send_history == send_history then
915bdcb35e79 mod_mam_muc: Restructure initialization
Kim Alvefur <zash@zash.se>
parents: 1532
diff changeset
68 room.send_history = nil;
915bdcb35e79 mod_mam_muc: Restructure initialization
Kim Alvefur <zash@zash.se>
parents: 1532
diff changeset
69 room.save_to_history = nil;
1314
cc9831033f5d mod_mam_muc: Add and remove method overrides based on configuration instead of modifying room metatable
Kim Alvefur <zash@zash.se>
parents: 1313
diff changeset
70 end
cc9831033f5d mod_mam_muc: Add and remove method overrides based on configuration instead of modifying room metatable
Kim Alvefur <zash@zash.se>
parents: 1313
diff changeset
71 end
1533
915bdcb35e79 mod_mam_muc: Restructure initialization
Kim Alvefur <zash@zash.se>
parents: 1532
diff changeset
72 end
915bdcb35e79 mod_mam_muc: Restructure initialization
Kim Alvefur <zash@zash.se>
parents: 1532
diff changeset
73
915bdcb35e79 mod_mam_muc: Restructure initialization
Kim Alvefur <zash@zash.se>
parents: 1532
diff changeset
74 if not log_all_rooms then
1276
01dfaf2f2782 mod_mam_muc: Hide logging option from room configuration if set to log all rooms
Kim Alvefur <zash@zash.se>
parents: 1275
diff changeset
75 module:hook("muc-config-form", function(event)
01dfaf2f2782 mod_mam_muc: Hide logging option from room configuration if set to log all rooms
Kim Alvefur <zash@zash.se>
parents: 1275
diff changeset
76 local room, form = event.room, event.form;
01dfaf2f2782 mod_mam_muc: Hide logging option from room configuration if set to log all rooms
Kim Alvefur <zash@zash.se>
parents: 1275
diff changeset
77 local logging_enabled = room._data.logging;
01dfaf2f2782 mod_mam_muc: Hide logging option from room configuration if set to log all rooms
Kim Alvefur <zash@zash.se>
parents: 1275
diff changeset
78 if logging_enabled == nil then
01dfaf2f2782 mod_mam_muc: Hide logging option from room configuration if set to log all rooms
Kim Alvefur <zash@zash.se>
parents: 1275
diff changeset
79 logging_enabled = log_by_default;
01dfaf2f2782 mod_mam_muc: Hide logging option from room configuration if set to log all rooms
Kim Alvefur <zash@zash.se>
parents: 1275
diff changeset
80 end
01dfaf2f2782 mod_mam_muc: Hide logging option from room configuration if set to log all rooms
Kim Alvefur <zash@zash.se>
parents: 1275
diff changeset
81 table.insert(form,
01dfaf2f2782 mod_mam_muc: Hide logging option from room configuration if set to log all rooms
Kim Alvefur <zash@zash.se>
parents: 1275
diff changeset
82 {
1313
440d7276ca62 mod_mam_muc: Rename variable
Kim Alvefur <zash@zash.se>
parents: 1312
diff changeset
83 name = muc_form_enable_logging,
1276
01dfaf2f2782 mod_mam_muc: Hide logging option from room configuration if set to log all rooms
Kim Alvefur <zash@zash.se>
parents: 1275
diff changeset
84 type = "boolean",
01dfaf2f2782 mod_mam_muc: Hide logging option from room configuration if set to log all rooms
Kim Alvefur <zash@zash.se>
parents: 1275
diff changeset
85 label = "Enable Logging?",
01dfaf2f2782 mod_mam_muc: Hide logging option from room configuration if set to log all rooms
Kim Alvefur <zash@zash.se>
parents: 1275
diff changeset
86 value = logging_enabled,
01dfaf2f2782 mod_mam_muc: Hide logging option from room configuration if set to log all rooms
Kim Alvefur <zash@zash.se>
parents: 1275
diff changeset
87 }
01dfaf2f2782 mod_mam_muc: Hide logging option from room configuration if set to log all rooms
Kim Alvefur <zash@zash.se>
parents: 1275
diff changeset
88 );
01dfaf2f2782 mod_mam_muc: Hide logging option from room configuration if set to log all rooms
Kim Alvefur <zash@zash.se>
parents: 1275
diff changeset
89 end);
1143
8098683b6d6f mod_mam_muc: Allow archiving to be enabled trough in the room configuration
Kim Alvefur <zash@zash.se>
parents: 1142
diff changeset
90
1276
01dfaf2f2782 mod_mam_muc: Hide logging option from room configuration if set to log all rooms
Kim Alvefur <zash@zash.se>
parents: 1275
diff changeset
91 module:hook("muc-config-submitted", function(event)
01dfaf2f2782 mod_mam_muc: Hide logging option from room configuration if set to log all rooms
Kim Alvefur <zash@zash.se>
parents: 1275
diff changeset
92 local room, fields, changed = event.room, event.fields, event.changed;
1313
440d7276ca62 mod_mam_muc: Rename variable
Kim Alvefur <zash@zash.se>
parents: 1312
diff changeset
93 local new = fields[muc_form_enable_logging];
1276
01dfaf2f2782 mod_mam_muc: Hide logging option from room configuration if set to log all rooms
Kim Alvefur <zash@zash.se>
parents: 1275
diff changeset
94 if new ~= room._data.logging then
01dfaf2f2782 mod_mam_muc: Hide logging option from room configuration if set to log all rooms
Kim Alvefur <zash@zash.se>
parents: 1275
diff changeset
95 room._data.logging = new;
01dfaf2f2782 mod_mam_muc: Hide logging option from room configuration if set to log all rooms
Kim Alvefur <zash@zash.se>
parents: 1275
diff changeset
96 if type(changed) == "table" then
1313
440d7276ca62 mod_mam_muc: Rename variable
Kim Alvefur <zash@zash.se>
parents: 1312
diff changeset
97 changed[muc_form_enable_logging] = true;
1276
01dfaf2f2782 mod_mam_muc: Hide logging option from room configuration if set to log all rooms
Kim Alvefur <zash@zash.se>
parents: 1275
diff changeset
98 else
01dfaf2f2782 mod_mam_muc: Hide logging option from room configuration if set to log all rooms
Kim Alvefur <zash@zash.se>
parents: 1275
diff changeset
99 event.changed = true;
01dfaf2f2782 mod_mam_muc: Hide logging option from room configuration if set to log all rooms
Kim Alvefur <zash@zash.se>
parents: 1275
diff changeset
100 end
1314
cc9831033f5d mod_mam_muc: Add and remove method overrides based on configuration instead of modifying room metatable
Kim Alvefur <zash@zash.se>
parents: 1313
diff changeset
101 if new then
cc9831033f5d mod_mam_muc: Add and remove method overrides based on configuration instead of modifying room metatable
Kim Alvefur <zash@zash.se>
parents: 1313
diff changeset
102 room.send_history = send_history;
cc9831033f5d mod_mam_muc: Add and remove method overrides based on configuration instead of modifying room metatable
Kim Alvefur <zash@zash.se>
parents: 1313
diff changeset
103 room.save_to_history = save_to_history;
cc9831033f5d mod_mam_muc: Add and remove method overrides based on configuration instead of modifying room metatable
Kim Alvefur <zash@zash.se>
parents: 1313
diff changeset
104 else
cc9831033f5d mod_mam_muc: Add and remove method overrides based on configuration instead of modifying room metatable
Kim Alvefur <zash@zash.se>
parents: 1313
diff changeset
105 room.send_history = nil;
cc9831033f5d mod_mam_muc: Add and remove method overrides based on configuration instead of modifying room metatable
Kim Alvefur <zash@zash.se>
parents: 1313
diff changeset
106 room.save_to_history = nil;
cc9831033f5d mod_mam_muc: Add and remove method overrides based on configuration instead of modifying room metatable
Kim Alvefur <zash@zash.se>
parents: 1313
diff changeset
107 end
1143
8098683b6d6f mod_mam_muc: Allow archiving to be enabled trough in the room configuration
Kim Alvefur <zash@zash.se>
parents: 1142
diff changeset
108 end
1276
01dfaf2f2782 mod_mam_muc: Hide logging option from room configuration if set to log all rooms
Kim Alvefur <zash@zash.se>
parents: 1275
diff changeset
109 end);
01dfaf2f2782 mod_mam_muc: Hide logging option from room configuration if set to log all rooms
Kim Alvefur <zash@zash.se>
parents: 1275
diff changeset
110 end
1143
8098683b6d6f mod_mam_muc: Allow archiving to be enabled trough in the room configuration
Kim Alvefur <zash@zash.se>
parents: 1142
diff changeset
111
820
005037032d65 mod_mam_muc: MUC version of mod_mam
Kim Alvefur <zash@zash.se>
parents:
diff changeset
112 -- Handle archive queries
1138
5c97ee75cadb mod_mam_muc: Switch to iq-get hook and drop some indentation
Kim Alvefur <zash@zash.se>
parents: 820
diff changeset
113 module:hook("iq-get/bare/"..xmlns_mam..":query", function(event)
820
005037032d65 mod_mam_muc: MUC version of mod_mam
Kim Alvefur <zash@zash.se>
parents:
diff changeset
114 local origin, stanza = event.origin, event.stanza;
1144
ccb0c5afe658 mod_mam_muc: Fix room lookup, should be indexed by bare jid
Kim Alvefur <zash@zash.se>
parents: 1143
diff changeset
115 local room = stanza.attr.to;
1146
9fa89dc7a86f mod_mam_muc: Search the rooms archive correctly (copypaste error from mod_mam)
Kim Alvefur <zash@zash.se>
parents: 1145
diff changeset
116 local room_node = jid_split(room);
1382
ba17268490b7 mod_mam_muc: Fix to, from on result messages (thanks daurnimator)
Kim Alvefur <zash@zash.se>
parents: 1369
diff changeset
117 local orig_from = stanza.attr.from;
820
005037032d65 mod_mam_muc: MUC version of mod_mam
Kim Alvefur <zash@zash.se>
parents:
diff changeset
118 local query = stanza.tags[1];
005037032d65 mod_mam_muc: MUC version of mod_mam
Kim Alvefur <zash@zash.se>
parents:
diff changeset
119
1139
b32d65e41755 mod_mam_muc: Get room objects in a less awkward fashion
Kim Alvefur <zash@zash.se>
parents: 1138
diff changeset
120 local room_obj = rooms[room];
820
005037032d65 mod_mam_muc: MUC version of mod_mam
Kim Alvefur <zash@zash.se>
parents:
diff changeset
121 if not room_obj then
1145
5a00f9bec6e7 mod_mam_muc: Send item-not-found if the requested room does not exist
Kim Alvefur <zash@zash.se>
parents: 1144
diff changeset
122 return origin.send(st.error_reply(stanza, "cancel", "item-not-found"))
820
005037032d65 mod_mam_muc: MUC version of mod_mam
Kim Alvefur <zash@zash.se>
parents:
diff changeset
123 end
1382
ba17268490b7 mod_mam_muc: Fix to, from on result messages (thanks daurnimator)
Kim Alvefur <zash@zash.se>
parents: 1369
diff changeset
124 local from = jid_bare(orig_from);
820
005037032d65 mod_mam_muc: MUC version of mod_mam
Kim Alvefur <zash@zash.se>
parents:
diff changeset
125
1140
402cb9b604eb mod_mam_muc: Send proper error reply when one is not allowed to query archive
Kim Alvefur <zash@zash.se>
parents: 1139
diff changeset
126 -- Banned or not a member of a members-only room?
1312
a48cf3ccdf9c mod_mam_muc: Use public API of rooms for authorization check
Kim Alvefur <zash@zash.se>
parents: 1311
diff changeset
127 local from_affiliation = room_obj:get_affiliation(from);
a48cf3ccdf9c mod_mam_muc: Use public API of rooms for authorization check
Kim Alvefur <zash@zash.se>
parents: 1311
diff changeset
128 if from_affiliation == "outcast" -- banned
1325
b21236b6b8d8 Backed out changeset 853a382c9bd6
Kim Alvefur <zash@zash.se>
parents: 1324
diff changeset
129 or room_obj:get_members_only() and not from_affiliation then -- members-only, not a member
1140
402cb9b604eb mod_mam_muc: Send proper error reply when one is not allowed to query archive
Kim Alvefur <zash@zash.se>
parents: 1139
diff changeset
130 return origin.send(st.error_reply(stanza, "auth", "forbidden"))
820
005037032d65 mod_mam_muc: MUC version of mod_mam
Kim Alvefur <zash@zash.se>
parents:
diff changeset
131 end
005037032d65 mod_mam_muc: MUC version of mod_mam
Kim Alvefur <zash@zash.se>
parents:
diff changeset
132
1138
5c97ee75cadb mod_mam_muc: Switch to iq-get hook and drop some indentation
Kim Alvefur <zash@zash.se>
parents: 820
diff changeset
133 local qid = query.attr.queryid;
5c97ee75cadb mod_mam_muc: Switch to iq-get hook and drop some indentation
Kim Alvefur <zash@zash.se>
parents: 820
diff changeset
134
5c97ee75cadb mod_mam_muc: Switch to iq-get hook and drop some indentation
Kim Alvefur <zash@zash.se>
parents: 820
diff changeset
135 -- Search query parameters
5c97ee75cadb mod_mam_muc: Switch to iq-get hook and drop some indentation
Kim Alvefur <zash@zash.se>
parents: 820
diff changeset
136 local qstart = query:get_child_text("start");
5c97ee75cadb mod_mam_muc: Switch to iq-get hook and drop some indentation
Kim Alvefur <zash@zash.se>
parents: 820
diff changeset
137 local qend = query:get_child_text("end");
1141
1091be1c3aba mod_mam_muc: Switch to new stanza storage API
Kim Alvefur <zash@zash.se>
parents: 1140
diff changeset
138 module:log("debug", "Archive query, id %s from %s until %s)",
1091be1c3aba mod_mam_muc: Switch to new stanza storage API
Kim Alvefur <zash@zash.se>
parents: 1140
diff changeset
139 tostring(qid), qstart or "the dawn of time", qend or "now");
820
005037032d65 mod_mam_muc: MUC version of mod_mam
Kim Alvefur <zash@zash.se>
parents:
diff changeset
140
1138
5c97ee75cadb mod_mam_muc: Switch to iq-get hook and drop some indentation
Kim Alvefur <zash@zash.se>
parents: 820
diff changeset
141 if qstart or qend then -- Validate timestamps
5c97ee75cadb mod_mam_muc: Switch to iq-get hook and drop some indentation
Kim Alvefur <zash@zash.se>
parents: 820
diff changeset
142 local vstart, vend = (qstart and timestamp_parse(qstart)), (qend and timestamp_parse(qend))
5c97ee75cadb mod_mam_muc: Switch to iq-get hook and drop some indentation
Kim Alvefur <zash@zash.se>
parents: 820
diff changeset
143 if (qstart and not vstart) or (qend and not vend) then
5c97ee75cadb mod_mam_muc: Switch to iq-get hook and drop some indentation
Kim Alvefur <zash@zash.se>
parents: 820
diff changeset
144 origin.send(st.error_reply(stanza, "modify", "bad-request", "Invalid timestamp"))
5c97ee75cadb mod_mam_muc: Switch to iq-get hook and drop some indentation
Kim Alvefur <zash@zash.se>
parents: 820
diff changeset
145 return true
5c97ee75cadb mod_mam_muc: Switch to iq-get hook and drop some indentation
Kim Alvefur <zash@zash.se>
parents: 820
diff changeset
146 end
5c97ee75cadb mod_mam_muc: Switch to iq-get hook and drop some indentation
Kim Alvefur <zash@zash.se>
parents: 820
diff changeset
147 qstart, qend = vstart, vend;
5c97ee75cadb mod_mam_muc: Switch to iq-get hook and drop some indentation
Kim Alvefur <zash@zash.se>
parents: 820
diff changeset
148 end
820
005037032d65 mod_mam_muc: MUC version of mod_mam
Kim Alvefur <zash@zash.se>
parents:
diff changeset
149
1141
1091be1c3aba mod_mam_muc: Switch to new stanza storage API
Kim Alvefur <zash@zash.se>
parents: 1140
diff changeset
150 -- RSM stuff
1091be1c3aba mod_mam_muc: Switch to new stanza storage API
Kim Alvefur <zash@zash.se>
parents: 1140
diff changeset
151 local qset = rsm.get(query);
1091be1c3aba mod_mam_muc: Switch to new stanza storage API
Kim Alvefur <zash@zash.se>
parents: 1140
diff changeset
152 local qmax = m_min(qset and qset.max or default_max_items, max_max_items);
1091be1c3aba mod_mam_muc: Switch to new stanza storage API
Kim Alvefur <zash@zash.se>
parents: 1140
diff changeset
153 local reverse = qset and qset.before or false;
1091be1c3aba mod_mam_muc: Switch to new stanza storage API
Kim Alvefur <zash@zash.se>
parents: 1140
diff changeset
154
1091be1c3aba mod_mam_muc: Switch to new stanza storage API
Kim Alvefur <zash@zash.se>
parents: 1140
diff changeset
155 local before, after = qset and qset.before, qset and qset.after;
1091be1c3aba mod_mam_muc: Switch to new stanza storage API
Kim Alvefur <zash@zash.se>
parents: 1140
diff changeset
156 if type(before) ~= "string" then before = nil; end
820
005037032d65 mod_mam_muc: MUC version of mod_mam
Kim Alvefur <zash@zash.se>
parents:
diff changeset
157
1138
5c97ee75cadb mod_mam_muc: Switch to iq-get hook and drop some indentation
Kim Alvefur <zash@zash.se>
parents: 820
diff changeset
158 -- Load all the data!
1146
9fa89dc7a86f mod_mam_muc: Search the rooms archive correctly (copypaste error from mod_mam)
Kim Alvefur <zash@zash.se>
parents: 1145
diff changeset
159 local data, err = archive:find(room_node, {
1141
1091be1c3aba mod_mam_muc: Switch to new stanza storage API
Kim Alvefur <zash@zash.se>
parents: 1140
diff changeset
160 start = qstart; ["end"] = qend; -- Time range
1091be1c3aba mod_mam_muc: Switch to new stanza storage API
Kim Alvefur <zash@zash.se>
parents: 1140
diff changeset
161 limit = qmax;
1091be1c3aba mod_mam_muc: Switch to new stanza storage API
Kim Alvefur <zash@zash.se>
parents: 1140
diff changeset
162 before = before; after = after;
1091be1c3aba mod_mam_muc: Switch to new stanza storage API
Kim Alvefur <zash@zash.se>
parents: 1140
diff changeset
163 reverse = reverse;
1091be1c3aba mod_mam_muc: Switch to new stanza storage API
Kim Alvefur <zash@zash.se>
parents: 1140
diff changeset
164 total = true;
1091be1c3aba mod_mam_muc: Switch to new stanza storage API
Kim Alvefur <zash@zash.se>
parents: 1140
diff changeset
165 });
1138
5c97ee75cadb mod_mam_muc: Switch to iq-get hook and drop some indentation
Kim Alvefur <zash@zash.se>
parents: 820
diff changeset
166
1141
1091be1c3aba mod_mam_muc: Switch to new stanza storage API
Kim Alvefur <zash@zash.se>
parents: 1140
diff changeset
167 if not data then
1091be1c3aba mod_mam_muc: Switch to new stanza storage API
Kim Alvefur <zash@zash.se>
parents: 1140
diff changeset
168 return origin.send(st.error_reply(stanza, "cancel", "internal-server-error"));
1091be1c3aba mod_mam_muc: Switch to new stanza storage API
Kim Alvefur <zash@zash.se>
parents: 1140
diff changeset
169 end
1091be1c3aba mod_mam_muc: Switch to new stanza storage API
Kim Alvefur <zash@zash.se>
parents: 1140
diff changeset
170 local count = err;
1138
5c97ee75cadb mod_mam_muc: Switch to iq-get hook and drop some indentation
Kim Alvefur <zash@zash.se>
parents: 820
diff changeset
171
1534
4dd6eebc8fbd mod_mam_muc: Minor moving about of variables
Kim Alvefur <zash@zash.se>
parents: 1533
diff changeset
172 local msg_reply_attr = { to = stanza.attr.from, from = stanza.attr.to };
4dd6eebc8fbd mod_mam_muc: Minor moving about of variables
Kim Alvefur <zash@zash.se>
parents: 1533
diff changeset
173
1141
1091be1c3aba mod_mam_muc: Switch to new stanza storage API
Kim Alvefur <zash@zash.se>
parents: 1140
diff changeset
174 -- Wrap it in stuff and deliver
1534
4dd6eebc8fbd mod_mam_muc: Minor moving about of variables
Kim Alvefur <zash@zash.se>
parents: 1533
diff changeset
175 local fwd_st, first, last;
1141
1091be1c3aba mod_mam_muc: Switch to new stanza storage API
Kim Alvefur <zash@zash.se>
parents: 1140
diff changeset
176 for id, item, when in data do
1534
4dd6eebc8fbd mod_mam_muc: Minor moving about of variables
Kim Alvefur <zash@zash.se>
parents: 1533
diff changeset
177 fwd_st = st.message(msg_reply_attr)
1141
1091be1c3aba mod_mam_muc: Switch to new stanza storage API
Kim Alvefur <zash@zash.se>
parents: 1140
diff changeset
178 :tag("result", { xmlns = xmlns_mam, queryid = qid, id = id })
1138
5c97ee75cadb mod_mam_muc: Switch to iq-get hook and drop some indentation
Kim Alvefur <zash@zash.se>
parents: 820
diff changeset
179 :tag("forwarded", { xmlns = xmlns_forward })
5c97ee75cadb mod_mam_muc: Switch to iq-get hook and drop some indentation
Kim Alvefur <zash@zash.se>
parents: 820
diff changeset
180 :tag("delay", { xmlns = xmlns_delay, stamp = timestamp(when) }):up();
1141
1091be1c3aba mod_mam_muc: Switch to new stanza storage API
Kim Alvefur <zash@zash.se>
parents: 1140
diff changeset
181
1091be1c3aba mod_mam_muc: Switch to new stanza storage API
Kim Alvefur <zash@zash.se>
parents: 1140
diff changeset
182 if not is_stanza(item) then
1091be1c3aba mod_mam_muc: Switch to new stanza storage API
Kim Alvefur <zash@zash.se>
parents: 1140
diff changeset
183 item = st.deserialize(item);
1138
5c97ee75cadb mod_mam_muc: Switch to iq-get hook and drop some indentation
Kim Alvefur <zash@zash.se>
parents: 820
diff changeset
184 end
1141
1091be1c3aba mod_mam_muc: Switch to new stanza storage API
Kim Alvefur <zash@zash.se>
parents: 1140
diff changeset
185 item.attr.xmlns = "jabber:client";
1091be1c3aba mod_mam_muc: Switch to new stanza storage API
Kim Alvefur <zash@zash.se>
parents: 1140
diff changeset
186 fwd_st:add_child(item);
820
005037032d65 mod_mam_muc: MUC version of mod_mam
Kim Alvefur <zash@zash.se>
parents:
diff changeset
187
1141
1091be1c3aba mod_mam_muc: Switch to new stanza storage API
Kim Alvefur <zash@zash.se>
parents: 1140
diff changeset
188 if not first then first = id; end
1091be1c3aba mod_mam_muc: Switch to new stanza storage API
Kim Alvefur <zash@zash.se>
parents: 1140
diff changeset
189 last = id;
1091be1c3aba mod_mam_muc: Switch to new stanza storage API
Kim Alvefur <zash@zash.se>
parents: 1140
diff changeset
190
1091be1c3aba mod_mam_muc: Switch to new stanza storage API
Kim Alvefur <zash@zash.se>
parents: 1140
diff changeset
191 origin.send(fwd_st);
1138
5c97ee75cadb mod_mam_muc: Switch to iq-get hook and drop some indentation
Kim Alvefur <zash@zash.se>
parents: 820
diff changeset
192 end
5c97ee75cadb mod_mam_muc: Switch to iq-get hook and drop some indentation
Kim Alvefur <zash@zash.se>
parents: 820
diff changeset
193 -- That's all folks!
5c97ee75cadb mod_mam_muc: Switch to iq-get hook and drop some indentation
Kim Alvefur <zash@zash.se>
parents: 820
diff changeset
194 module:log("debug", "Archive query %s completed", tostring(qid));
820
005037032d65 mod_mam_muc: MUC version of mod_mam
Kim Alvefur <zash@zash.se>
parents:
diff changeset
195
1141
1091be1c3aba mod_mam_muc: Switch to new stanza storage API
Kim Alvefur <zash@zash.se>
parents: 1140
diff changeset
196 if reverse then first, last = last, first; end
1091be1c3aba mod_mam_muc: Switch to new stanza storage API
Kim Alvefur <zash@zash.se>
parents: 1140
diff changeset
197 return origin.send(st.reply(stanza)
1091be1c3aba mod_mam_muc: Switch to new stanza storage API
Kim Alvefur <zash@zash.se>
parents: 1140
diff changeset
198 :query(xmlns_mam):add_child(rsm.generate {
1091be1c3aba mod_mam_muc: Switch to new stanza storage API
Kim Alvefur <zash@zash.se>
parents: 1140
diff changeset
199 first = first, last = last, count = count }));
820
005037032d65 mod_mam_muc: MUC version of mod_mam
Kim Alvefur <zash@zash.se>
parents:
diff changeset
200 end);
005037032d65 mod_mam_muc: MUC version of mod_mam
Kim Alvefur <zash@zash.se>
parents:
diff changeset
201
1519
67c80abe742e mod_mam_muc: Fix add/removal of room method overrides
Kim Alvefur <zash@zash.se>
parents: 1430
diff changeset
202 function send_history(self, to, stanza)
1278
40f077b18dfe mod_mam_muc: Override sending of room history and use archives
Kim Alvefur <zash@zash.se>
parents: 1277
diff changeset
203 local maxchars, maxstanzas, seconds, since;
40f077b18dfe mod_mam_muc: Override sending of room history and use archives
Kim Alvefur <zash@zash.se>
parents: 1277
diff changeset
204 local history_tag = stanza:find("{http://jabber.org/protocol/muc}x/history")
40f077b18dfe mod_mam_muc: Override sending of room history and use archives
Kim Alvefur <zash@zash.se>
parents: 1277
diff changeset
205 if history_tag then
40f077b18dfe mod_mam_muc: Override sending of room history and use archives
Kim Alvefur <zash@zash.se>
parents: 1277
diff changeset
206 module:log("debug", tostring(history_tag));
40f077b18dfe mod_mam_muc: Override sending of room history and use archives
Kim Alvefur <zash@zash.se>
parents: 1277
diff changeset
207 local history_attr = history_tag.attr;
40f077b18dfe mod_mam_muc: Override sending of room history and use archives
Kim Alvefur <zash@zash.se>
parents: 1277
diff changeset
208 maxchars = tonumber(history_attr.maxchars);
40f077b18dfe mod_mam_muc: Override sending of room history and use archives
Kim Alvefur <zash@zash.se>
parents: 1277
diff changeset
209 maxstanzas = tonumber(history_attr.maxstanzas);
40f077b18dfe mod_mam_muc: Override sending of room history and use archives
Kim Alvefur <zash@zash.se>
parents: 1277
diff changeset
210 seconds = tonumber(history_attr.seconds);
40f077b18dfe mod_mam_muc: Override sending of room history and use archives
Kim Alvefur <zash@zash.se>
parents: 1277
diff changeset
211 since = history_attr.since;
40f077b18dfe mod_mam_muc: Override sending of room history and use archives
Kim Alvefur <zash@zash.se>
parents: 1277
diff changeset
212 if since then
40f077b18dfe mod_mam_muc: Override sending of room history and use archives
Kim Alvefur <zash@zash.se>
parents: 1277
diff changeset
213 since = timestamp_parse(since);
40f077b18dfe mod_mam_muc: Override sending of room history and use archives
Kim Alvefur <zash@zash.se>
parents: 1277
diff changeset
214 end
40f077b18dfe mod_mam_muc: Override sending of room history and use archives
Kim Alvefur <zash@zash.se>
parents: 1277
diff changeset
215 if seconds then
40f077b18dfe mod_mam_muc: Override sending of room history and use archives
Kim Alvefur <zash@zash.se>
parents: 1277
diff changeset
216 since = math.max(os.time() - seconds, since or 0);
40f077b18dfe mod_mam_muc: Override sending of room history and use archives
Kim Alvefur <zash@zash.se>
parents: 1277
diff changeset
217 end
40f077b18dfe mod_mam_muc: Override sending of room history and use archives
Kim Alvefur <zash@zash.se>
parents: 1277
diff changeset
218 end
40f077b18dfe mod_mam_muc: Override sending of room history and use archives
Kim Alvefur <zash@zash.se>
parents: 1277
diff changeset
219
40f077b18dfe mod_mam_muc: Override sending of room history and use archives
Kim Alvefur <zash@zash.se>
parents: 1277
diff changeset
220 -- Load all the data!
40f077b18dfe mod_mam_muc: Override sending of room history and use archives
Kim Alvefur <zash@zash.se>
parents: 1277
diff changeset
221 local data, err = archive:find(jid_split(self.jid), {
40f077b18dfe mod_mam_muc: Override sending of room history and use archives
Kim Alvefur <zash@zash.se>
parents: 1277
diff changeset
222 limit = m_min(maxstanzas or 20, max_history_length);
1532
71d85bc0dea8 mod_mam_muc: Fix for muc history query
Stuart Carnie <stuart.carnie@gmail.com>
parents: 1519
diff changeset
223 start = since;
1278
40f077b18dfe mod_mam_muc: Override sending of room history and use archives
Kim Alvefur <zash@zash.se>
parents: 1277
diff changeset
224 reverse = true;
1385
da9469e68dee mod_mam_muc: Place stanza type in 'with' column; when sending history, only send messages with type=groupchat
daurnimator <quae@daurnimator.com>
parents: 1382
diff changeset
225 with = "message<groupchat";
1278
40f077b18dfe mod_mam_muc: Override sending of room history and use archives
Kim Alvefur <zash@zash.se>
parents: 1277
diff changeset
226 });
40f077b18dfe mod_mam_muc: Override sending of room history and use archives
Kim Alvefur <zash@zash.se>
parents: 1277
diff changeset
227
40f077b18dfe mod_mam_muc: Override sending of room history and use archives
Kim Alvefur <zash@zash.se>
parents: 1277
diff changeset
228 if not data then
40f077b18dfe mod_mam_muc: Override sending of room history and use archives
Kim Alvefur <zash@zash.se>
parents: 1277
diff changeset
229 module:log("error", "Could not fetch history: %s", tostring(err));
40f077b18dfe mod_mam_muc: Override sending of room history and use archives
Kim Alvefur <zash@zash.se>
parents: 1277
diff changeset
230 return
40f077b18dfe mod_mam_muc: Override sending of room history and use archives
Kim Alvefur <zash@zash.se>
parents: 1277
diff changeset
231 end
40f077b18dfe mod_mam_muc: Override sending of room history and use archives
Kim Alvefur <zash@zash.se>
parents: 1277
diff changeset
232
40f077b18dfe mod_mam_muc: Override sending of room history and use archives
Kim Alvefur <zash@zash.se>
parents: 1277
diff changeset
233 local to_send = {};
40f077b18dfe mod_mam_muc: Override sending of room history and use archives
Kim Alvefur <zash@zash.se>
parents: 1277
diff changeset
234 local charcount = 0;
40f077b18dfe mod_mam_muc: Override sending of room history and use archives
Kim Alvefur <zash@zash.se>
parents: 1277
diff changeset
235 local chars;
40f077b18dfe mod_mam_muc: Override sending of room history and use archives
Kim Alvefur <zash@zash.se>
parents: 1277
diff changeset
236 for id, item, when in data do
40f077b18dfe mod_mam_muc: Override sending of room history and use archives
Kim Alvefur <zash@zash.se>
parents: 1277
diff changeset
237 item.attr.to = to;
40f077b18dfe mod_mam_muc: Override sending of room history and use archives
Kim Alvefur <zash@zash.se>
parents: 1277
diff changeset
238 item:tag("delay", { xmlns = "urn:xmpp:delay", from = self.jid, stamp = timestamp(when) }):up(); -- XEP-0203
40f077b18dfe mod_mam_muc: Override sending of room history and use archives
Kim Alvefur <zash@zash.se>
parents: 1277
diff changeset
239 if maxchars then
40f077b18dfe mod_mam_muc: Override sending of room history and use archives
Kim Alvefur <zash@zash.se>
parents: 1277
diff changeset
240 chars = #tostring(item);
40f077b18dfe mod_mam_muc: Override sending of room history and use archives
Kim Alvefur <zash@zash.se>
parents: 1277
diff changeset
241 if chars + charcount > maxchars then break end
40f077b18dfe mod_mam_muc: Override sending of room history and use archives
Kim Alvefur <zash@zash.se>
parents: 1277
diff changeset
242 charcount = charcount + chars;
40f077b18dfe mod_mam_muc: Override sending of room history and use archives
Kim Alvefur <zash@zash.se>
parents: 1277
diff changeset
243 end
40f077b18dfe mod_mam_muc: Override sending of room history and use archives
Kim Alvefur <zash@zash.se>
parents: 1277
diff changeset
244 to_send[1+#to_send] = item;
40f077b18dfe mod_mam_muc: Override sending of room history and use archives
Kim Alvefur <zash@zash.se>
parents: 1277
diff changeset
245 end
40f077b18dfe mod_mam_muc: Override sending of room history and use archives
Kim Alvefur <zash@zash.se>
parents: 1277
diff changeset
246 for i = #to_send,1,-1 do
40f077b18dfe mod_mam_muc: Override sending of room history and use archives
Kim Alvefur <zash@zash.se>
parents: 1277
diff changeset
247 self:_route_stanza(to_send[i]);
40f077b18dfe mod_mam_muc: Override sending of room history and use archives
Kim Alvefur <zash@zash.se>
parents: 1277
diff changeset
248 end
40f077b18dfe mod_mam_muc: Override sending of room history and use archives
Kim Alvefur <zash@zash.se>
parents: 1277
diff changeset
249 end
40f077b18dfe mod_mam_muc: Override sending of room history and use archives
Kim Alvefur <zash@zash.se>
parents: 1277
diff changeset
250
820
005037032d65 mod_mam_muc: MUC version of mod_mam
Kim Alvefur <zash@zash.se>
parents:
diff changeset
251 -- Handle messages
1519
67c80abe742e mod_mam_muc: Fix add/removal of room method overrides
Kim Alvefur <zash@zash.se>
parents: 1430
diff changeset
252 function save_to_history(self, stanza)
820
005037032d65 mod_mam_muc: MUC version of mod_mam
Kim Alvefur <zash@zash.se>
parents:
diff changeset
253 local orig_to = stanza.attr.to;
1279
2118a2eeb1d5 mod_mam_muc: Override method for storing history messages instead of hooking stanza events
Kim Alvefur <zash@zash.se>
parents: 1278
diff changeset
254 local room = jid_split(self.jid);
820
005037032d65 mod_mam_muc: MUC version of mod_mam
Kim Alvefur <zash@zash.se>
parents:
diff changeset
255
1279
2118a2eeb1d5 mod_mam_muc: Override method for storing history messages instead of hooking stanza events
Kim Alvefur <zash@zash.se>
parents: 1278
diff changeset
256 -- Policy check
1143
8098683b6d6f mod_mam_muc: Allow archiving to be enabled trough in the room configuration
Kim Alvefur <zash@zash.se>
parents: 1142
diff changeset
257 if not ( log_all_rooms == true -- Logging forced on all rooms
1279
2118a2eeb1d5 mod_mam_muc: Override method for storing history messages instead of hooking stanza events
Kim Alvefur <zash@zash.se>
parents: 1278
diff changeset
258 or (self._data.logging == nil and log_by_default == true)
2118a2eeb1d5 mod_mam_muc: Override method for storing history messages instead of hooking stanza events
Kim Alvefur <zash@zash.se>
parents: 1278
diff changeset
259 or self._data.logging ) then return end -- Don't log
1143
8098683b6d6f mod_mam_muc: Allow archiving to be enabled trough in the room configuration
Kim Alvefur <zash@zash.se>
parents: 1142
diff changeset
260
1279
2118a2eeb1d5 mod_mam_muc: Override method for storing history messages instead of hooking stanza events
Kim Alvefur <zash@zash.se>
parents: 1278
diff changeset
261 module:log("debug", "We're logging this")
820
005037032d65 mod_mam_muc: MUC version of mod_mam
Kim Alvefur <zash@zash.se>
parents:
diff changeset
262 -- And stash it
1385
da9469e68dee mod_mam_muc: Place stanza type in 'with' column; when sending history, only send messages with type=groupchat
daurnimator <quae@daurnimator.com>
parents: 1382
diff changeset
263 local with = stanza.name
da9469e68dee mod_mam_muc: Place stanza type in 'with' column; when sending history, only send messages with type=groupchat
daurnimator <quae@daurnimator.com>
parents: 1382
diff changeset
264 if stanza.attr.type then
da9469e68dee mod_mam_muc: Place stanza type in 'with' column; when sending history, only send messages with type=groupchat
daurnimator <quae@daurnimator.com>
parents: 1382
diff changeset
265 with = with .. "<" .. stanza.attr.type
da9469e68dee mod_mam_muc: Place stanza type in 'with' column; when sending history, only send messages with type=groupchat
daurnimator <quae@daurnimator.com>
parents: 1382
diff changeset
266 end
da9469e68dee mod_mam_muc: Place stanza type in 'with' column; when sending history, only send messages with type=groupchat
daurnimator <quae@daurnimator.com>
parents: 1382
diff changeset
267 local ok, id = archive:append(room, nil, time_now(), with, stanza);
1142
fabdaa0d99e3 mod_mam_muc: Stap archived messages
Kim Alvefur <zash@zash.se>
parents: 1141
diff changeset
268 if ok and advertise_archive then
fabdaa0d99e3 mod_mam_muc: Stap archived messages
Kim Alvefur <zash@zash.se>
parents: 1141
diff changeset
269 stanza:tag("archived", { xmlns = xmlns_mam, by = jid_bare(orig_to), id = id }):up();
fabdaa0d99e3 mod_mam_muc: Stap archived messages
Kim Alvefur <zash@zash.se>
parents: 1141
diff changeset
270 end
820
005037032d65 mod_mam_muc: MUC version of mod_mam
Kim Alvefur <zash@zash.se>
parents:
diff changeset
271 end
005037032d65 mod_mam_muc: MUC version of mod_mam
Kim Alvefur <zash@zash.se>
parents:
diff changeset
272
1277
999891a9ae5d mod_mam_muc: Remove archives when a room is destroyed
Kim Alvefur <zash@zash.se>
parents: 1276
diff changeset
273 module:hook("muc-room-destroyed", function(event)
999891a9ae5d mod_mam_muc: Remove archives when a room is destroyed
Kim Alvefur <zash@zash.se>
parents: 1276
diff changeset
274 archive:delete(jid_split(event.room.jid));
999891a9ae5d mod_mam_muc: Remove archives when a room is destroyed
Kim Alvefur <zash@zash.se>
parents: 1276
diff changeset
275 end);
999891a9ae5d mod_mam_muc: Remove archives when a room is destroyed
Kim Alvefur <zash@zash.se>
parents: 1276
diff changeset
276
1141
1091be1c3aba mod_mam_muc: Switch to new stanza storage API
Kim Alvefur <zash@zash.se>
parents: 1140
diff changeset
277 -- TODO should we perhaps log presence as well?
1091be1c3aba mod_mam_muc: Switch to new stanza storage API
Kim Alvefur <zash@zash.se>
parents: 1140
diff changeset
278 -- And role/affiliation changes?
1091be1c3aba mod_mam_muc: Switch to new stanza storage API
Kim Alvefur <zash@zash.se>
parents: 1140
diff changeset
279
820
005037032d65 mod_mam_muc: MUC version of mod_mam
Kim Alvefur <zash@zash.se>
parents:
diff changeset
280 module:add_feature(xmlns_mam);