author | Kim Alvefur <zash@zash.se> |
Sat, 04 Mar 2017 19:52:41 +0100 | |
changeset 2599 | 307ddebb72e1 |
parent 2511 | b8a66805459e |
child 2630 | 17883c405df3 |
permissions | -rw-r--r-- |
1313 | 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 | 3 |
-- |
4 |
-- This file is MIT/X11 licensed. |
|
5 |
||
1977
9329a11c03a6
mod_mam_muc: Add guard to prevent loading on normal hosts
Kim Alvefur <zash@zash.se>
parents:
1869
diff
changeset
|
6 |
if module:get_host_type() ~= "component" then |
9329a11c03a6
mod_mam_muc: Add guard to prevent loading on normal hosts
Kim Alvefur <zash@zash.se>
parents:
1869
diff
changeset
|
7 |
module:log("error", "mod_%s should be loaded only on a MUC component, not normal hosts", module.name); |
9329a11c03a6
mod_mam_muc: Add guard to prevent loading on normal hosts
Kim Alvefur <zash@zash.se>
parents:
1869
diff
changeset
|
8 |
return; |
9329a11c03a6
mod_mam_muc: Add guard to prevent loading on normal hosts
Kim Alvefur <zash@zash.se>
parents:
1869
diff
changeset
|
9 |
end |
9329a11c03a6
mod_mam_muc: Add guard to prevent loading on normal hosts
Kim Alvefur <zash@zash.se>
parents:
1869
diff
changeset
|
10 |
|
2511
b8a66805459e
mod_mam_muc: Update to XEP-0313 0.5.1
Kim Alvefur <zash@zash.se>
parents:
2506
diff
changeset
|
11 |
local xmlns_mam = "urn:xmpp:mam:1"; |
820 | 12 |
local xmlns_delay = "urn:xmpp:delay"; |
13 |
local xmlns_forward = "urn:xmpp:forward:0"; |
|
1313 | 14 |
local muc_form_enable_logging = "muc#roomconfig_enablelogging" |
820 | 15 |
|
16 |
local st = require "util.stanza"; |
|
2501
c6761ebe613b
mod_mam_muc: Use util.rsm (fixes #829, depends on a recent 0.10+)
Kim Alvefur <zash@zash.se>
parents:
2433
diff
changeset
|
17 |
local rsm = require "util.rsm"; |
820 | 18 |
local jid_bare = require "util.jid".bare; |
19 |
local jid_split = require "util.jid".split; |
|
1536
4fb280768efc
mod_mam_muc: Add missing import and change the namespace to MAM v0.3
Kim Alvefur <zash@zash.se>
parents:
1535
diff
changeset
|
20 |
local dataform = require "util.dataforms".new; |
1551
5127f4db9d39
mod_mam_muc: Try to use new MUC API for getting room objects (fixes queries to not yet initialized rooms)
Kim Alvefur <zash@zash.se>
parents:
1548
diff
changeset
|
21 |
local it = require"util.iterators"; |
1534
4dd6eebc8fbd
mod_mam_muc: Minor moving about of variables
Kim Alvefur <zash@zash.se>
parents:
1533
diff
changeset
|
22 |
|
1551
5127f4db9d39
mod_mam_muc: Try to use new MUC API for getting room objects (fixes queries to not yet initialized rooms)
Kim Alvefur <zash@zash.se>
parents:
1548
diff
changeset
|
23 |
-- Support both old and new MUC code |
1534
4dd6eebc8fbd
mod_mam_muc: Minor moving about of variables
Kim Alvefur <zash@zash.se>
parents:
1533
diff
changeset
|
24 |
local mod_muc = module:depends"muc"; |
1543
57fb9ce21f9c
mod_mam_muc: Add compatibility with the new MUC code in trunk
Kim Alvefur <zash@zash.se>
parents:
1542
diff
changeset
|
25 |
local rooms = rawget(mod_muc, "rooms"); |
1551
5127f4db9d39
mod_mam_muc: Try to use new MUC API for getting room objects (fixes queries to not yet initialized rooms)
Kim Alvefur <zash@zash.se>
parents:
1548
diff
changeset
|
26 |
local each_room = rawget(mod_muc, "each_room") or function() return it.values(rooms); end; |
1543
57fb9ce21f9c
mod_mam_muc: Add compatibility with the new MUC code in trunk
Kim Alvefur <zash@zash.se>
parents:
1542
diff
changeset
|
27 |
local new_muc = not rooms; |
57fb9ce21f9c
mod_mam_muc: Add compatibility with the new MUC code in trunk
Kim Alvefur <zash@zash.se>
parents:
1542
diff
changeset
|
28 |
if new_muc then |
57fb9ce21f9c
mod_mam_muc: Add compatibility with the new MUC code in trunk
Kim Alvefur <zash@zash.se>
parents:
1542
diff
changeset
|
29 |
rooms = module:shared"muc/rooms"; |
57fb9ce21f9c
mod_mam_muc: Add compatibility with the new MUC code in trunk
Kim Alvefur <zash@zash.se>
parents:
1542
diff
changeset
|
30 |
end |
1551
5127f4db9d39
mod_mam_muc: Try to use new MUC API for getting room objects (fixes queries to not yet initialized rooms)
Kim Alvefur <zash@zash.se>
parents:
1548
diff
changeset
|
31 |
local get_room_from_jid = rawget(mod_muc, "get_room_from_jid") or |
5127f4db9d39
mod_mam_muc: Try to use new MUC API for getting room objects (fixes queries to not yet initialized rooms)
Kim Alvefur <zash@zash.se>
parents:
1548
diff
changeset
|
32 |
function (jid) |
5127f4db9d39
mod_mam_muc: Try to use new MUC API for getting room objects (fixes queries to not yet initialized rooms)
Kim Alvefur <zash@zash.se>
parents:
1548
diff
changeset
|
33 |
return rooms[jid]; |
5127f4db9d39
mod_mam_muc: Try to use new MUC API for getting room objects (fixes queries to not yet initialized rooms)
Kim Alvefur <zash@zash.se>
parents:
1548
diff
changeset
|
34 |
end |
820 | 35 |
|
2502
e065e94f0ac6
mod_mam_muc: Remove fallback for util.stanza.is_stanza, it should be available
Kim Alvefur <zash@zash.se>
parents:
2501
diff
changeset
|
36 |
local is_stanza = st.is_stanza; |
820 | 37 |
local tostring = tostring; |
38 |
local time_now = os.time; |
|
39 |
local m_min = math.min; |
|
40 |
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
|
41 |
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
|
42 |
local default_max_items, max_max_items = 20, module:get_option_number("max_archive_query_results", max_history_length); |
820 | 43 |
|
1143
8098683b6d6f
mod_mam_muc: Allow archiving to be enabled trough in the room configuration
Kim Alvefur <zash@zash.se>
parents:
1142
diff
changeset
|
44 |
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
|
45 |
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
|
46 |
|
1571
eed7db9f3157
mod_mam_muc, mod_http_muc_log: Change store name from 'archive2' to 'muc_log' to distinguish it from personal MAM archives. Old data will require migration.
Kim Alvefur <zash@zash.se>
parents:
1551
diff
changeset
|
47 |
local archive_store = "muc_log"; |
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
|
48 |
local archive = module:open_store(archive_store, "archive"); |
2035
f21147d56bc4
mod_mam_muc: Yell loudly when archive store can't be opened
Kim Alvefur <zash@zash.se>
parents:
1977
diff
changeset
|
49 |
|
f21147d56bc4
mod_mam_muc: Yell loudly when archive store can't be opened
Kim Alvefur <zash@zash.se>
parents:
1977
diff
changeset
|
50 |
if archive.name == "null" or not archive.find then |
f21147d56bc4
mod_mam_muc: Yell loudly when archive store can't be opened
Kim Alvefur <zash@zash.se>
parents:
1977
diff
changeset
|
51 |
if not archive.find then |
f21147d56bc4
mod_mam_muc: Yell loudly when archive store can't be opened
Kim Alvefur <zash@zash.se>
parents:
1977
diff
changeset
|
52 |
module:log("error", "Attempt to open archive storage returned a valid driver but it does not seem to implement the storage API"); |
f21147d56bc4
mod_mam_muc: Yell loudly when archive store can't be opened
Kim Alvefur <zash@zash.se>
parents:
1977
diff
changeset
|
53 |
module:log("error", "mod_%s does not support archiving", archive._provided_by or archive.name and "storage_"..archive.name.."(?)" or "<unknown>"); |
f21147d56bc4
mod_mam_muc: Yell loudly when archive store can't be opened
Kim Alvefur <zash@zash.se>
parents:
1977
|