--- a/plugins/mod_message.lua Mon Jun 01 15:48:39 2009 +0500
+++ b/plugins/mod_message.lua Mon Jun 01 17:36:33 2009 +0500
@@ -5,25 +5,8 @@
local jid_bare = require "util.jid".bare;
local user_exists = require "core.usermanager".user_exists;
-module:hook("message/full", function(data)
- -- message to full JID recieved
- local origin, stanza = data.origin, data.stanza;
-
- local session = full_sessions[stanza.attr.to];
- if session then
- -- TODO fire post processing event
- session.send(stanza);
- return true;
- else -- resource not online
- -- TODO fire event to send to bare JID
- end
-end);
-
-module:hook("message/bare", function(data)
- -- message to bare JID recieved
- local origin, stanza = data.origin, data.stanza;
-
- local sessions = bare_sessions[stanza.attr.to];
+local function process_to_bare(bare, origin, stanza)
+ local sessions = bare_sessions[bare];
if sessions then sessions = sessions.sessions; end
if sessions then
@@ -38,4 +21,25 @@
-- TODO and store into offline storage
-- TODO or maybe the offline store can apply privacy lists
end
+end
+
+module:hook("message/full", function(data)
+ -- message to full JID recieved
+ local origin, stanza = data.origin, data.stanza;
+
+ local session = full_sessions[stanza.attr.to];
+ if session then
+ -- TODO fire post processing event
+ session.send(stanza);
+ return true;
+ else -- resource not online
+ return process_to_bare(jid_bare(stanza.attr.to), origin, stanza);
+ end
end);
+
+module:hook("message/bare", function(data)
+ -- message to bare JID recieved
+ local origin, stanza = data.origin, data.stanza;
+
+ return process_to_bare(stanza.attr.to or (origin.username..'@'..origin.host), origin, stanza);
+end);