Software /
code /
prosody
Annotate
plugins/mod_message.lua @ 1924:75e6ba240888
mod_console: Also search piggy-backed, er, multiplexed domains when passing a filter to s2s:show()
author | Matthew Wild <mwild1@gmail.com> |
---|---|
date | Mon, 05 Oct 2009 18:47:01 +0100 |
parent | 1522:569d58d21612 |
child | 2923:b7049746bd29 |
rev | line source |
---|---|
1522
569d58d21612
Add copyright header to those files missing one
Matthew Wild <mwild1@gmail.com>
parents:
1423
diff
changeset
|
1 -- Prosody IM |
569d58d21612
Add copyright header to those files missing one
Matthew Wild <mwild1@gmail.com>
parents:
1423
diff
changeset
|
2 -- Copyright (C) 2008-2009 Matthew Wild |
569d58d21612
Add copyright header to those files missing one
Matthew Wild <mwild1@gmail.com>
parents:
1423
diff
changeset
|
3 -- Copyright (C) 2008-2009 Waqas Hussain |
569d58d21612
Add copyright header to those files missing one
Matthew Wild <mwild1@gmail.com>
parents:
1423
diff
changeset
|
4 -- |
569d58d21612
Add copyright header to those files missing one
Matthew Wild <mwild1@gmail.com>
parents:
1423
diff
changeset
|
5 -- This project is MIT/X11 licensed. Please see the |
569d58d21612
Add copyright header to those files missing one
Matthew Wild <mwild1@gmail.com>
parents:
1423
diff
changeset
|
6 -- COPYING file in the source package for more information. |
569d58d21612
Add copyright header to those files missing one
Matthew Wild <mwild1@gmail.com>
parents:
1423
diff
changeset
|
7 -- |
569d58d21612
Add copyright header to those files missing one
Matthew Wild <mwild1@gmail.com>
parents:
1423
diff
changeset
|
8 |
1232 | 9 |
10 local full_sessions = full_sessions; | |
11 local bare_sessions = bare_sessions; | |
12 | |
1329
599a058d3961
mod_message: Require stanza lib to prevent traceback on error replies
Matthew Wild <mwild1@gmail.com>
parents:
1289
diff
changeset
|
13 local st = require "util.stanza"; |
1232 | 14 local jid_bare = require "util.jid".bare; |
1289
d0c38cac1687
mod_message: Fix global access
Waqas Hussain <waqas20@gmail.com>
parents:
1275
diff
changeset
|
15 local jid_split = require "util.jid".split; |
1232 | 16 local user_exists = require "core.usermanager".user_exists; |
1274
50babb72edac
mod_message: mod_message now handles all cases
Waqas Hussain <waqas20@gmail.com>
parents:
1272
diff
changeset
|
17 local offlinemanager = require "core.offlinemanager"; |
1289
d0c38cac1687
mod_message: Fix global access
Waqas Hussain <waqas20@gmail.com>
parents:
1275
diff
changeset
|
18 local t_insert = table.insert; |
1274
50babb72edac
mod_message: mod_message now handles all cases
Waqas Hussain <waqas20@gmail.com>
parents:
1272
diff
changeset
|
19 |
1271
e78c161944ab
mod_message: Move bare JID processing to it's own function
Waqas Hussain <waqas20@gmail.com>
parents:
1234
diff
changeset
|
20 local function process_to_bare(bare, origin, stanza) |
1274
50babb72edac
mod_message: mod_message now handles all cases
Waqas Hussain <waqas20@gmail.com>
parents:
1272
diff
changeset
|
21 local user = bare_sessions[bare]; |
1232 | 22 |
1272
28f9041d8c55
mod_message: Added code to handle error groupchat and headline messages to bare JID
Waqas Hussain <waqas20@gmail.com>
parents:
1271
diff
changeset
|
23 local t = stanza.attr.type; |
1275
850cf92b8ad4
mod_message: A little cleanup
Waqas Hussain <waqas20@gmail.com>
parents:
1274
diff
changeset
|
24 if t == "error" then |
850cf92b8ad4
mod_message: A little cleanup
Waqas Hussain <waqas20@gmail.com>
parents:
1274
diff
changeset
|
25 -- discard |
850cf92b8ad4
mod_message: A little cleanup
Waqas Hussain <waqas20@gmail.com>
parents:
1274
diff
changeset
|
26 elseif t == "groupchat" then |
1272
28f9041d8c55
mod_message: Added code to handle error groupchat and headline messages to bare JID
Waqas Hussain <waqas20@gmail.com>
parents:
1271
diff
changeset
|
27 origin.send(st.error_reply(stanza, "cancel", "service-unavailable")); |
1275
850cf92b8ad4
mod_message: A little cleanup
Waqas Hussain <waqas20@gmail.com>
parents:
1274
diff
changeset
|
28 elseif t == "headline" then |
1274
50babb72edac
mod_message: mod_message now handles all cases
Waqas Hussain <waqas20@gmail.com>
parents:
1272
diff
changeset
|
29 if user then |
50babb72edac
mod_message: mod_message now handles all cases
Waqas Hussain <waqas20@gmail.com>
parents:
1272
diff
changeset
|
30 for _, session in pairs(user.sessions) do |
1272
28f9041d8c55
mod_message: Added code to handle error groupchat and headline messages to bare JID
Waqas Hussain <waqas20@gmail.com>
parents:
1271
diff
changeset
|
31 if session.presence and session.priority >= 0 then |
28f9041d8c55
mod_message: Added code to handle error groupchat and headline messages to bare JID
Waqas Hussain <waqas20@gmail.com>
parents:
1271
diff
changeset
|
32 session.send(stanza); |
28f9041d8c55
mod_message: Added code to handle error groupchat and headline messages to bare JID
Waqas Hussain <waqas20@gmail.com>
parents:
1271
diff
changeset
|
33 end |
28f9041d8c55
mod_message: Added code to handle error groupchat and headline messages to bare JID
Waqas Hussain <waqas20@gmail.com>
parents:
1271
diff
changeset
|
34 end |
1274
50babb72edac
mod_message: mod_message now handles all cases
Waqas Hussain <waqas20@gmail.com>
parents:
1272
diff
changeset
|
35 end -- current policy is to discard headlines if no recipient is available |
1275
850cf92b8ad4
mod_message: A little cleanup
Waqas Hussain <waqas20@gmail.com>
parents:
1274
diff
changeset
|
36 else -- chat or normal message |
850cf92b8ad4
mod_message: A little cleanup
Waqas Hussain <waqas20@gmail.com>
parents:
1274
diff
changeset
|
37 if user then -- some resources are connected |
1418
d14de6cb8b5b
mod_message, mod_presence: Maintain list of top resources. Less work in routing messages to bare JIDs. - #optimization
Waqas Hussain <waqas20@gmail.com>
parents:
1329
diff
changeset
|
38 local recipients = user.top_resources; |
d14de6cb8b5b
mod_message, mod_presence: Maintain list of top resources. Less work in routing messages to bare JIDs. - #optimization
Waqas Hussain <waqas20@gmail.com>
parents:
1329
diff
changeset
|
39 if recipients then |
1275
850cf92b8ad4
mod_message: A little cleanup
Waqas Hussain <waqas20@gmail.com>
parents:
1274
diff
changeset
|
40 for i=1,#recipients do |
850cf92b8ad4
mod_message: A little cleanup
Waqas Hussain <waqas20@gmail.com>
parents:
1274
diff
changeset
|
41 recipients[i].send(stanza); |
850cf92b8ad4
mod_message: A little cleanup
Waqas Hussain <waqas20@gmail.com>
parents:
1274
diff
changeset
|
42 end |
850cf92b8ad4
mod_message: A little cleanup
Waqas Hussain <waqas20@gmail.com>
parents:
1274
diff
changeset
|
43 return true; |
1274
50babb72edac
mod_message: mod_message now handles all cases
Waqas Hussain <waqas20@gmail.com>
parents:
1272
diff
changeset
|
44 end |
1272
28f9041d8c55
mod_message: Added code to handle error groupchat and headline messages to bare JID
Waqas Hussain <waqas20@gmail.com>
parents:
1271
diff
changeset
|
45 end |
1275
850cf92b8ad4
mod_message: A little cleanup
Waqas Hussain <waqas20@gmail.com>
parents:
1274
diff
changeset
|
46 -- no resources are online |
850cf92b8ad4
mod_message: A little cleanup
Waqas Hussain <waqas20@gmail.com>
parents:
1274
diff
changeset
|
47 local node, host = jid_split(bare); |
850cf92b8ad4
mod_message: A little cleanup
Waqas Hussain <waqas20@gmail.com>
parents:
1274
diff
changeset
|
48 if user_exists(node, host) then |
850cf92b8ad4
mod_message: A little cleanup
Waqas Hussain <waqas20@gmail.com>
parents:
1274
diff
changeset
|
49 -- TODO apply the default privacy list |
850cf92b8ad4
mod_message: A little cleanup
Waqas Hussain <waqas20@gmail.com>
parents:
1274
diff
changeset
|
50 offlinemanager.store(node, host, stanza); |
850cf92b8ad4
mod_message: A little cleanup
Waqas Hussain <waqas20@gmail.com>
parents:
1274
diff
changeset
|
51 else |
850cf92b8ad4
mod_message: A little cleanup
Waqas Hussain <waqas20@gmail.com>
parents:
1274
diff
changeset
|
52 origin.send(st.error_reply(stanza, "cancel", "service-unavailable")); |
850cf92b8ad4
mod_message: A little cleanup
Waqas Hussain <waqas20@gmail.com>
parents:
1274
diff
changeset
|
53 end |
1274
50babb72edac
mod_message: mod_message now handles all cases
Waqas Hussain <waqas20@gmail.com>
parents:
1272
diff
changeset
|
54 end |
50babb72edac
mod_message: mod_message now handles all cases
Waqas Hussain <waqas20@gmail.com>
parents:
1272
diff
changeset
|
55 return true; |
1271
e78c161944ab
mod_message: Move bare JID processing to it's own function
Waqas Hussain <waqas20@gmail.com>
parents:
1234
diff
changeset
|
56 end |
e78c161944ab
mod_message: Move bare JID processing to it's own function
Waqas Hussain <waqas20@gmail.com>
parents:
1234
diff
changeset
|
57 |
e78c161944ab
mod_message: Move bare JID processing to it's own function
Waqas Hussain <waqas20@gmail.com>
parents:
1234
diff
changeset
|
58 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
|
59 -- 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
|
60 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
|
61 |
e78c161944ab
mod_message: Move bare JID processing to it's own function
Waqas Hussain <waqas20@gmail.com>
parents:
1234
diff
changeset
|
62 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
|
63 if session then |
e78c161944ab
mod_message: Move bare JID processing to it's own function
Waqas Hussain <waqas20@gmail.com>
parents:
1234
diff
changeset
|
64 -- 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
|
65 session.send(stanza); |
e78c161944ab
mod_message: Move bare JID processing to it's own function
Waqas Hussain <waqas20@gmail.com>
parents:
1234
diff
changeset
|
66 return true; |
e78c161944ab
mod_message: Move bare JID processing to it's own function
Waqas Hussain <waqas20@gmail.com>
parents:
1234
diff
changeset
|
67 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
|
68 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
|
69 end |
1232 | 70 end); |
1271
e78c161944ab
mod_message: Move bare JID processing to it's own function
Waqas Hussain <waqas20@gmail.com>
parents:
1234
diff
changeset
|
71 |
e78c161944ab
mod_message: Move bare JID processing to it's own function
Waqas Hussain <waqas20@gmail.com>
parents:
1234
diff
changeset
|
72 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
|
73 -- 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
|
74 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
|
75 |
e78c161944ab
mod_message: Move bare JID processing to it's own function
Waqas Hussain <waqas20@gmail.com>
parents:
1234
diff
changeset
|
76 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
|
77 end); |
1423
5e72c3e1743a
mod_message: Advertise offline message support as per XEP-0160 (thanks nolan)
Matthew Wild <mwild1@gmail.com>
parents:
1418
diff
changeset
|
78 |
5e72c3e1743a
mod_message: Advertise offline message support as per XEP-0160 (thanks nolan)
Matthew Wild <mwild1@gmail.com>
parents:
1418
diff
changeset
|
79 module:add_feature("msgoffline"); |