Software /
code /
prosody
Annotate
plugins/muc/affiliation_notify.lib.lua @ 6991:84e01dbb739e
MUC: Update all config form handlers to take advantage of the new per-option events
author | Matthew Wild <mwild1@gmail.com> |
---|---|
date | Fri, 11 Dec 2015 15:33:58 +0000 |
parent | 6394:fe034fa564ee |
child | 7352:50b24b3476e6 |
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 if room.save then room:save(true); end |
fe034fa564ee
plugins/muc: Add affiliation_notify config option to send out status code 101
daurnimator <quae@daurnimator.com>
parents:
diff
changeset
|
28 return true; |
fe034fa564ee
plugins/muc: Add affiliation_notify config option to send out status code 101
daurnimator <quae@daurnimator.com>
parents:
diff
changeset
|
29 end |
fe034fa564ee
plugins/muc: Add affiliation_notify config option to send out status code 101
daurnimator <quae@daurnimator.com>
parents:
diff
changeset
|
30 |
fe034fa564ee
plugins/muc: Add affiliation_notify config option to send out status code 101
daurnimator <quae@daurnimator.com>
parents:
diff
changeset
|
31 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
|
32 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
|
33 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
|
34 type = "boolean"; |
fe034fa564ee
plugins/muc: Add affiliation_notify config option to send out status code 101
daurnimator <quae@daurnimator.com>
parents:
diff
changeset
|
35 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
|
36 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
|
37 }); |
fe034fa564ee
plugins/muc: Add affiliation_notify config option to send out status code 101
daurnimator <quae@daurnimator.com>
parents:
diff
changeset
|
38 end); |
fe034fa564ee
plugins/muc: Add affiliation_notify config option to send out status code 101
daurnimator <quae@daurnimator.com>
parents:
diff
changeset
|
39 |
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
|
40 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
|
41 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
|
42 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
|
43 end |
fe034fa564ee
plugins/muc: Add affiliation_notify config option to send out status code 101
daurnimator <quae@daurnimator.com>
parents:
diff
changeset
|
44 end); |
fe034fa564ee
plugins/muc: Add affiliation_notify config option to send out status code 101
daurnimator <quae@daurnimator.com>
parents:
diff
changeset
|
45 |
fe034fa564ee
plugins/muc: Add affiliation_notify config option to send out status code 101
daurnimator <quae@daurnimator.com>
parents:
diff
changeset
|
46 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
|
47 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
|
48 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
|
49 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
|
50 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
|
51 type = "headline"; |
fe034fa564ee
plugins/muc: Add affiliation_notify config option to send out status code 101
daurnimator <quae@daurnimator.com>
parents:
diff
changeset
|
52 from = room.jid; |
fe034fa564ee
plugins/muc: Add affiliation_notify config option to send out status code 101
daurnimator <quae@daurnimator.com>
parents:
diff
changeset
|
53 to = event.jid; |
fe034fa564ee
plugins/muc: Add affiliation_notify config option to send out status code 101
daurnimator <quae@daurnimator.com>
parents:
diff
changeset
|
54 }, body) |
fe034fa564ee
plugins/muc: Add affiliation_notify config option to send out status code 101
daurnimator <quae@daurnimator.com>
parents:
diff
changeset
|
55 :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
|
56 :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
|
57 :up(); |
fe034fa564ee
plugins/muc: Add affiliation_notify config option to send out status code 101
daurnimator <quae@daurnimator.com>
parents:
diff
changeset
|
58 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
|
59 end |
fe034fa564ee
plugins/muc: Add affiliation_notify config option to send out status code 101
daurnimator <quae@daurnimator.com>
parents:
diff
changeset
|
60 end); |
fe034fa564ee
plugins/muc: Add affiliation_notify config option to send out status code 101
daurnimator <quae@daurnimator.com>
parents:
diff
changeset
|
61 |
fe034fa564ee
plugins/muc: Add affiliation_notify config option to send out status code 101
daurnimator <quae@daurnimator.com>
parents:
diff
changeset
|
62 return { |
fe034fa564ee
plugins/muc: Add affiliation_notify config option to send out status code 101
daurnimator <quae@daurnimator.com>
parents:
diff
changeset
|
63 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
|
64 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
|
65 }; |