Mercurial > prosody-modules
comparison mod_carbons_copies/mod_carbons_copies.lua @ 889:9901d267f938
mod_carbons_copies: Initial commit; allow the user to enable v0 style carbons
for clients which are not carbons-capable yet. This will not interfere with
clients which have support for regular Message Carbons (XEP-0280).
This module takes two optional parameters:
carbons_copies_default - if set to true, copies will be enabled by default
carbons_copies_adhoc - Enable Adhoc-commands to allow the user to
enable/disable copies
author | Michael Holzt <kju@fqdn.org> |
---|---|
date | Sun, 23 Dec 2012 19:34:29 +0100 |
parents | |
children | 7dbde05b48a9 |
comparison
equal
deleted
inserted
replaced
888:f8d08f8ed7de | 889:9901d267f938 |
---|---|
1 -- Send carbons v0 style copies of incoming messages to clients which | |
2 -- are not (yet) capable of Message Carbons (XEP-0280). | |
3 -- | |
4 -- This extension integrates with the mod_carbons plugin in such a way | |
5 -- that a client capable of Message Carbons will not get a v0 copy. | |
6 -- | |
7 -- This extension can be enabled for all users by default by setting | |
8 -- carbons_copies_default = true. | |
9 -- | |
10 -- Alternatively or additionally setting carbons_copies_adhoc = true | |
11 -- will allow the user to enable or disable copies through Adhoc | |
12 -- commands. | |
13 -- | |
14 -- Copyright (C) 2012 Michael Holzt | |
15 -- | |
16 -- This file is MIT/X11 licensed. | |
17 | |
18 local jid_split = require "util.jid".split; | |
19 local dm_load = require "util.datamanager".load; | |
20 local dm_store = require "util.datamanager".store; | |
21 local adhoc_new = module:require "adhoc".new; | |
22 local xmlns_carbons_v0 = "urn:xmpp:carbons:0"; | |
23 local storename = "mod_carbons_copies"; | |
24 | |
25 local function toggle_copies(data, on) | |
26 local username, hostname, resource = jid_split(data.from); | |
27 dm_store(username, hostname, storename, { enabled = on }); | |
28 end | |
29 | |
30 local function adhoc_enable_copies(self, data, state) | |
31 toggle_copies(data, true); | |
32 return { info = "Copies are enabled for you now.\nPlease restart/reconnect clients.", status = "completed" }; | |
33 end | |
34 | |
35 local function adhoc_disable_copies(self, data, state) | |
36 toggle_copies(data, false); | |
37 return { info = "Copies are disabled for you now.\nPlease restart/reconnect clients.", status = "completed" }; | |
38 end | |
39 | |
40 module:hook("resource-bind", function(event) | |
41 local session = event.session; | |
42 local username, hostname, resource = jid_split(session.full_jid); | |
43 | |
44 local store = dm_load(username, hostname, storename) or | |
45 { enabled = | |
46 module:get_option_boolean("carbons_copies_default") }; | |
47 | |
48 if store.enabled then | |
49 session.want_carbons = xmlns_carbons_v0; | |
50 module:log("debug", "%s enabling copies", session.full_jid); | |
51 end | |
52 end); | |
53 | |
54 -- Adhoc-Support | |
55 if module:get_option_boolean("carbons_copies_adhoc") then | |
56 local enable_desc = adhoc_new("Carbons: Enable Copies", | |
57 "mod_carbons_copies#enable", adhoc_enable_copies); | |
58 local disable_desc = adhoc_new("Carbons: Disable Copies", | |
59 "mod_carbons_copies#disable", adhoc_disable_copies); | |
60 | |
61 module:add_item("adhoc", enable_desc); | |
62 module:add_item("adhoc", disable_desc); | |
63 end |