fix send_to_chan: non mebers cant send to moderated channels

This commit is contained in:
tali 2024-02-02 17:08:04 -05:00
parent 81918b9813
commit a34651b283
1 changed files with 16 additions and 13 deletions

View File

@ -280,22 +280,22 @@ let on_msg_mode t name args =
Ok () Ok ()
(* messages and channels *) (* messages *)
let get_priv_opt chan user =
try
let mem = Router.membership chan user in
Some mem.mem_priv
with Not_found ->
None
let send_to_chan ~from chan = let send_to_chan ~from chan =
let cannot_send = let priv_required =
try if Mode.Set.mem `m (Chan.mode chan) then Some Voice
let mem = Router.membership chan from in else if Mode.Set.mem `n (Chan.mode chan) then Some Normal
(* check if moderated (+m) *) else None
if Mode.Set.mem `m (Chan.mode chan) then
mem.mem_priv < Voice
else
false
with Not_found ->
(* check if no external messages (+n) *)
Mode.Set.mem `n (Chan.mode chan)
in in
if cannot_send then if get_priv_opt chan from < priv_required then
Error (cannotsendtochan (Chan.name chan)) Error (cannotsendtochan (Chan.name chan))
else else
Ok (Chan.name chan, [`to_chan chan]) Ok (Chan.name chan, [`to_chan chan])
@ -336,6 +336,9 @@ let on_msg_away t status =
set_away t me status; set_away t me status;
Ok () Ok ()
(* channels *)
let membership_prefix = function let membership_prefix = function
| Normal -> "" | Normal -> ""
| Voice -> "+" | Voice -> "+"