Annotate

plugins/mod_message.lua @ 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
parent 1234:0ff02499f05c
child 1272:28f9041d8c55
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1232
6ddbb583f067 mod_message: Initial commit
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
1
6ddbb583f067 mod_message: Initial commit
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
2 local full_sessions = full_sessions;
6ddbb583f067 mod_message: Initial commit
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
3 local bare_sessions = bare_sessions;
6ddbb583f067 mod_message: Initial commit
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
4
6ddbb583f067 mod_message: Initial commit
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
5 local jid_bare = require "util.jid".bare;
6ddbb583f067 mod_message: Initial commit
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
6 local user_exists = require "core.usermanager".user_exists;
6ddbb583f067 mod_message: Initial commit
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
7
1271
e78c161944ab mod_message: Move bare JID processing to it's own function
Waqas Hussain <waqas20@gmail.com>
parents: 1234
diff changeset
8 local function process_to_bare(bare, origin, stanza)
e78c161944ab mod_message: Move bare JID processing to it's own function
Waqas Hussain <waqas20@gmail.com>
parents: 1234
diff changeset
9 local sessions = bare_sessions[bare];
1232
6ddbb583f067 mod_message: Initial commit
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
10 if sessions then sessions = sessions.sessions; end
6ddbb583f067 mod_message: Initial commit
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
11
6ddbb583f067 mod_message: Initial commit
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
12 if sessions then
6ddbb583f067 mod_message: Initial commit
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
13 -- some resources are online
6ddbb583f067 mod_message: Initial commit
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
14 -- TODO find top resources willing to accept this message
6ddbb583f067 mod_message: Initial commit
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
15 -- TODO then send them each the stanza
6ddbb583f067 mod_message: Initial commit
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
16 else
6ddbb583f067 mod_message: Initial commit
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
17 -- no resources are online
6ddbb583f067 mod_message: Initial commit
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
18 -- TODO check if the user exists
6ddbb583f067 mod_message: Initial commit
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
19 -- TODO if it doesn't, return an error reply
6ddbb583f067 mod_message: Initial commit
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
20 -- TODO otherwise, apply the default privacy list
6ddbb583f067 mod_message: Initial commit
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
21 -- TODO and store into offline storage
6ddbb583f067 mod_message: Initial commit
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
22 -- TODO or maybe the offline store can apply privacy lists
6ddbb583f067 mod_message: Initial commit
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
23 end
1271
e78c161944ab mod_message: Move bare JID processing to it's own function
Waqas Hussain <waqas20@gmail.com>
parents: 1234
diff changeset
24 end
e78c161944ab mod_message: Move bare JID processing to it's own function
Waqas Hussain <waqas20@gmail.com>
parents: 1234
diff changeset
25
e78c161944ab mod_message: Move bare JID processing to it's own function
Waqas Hussain <waqas20@gmail.com>
parents: 1234
diff changeset
26 module:hook("message/full", function(data)
e78c161944ab mod_message: Move bare JID processing to it's own function
Waqas Hussain <waqas20@gmail.com>
parents: 1234
diff changeset
27 -- message to full JID recieved
e78c161944ab mod_message: Move bare JID processing to it's own function
Waqas Hussain <waqas20@gmail.com>
parents: 1234
diff changeset
28 local origin, stanza = data.origin, data.stanza;
e78c161944ab mod_message: Move bare JID processing to it's own function
Waqas Hussain <waqas20@gmail.com>
parents: 1234
diff changeset
29
e78c161944ab mod_message: Move bare JID processing to it's own function
Waqas Hussain <waqas20@gmail.com>
parents: 1234
diff changeset
30 local session = full_sessions[stanza.attr.to];
e78c161944ab mod_message: Move bare JID processing to it's own function
Waqas Hussain <waqas20@gmail.com>
parents: 1234
diff changeset
31 if session then
e78c161944ab mod_message: Move bare JID processing to it's own function
Waqas Hussain <waqas20@gmail.com>
parents: 1234
diff changeset
32 -- TODO fire post processing event
e78c161944ab mod_message: Move bare JID processing to it's own function
Waqas Hussain <waqas20@gmail.com>
parents: 1234
diff changeset
33 session.send(stanza);
e78c161944ab mod_message: Move bare JID processing to it's own function
Waqas Hussain <waqas20@gmail.com>
parents: 1234
diff changeset
34 return true;
e78c161944ab mod_message: Move bare JID processing to it's own function
Waqas Hussain <waqas20@gmail.com>
parents: 1234
diff changeset
35 else -- resource not online
e78c161944ab mod_message: Move bare JID processing to it's own function
Waqas Hussain <waqas20@gmail.com>
parents: 1234
diff changeset
36 return process_to_bare(jid_bare(stanza.attr.to), origin, stanza);
e78c161944ab mod_message: Move bare JID processing to it's own function
Waqas Hussain <waqas20@gmail.com>
parents: 1234
diff changeset
37 end
1232
6ddbb583f067 mod_message: Initial commit
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
38 end);
1271
e78c161944ab mod_message: Move bare JID processing to it's own function
Waqas Hussain <waqas20@gmail.com>
parents: 1234
diff changeset
39
e78c161944ab mod_message: Move bare JID processing to it's own function
Waqas Hussain <waqas20@gmail.com>
parents: 1234
diff changeset
40 module:hook("message/bare", function(data)
e78c161944ab mod_message: Move bare JID processing to it's own function
Waqas Hussain <waqas20@gmail.com>
parents: 1234
diff changeset
41 -- message to bare JID recieved
e78c161944ab mod_message: Move bare JID processing to it's own function
Waqas Hussain <waqas20@gmail.com>
parents: 1234
diff changeset
42 local origin, stanza = data.origin, data.stanza;
e78c161944ab mod_message: Move bare JID processing to it's own function
Waqas Hussain <waqas20@gmail.com>
parents: 1234
diff changeset
43
e78c161944ab mod_message: Move bare JID processing to it's own function
Waqas Hussain <waqas20@gmail.com>
parents: 1234
diff changeset
44 return process_to_bare(stanza.attr.to or (origin.username..'@'..origin.host), origin, stanza);
e78c161944ab mod_message: Move bare JID processing to it's own function
Waqas Hussain <waqas20@gmail.com>
parents: 1234
diff changeset
45 end);