diff options
author | daurnimator <quae@daurnimator.com> | 2014-09-05 12:16:53 -0400 |
---|---|---|
committer | daurnimator <quae@daurnimator.com> | 2014-09-05 12:16:53 -0400 |
commit | c35ba29a9af6e98aa3972e486a37ff6e0090113d (patch) | |
tree | 9dc607fa464c87a22f8e3e929b6e06f3324140f3 /plugins/muc | |
parent | aa0dea0c38d2911bf9a531b78f9b7b3b54bf0865 (diff) | |
download | prosody-c35ba29a9af6e98aa3972e486a37ff6e0090113d.tar.gz prosody-c35ba29a9af6e98aa3972e486a37ff6e0090113d.zip |
plugins/muc: Add affiliation_notify config option to send out status code 101
Diffstat (limited to 'plugins/muc')
-rw-r--r-- | plugins/muc/affiliation_notify.lib.lua | 66 | ||||
-rw-r--r-- | plugins/muc/muc.lib.lua | 2 |
2 files changed, 68 insertions, 0 deletions
diff --git a/plugins/muc/affiliation_notify.lib.lua b/plugins/muc/affiliation_notify.lib.lua new file mode 100644 index 00000000..e2ecbc3b --- /dev/null +++ b/plugins/muc/affiliation_notify.lib.lua @@ -0,0 +1,66 @@ +-- Prosody IM +-- Copyright (C) 2014 Daurnimator +-- +-- This project is MIT/X11 licensed. Please see the +-- COPYING file in the source package for more information. +-- + +--[[ +Out of courtesy, a MUC service MAY send an out-of-room <message/> +if a user's affiliation changes while the user is not in the room; +the message SHOULD be sent from the room to the user's bare JID, +MAY contain a <body/> element describing the affiliation change, +and MUST contain a status code of 101. +]] + + +local st = require "util.stanza"; + +local function get_affiliation_notify(room) + return room._data.affiliation_notify; +end + +local function set_affiliation_notify(room, affiliation_notify) + affiliation_notify = affiliation_notify and true or nil; + if room._data.affiliation_notify == affiliation_notify then return false; end + room._data.affiliation_notify = affiliation_notify; + if room.save then room:save(true); end + return true; +end + +module:hook("muc-config-form", function(event) + table.insert(event.form, { + name = "muc#roomconfig_affiliationnotify"; + type = "boolean"; + label = "Notify users when their affiliation changes when they are not in the room?"; + value = get_affiliation_notify(event.room); + }); +end); + +module:hook("muc-config-submitted", function(event) + local new = event.fields["muc#roomconfig_affiliationnotify"]; + if new ~= nil and set_affiliation_notify(event.room, new) then + event.status_codes["104"] = true; + end +end); + +module:hook("muc-set-affiliation", function(event) + local room = event.room; + if not event.in_room and get_affiliation_notify(room) then + local body = string.format("Your affiliation in room %s is now %s.", room.jid, event.affiliation); + local stanza = st.message({ + type = "headline"; + from = room.jid; + to = event.jid; + }, body) + :tag("x", {xmlns = "http://jabber.org/protocol/muc#user"}) + :tag("status", {code="101"}):up() + :up(); + room:route_stanza(stanza); + end +end); + +return { + get = get_affiliation_notify; + set = set_affiliation_notify; +}; diff --git a/plugins/muc/muc.lib.lua b/plugins/muc/muc.lib.lua index 4e461df6..3dd21303 100644 --- a/plugins/muc/muc.lib.lua +++ b/plugins/muc/muc.lib.lua @@ -1111,6 +1111,8 @@ function room_mt:set_role(actor, occupant_jid, role, reason) return true; end +local affiliation_notify = module:require "muc/affiliation_notify"; + local name = module:require "muc/name"; room_mt.get_name = name.get; room_mt.set_name = name.set; |