comparison plugins/muc/affiliation_notify.lib.lua @ 8942:ecb5e13d97bb

MUC: Remove 'affiliation notify' config option, as it's irrelevant to room owners, always notify instead
author Matthew Wild <mwild1@gmail.com>
date Wed, 27 Jun 2018 15:25:35 +0100
parents 3d17b2bf0e0c
children 3a416b866c94
comparison
equal deleted inserted replaced
8941:f0beba9c2822 8942:ecb5e13d97bb
14 ]] 14 ]]
15 15
16 16
17 local st = require "util.stanza"; 17 local st = require "util.stanza";
18 18
19 local function get_affiliation_notify(room)
20 return room._data.affiliation_notify;
21 end
22
23 local function set_affiliation_notify(room, affiliation_notify)
24 affiliation_notify = affiliation_notify and true or nil;
25 if room._data.affiliation_notify == affiliation_notify then return false; end
26 room._data.affiliation_notify = affiliation_notify;
27 return true;
28 end
29
30 module:hook("muc-config-form", function(event)
31 table.insert(event.form, {
32 name = "muc#roomconfig_affiliationnotify";
33 type = "boolean";
34 label = "Notify absent users when their affiliation changes?";
35 value = get_affiliation_notify(event.room);
36 });
37 end, 100-11);
38
39 module:hook("muc-config-submitted/muc#roomconfig_affiliationnotify", function(event)
40 if set_affiliation_notify(event.room, event.value) then
41 event.status_codes["104"] = true;
42 end
43 end);
44
45 module:hook("muc-set-affiliation", function(event) 19 module:hook("muc-set-affiliation", function(event)
46 local room = event.room; 20 local room = event.room;
47 if not event.in_room and get_affiliation_notify(room) then 21 if not event.in_room then
48 local body = string.format("Your affiliation in room %s is now %s.", room.jid, event.affiliation); 22 local body = string.format("Your affiliation in room %s is now %s.", room.jid, event.affiliation);
49 local stanza = st.message({ 23 local stanza = st.message({
50 type = "headline"; 24 type = "headline";
51 from = room.jid; 25 from = room.jid;
52 to = event.jid; 26 to = event.jid;
55 :tag("status", {code="101"}):up() 29 :tag("status", {code="101"}):up()
56 :up(); 30 :up();
57 room:route_stanza(stanza); 31 room:route_stanza(stanza);
58 end 32 end
59 end); 33 end);
60
61 return {
62 get = get_affiliation_notify;
63 set = set_affiliation_notify;
64 };