Mercurial > prosody-modules
comparison mod_archive_muc/mod_archive_muc.lua @ 238:5343b3ebaffb
mod_archive_muc: use usermanager to check if some user exists; use rostermanager to check if someone is in the roster; minor fixes.
| author | shinysky<shinysky1986(AT)gmail.com> |
|---|---|
| date | Tue, 10 Aug 2010 08:58:57 +0800 |
| parents | d900be0dee3e |
| children | ef0b580f434d |
comparison
equal
deleted
inserted
replaced
| 237:d900be0dee3e | 238:5343b3ebaffb |
|---|---|
| 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 local jid = require "util.jid"; |
| 11 local datetime = require "util.datetime"; | 11 local datetime = require "util.datetime"; |
| 12 local um = require "core.usermanager"; | |
| 13 local rom = require "core.rostermanager"; | |
| 12 | 14 |
| 13 local PREFS_DIR = "archive_muc_prefs"; | 15 local PREFS_DIR = "archive_muc_prefs"; |
| 14 local ARCHIVE_DIR = "archive_muc"; | 16 local ARCHIVE_DIR = "archive_muc"; |
| 15 | |
| 16 local HOST = 'localhost'; | |
| 17 | 17 |
| 18 local AUTO_ARCHIVING_ENABLED = true; | 18 local AUTO_ARCHIVING_ENABLED = true; |
| 19 | 19 |
| 20 module:add_feature("urn:xmpp:archive#preferences"); | 20 module:add_feature("urn:xmpp:archive#preferences"); |
| 21 module:add_feature("urn:xmpp:archive#management"); | 21 module:add_feature("urn:xmpp:archive#management"); |
| 29 | 29 |
| 30 local function store_prefs(data, node, host) | 30 local function store_prefs(data, node, host) |
| 31 dm.store(node, host, PREFS_DIR, st.preserialize(data)); | 31 dm.store(node, host, PREFS_DIR, st.preserialize(data)); |
| 32 end | 32 end |
| 33 | 33 |
| 34 local function date_time(localtime) | 34 local date_time = datetime.datetime; |
| 35 return datetime.datetime(localtime); | |
| 36 end | |
| 37 | 35 |
| 38 local function match_jid(rule, id) | 36 local function match_jid(rule, id) |
| 39 return not rule or jid.compare(id, rule); | 37 return not rule or jid.compare(id, rule); |
| 40 end | 38 end |
| 41 | 39 |
| 121 end | 119 end |
| 122 end | 120 end |
| 123 return false; | 121 return false; |
| 124 end | 122 end |
| 125 | 123 |
| 126 local function is_in_roster(node, host, jid) | 124 local function is_in_roster(node, host, id) |
| 127 -- TODO | 125 return rom.is_contact_subscribed(node, host, jid.bare(id)); |
| 128 return true; | |
| 129 end | 126 end |
| 130 | 127 |
| 131 local function apply_pref(node, host, jid) | 128 local function apply_pref(node, host, jid) |
| 132 local pref = load_prefs(node, host); | 129 local pref = load_prefs(node, host); |
| 133 if not pref then | 130 if not pref then |
| 164 local origin, stanza = data.origin, data.stanza; | 161 local origin, stanza = data.origin, data.stanza; |
| 165 local body = stanza:child_with_name("body"); | 162 local body = stanza:child_with_name("body"); |
| 166 if body then | 163 if body then |
| 167 local from_node, from_host = jid.split(stanza.attr.from); | 164 local from_node, from_host = jid.split(stanza.attr.from); |
| 168 local to_node, to_host = jid.split(stanza.attr.to); | 165 local to_node, to_host = jid.split(stanza.attr.to); |
| 169 -- FIXME only archive messages of users on this host | 166 if um.user_exists(from_node, from_host) and apply_pref(from_node, from_host, stanza.attr.to) then |
| 170 if from_host == HOST and apply_pref(from_node, from_host, stanza.attr.to) then | |
| 171 store_msg(stanza, from_node, from_host); | 167 store_msg(stanza, from_node, from_host); |
| 172 end | 168 end |
| 173 if to_host == HOST and apply_pref(to_node, to_host, stanza.attr.from) then | 169 if um.user_exists(to_node, to_host) and apply_pref(to_node, to_host, stanza.attr.from) then |
| 174 store_msg(stanza, to_node, to_host); | 170 store_msg(stanza, to_node, to_host); |
| 175 end | 171 end |
| 176 end | 172 end |
| 177 | 173 |
| 178 return nil; | 174 return nil; |
| 181 -- Preferences | 177 -- Preferences |
| 182 module:hook("iq/self/urn:xmpp:archive#preferences:prefs", preferences_handler); | 178 module:hook("iq/self/urn:xmpp:archive#preferences:prefs", preferences_handler); |
| 183 -- Archive management | 179 -- Archive management |
| 184 module:hook("iq/self/urn:xmpp:archive#management:query", management_handler); | 180 module:hook("iq/self/urn:xmpp:archive#management:query", management_handler); |
| 185 | 181 |
| 186 module:hook("message/full", msg_handler, 20); | |
| 187 module:hook("message/bare", msg_handler, 20); | 182 module:hook("message/bare", msg_handler, 20); |
| 188 | 183 |
| 189 -- TODO prefs: [1] = "\n "; | 184 -- TODO prefs: [1] = "\n "; |
