Mercurial > prosody-modules
annotate mod_mam_muc/mod_mam_muc.lua @ 1138:5c97ee75cadb
mod_mam_muc: Switch to iq-get hook and drop some indentation
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Sat, 10 Aug 2013 21:05:38 +0200 |
parents | 005037032d65 |
children | b32d65e41755 |
rev | line source |
---|---|
820 | 1 -- XEP-0313: Message Archive Management for Prosody |
2 -- Copyright (C) 2011-2012 Kim Alvefur | |
3 -- | |
4 -- This file is MIT/X11 licensed. | |
5 | |
6 local xmlns_mam = "urn:xmpp:mam:tmp"; | |
7 local xmlns_delay = "urn:xmpp:delay"; | |
8 local xmlns_forward = "urn:xmpp:forward:0"; | |
9 | |
10 local st = require "util.stanza"; | |
11 local rsm = module:require "mod_mam/rsm"; | |
12 local jid_bare = require "util.jid".bare; | |
13 local jid_split = require "util.jid".split; | |
14 local jid_prep = require "util.jid".prep; | |
15 local host = module.host; | |
16 | |
17 local dm_list_load = require "util.datamanager".list_load; | |
18 local dm_list_append = require "util.datamanager".list_append; | |
19 | |
20 local tostring = tostring; | |
21 local time_now = os.time; | |
22 local m_min = math.min; | |
23 local timestamp, timestamp_parse = require "util.datetime".datetime, require "util.datetime".parse; | |
24 local uuid = require "util.uuid".generate; | |
25 local default_max_items, max_max_items = 20, module:get_option_number("max_archive_query_results", 50); | |
26 --local rooms_to_archive = module:get_option_set("rooms_to_archive",{}); | |
27 -- TODO Should be possible to enforce it too | |
28 | |
29 local archive_store = "archive2"; | |
30 | |
31 -- 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
|
32 module:hook("iq-get/bare/"..xmlns_mam..":query", function(event) |
820 | 33 local origin, stanza = event.origin, event.stanza; |
34 local room = jid_split(stanza.attr.to); | |
35 local query = stanza.tags[1]; | |
36 | |
37 local room_obj = hosts[module.host].modules.muc.rooms[jid_bare(stanza.attr.to)]; | |
38 if not room_obj then | |
39 return -- FIXME not found | |
40 end | |
41 local from = jid_bare(stanza.attr.from); | |
42 | |
43 if room_obj._affiliations[from] == "outcast" | |
44 or room_obj._data.members_only and not room_obj._affiliations[from] then | |
45 return -- FIXME unauth | |
46 end | |
47 | |
1138
5c97ee75cadb
mod_mam_muc: Switch to iq-get hook and drop some indentation
Kim Alvefur <zash@zash.se>
parents:
820
diff
changeset
|
48 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
|
49 |
5c97ee75cadb
mod_mam_muc: Switch to iq-get hook and drop some indentation
Kim Alvefur <zash@zash.se>
parents:
820
diff
changeset
|
50 -- 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
|
51 local qwith = query:get_child_text("with"); |
5c97ee75cadb
mod_mam_muc: Switch to iq-get hook and drop some indentation
Kim Alvefur <zash@zash.se>
parents:
820
diff
changeset
|
52 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
|
53 local qend = query:get_child_text("end"); |
5c97ee75cadb
mod_mam_muc: Switch to iq-get hook and drop some indentation
Kim Alvefur <zash@zash.se>
parents:
820
diff
changeset
|
54 local qset = rsm.get(query); |
5c97ee75cadb
mod_mam_muc: Switch to iq-get hook and drop some indentation
Kim Alvefur <zash@zash.se>
parents:
820
diff
changeset
|
55 module:log("debug", "Archive query, id %s with %s from %s until %s)", |
5c97ee75cadb
mod_mam_muc: Switch to iq-get hook and drop some indentation
Kim Alvefur <zash@zash.se>
parents:
820
diff
changeset
|
56 tostring(qid), qwith or "anyone", qstart or "the dawn of time", qend or "now"); |
820 | 57 |
1138
5c97ee75cadb
mod_mam_muc: Switch to iq-get hook and drop some indentation
Kim Alvefur <zash@zash.se>
parents:
820
diff
changeset
|
58 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
|
59 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
|
60 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
|
61 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
|
62 return true |
5c97ee75cadb
mod_mam_muc: Switch to iq-get hook and drop some indentation
Kim Alvefur <zash@zash.se>
parents:
820
diff
changeset
|
63 end |
5c97ee75cadb
mod_mam_muc: Switch to iq-get hook and drop some indentation
Kim Alvefur <zash@zash.se>
parents:
820
diff
changeset
|
64 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
|
65 end |
820 | 66 |
1138
5c97ee75cadb
mod_mam_muc: Switch to iq-get hook and drop some indentation
Kim Alvefur <zash@zash.se>
parents:
820
diff
changeset
|
67 local qres; |
5c97ee75cadb
mod_mam_muc: Switch to iq-get hook and drop some indentation
Kim Alvefur <zash@zash.se>
parents:
820
diff
changeset
|
68 if qwith then -- Validate the 'with' jid |
5c97ee75cadb
mod_mam_muc: Switch to iq-get hook and drop some indentation
Kim Alvefur <zash@zash.se>
parents:
820
diff
changeset
|
69 local pwith = qwith and jid_prep(qwith); |
5c97ee75cadb
mod_mam_muc: Switch to iq-get hook and drop some indentation
Kim Alvefur <zash@zash.se>
parents:
820
diff
changeset
|
70 if pwith and not qwith then -- it failed prepping |
5c97ee75cadb
mod_mam_muc: Switch to iq-get hook and drop some indentation
Kim Alvefur <zash@zash.se>
parents:
820
diff
changeset
|
71 origin.send(st.error_reply(stanza, "modify", "bad-request", "Invalid JID")) |
5c97ee75cadb
mod_mam_muc: Switch to iq-get hook and drop some indentation
Kim Alvefur <zash@zash.se>
parents:
820
diff
changeset
|
72 return true |
820 | 73 end |
1138
5c97ee75cadb
mod_mam_muc: Switch to iq-get hook and drop some indentation
Kim Alvefur <zash@zash.se>
parents:
820
diff
changeset
|
74 local _, _, resource = jid_split(qwith); |
5c97ee75cadb
mod_mam_muc: Switch to iq-get hook and drop some indentation
Kim Alvefur <zash@zash.se>
parents:
820
diff
changeset
|
75 qwith = jid_bare(pwith); |
5c97ee75cadb
mod_mam_muc: Switch to iq-get hook and drop some indentation
Kim Alvefur <zash@zash.se>
parents:
820
diff
changeset
|
76 qres = resource; |
5c97ee75cadb
mod_mam_muc: Switch to iq-get hook and drop some indentation
Kim Alvefur <zash@zash.se>
parents:
820
diff
changeset
|
77 end |
820 | 78 |
1138
5c97ee75cadb
mod_mam_muc: Switch to iq-get hook and drop some indentation
Kim Alvefur <zash@zash.se>
parents:
820
diff
changeset
|
79 -- Load all the data! |
5c97ee75cadb
mod_mam_muc: Switch to iq-get hook and drop some indentation
Kim Alvefur <zash@zash.se>
parents:
820
diff
changeset
|
80 local data, err = dm_list_load(room, module.host, archive_store); |
5c97ee75cadb
mod_mam_muc: Switch to iq-get hook and drop some indentation
Kim Alvefur <zash@zash.se>
parents:
820
diff
changeset
|
81 if not data then |
5c97ee75cadb
mod_mam_muc: Switch to iq-get hook and drop some indentation
Kim Alvefur <zash@zash.se>
parents:
820
diff
changeset
|
82 if (not err) then |
5c97ee75cadb
mod_mam_muc: Switch to iq-get hook and drop some indentation
Kim Alvefur <zash@zash.se>
parents:
820
diff
changeset
|
83 module:log("debug", "The archive was empty."); |
5c97ee75cadb
mod_mam_muc: Switch to iq-get hook and drop some indentation
Kim Alvefur <zash@zash.se>
parents:
820
diff
changeset
|
84 origin.send(st.reply(stanza)); |
5c97ee75cadb
mod_mam_muc: Switch to iq-get hook and drop some indentation
Kim Alvefur <zash@zash.se>
parents:
820
diff
changeset
|
85 else |
5c97ee75cadb
mod_mam_muc: Switch to iq-get hook and drop some indentation
Kim Alvefur <zash@zash.se>
parents:
820
diff
changeset
|
86 origin.send(st.error_reply(stanza, "cancel", "internal-server-error", "Error loading archive: "..tostring(err))); |
820 | 87 end |
1138
5c97ee75cadb
mod_mam_muc: Switch to iq-get hook and drop some indentation
Kim Alvefur <zash@zash.se>
parents:
820
diff
changeset
|
88 return true |
5c97ee75cadb
mod_mam_muc: Switch to iq-get hook and drop some indentation
Kim Alvefur <zash@zash.se>
parents:
820
diff
changeset
|
89 end |
820 | 90 |
1138
5c97ee75cadb
mod_mam_muc: Switch to iq-get hook and drop some indentation
Kim Alvefur <zash@zash.se>
parents:
820
diff
changeset
|
91 -- RSM stuff |
5c97ee75cadb
mod_mam_muc: Switch to iq-get hook and drop some indentation
Kim Alvefur <zash@zash.se>
parents:
820
diff
changeset
|
92 local qmax = m_min(qset and qset.max or default_max_items, max_max_items); |
5c97ee75cadb
mod_mam_muc: Switch to iq-get hook and drop some indentation
Kim Alvefur <zash@zash.se>
parents:
820
diff
changeset
|
93 local qset_matches = not (qset and qset.after); |
5c97ee75cadb
mod_mam_muc: Switch to iq-get hook and drop some indentation
Kim Alvefur <zash@zash.se>
parents:
820
diff
changeset
|
94 local first, last, index; |
5c97ee75cadb
mod_mam_muc: Switch to iq-get hook and drop some indentation
Kim Alvefur <zash@zash.se>
parents:
820
diff
changeset
|
95 local n = 0; |
5c97ee75cadb
mod_mam_muc: Switch to iq-get hook and drop some indentation
Kim Alvefur <zash@zash.se>
parents:
820
diff
changeset
|
96 local start = qset and qset.index or 1; |
5c97ee75cadb
mod_mam_muc: Switch to iq-get hook and drop some indentation
Kim Alvefur <zash@zash.se>
parents:
820
diff
changeset
|
97 |
5c97ee75cadb
mod_mam_muc: Switch to iq-get hook and drop some indentation
Kim Alvefur <zash@zash.se>
parents:
820
diff
changeset
|
98 module:log("debug", "Loaded %d items, about to filter", #data); |
5c97ee75cadb
mod_mam_muc: Switch to iq-get hook and drop some indentation
Kim Alvefur <zash@zash.se>
parents:
820
diff
changeset
|
99 for i=start,#data do |
5c97ee75cadb
mod_mam_muc: Switch to iq-get hook and drop some indentation
Kim Alvefur <zash@zash.se>
parents:
820
diff
changeset
|
100 local item = data[i]; |
5c97ee75cadb
mod_mam_muc: Switch to iq-get hook and drop some indentation
Kim Alvefur <zash@zash.se>
parents:
820
diff
changeset
|
101 local when, nick = item.when, item.resource; |
5c97ee75cadb
mod_mam_muc: Switch to iq-get hook and drop some indentation
Kim Alvefur <zash@zash.se>
parents:
820
diff
changeset
|
102 local id = item.id; |
5c97ee75cadb
mod_mam_muc: Switch to iq-get hook and drop some indentation
Kim Alvefur <zash@zash.se>
parents:
820
diff
changeset
|
103 --module:log("debug", "id is %s", id); |
5c97ee75cadb
mod_mam_muc: Switch to iq-get hook and drop some indentation
Kim Alvefur <zash@zash.se>
parents:
820
diff
changeset
|
104 |
5c97ee75cadb
mod_mam_muc: Switch to iq-get hook and drop some indentation
Kim Alvefur <zash@zash.se>
parents:
820
diff
changeset
|
105 -- RSM pre-send-checking |
5c97ee75cadb
mod_mam_muc: Switch to iq-get hook and drop some indentation
Kim Alvefur <zash@zash.se>
parents:
820
diff
changeset
|
106 if qset then |
5c97ee75cadb
mod_mam_muc: Switch to iq-get hook and drop some indentation
Kim Alvefur <zash@zash.se>
parents:
820
diff
changeset
|
107 if qset.before == id then |
5c97ee75cadb
mod_mam_muc: Switch to iq-get hook and drop some indentation
Kim Alvefur <zash@zash.se>
parents:
820
diff
changeset
|
108 module:log("debug", "End of matching range found"); |
5c97ee75cadb
mod_mam_muc: Switch to iq-get hook and drop some indentation
Kim Alvefur <zash@zash.se>
parents:
820
diff
changeset
|
109 qset_matches = false; |
5c97ee75cadb
mod_mam_muc: Switch to iq-get hook and drop some indentation
Kim Alvefur <zash@zash.se>
parents:
820
diff
changeset
|
110 break; |
820 | 111 end |
112 end | |
113 | |
1138
5c97ee75cadb
mod_mam_muc: Switch to iq-get hook and drop some indentation
Kim Alvefur <zash@zash.se>
parents:
820
diff
changeset
|
114 --module:log("debug", "message with %s at %s", with, when or "???"); |
5c97ee75cadb
mod_mam_muc: Switch to iq-get hook and drop some indentation
Kim Alvefur <zash@zash.se>
parents:
820
diff
changeset
|
115 -- Apply query filter |
5c97ee75cadb
mod_mam_muc: Switch to iq-get hook and drop some indentation
Kim Alvefur <zash@zash.se>
parents:
820
diff
changeset
|
116 if (not qres or (qres == nick)) |
5c97ee75cadb
mod_mam_muc: Switch to iq-get hook and drop some indentation
Kim Alvefur <zash@zash.se>
parents:
820
diff
changeset
|
117 and (not qstart or when >= qstart) |
5c97ee75cadb
mod_mam_muc: Switch to iq-get hook and drop some indentation
Kim Alvefur <zash@zash.se>
parents:
820
diff
changeset
|
118 and (not qend or when <= qend) |
5c97ee75cadb
mod_mam_muc: Switch to iq-get hook and drop some indentation
Kim Alvefur <zash@zash.se>
parents:
820
diff
changeset
|
119 and (not qset or qset_matches) then |
5c97ee75cadb
mod_mam_muc: Switch to iq-get hook and drop some indentation
Kim Alvefur <zash@zash.se>
parents:
820
diff
changeset
|
120 local fwd_st = st.message{ to = stanza.attr.from } |
5c97ee75cadb
mod_mam_muc: Switch to iq-get hook and drop some indentation
Kim Alvefur <zash@zash.se>
parents:
820
diff
changeset
|
121 :tag("result", { xmlns = xmlns_mam, queryid = qid, id = id }):up() |
5c97ee75cadb
mod_mam_muc: Switch to iq-get hook and drop some indentation
Kim Alvefur <zash@zash.se>
parents:
820
diff
changeset
|
122 :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
|
123 :tag("delay", { xmlns = xmlns_delay, stamp = timestamp(when) }):up(); |
5c97ee75cadb
mod_mam_muc: Switch to iq-get hook and drop some indentation
Kim Alvefur <zash@zash.se>
parents:
820
diff
changeset
|
124 local orig_stanza = st.deserialize(item.stanza); |
5c97ee75cadb
mod_mam_muc: Switch to iq-get hook and drop some indentation
Kim Alvefur <zash@zash.se>
parents:
820
diff
changeset
|
125 orig_stanza.attr.xmlns = "jabber:client"; |
5c97ee75cadb
mod_mam_muc: Switch to iq-get hook and drop some indentation
Kim Alvefur <zash@zash.se>
parents:
820
diff
changeset
|
126 fwd_st:add_child(orig_stanza); |
5c97ee75cadb
mod_mam_muc: Switch to iq-get hook and drop some indentation
Kim Alvefur <zash@zash.se>
parents:
820
diff
changeset
|
127 origin.send(fwd_st); |
5c97ee75cadb
mod_mam_muc: Switch to iq-get hook and drop some indentation
Kim Alvefur <zash@zash.se>
parents:
820
diff
changeset
|
128 if not first then |
5c97ee75cadb
mod_mam_muc: Switch to iq-get hook and drop some indentation
Kim Alvefur <zash@zash.se>
parents:
820
diff
changeset
|
129 index = i; |
5c97ee75cadb
mod_mam_muc: Switch to iq-get hook and drop some indentation
Kim Alvefur <zash@zash.se>
parents:
820
diff
changeset
|
130 first = id; |
820 | 131 end |
1138
5c97ee75cadb
mod_mam_muc: Switch to iq-get hook and drop some indentation
Kim Alvefur <zash@zash.se>
parents:
820
diff
changeset
|
132 last = id; |
5c97ee75cadb
mod_mam_muc: Switch to iq-get hook and drop some indentation
Kim Alvefur <zash@zash.se>
parents:
820
diff
changeset
|
133 n = n + 1; |
5c97ee75cadb
mod_mam_muc: Switch to iq-get hook and drop some indentation
Kim Alvefur <zash@zash.se>
parents:
820
diff
changeset
|
134 elseif (qend and when > qend) then |
5c97ee75cadb
mod_mam_muc: Switch to iq-get hook and drop some indentation
Kim Alvefur <zash@zash.se>
parents:
820
diff
changeset
|
135 module:log("debug", "We have passed into messages more recent than requested"); |
5c97ee75cadb
mod_mam_muc: Switch to iq-get hook and drop some indentation
Kim Alvefur <zash@zash.se>
parents:
820
diff
changeset
|
136 break -- We have passed into messages more recent than requested |
5c97ee75cadb
mod_mam_muc: Switch to iq-get hook and drop some indentation
Kim Alvefur <zash@zash.se>
parents:
820
diff
changeset
|
137 end |
820 | 138 |
1138
5c97ee75cadb
mod_mam_muc: Switch to iq-get hook and drop some indentation
Kim Alvefur <zash@zash.se>
parents:
820
diff
changeset
|
139 -- RSM post-send-checking |
5c97ee75cadb
mod_mam_muc: Switch to iq-get hook and drop some indentation
Kim Alvefur <zash@zash.se>
parents:
820
diff
changeset
|
140 if qset then |
5c97ee75cadb
mod_mam_muc: Switch to iq-get hook and drop some indentation
Kim Alvefur <zash@zash.se>
parents:
820
diff
changeset
|
141 if qset.after == id then |
5c97ee75cadb
mod_mam_muc: Switch to iq-get hook and drop some indentation
Kim Alvefur <zash@zash.se>
parents:
820
diff
changeset
|
142 module:log("debug", "Start of matching range found"); |
5c97ee75cadb
mod_mam_muc: Switch to iq-get hook and drop some indentation
Kim Alvefur <zash@zash.se>
parents:
820
diff
changeset
|
143 qset_matches = true; |
820 | 144 end |
145 end | |
1138
5c97ee75cadb
mod_mam_muc: Switch to iq-get hook and drop some indentation
Kim Alvefur <zash@zash.se>
parents:
820
diff
changeset
|
146 if n >= qmax then |
5c97ee75cadb
mod_mam_muc: Switch to iq-get hook and drop some indentation
Kim Alvefur <zash@zash.se>
parents:
820
diff
changeset
|
147 module:log("debug", "Max number of items matched"); |
5c97ee75cadb
mod_mam_muc: Switch to iq-get hook and drop some indentation
Kim Alvefur <zash@zash.se>
parents:
820
diff
changeset
|
148 break |
5c97ee75cadb
mod_mam_muc: Switch to iq-get hook and drop some indentation
Kim Alvefur <zash@zash.se>
parents:
820
diff
changeset
|
149 end |
5c97ee75cadb
mod_mam_muc: Switch to iq-get hook and drop some indentation
Kim Alvefur <zash@zash.se>
parents:
820
diff
changeset
|
150 end |
5c97ee75cadb
mod_mam_muc: Switch to iq-get hook and drop some indentation
Kim Alvefur <zash@zash.se>
parents:
820
diff
changeset
|
151 -- 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
|
152 module:log("debug", "Archive query %s completed", tostring(qid)); |
820 | 153 |
1138
5c97ee75cadb
mod_mam_muc: Switch to iq-get hook and drop some indentation
Kim Alvefur <zash@zash.se>
parents:
820
diff
changeset
|
154 local reply = st.reply(stanza); |
5c97ee75cadb
mod_mam_muc: Switch to iq-get hook and drop some indentation
Kim Alvefur <zash@zash.se>
parents:
820
diff
changeset
|
155 if last then |
5c97ee75cadb
mod_mam_muc: Switch to iq-get hook and drop some indentation
Kim Alvefur <zash@zash.se>
parents:
820
diff
changeset
|
156 -- This is a bit redundant, isn't it? |
5c97ee75cadb
mod_mam_muc: Switch to iq-get hook and drop some indentation
Kim Alvefur <zash@zash.se>
parents:
820
diff
changeset
|
157 reply:query(xmlns_mam):add_child(rsm.generate{first = first, last = last, count = n}); |
820 | 158 end |
1138
5c97ee75cadb
mod_mam_muc: Switch to iq-get hook and drop some indentation
Kim Alvefur <zash@zash.se>
parents:
820
diff
changeset
|
159 origin.send(reply); |
5c97ee75cadb
mod_mam_muc: Switch to iq-get hook and drop some indentation
Kim Alvefur <zash@zash.se>
parents:
820
diff
changeset
|
160 return true |
820 | 161 end); |
162 | |
163 -- Handle messages | |
164 local function message_handler(event) | |
165 local origin, stanza = event.origin, event.stanza; | |
166 local orig_type = stanza.attr.type or "normal"; | |
167 local orig_to = stanza.attr.to; | |
168 local orig_from = stanza.attr.from; | |
169 | |
170 -- Still needed? | |
171 if not orig_from then | |
172 orig_from = origin.full_jid; | |
173 end | |
174 | |
175 -- Only store groupchat messages | |
176 if not (orig_type == "groupchat" and (stanza:get_child("body") or stanza:get_child("subject"))) then | |
177 return; | |
178 end | |
179 | |
180 local room = jid_split(orig_to); | |
181 local room_obj = hosts[host].modules.muc.rooms[orig_to] | |
182 if not room_obj then return end | |
183 | |
184 local id = uuid(); | |
185 local when = time_now(); | |
186 local stanza = st.clone(stanza); -- Private copy | |
187 --stanza.attr.to = nil; | |
188 local nick = room_obj._jid_nick[orig_from]; | |
189 if not nick then return end | |
190 stanza.attr.from = nick; | |
191 local _, _, nick = jid_split(nick); | |
192 -- And stash it | |
193 local ok, err = dm_list_append(room, host, archive_store, { | |
194 -- WARNING This format may change. | |
195 id = id, | |
196 when = when, | |
197 resource = nick, | |
198 stanza = st.preserialize(stanza) | |
199 }); | |
200 --[[ This was dropped from the spec | |
201 if ok then | |
202 stanza:tag("archived", { xmlns = xmlns_mam, by = host, id = id }):up(); | |
203 end | |
204 --]] | |
205 end | |
206 | |
207 module:hook("message/bare", message_handler, 2); | |
208 | |
209 module:add_feature(xmlns_mam); |