Software /
code /
prosody
Annotate
plugins/mod_offline.lua @ 1700:255935c7a915
mod_disco: Added identity server/im with name 'Prosody'
author | Waqas Hussain <waqas20@gmail.com> |
---|---|
date | Tue, 18 Aug 2009 12:38:28 +0500 |
parent | 1522:569d58d21612 |
child | 1776:d4835b79d2ca |
rev | line source |
---|---|
1522
569d58d21612
Add copyright header to those files missing one
Matthew Wild <mwild1@gmail.com>
parents:
1453
diff
changeset
|
1 -- Prosody IM |
569d58d21612
Add copyright header to those files missing one
Matthew Wild <mwild1@gmail.com>
parents:
1453
diff
changeset
|
2 -- Copyright (C) 2008-2009 Matthew Wild |
569d58d21612
Add copyright header to those files missing one
Matthew Wild <mwild1@gmail.com>
parents:
1453
diff
changeset
|
3 -- Copyright (C) 2008-2009 Waqas Hussain |
569d58d21612
Add copyright header to those files missing one
Matthew Wild <mwild1@gmail.com>
parents:
1453
diff
changeset
|
4 -- |
569d58d21612
Add copyright header to those files missing one
Matthew Wild <mwild1@gmail.com>
parents:
1453
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:
1453
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:
1453
diff
changeset
|
7 -- |
569d58d21612
Add copyright header to those files missing one
Matthew Wild <mwild1@gmail.com>
parents:
1453
diff
changeset
|
8 |
1453 | 9 |
10 local datamanager = require "util.datamanager"; | |
11 local st = require "util.stanza"; | |
12 local datetime = require "util.datetime"; | |
13 local ipairs = ipairs; | |
14 | |
15 module:add_feature("msgoffline"); | |
16 | |
17 module:hook("message/offline/store", function(event) | |
18 local origin, stanza = event.origin, event.stanza; | |
19 local to = stanza.attr.to; | |
20 local node, host; | |
21 if to then | |
22 node, host = jid_split(to) | |
23 else | |
24 node, host = origin.username, origin.host; | |
25 end | |
26 | |
27 stanza.attr.stamp, stanza.attr.stamp_legacy = datetime.datetime(), datetime.legacy(); | |
28 local result = datamanager.list_append(node, host, "offline", st.preserialize(stanza)); | |
29 stanza.attr.stamp, stanza.attr.stamp_legacy = nil, nil; | |
30 | |
31 return true; | |
32 end); | |
33 | |
34 module:hook("message/offline/broadcast", function(event) | |
35 local origin = event.origin; | |
36 local node, host = origin.username, origin.host; | |
37 | |
38 local data = datamanager.list_load(node, host, "offline"); | |
39 if not data then return true; end | |
40 for _, stanza in ipairs(data) do | |
41 stanza = st.deserialize(stanza); | |
42 stanza:tag("delay", {xmlns = "urn:xmpp:delay", from = host, stamp = stanza.attr.stamp}):up(); -- XEP-0203 | |
43 stanza:tag("x", {xmlns = "jabber:x:delay", from = host, stamp = stanza.attr.stamp_legacy}):up(); -- XEP-0091 (deprecated) | |
44 stanza.attr.stamp, stanza.attr.stamp_legacy = nil, nil; | |
45 origin.send(stanza); | |
46 end | |
47 return true; | |
48 end); | |
49 | |
50 module:hook("message/offline/delete", function(event) | |
51 local origin = event.origin; | |
52 local node, host = origin.username, origin.host; | |
53 | |
54 return datamanager.list_store(node, host, "offline", nil); | |
55 end); |