Software /
code /
prosody-modules
Changeset
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 |
parents | 177:bcd7dc51a5e3 |
children | 179:af6143756a9e |
files | mod_archive/mod_archive.lua |
diffstat | 1 files changed, 22 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- a/mod_archive/mod_archive.lua Mon Jun 14 12:26:25 2010 +0100 +++ b/mod_archive/mod_archive.lua Mon Jun 14 22:13:33 2010 +0800 @@ -7,6 +7,7 @@ local st = require "util.stanza"; local dm = require "util.datamanager"; +local jid = require "util.jid"; local PREFS_DIR = "archive_prefs"; local ARCHIVE_DIR = "archive"; @@ -28,6 +29,10 @@ dm.store(node, host, dir or PREFS_DIR, st.preserialize(data)); end +local function store_msg(data, node, host, dir) + dm.list_append(node, host, dir or ARCHIVE_DIR, st.preserialize(data)); +end + ------------------------------------------------------------ -- Preferences ------------------------------------------------------------ @@ -242,10 +247,27 @@ return true; end +------------------------------------------------------------ +-- Message Handler +------------------------------------------------------------ local function msg_handler(data) module:log("debug", "-- Enter msg_handler()"); local origin, stanza = data.origin, data.stanza; + local body = stanza:child_with_name("body"); module:log("debug", "-- msg:\n%s", tostring(stanza)); + if body then + module:log("debug", "-- msg body:\n%s", tostring(body)); + -- module:log("debug", "-- msg body text:\n%s", body:get_text()); + local from_node, from_host = jid.split(stanza.attr.from); + local to_node, to_host = jid.split(stanza.attr.to); + -- FIXME the format of collections + if from_host == "localhost" then -- FIXME only archive messages of users on this host + store_msg(stanza, from_node, from_host); + end + if to_host == "localhost" then + store_msg(stanza, to_node, to_host); + end + end return nil; end