Changeset

1271:e78c161944ab

mod_message: Move bare JID processing to it's own function
author Waqas Hussain <waqas20@gmail.com>
date Mon, 01 Jun 2009 17:36:33 +0500
parents 1270:0e700e2041ef
children 1272:28f9041d8c55
files plugins/mod_message.lua
diffstat 1 files changed, 23 insertions(+), 19 deletions(-) [+]
line wrap: on
line diff
--- 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);