Mercurial > prosody-hg
comparison plugins/mod_offline.lua @ 2680:1b267876246a
Backed out changeset e7b09424b486 (not removing mod_offline for trunk)
| author | Matthew Wild <mwild1@gmail.com> |
|---|---|
| date | Sat, 20 Feb 2010 00:47:18 +0000 |
| parents | |
| children | 2251f8898900 |
comparison
equal
deleted
inserted
replaced
| 2679:e7b09424b486 | 2680:1b267876246a |
|---|---|
| 1 -- Prosody IM | |
| 2 -- Copyright (C) 2008-2009 Matthew Wild | |
| 3 -- Copyright (C) 2008-2009 Waqas Hussain | |
| 4 -- | |
| 5 -- This project is MIT/X11 licensed. Please see the | |
| 6 -- COPYING file in the source package for more information. | |
| 7 -- | |
| 8 | |
| 9 | |
| 10 local datamanager = require "util.datamanager"; | |
| 11 local st = require "util.stanza"; | |
| 12 local datetime = require "util.datetime"; | |
| 13 local ipairs = ipairs; | |
| 14 local jid_split = require "util.jid".split; | |
| 15 | |
| 16 module:add_feature("msgoffline"); | |
| 17 | |
| 18 module:hook("message/offline/store", function(event) | |
| 19 local origin, stanza = event.origin, event.stanza; | |
| 20 local to = stanza.attr.to; | |
| 21 local node, host; | |
| 22 if to then | |
| 23 node, host = jid_split(to) | |
| 24 else | |
| 25 node, host = origin.username, origin.host; | |
| 26 end | |
| 27 | |
| 28 stanza.attr.stamp, stanza.attr.stamp_legacy = datetime.datetime(), datetime.legacy(); | |
| 29 local result = datamanager.list_append(node, host, "offline", st.preserialize(stanza)); | |
| 30 stanza.attr.stamp, stanza.attr.stamp_legacy = nil, nil; | |
| 31 | |
| 32 return true; | |
| 33 end); | |
| 34 | |
| 35 module:hook("message/offline/broadcast", function(event) | |
| 36 local origin = event.origin; | |
| 37 local node, host = origin.username, origin.host; | |
| 38 | |
| 39 local data = datamanager.list_load(node, host, "offline"); | |
| 40 if not data then return true; end | |
| 41 for _, stanza in ipairs(data) do | |
| 42 stanza = st.deserialize(stanza); | |
| 43 stanza:tag("delay", {xmlns = "urn:xmpp:delay", from = host, stamp = stanza.attr.stamp}):up(); -- XEP-0203 | |
| 44 stanza:tag("x", {xmlns = "jabber:x:delay", from = host, stamp = stanza.attr.stamp_legacy}):up(); -- XEP-0091 (deprecated) | |
| 45 stanza.attr.stamp, stanza.attr.stamp_legacy = nil, nil; | |
| 46 origin.send(stanza); | |
| 47 end | |
| 48 return true; | |
| 49 end); | |
| 50 | |
| 51 module:hook("message/offline/delete", function(event) | |
| 52 local origin = event.origin; | |
| 53 local node, host = origin.username, origin.host; | |
| 54 | |
| 55 return datamanager.list_store(node, host, "offline", nil); | |
| 56 end); |
