Software /
code /
prosody-modules
Comparison
mod_mam/mod_mam.lua @ 2270:9c99200afd17
mod_mam: Log messages from local clients on the clients session
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Fri, 12 Aug 2016 18:20:08 +0200 |
parent | 2049:50c188cf0ae3 |
child | 2293:144b74caa5ef |
comparison
equal
deleted
inserted
replaced
2269:a730ab6f3aaa | 2270:9c99200afd17 |
---|---|
226 end | 226 end |
227 | 227 |
228 -- Handle messages | 228 -- Handle messages |
229 local function message_handler(event, c2s) | 229 local function message_handler(event, c2s) |
230 local origin, stanza = event.origin, event.stanza; | 230 local origin, stanza = event.origin, event.stanza; |
231 local log = c2s and origin.log or module._log; | |
231 local orig_type = stanza.attr.type or "normal"; | 232 local orig_type = stanza.attr.type or "normal"; |
232 local orig_from = stanza.attr.from; | 233 local orig_from = stanza.attr.from; |
233 local orig_to = stanza.attr.to or orig_from; | 234 local orig_to = stanza.attr.to or orig_from; |
234 -- Stanza without 'to' are treated as if it was to their own bare jid | 235 -- Stanza without 'to' are treated as if it was to their own bare jid |
235 | 236 |
236 -- We store chat messages or normal messages that have a body | 237 -- We store chat messages or normal messages that have a body |
237 if not(orig_type == "chat" or (orig_type == "normal" and stanza:get_child("body")) ) then | 238 if not(orig_type == "chat" or (orig_type == "normal" and stanza:get_child("body")) ) then |
238 module:log("debug", "Not archiving stanza: %s (type)", stanza:top_tag()); | 239 log("debug", "Not archiving stanza: %s (type)", stanza:top_tag()); |
239 return; | 240 return; |
240 end | 241 end |
241 -- or if hints suggest we shouldn't | 242 -- or if hints suggest we shouldn't |
242 if stanza:get_child("no-permanent-storage", "urn:xmpp:hints") -- The XEP needs to decide on "store" or "storage" | 243 if stanza:get_child("no-permanent-storage", "urn:xmpp:hints") -- The XEP needs to decide on "store" or "storage" |
243 or stanza:get_child("no-permanent-store", "urn:xmpp:hints") | 244 or stanza:get_child("no-permanent-store", "urn:xmpp:hints") |
244 or stanza:get_child("no-storage", "urn:xmpp:hints") | 245 or stanza:get_child("no-storage", "urn:xmpp:hints") |
245 or stanza:get_child("no-store", "urn:xmpp:hints") then | 246 or stanza:get_child("no-store", "urn:xmpp:hints") then |
246 module:log("debug", "Not archiving stanza: %s (hint)", stanza:top_tag()); | 247 log("debug", "Not archiving stanza: %s (hint)", stanza:top_tag()); |
247 return; | 248 return; |
248 end | 249 end |
249 | 250 |
250 -- Whos storage do we put it in? | 251 -- Whos storage do we put it in? |
251 local store_user = c2s and origin.username or jid_split(orig_to); | 252 local store_user = c2s and origin.username or jid_split(orig_to); |
252 -- And who are they chatting with? | 253 -- And who are they chatting with? |
253 local with = jid_bare(c2s and orig_to or orig_from); | 254 local with = jid_bare(c2s and orig_to or orig_from); |
254 | 255 |
255 -- Check with the users preferences | 256 -- Check with the users preferences |
256 if shall_store(store_user, with) then | 257 if shall_store(store_user, with) then |
257 module:log("debug", "Archiving stanza: %s", stanza:top_tag()); | 258 log("debug", "Archiving stanza: %s", stanza:top_tag()); |
258 | 259 |
259 -- And stash it | 260 -- And stash it |
260 local ok, id = archive:append(store_user, nil, stanza, time_now(), with); | 261 local ok, id = archive:append(store_user, nil, stanza, time_now(), with); |
261 if ok then | 262 if ok then |
262 if cleanup then cleanup[store_user] = true; end | 263 if cleanup then cleanup[store_user] = true; end |
263 module:fire_event("archive-message-added", { origin = origin, stanza = stanza, for_user = store_user, id = id }); | 264 module:fire_event("archive-message-added", { origin = origin, stanza = stanza, for_user = store_user, id = id }); |
264 end | 265 end |
265 else | 266 else |
266 module:log("debug", "Not archiving stanza: %s (prefs)", stanza:top_tag()); | 267 log("debug", "Not archiving stanza: %s (prefs)", stanza:top_tag()); |
267 end | 268 end |
268 end | 269 end |
269 | 270 |
270 local function c2s_message_handler(event) | 271 local function c2s_message_handler(event) |
271 return message_handler(event, true); | 272 return message_handler(event, true); |