Software /
code /
prosody
Comparison
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 |
comparison
equal
deleted
inserted
replaced
1270:0e700e2041ef | 1271:e78c161944ab |
---|---|
3 local bare_sessions = bare_sessions; | 3 local bare_sessions = bare_sessions; |
4 | 4 |
5 local jid_bare = require "util.jid".bare; | 5 local jid_bare = require "util.jid".bare; |
6 local user_exists = require "core.usermanager".user_exists; | 6 local user_exists = require "core.usermanager".user_exists; |
7 | 7 |
8 module:hook("message/full", function(data) | 8 local function process_to_bare(bare, origin, stanza) |
9 -- message to full JID recieved | 9 local sessions = bare_sessions[bare]; |
10 local origin, stanza = data.origin, data.stanza; | |
11 | |
12 local session = full_sessions[stanza.attr.to]; | |
13 if session then | |
14 -- TODO fire post processing event | |
15 session.send(stanza); | |
16 return true; | |
17 else -- resource not online | |
18 -- TODO fire event to send to bare JID | |
19 end | |
20 end); | |
21 | |
22 module:hook("message/bare", function(data) | |
23 -- message to bare JID recieved | |
24 local origin, stanza = data.origin, data.stanza; | |
25 | |
26 local sessions = bare_sessions[stanza.attr.to]; | |
27 if sessions then sessions = sessions.sessions; end | 10 if sessions then sessions = sessions.sessions; end |
28 | 11 |
29 if sessions then | 12 if sessions then |
30 -- some resources are online | 13 -- some resources are online |
31 -- TODO find top resources willing to accept this message | 14 -- TODO find top resources willing to accept this message |
36 -- TODO if it doesn't, return an error reply | 19 -- TODO if it doesn't, return an error reply |
37 -- TODO otherwise, apply the default privacy list | 20 -- TODO otherwise, apply the default privacy list |
38 -- TODO and store into offline storage | 21 -- TODO and store into offline storage |
39 -- TODO or maybe the offline store can apply privacy lists | 22 -- TODO or maybe the offline store can apply privacy lists |
40 end | 23 end |
24 end | |
25 | |
26 module:hook("message/full", function(data) | |
27 -- message to full JID recieved | |
28 local origin, stanza = data.origin, data.stanza; | |
29 | |
30 local session = full_sessions[stanza.attr.to]; | |
31 if session then | |
32 -- TODO fire post processing event | |
33 session.send(stanza); | |
34 return true; | |
35 else -- resource not online | |
36 return process_to_bare(jid_bare(stanza.attr.to), origin, stanza); | |
37 end | |
41 end); | 38 end); |
39 | |
40 module:hook("message/bare", function(data) | |
41 -- message to bare JID recieved | |
42 local origin, stanza = data.origin, data.stanza; | |
43 | |
44 return process_to_bare(stanza.attr.to or (origin.username..'@'..origin.host), origin, stanza); | |
45 end); |