Software /
code /
prosody
Comparison
plugins/muc/subject.lib.lua @ 8930:2e45b1b47918
Backed out changeset d41f8ce67c8e
Turns out this argument wasn’t only in trunk, but has been like this
since 81406277279e
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Tue, 26 Jun 2018 02:40:06 +0200 |
parent | 8929:415b2e9d8ba8 |
child | 9034:1c709e3d2e5e |
comparison
equal
deleted
inserted
replaced
8929:415b2e9d8ba8 | 8930:2e45b1b47918 |
---|---|
11 local dt = require "util.datetime"; | 11 local dt = require "util.datetime"; |
12 | 12 |
13 local muc_util = module:require "muc/util"; | 13 local muc_util = module:require "muc/util"; |
14 local valid_roles = muc_util.valid_roles; | 14 local valid_roles = muc_util.valid_roles; |
15 | 15 |
16 local function create_subject_message(subject, from) | 16 local function create_subject_message(from, subject) |
17 return st.message({from = from; type = "groupchat"}) | 17 return st.message({from = from; type = "groupchat"}) |
18 :tag("subject"):text(subject or ""):up(); | 18 :tag("subject"):text(subject or ""):up(); |
19 end | 19 end |
20 | 20 |
21 local function get_changesubject(room) | 21 local function get_changesubject(room) |
52 end | 52 end |
53 end); | 53 end); |
54 | 54 |
55 local function get_subject(room) | 55 local function get_subject(room) |
56 -- a <message/> stanza from the room JID (or from the occupant JID of the entity that set the subject) | 56 -- a <message/> stanza from the room JID (or from the occupant JID of the entity that set the subject) |
57 return room._data.subject, room._data.subject_from or room.jid; | 57 return room._data.subject_from or room.jid, room._data.subject; |
58 end | 58 end |
59 | 59 |
60 local function send_subject(room, to, time) | 60 local function send_subject(room, to, time) |
61 local msg = create_subject_message(get_subject(room)); | 61 local msg = create_subject_message(get_subject(room)); |
62 msg.attr.to = to; | 62 msg.attr.to = to; |
68 }):up(); | 68 }):up(); |
69 end | 69 end |
70 room:route_stanza(msg); | 70 room:route_stanza(msg); |
71 end | 71 end |
72 | 72 |
73 local function set_subject(room, subject, from) | 73 local function set_subject(room, from, subject) |
74 if subject == "" then subject = nil; end | 74 if subject == "" then subject = nil; end |
75 local old_subject, old_from = get_subject(room); | 75 local old_from, old_subject = get_subject(room); |
76 if old_subject == subject and old_from == from then return false; end | 76 if old_subject == subject and old_from == from then return false; end |
77 room._data.subject_from = from; | 77 room._data.subject_from = from; |
78 room._data.subject = subject; | 78 room._data.subject = subject; |
79 room._data.subject_time = os.time(); | 79 room._data.subject_time = os.time(); |
80 local msg = create_subject_message(subject, from); | 80 local msg = create_subject_message(from, subject); |
81 room:broadcast_message(msg); | 81 room:broadcast_message(msg); |
82 return true; | 82 return true; |
83 end | 83 end |
84 | 84 |
85 -- Send subject to joining user | 85 -- Send subject to joining user |
97 local occupant = event.occupant; | 97 local occupant = event.occupant; |
98 -- Role check for subject changes | 98 -- Role check for subject changes |
99 local role_rank = valid_roles[occupant and occupant.role or "none"]; | 99 local role_rank = valid_roles[occupant and occupant.role or "none"]; |
100 if role_rank >= valid_roles.moderator or | 100 if role_rank >= valid_roles.moderator or |
101 ( role_rank >= valid_roles.participant and get_changesubject(room) ) then -- and participant | 101 ( role_rank >= valid_roles.participant and get_changesubject(room) ) then -- and participant |
102 set_subject(room, subject:get_text(), occupant.nick); | 102 set_subject(room, occupant.nick, subject:get_text()); |
103 room:save(); | 103 room:save(); |
104 return true; | 104 return true; |
105 else | 105 else |
106 event.origin.send(st.error_reply(stanza, "auth", "forbidden", "You are not allowed to change the subject")); | 106 event.origin.send(st.error_reply(stanza, "auth", "forbidden", "You are not allowed to change the subject")); |
107 return true; | 107 return true; |