annotate mod_carbons_copies/mod_carbons_copies.lua @ 3174:f02c0f5e44ac

various/README: Add a Statistics label
author Kim Alvefur <zash@zash.se>
date Thu, 05 Jul 2018 02:03:29 +0200
parents 7dbde05b48a9
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
889
9901d267f938 mod_carbons_copies: Initial commit; allow the user to enable v0 style carbons
Michael Holzt <kju@fqdn.org>
parents:
diff changeset
1 -- Send carbons v0 style copies of incoming messages to clients which
9901d267f938 mod_carbons_copies: Initial commit; allow the user to enable v0 style carbons
Michael Holzt <kju@fqdn.org>
parents:
diff changeset
2 -- are not (yet) capable of Message Carbons (XEP-0280).
9901d267f938 mod_carbons_copies: Initial commit; allow the user to enable v0 style carbons
Michael Holzt <kju@fqdn.org>
parents:
diff changeset
3 --
9901d267f938 mod_carbons_copies: Initial commit; allow the user to enable v0 style carbons
Michael Holzt <kju@fqdn.org>
parents:
diff changeset
4 -- This extension integrates with the mod_carbons plugin in such a way
9901d267f938 mod_carbons_copies: Initial commit; allow the user to enable v0 style carbons
Michael Holzt <kju@fqdn.org>
parents:
diff changeset
5 -- that a client capable of Message Carbons will not get a v0 copy.
9901d267f938 mod_carbons_copies: Initial commit; allow the user to enable v0 style carbons
Michael Holzt <kju@fqdn.org>
parents:
diff changeset
6 --
9901d267f938 mod_carbons_copies: Initial commit; allow the user to enable v0 style carbons
Michael Holzt <kju@fqdn.org>
parents:
diff changeset
7 -- This extension can be enabled for all users by default by setting
9901d267f938 mod_carbons_copies: Initial commit; allow the user to enable v0 style carbons
Michael Holzt <kju@fqdn.org>
parents:
diff changeset
8 -- carbons_copies_default = true.
9901d267f938 mod_carbons_copies: Initial commit; allow the user to enable v0 style carbons
Michael Holzt <kju@fqdn.org>
parents:
diff changeset
9 --
9901d267f938 mod_carbons_copies: Initial commit; allow the user to enable v0 style carbons
Michael Holzt <kju@fqdn.org>
parents:
diff changeset
10 -- Alternatively or additionally setting carbons_copies_adhoc = true
9901d267f938 mod_carbons_copies: Initial commit; allow the user to enable v0 style carbons
Michael Holzt <kju@fqdn.org>
parents:
diff changeset
11 -- will allow the user to enable or disable copies through Adhoc
9901d267f938 mod_carbons_copies: Initial commit; allow the user to enable v0 style carbons
Michael Holzt <kju@fqdn.org>
parents:
diff changeset
12 -- commands.
9901d267f938 mod_carbons_copies: Initial commit; allow the user to enable v0 style carbons
Michael Holzt <kju@fqdn.org>
parents:
diff changeset
13 --
9901d267f938 mod_carbons_copies: Initial commit; allow the user to enable v0 style carbons
Michael Holzt <kju@fqdn.org>
parents:
diff changeset
14 -- Copyright (C) 2012 Michael Holzt
9901d267f938 mod_carbons_copies: Initial commit; allow the user to enable v0 style carbons
Michael Holzt <kju@fqdn.org>
parents:
diff changeset
15 --
9901d267f938 mod_carbons_copies: Initial commit; allow the user to enable v0 style carbons
Michael Holzt <kju@fqdn.org>
parents:
diff changeset
16 -- This file is MIT/X11 licensed.
9901d267f938 mod_carbons_copies: Initial commit; allow the user to enable v0 style carbons
Michael Holzt <kju@fqdn.org>
parents:
diff changeset
17
9901d267f938 mod_carbons_copies: Initial commit; allow the user to enable v0 style carbons
Michael Holzt <kju@fqdn.org>
parents:
diff changeset
18 local jid_split = require "util.jid".split;
9901d267f938 mod_carbons_copies: Initial commit; allow the user to enable v0 style carbons
Michael Holzt <kju@fqdn.org>
parents:
diff changeset
19 local dm_load = require "util.datamanager".load;
1343
7dbde05b48a9 all the things: Remove trailing whitespace
Florian Zeitz <florob@babelmonkeys.de>
parents: 889
diff changeset
20 local dm_store = require "util.datamanager".store;
889
9901d267f938 mod_carbons_copies: Initial commit; allow the user to enable v0 style carbons
Michael Holzt <kju@fqdn.org>
parents:
diff changeset
21 local adhoc_new = module:require "adhoc".new;
9901d267f938 mod_carbons_copies: Initial commit; allow the user to enable v0 style carbons
Michael Holzt <kju@fqdn.org>
parents:
diff changeset
22 local xmlns_carbons_v0 = "urn:xmpp:carbons:0";
9901d267f938 mod_carbons_copies: Initial commit; allow the user to enable v0 style carbons
Michael Holzt <kju@fqdn.org>
parents:
diff changeset
23 local storename = "mod_carbons_copies";
9901d267f938 mod_carbons_copies: Initial commit; allow the user to enable v0 style carbons
Michael Holzt <kju@fqdn.org>
parents:
diff changeset
24
9901d267f938 mod_carbons_copies: Initial commit; allow the user to enable v0 style carbons
Michael Holzt <kju@fqdn.org>
parents:
diff changeset
25 local function toggle_copies(data, on)
1343
7dbde05b48a9 all the things: Remove trailing whitespace
Florian Zeitz <florob@babelmonkeys.de>
parents: 889
diff changeset
26 local username, hostname, resource = jid_split(data.from);
889
9901d267f938 mod_carbons_copies: Initial commit; allow the user to enable v0 style carbons
Michael Holzt <kju@fqdn.org>
parents:
diff changeset
27 dm_store(username, hostname, storename, { enabled = on });
1343
7dbde05b48a9 all the things: Remove trailing whitespace
Florian Zeitz <florob@babelmonkeys.de>
parents: 889
diff changeset
28 end
889
9901d267f938 mod_carbons_copies: Initial commit; allow the user to enable v0 style carbons
Michael Holzt <kju@fqdn.org>
parents:
diff changeset
29
9901d267f938 mod_carbons_copies: Initial commit; allow the user to enable v0 style carbons
Michael Holzt <kju@fqdn.org>
parents:
diff changeset
30 local function adhoc_enable_copies(self, data, state)
9901d267f938 mod_carbons_copies: Initial commit; allow the user to enable v0 style carbons
Michael Holzt <kju@fqdn.org>
parents:
diff changeset
31 toggle_copies(data, true);
9901d267f938 mod_carbons_copies: Initial commit; allow the user to enable v0 style carbons
Michael Holzt <kju@fqdn.org>
parents:
diff changeset
32 return { info = "Copies are enabled for you now.\nPlease restart/reconnect clients.", status = "completed" };
9901d267f938 mod_carbons_copies: Initial commit; allow the user to enable v0 style carbons
Michael Holzt <kju@fqdn.org>
parents:
diff changeset
33 end
9901d267f938 mod_carbons_copies: Initial commit; allow the user to enable v0 style carbons
Michael Holzt <kju@fqdn.org>
parents:
diff changeset
34
9901d267f938 mod_carbons_copies: Initial commit; allow the user to enable v0 style carbons
Michael Holzt <kju@fqdn.org>
parents:
diff changeset
35 local function adhoc_disable_copies(self, data, state)
9901d267f938 mod_carbons_copies: Initial commit; allow the user to enable v0 style carbons
Michael Holzt <kju@fqdn.org>
parents:
diff changeset
36 toggle_copies(data, false);
9901d267f938 mod_carbons_copies: Initial commit; allow the user to enable v0 style carbons
Michael Holzt <kju@fqdn.org>
parents:
diff changeset
37 return { info = "Copies are disabled for you now.\nPlease restart/reconnect clients.", status = "completed" };
9901d267f938 mod_carbons_copies: Initial commit; allow the user to enable v0 style carbons
Michael Holzt <kju@fqdn.org>
parents:
diff changeset
38 end
9901d267f938 mod_carbons_copies: Initial commit; allow the user to enable v0 style carbons
Michael Holzt <kju@fqdn.org>
parents:
diff changeset
39
9901d267f938 mod_carbons_copies: Initial commit; allow the user to enable v0 style carbons
Michael Holzt <kju@fqdn.org>
parents:
diff changeset
40 module:hook("resource-bind", function(event)
9901d267f938 mod_carbons_copies: Initial commit; allow the user to enable v0 style carbons
Michael Holzt <kju@fqdn.org>
parents:
diff changeset
41 local session = event.session;
9901d267f938 mod_carbons_copies: Initial commit; allow the user to enable v0 style carbons
Michael Holzt <kju@fqdn.org>
parents:
diff changeset
42 local username, hostname, resource = jid_split(session.full_jid);
1343
7dbde05b48a9 all the things: Remove trailing whitespace
Florian Zeitz <florob@babelmonkeys.de>
parents: 889
diff changeset
43
7dbde05b48a9 all the things: Remove trailing whitespace
Florian Zeitz <florob@babelmonkeys.de>
parents: 889
diff changeset
44 local store = dm_load(username, hostname, storename) or
7dbde05b48a9 all the things: Remove trailing whitespace
Florian Zeitz <florob@babelmonkeys.de>
parents: 889
diff changeset
45 { enabled =
889
9901d267f938 mod_carbons_copies: Initial commit; allow the user to enable v0 style carbons
Michael Holzt <kju@fqdn.org>
parents:
diff changeset
46 module:get_option_boolean("carbons_copies_default") };
1343
7dbde05b48a9 all the things: Remove trailing whitespace
Florian Zeitz <florob@babelmonkeys.de>
parents: 889
diff changeset
47
889
9901d267f938 mod_carbons_copies: Initial commit; allow the user to enable v0 style carbons
Michael Holzt <kju@fqdn.org>
parents:
diff changeset
48 if store.enabled then
9901d267f938 mod_carbons_copies: Initial commit; allow the user to enable v0 style carbons
Michael Holzt <kju@fqdn.org>
parents:
diff changeset
49 session.want_carbons = xmlns_carbons_v0;
9901d267f938 mod_carbons_copies: Initial commit; allow the user to enable v0 style carbons
Michael Holzt <kju@fqdn.org>
parents:
diff changeset
50 module:log("debug", "%s enabling copies", session.full_jid);
9901d267f938 mod_carbons_copies: Initial commit; allow the user to enable v0 style carbons
Michael Holzt <kju@fqdn.org>
parents:
diff changeset
51 end
9901d267f938 mod_carbons_copies: Initial commit; allow the user to enable v0 style carbons
Michael Holzt <kju@fqdn.org>
parents:
diff changeset
52 end);
1343
7dbde05b48a9 all the things: Remove trailing whitespace
Florian Zeitz <florob@babelmonkeys.de>
parents: 889
diff changeset
53
889
9901d267f938 mod_carbons_copies: Initial commit; allow the user to enable v0 style carbons
Michael Holzt <kju@fqdn.org>
parents:
diff changeset
54 -- Adhoc-Support
9901d267f938 mod_carbons_copies: Initial commit; allow the user to enable v0 style carbons
Michael Holzt <kju@fqdn.org>
parents:
diff changeset
55 if module:get_option_boolean("carbons_copies_adhoc") then
9901d267f938 mod_carbons_copies: Initial commit; allow the user to enable v0 style carbons
Michael Holzt <kju@fqdn.org>
parents:
diff changeset
56 local enable_desc = adhoc_new("Carbons: Enable Copies",
9901d267f938 mod_carbons_copies: Initial commit; allow the user to enable v0 style carbons
Michael Holzt <kju@fqdn.org>
parents:
diff changeset
57 "mod_carbons_copies#enable", adhoc_enable_copies);
9901d267f938 mod_carbons_copies: Initial commit; allow the user to enable v0 style carbons
Michael Holzt <kju@fqdn.org>
parents:
diff changeset
58 local disable_desc = adhoc_new("Carbons: Disable Copies",
9901d267f938 mod_carbons_copies: Initial commit; allow the user to enable v0 style carbons
Michael Holzt <kju@fqdn.org>
parents:
diff changeset
59 "mod_carbons_copies#disable", adhoc_disable_copies);
1343
7dbde05b48a9 all the things: Remove trailing whitespace
Florian Zeitz <florob@babelmonkeys.de>
parents: 889
diff changeset
60
889
9901d267f938 mod_carbons_copies: Initial commit; allow the user to enable v0 style carbons
Michael Holzt <kju@fqdn.org>
parents:
diff changeset
61 module:add_item("adhoc", enable_desc);
9901d267f938 mod_carbons_copies: Initial commit; allow the user to enable v0 style carbons
Michael Holzt <kju@fqdn.org>
parents:
diff changeset
62 module:add_item("adhoc", disable_desc);
9901d267f938 mod_carbons_copies: Initial commit; allow the user to enable v0 style carbons
Michael Holzt <kju@fqdn.org>
parents:
diff changeset
63 end