Software /
code /
prosody
File
plugins/mod_offline.lua @ 11628:0807e835d3b5
mod_external_services: Report overall status as a module status
Because during startup, if all items are provided by a different module
(e.g. mod_turn_external) then this would log a scary warning even if
everything is fine after that other module has been loaded.
This way, any persistent problematic state is reported in the console.
Errors with individual items should still be reported by prepare().
Now, if you load mod_external_services alone without configuring any
services, no error or warning is reported in the log, but maybe that's
not so bad with it reported in the console.
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Mon, 21 Jun 2021 22:43:26 +0200 |
parent | 10296:7072569044d4 |
child | 12977:74b9e05af71e |
line wrap: on
line source
-- Prosody IM -- Copyright (C) 2008-2009 Matthew Wild -- Copyright (C) 2008-2009 Waqas Hussain -- -- This project is MIT/X11 licensed. Please see the -- COPYING file in the source package for more information. -- local datetime = require "util.datetime"; local jid_split = require "util.jid".split; local offline_messages = module:open_store("offline", "archive"); module:add_feature("msgoffline"); module:hook("message/offline/handle", function(event) local origin, stanza = event.origin, event.stanza; local to = stanza.attr.to; local node; if to then node = jid_split(to) else node = origin.username; end local ok = offline_messages:append(node, nil, stanza, os.time(), ""); if ok then module:log("debug", "Saved to offline storage: %s", stanza:top_tag()); end return ok; end, -1); module:hook("message/offline/broadcast", function(event) local origin = event.origin; origin.log("debug", "Broadcasting offline messages"); local node, host = origin.username, origin.host; local data = offline_messages:find(node); if not data then return true; end for _, stanza, when in data do stanza:tag("delay", {xmlns = "urn:xmpp:delay", from = host, stamp = datetime.datetime(when)}):up(); -- XEP-0203 origin.send(stanza); end local ok = offline_messages:delete(node); if type(ok) == "number" and ok > 0 then origin.log("debug", "%d offline messages consumed"); end return true; end, -1);