# HG changeset patch # User Waqas Hussain # Date 1243859793 -18000 # Node ID e78c161944ab388ede4e8daa92594a9a851e468c # Parent 0e700e2041eff36a8f587368fdcde0a11e67fcb2 mod_message: Move bare JID processing to it's own function diff -r 0e700e2041ef -r e78c161944ab plugins/mod_message.lua --- 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);