Mercurial > prosody-modules
comparison mod_mam_muc/mod_mam_muc.lua @ 1324:853a382c9bd6
mod_turncredentials: Advertise the XEP-0215 feature (thanks Gryffus)
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Fri, 28 Feb 2014 15:36:06 +0100 |
parents | e8eebf281405 |
children | b21236b6b8d8 |
comparison
equal
deleted
inserted
replaced
1323:c84ff82658cb | 1324:853a382c9bd6 |
---|---|
109 end | 109 end |
110 end | 110 end |
111 end); | 111 end); |
112 end | 112 end |
113 | 113 |
114 module:hook("muc-config-form", function(event) | |
115 local room, form = event.room, event.form; | |
116 local mam_query = room._data.mam_query or 'anyone'; | |
117 table.insert(form, { | |
118 name = muc_form_allow_who, | |
119 type = 'list-single', | |
120 label = 'Who may query the archive?', | |
121 value = { | |
122 { value = 'moderators', label = 'Moderators Only', default = mam_query == 'moderators' }, | |
123 { value = 'members', label = 'Members', default = mam_query == 'members' }, | |
124 { value = 'anyone', label = 'Anyone who can join', default = mam_query == 'anyone' }, | |
125 } | |
126 } | |
127 ); | |
128 end); | |
129 | |
130 module:hook("muc-config-submitted", function(event) | |
131 local room, fields, changed = event.room, event.fields, event.changed; | |
132 local new = fields[muc_form_allow_who]; | |
133 if new ~= room._data.mam_query then | |
134 room._data.mam_query = new; | |
135 if type(changed) == "table" then | |
136 changed[muc_form_allow_who] = true; | |
137 else | |
138 event.changed = true; | |
139 end | |
140 end | |
141 end); | |
142 | |
143 | |
114 -- Handle archive queries | 144 -- Handle archive queries |
115 module:hook("iq-get/bare/"..xmlns_mam..":query", function(event) | 145 module:hook("iq-get/bare/"..xmlns_mam..":query", function(event) |
116 local origin, stanza = event.origin, event.stanza; | 146 local origin, stanza = event.origin, event.stanza; |
117 local room = stanza.attr.to; | 147 local room = stanza.attr.to; |
118 local room_node = jid_split(room); | 148 local room_node = jid_split(room); |
124 end | 154 end |
125 local from = jid_bare(stanza.attr.from); | 155 local from = jid_bare(stanza.attr.from); |
126 | 156 |
127 -- Banned or not a member of a members-only room? | 157 -- Banned or not a member of a members-only room? |
128 local from_affiliation = room_obj:get_affiliation(from); | 158 local from_affiliation = room_obj:get_affiliation(from); |
159 local allowed_to_query = room_obj._data.mam_query or "anyone"; | |
129 if from_affiliation == "outcast" -- banned | 160 if from_affiliation == "outcast" -- banned |
130 or room_obj:get_members_only() and not from_affiliation then -- members-only, not a member | 161 or room_obj:get_members_only() and not from_affiliation -- members-only, not a member |
162 or allowed_to_query == "moderators" and not (from_affiliation == "owner" or from_affiliation == "admin" ) | |
163 or allowed_to_query ~= "anyone" then | |
131 return origin.send(st.error_reply(stanza, "auth", "forbidden")) | 164 return origin.send(st.error_reply(stanza, "auth", "forbidden")) |
132 end | 165 end |
133 | 166 |
134 local qid = query.attr.queryid; | 167 local qid = query.attr.queryid; |
135 | 168 |