Mercurial > prosody-hg
comparison plugins/muc/subject.lib.lua @ 8928:d41f8ce67c8e
MUC: Reorder subject related arguments to increasing requiredness (API break)
| author | Kim Alvefur <zash@zash.se> |
|---|---|
| date | Tue, 26 Jun 2018 02:14:14 +0200 |
| parents | a387e00471d6 |
| children | 415b2e9d8ba8 |
comparison
equal
deleted
inserted
replaced
| 8927:ed0891383e78 | 8928:d41f8ce67c8e |
|---|---|
| 10 local st = require "util.stanza"; | 10 local st = require "util.stanza"; |
| 11 | 11 |
| 12 local muc_util = module:require "muc/util"; | 12 local muc_util = module:require "muc/util"; |
| 13 local valid_roles = muc_util.valid_roles; | 13 local valid_roles = muc_util.valid_roles; |
| 14 | 14 |
| 15 local function create_subject_message(from, subject) | 15 local function create_subject_message(subject, from) |
| 16 return st.message({from = from; type = "groupchat"}) | 16 return st.message({from = from; type = "groupchat"}) |
| 17 :tag("subject"):text(subject or ""):up(); | 17 :tag("subject"):text(subject or ""):up(); |
| 18 end | 18 end |
| 19 | 19 |
| 20 local function get_changesubject(room) | 20 local function get_changesubject(room) |
| 51 end | 51 end |
| 52 end); | 52 end); |
| 53 | 53 |
| 54 local function get_subject(room) | 54 local function get_subject(room) |
| 55 -- a <message/> stanza from the room JID (or from the occupant JID of the entity that set the subject) | 55 -- a <message/> stanza from the room JID (or from the occupant JID of the entity that set the subject) |
| 56 return room._data.subject_from or room.jid, room._data.subject; | 56 return room._data.subject, room._data.subject_from or room.jid; |
| 57 end | 57 end |
| 58 | 58 |
| 59 local function send_subject(room, to) | 59 local function send_subject(room, to) |
| 60 local msg = create_subject_message(get_subject(room)); | 60 local msg = create_subject_message(get_subject(room)); |
| 61 msg.attr.to = to; | 61 msg.attr.to = to; |
| 62 room:route_stanza(msg); | 62 room:route_stanza(msg); |
| 63 end | 63 end |
| 64 | 64 |
| 65 local function set_subject(room, from, subject) | 65 local function set_subject(room, subject, from) |
| 66 if subject == "" then subject = nil; end | 66 if subject == "" then subject = nil; end |
| 67 local old_from, old_subject = get_subject(room); | 67 local old_subject, old_from = get_subject(room); |
| 68 if old_subject == subject and old_from == from then return false; end | 68 if old_subject == subject and old_from == from then return false; end |
| 69 room._data.subject_from = from; | 69 room._data.subject_from = from; |
| 70 room._data.subject = subject; | 70 room._data.subject = subject; |
| 71 local msg = create_subject_message(from, subject); | 71 local msg = create_subject_message(subject, from); |
| 72 room:broadcast_message(msg); | 72 room:broadcast_message(msg); |
| 73 return true; | 73 return true; |
| 74 end | 74 end |
| 75 | 75 |
| 76 -- Send subject to joining user | 76 -- Send subject to joining user |
| 88 local occupant = event.occupant; | 88 local occupant = event.occupant; |
| 89 -- Role check for subject changes | 89 -- Role check for subject changes |
| 90 local role_rank = valid_roles[occupant and occupant.role or "none"]; | 90 local role_rank = valid_roles[occupant and occupant.role or "none"]; |
| 91 if role_rank >= valid_roles.moderator or | 91 if role_rank >= valid_roles.moderator or |
| 92 ( role_rank >= valid_roles.participant and get_changesubject(room) ) then -- and participant | 92 ( role_rank >= valid_roles.participant and get_changesubject(room) ) then -- and participant |
| 93 set_subject(room, occupant.nick, subject:get_text()); | 93 set_subject(room, subject:get_text(), occupant.nick); |
| 94 room:save(); | 94 room:save(); |
| 95 return true; | 95 return true; |
| 96 else | 96 else |
| 97 event.origin.send(st.error_reply(stanza, "auth", "forbidden", "You are not allowed to change the subject")); | 97 event.origin.send(st.error_reply(stanza, "auth", "forbidden", "You are not allowed to change the subject")); |
| 98 return true; | 98 return true; |
