2 -- Copyright (C) 2014 Daurnimator
4 -- This project is MIT/X11 licensed. Please see the
5 -- COPYING file in the source package for more information.
9 Out of courtesy, a MUC service MAY send an out-of-room <message/>
10 if a user's affiliation changes while the user is not in the room;
11 the message SHOULD be sent from the room to the user's bare JID,
12 MAY contain a <body/> element describing the affiliation change,
13 and MUST contain a status code of 101.
17 local st = require "util.stanza";
19 local function get_affiliation_notify(room)
20 return room._data.affiliation_notify;
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;
30 module:hook("muc-config-form", function(event)
31 table.insert(event.form, {
32 name = "muc#roomconfig_affiliationnotify";
34 label = "Notify users when their affiliation changes when they are not in the room?";
35 value = get_affiliation_notify(event.room);
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;
45 module:hook("muc-set-affiliation", function(event)
46 local room = event.room;
47 if not event.in_room and get_affiliation_notify(room) then
48 local body = string.format("Your affiliation in room %s is now %s.", room.jid, event.affiliation);
49 local stanza = st.message({
54 :tag("x", {xmlns = "http://jabber.org/protocol/muc#user"})
55 :tag("status", {code="101"}):up()
57 room:route_stanza(stanza);
62 get = get_affiliation_notify;
63 set = set_affiliation_notify;