Software /
code /
prosody-modules
Comparison
mod_archive/mod_archive.lua @ 178:62f47a93b5b7
mod_archive: Now we can archive messages, even though not in organized way.
author | shinysky<shinysky1986(AT)gmail.com> |
---|---|
date | Mon, 14 Jun 2010 22:13:33 +0800 |
parent | 172:ac826882a8cf |
child | 182:43d9e0944276 |
comparison
equal
deleted
inserted
replaced
177:bcd7dc51a5e3 | 178:62f47a93b5b7 |
---|---|
5 -- COPYING file in the source package for more information. | 5 -- COPYING file in the source package for more information. |
6 -- | 6 -- |
7 | 7 |
8 local st = require "util.stanza"; | 8 local st = require "util.stanza"; |
9 local dm = require "util.datamanager"; | 9 local dm = require "util.datamanager"; |
10 local jid = require "util.jid"; | |
10 | 11 |
11 local PREFS_DIR = "archive_prefs"; | 12 local PREFS_DIR = "archive_prefs"; |
12 local ARCHIVE_DIR = "archive"; | 13 local ARCHIVE_DIR = "archive"; |
13 | 14 |
14 module:add_feature("urn:xmpp:archive"); | 15 module:add_feature("urn:xmpp:archive"); |
24 return st.deserialize(dm.load(node, host, dir or PREFS_DIR)); | 25 return st.deserialize(dm.load(node, host, dir or PREFS_DIR)); |
25 end | 26 end |
26 | 27 |
27 local function store_prefs(data, node, host, dir) | 28 local function store_prefs(data, node, host, dir) |
28 dm.store(node, host, dir or PREFS_DIR, st.preserialize(data)); | 29 dm.store(node, host, dir or PREFS_DIR, st.preserialize(data)); |
30 end | |
31 | |
32 local function store_msg(data, node, host, dir) | |
33 dm.list_append(node, host, dir or ARCHIVE_DIR, st.preserialize(data)); | |
29 end | 34 end |
30 | 35 |
31 ------------------------------------------------------------ | 36 ------------------------------------------------------------ |
32 -- Preferences | 37 -- Preferences |
33 ------------------------------------------------------------ | 38 ------------------------------------------------------------ |
240 local function save_handler(event) | 245 local function save_handler(event) |
241 module:log("debug", "-- stanza:\n%s", tostring(event.stanza)); | 246 module:log("debug", "-- stanza:\n%s", tostring(event.stanza)); |
242 return true; | 247 return true; |
243 end | 248 end |
244 | 249 |
250 ------------------------------------------------------------ | |
251 -- Message Handler | |
252 ------------------------------------------------------------ | |
245 local function msg_handler(data) | 253 local function msg_handler(data) |
246 module:log("debug", "-- Enter msg_handler()"); | 254 module:log("debug", "-- Enter msg_handler()"); |
247 local origin, stanza = data.origin, data.stanza; | 255 local origin, stanza = data.origin, data.stanza; |
256 local body = stanza:child_with_name("body"); | |
248 module:log("debug", "-- msg:\n%s", tostring(stanza)); | 257 module:log("debug", "-- msg:\n%s", tostring(stanza)); |
258 if body then | |
259 module:log("debug", "-- msg body:\n%s", tostring(body)); | |
260 -- module:log("debug", "-- msg body text:\n%s", body:get_text()); | |
261 local from_node, from_host = jid.split(stanza.attr.from); | |
262 local to_node, to_host = jid.split(stanza.attr.to); | |
263 -- FIXME the format of collections | |
264 if from_host == "localhost" then -- FIXME only archive messages of users on this host | |
265 store_msg(stanza, from_node, from_host); | |
266 end | |
267 if to_host == "localhost" then | |
268 store_msg(stanza, to_node, to_host); | |
269 end | |
270 end | |
249 return nil; | 271 return nil; |
250 end | 272 end |
251 | 273 |
252 module:hook("iq/self/urn:xmpp:archive:pref", preferences_handler); | 274 module:hook("iq/self/urn:xmpp:archive:pref", preferences_handler); |
253 module:hook("iq/self/urn:xmpp:archive:itemremove", itemremove_handler); | 275 module:hook("iq/self/urn:xmpp:archive:itemremove", itemremove_handler); |