comparison mod_mam_muc/mod_mam_muc.lua @ 1325:b21236b6b8d8

Backed out changeset 853a382c9bd6
author Kim Alvefur <zash@zash.se>
date Fri, 28 Feb 2014 15:37:55 +0100
parents 853a382c9bd6
children 8be609f5610e
comparison
equal deleted inserted replaced
1324:853a382c9bd6 1325:b21236b6b8d8
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
144 -- Handle archive queries 114 -- Handle archive queries
145 module:hook("iq-get/bare/"..xmlns_mam..":query", function(event) 115 module:hook("iq-get/bare/"..xmlns_mam..":query", function(event)
146 local origin, stanza = event.origin, event.stanza; 116 local origin, stanza = event.origin, event.stanza;
147 local room = stanza.attr.to; 117 local room = stanza.attr.to;
148 local room_node = jid_split(room); 118 local room_node = jid_split(room);
154 end 124 end
155 local from = jid_bare(stanza.attr.from); 125 local from = jid_bare(stanza.attr.from);
156 126
157 -- Banned or not a member of a members-only room? 127 -- Banned or not a member of a members-only room?
158 local from_affiliation = room_obj:get_affiliation(from); 128 local from_affiliation = room_obj:get_affiliation(from);
159 local allowed_to_query = room_obj._data.mam_query or "anyone";
160 if from_affiliation == "outcast" -- banned 129 if from_affiliation == "outcast" -- banned
161 or room_obj:get_members_only() and not from_affiliation -- members-only, not a member 130 or room_obj:get_members_only() and not from_affiliation then -- 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
164 return origin.send(st.error_reply(stanza, "auth", "forbidden")) 131 return origin.send(st.error_reply(stanza, "auth", "forbidden"))
165 end 132 end
166 133
167 local qid = query.attr.queryid; 134 local qid = query.attr.queryid;
168 135