Annotate

plugins/muc/affiliation_notify.lib.lua @ 7427:bf43a08e5a74

MUC: Send participant list and subject on explicit joins (thanks daurnimator)
author Kim Alvefur <zash@zash.se>
date Sun, 15 May 2016 16:55:19 +0200
parent 7401:e16b3fd0bd80
child 7990:3d17b2bf0e0c
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
6394
fe034fa564ee plugins/muc: Add affiliation_notify config option to send out status code 101
daurnimator <quae@daurnimator.com>
parents:
diff changeset
1 -- Prosody IM
fe034fa564ee plugins/muc: Add affiliation_notify config option to send out status code 101
daurnimator <quae@daurnimator.com>
parents:
diff changeset
2 -- Copyright (C) 2014 Daurnimator
fe034fa564ee plugins/muc: Add affiliation_notify config option to send out status code 101
daurnimator <quae@daurnimator.com>
parents:
diff changeset
3 --
fe034fa564ee plugins/muc: Add affiliation_notify config option to send out status code 101
daurnimator <quae@daurnimator.com>
parents:
diff changeset
4 -- This project is MIT/X11 licensed. Please see the
fe034fa564ee plugins/muc: Add affiliation_notify config option to send out status code 101
daurnimator <quae@daurnimator.com>
parents:
diff changeset
5 -- COPYING file in the source package for more information.
fe034fa564ee plugins/muc: Add affiliation_notify config option to send out status code 101
daurnimator <quae@daurnimator.com>
parents:
diff changeset
6 --
fe034fa564ee plugins/muc: Add affiliation_notify config option to send out status code 101
daurnimator <quae@daurnimator.com>
parents:
diff changeset
7
fe034fa564ee plugins/muc: Add affiliation_notify config option to send out status code 101
daurnimator <quae@daurnimator.com>
parents:
diff changeset
8 --[[
fe034fa564ee plugins/muc: Add affiliation_notify config option to send out status code 101
daurnimator <quae@daurnimator.com>
parents:
diff changeset
9 Out of courtesy, a MUC service MAY send an out-of-room <message/>
fe034fa564ee plugins/muc: Add affiliation_notify config option to send out status code 101
daurnimator <quae@daurnimator.com>
parents:
diff changeset
10 if a user's affiliation changes while the user is not in the room;
fe034fa564ee plugins/muc: Add affiliation_notify config option to send out status code 101
daurnimator <quae@daurnimator.com>
parents:
diff changeset
11 the message SHOULD be sent from the room to the user's bare JID,
fe034fa564ee plugins/muc: Add affiliation_notify config option to send out status code 101
daurnimator <quae@daurnimator.com>
parents:
diff changeset
12 MAY contain a <body/> element describing the affiliation change,
fe034fa564ee plugins/muc: Add affiliation_notify config option to send out status code 101
daurnimator <quae@daurnimator.com>
parents:
diff changeset
13 and MUST contain a status code of 101.
fe034fa564ee plugins/muc: Add affiliation_notify config option to send out status code 101
daurnimator <quae@daurnimator.com>
parents:
diff changeset
14 ]]
fe034fa564ee plugins/muc: Add affiliation_notify config option to send out status code 101
daurnimator <quae@daurnimator.com>
parents:
diff changeset
15
fe034fa564ee plugins/muc: Add affiliation_notify config option to send out status code 101
daurnimator <quae@daurnimator.com>
parents:
diff changeset
16
fe034fa564ee plugins/muc: Add affiliation_notify config option to send out status code 101
daurnimator <quae@daurnimator.com>
parents:
diff changeset
17 local st = require "util.stanza";
fe034fa564ee plugins/muc: Add affiliation_notify config option to send out status code 101
daurnimator <quae@daurnimator.com>
parents:
diff changeset
18
fe034fa564ee plugins/muc: Add affiliation_notify config option to send out status code 101
daurnimator <quae@daurnimator.com>
parents:
diff changeset
19 local function get_affiliation_notify(room)
fe034fa564ee plugins/muc: Add affiliation_notify config option to send out status code 101
daurnimator <quae@daurnimator.com>
parents:
diff changeset
20 return room._data.affiliation_notify;
fe034fa564ee plugins/muc: Add affiliation_notify config option to send out status code 101
daurnimator <quae@daurnimator.com>
parents:
diff changeset
21 end
fe034fa564ee plugins/muc: Add affiliation_notify config option to send out status code 101
daurnimator <quae@daurnimator.com>
parents:
diff changeset
22
fe034fa564ee plugins/muc: Add affiliation_notify config option to send out status code 101
daurnimator <quae@daurnimator.com>
parents:
diff changeset
23 local function set_affiliation_notify(room, affiliation_notify)
fe034fa564ee plugins/muc: Add affiliation_notify config option to send out status code 101
daurnimator <quae@daurnimator.com>
parents:
diff changeset
24 affiliation_notify = affiliation_notify and true or nil;
fe034fa564ee plugins/muc: Add affiliation_notify config option to send out status code 101
daurnimator <quae@daurnimator.com>
parents:
diff changeset
25 if room._data.affiliation_notify == affiliation_notify then return false; end
fe034fa564ee plugins/muc: Add affiliation_notify config option to send out status code 101
daurnimator <quae@daurnimator.com>
parents:
diff changeset
26 room._data.affiliation_notify = affiliation_notify;
fe034fa564ee plugins/muc: Add affiliation_notify config option to send out status code 101
daurnimator <quae@daurnimator.com>
parents:
diff changeset
27 return true;
fe034fa564ee plugins/muc: Add affiliation_notify config option to send out status code 101
daurnimator <quae@daurnimator.com>
parents:
diff changeset
28 end
fe034fa564ee plugins/muc: Add affiliation_notify config option to send out status code 101
daurnimator <quae@daurnimator.com>
parents:
diff changeset
29
fe034fa564ee plugins/muc: Add affiliation_notify config option to send out status code 101
daurnimator <quae@daurnimator.com>
parents:
diff changeset
30 module:hook("muc-config-form", function(event)
fe034fa564ee plugins/muc: Add affiliation_notify config option to send out status code 101
daurnimator <quae@daurnimator.com>
parents:
diff changeset
31 table.insert(event.form, {
fe034fa564ee plugins/muc: Add affiliation_notify config option to send out status code 101
daurnimator <quae@daurnimator.com>
parents:
diff changeset
32 name = "muc#roomconfig_affiliationnotify";
fe034fa564ee plugins/muc: Add affiliation_notify config option to send out status code 101
daurnimator <quae@daurnimator.com>
parents:
diff changeset
33 type = "boolean";
fe034fa564ee plugins/muc: Add affiliation_notify config option to send out status code 101
daurnimator <quae@daurnimator.com>
parents:
diff changeset
34 label = "Notify users when their affiliation changes when they are not in the room?";
fe034fa564ee plugins/muc: Add affiliation_notify config option to send out status code 101
daurnimator <quae@daurnimator.com>
parents:
diff changeset
35 value = get_affiliation_notify(event.room);
fe034fa564ee plugins/muc: Add affiliation_notify config option to send out status code 101
daurnimator <quae@daurnimator.com>
parents:
diff changeset
36 });
7401
e16b3fd0bd80 MUC: Assign priorities to config form hooks so they have a consistent order on each start
Kim Alvefur <zash@zash.se>
parents: 7353
diff changeset
37 end, 100-11);
6394
fe034fa564ee plugins/muc: Add affiliation_notify config option to send out status code 101
daurnimator <quae@daurnimator.com>
parents:
diff changeset
38
6991
84e01dbb739e MUC: Update all config form handlers to take advantage of the new per-option events
Matthew Wild <mwild1@gmail.com>
parents: 6394
diff changeset
39 module:hook("muc-config-submitted/muc#roomconfig_affiliationnotify", function(event)
84e01dbb739e MUC: Update all config form handlers to take advantage of the new per-option events
Matthew Wild <mwild1@gmail.com>
parents: 6394
diff changeset
40 if set_affiliation_notify(event.room, event.value) then
6394
fe034fa564ee plugins/muc: Add affiliation_notify config option to send out status code 101
daurnimator <quae@daurnimator.com>
parents:
diff changeset
41 event.status_codes["104"] = true;
fe034fa564ee plugins/muc: Add affiliation_notify config option to send out status code 101
daurnimator <quae@daurnimator.com>
parents:
diff changeset
42 end
fe034fa564ee plugins/muc: Add affiliation_notify config option to send out status code 101
daurnimator <quae@daurnimator.com>
parents:
diff changeset
43 end);
fe034fa564ee plugins/muc: Add affiliation_notify config option to send out status code 101
daurnimator <quae@daurnimator.com>
parents:
diff changeset
44
fe034fa564ee plugins/muc: Add affiliation_notify config option to send out status code 101
daurnimator <quae@daurnimator.com>
parents:
diff changeset
45 module:hook("muc-set-affiliation", function(event)
fe034fa564ee plugins/muc: Add affiliation_notify config option to send out status code 101
daurnimator <quae@daurnimator.com>
parents:
diff changeset
46 local room = event.room;
fe034fa564ee plugins/muc: Add affiliation_notify config option to send out status code 101
daurnimator <quae@daurnimator.com>
parents:
diff changeset
47 if not event.in_room and get_affiliation_notify(room) then
fe034fa564ee plugins/muc: Add affiliation_notify config option to send out status code 101
daurnimator <quae@daurnimator.com>
parents:
diff changeset
48 local body = string.format("Your affiliation in room %s is now %s.", room.jid, event.affiliation);
fe034fa564ee plugins/muc: Add affiliation_notify config option to send out status code 101
daurnimator <quae@daurnimator.com>
parents:
diff changeset
49 local stanza = st.message({
fe034fa564ee plugins/muc: Add affiliation_notify config option to send out status code 101
daurnimator <quae@daurnimator.com>
parents:
diff changeset
50 type = "headline";
fe034fa564ee plugins/muc: Add affiliation_notify config option to send out status code 101
daurnimator <quae@daurnimator.com>
parents:
diff changeset
51 from = room.jid;
fe034fa564ee plugins/muc: Add affiliation_notify config option to send out status code 101
daurnimator <quae@daurnimator.com>
parents:
diff changeset
52 to = event.jid;
fe034fa564ee plugins/muc: Add affiliation_notify config option to send out status code 101
daurnimator <quae@daurnimator.com>
parents:
diff changeset
53 }, body)
fe034fa564ee plugins/muc: Add affiliation_notify config option to send out status code 101
daurnimator <quae@daurnimator.com>
parents:
diff changeset
54 :tag("x", {xmlns = "http://jabber.org/protocol/muc#user"})
fe034fa564ee plugins/muc: Add affiliation_notify config option to send out status code 101
daurnimator <quae@daurnimator.com>
parents:
diff changeset
55 :tag("status", {code="101"}):up()
fe034fa564ee plugins/muc: Add affiliation_notify config option to send out status code 101
daurnimator <quae@daurnimator.com>
parents:
diff changeset
56 :up();
fe034fa564ee plugins/muc: Add affiliation_notify config option to send out status code 101
daurnimator <quae@daurnimator.com>
parents:
diff changeset
57 room:route_stanza(stanza);
fe034fa564ee plugins/muc: Add affiliation_notify config option to send out status code 101
daurnimator <quae@daurnimator.com>
parents:
diff changeset
58 end
fe034fa564ee plugins/muc: Add affiliation_notify config option to send out status code 101
daurnimator <quae@daurnimator.com>
parents:
diff changeset
59 end);
fe034fa564ee plugins/muc: Add affiliation_notify config option to send out status code 101
daurnimator <quae@daurnimator.com>
parents:
diff changeset
60
fe034fa564ee plugins/muc: Add affiliation_notify config option to send out status code 101
daurnimator <quae@daurnimator.com>
parents:
diff changeset
61 return {
fe034fa564ee plugins/muc: Add affiliation_notify config option to send out status code 101
daurnimator <quae@daurnimator.com>
parents:
diff changeset
62 get = get_affiliation_notify;
fe034fa564ee plugins/muc: Add affiliation_notify config option to send out status code 101
daurnimator <quae@daurnimator.com>
parents:
diff changeset
63 set = set_affiliation_notify;
fe034fa564ee plugins/muc: Add affiliation_notify config option to send out status code 101
daurnimator <quae@daurnimator.com>
parents:
diff changeset
64 };