Skip to content

Commit

Permalink
Simplify inspect_message (#4436)
Browse files Browse the repository at this point in the history
  • Loading branch information
hpeebles authored Sep 25, 2023
1 parent 9d7404d commit 2f16e62
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 33 deletions.
1 change: 1 addition & 0 deletions backend/canisters/group/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
### Changed

- Disable mentions for messages sent by the ProposalsBot ([#4424](https://github.com/open-chat-labs/open-chat/pull/4424))
- Simplify `inspect_message` ([#4436](https://github.com/open-chat-labs/open-chat/pull/4436))

### Fixed

Expand Down
35 changes: 2 additions & 33 deletions backend/canisters/group/impl/src/lifecycle/inspect_message.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,39 +18,8 @@ fn accept_if_valid(state: &RuntimeState) {
}

let caller = state.env.caller();
let permissions = &state.data.chat.permissions;
let is_valid = if let Some(role) = state.data.get_member(caller).map(|p| p.role) {
match method_name.as_str() {
"add_reaction" | "remove_reaction" => role.can_react_to_messages(permissions),
"block_user" => role.can_block_users(permissions),
"convert_into_community" => role.is_owner(),
"delete_group" => role.can_delete_group(),
"enable_invite_code" | "disable_invite_code" | "reset_invite_code" => role.can_invite_users(permissions),
"make_private" => role.can_change_group_visibility(),
"pin_message" | "pin_message_v2" => role.can_pin_messages(permissions),
"remove_participant" => role.can_remove_members(permissions),
"send_message_v2" => role.can_send_messages(permissions) || role.can_reply_in_thread(permissions),
"unblock_user" => role.can_unblock_users(permissions),
"unpin_message" => role.can_pin_messages(permissions),
"update_group_v2" => role.can_update_group(permissions),
"update_permissions" => role.can_change_permissions(),
"delete_messages"
| "undelete_messages"
| "change_role"
| "claim_prize"
| "edit_message_v2"
| "follow_thread"
| "unfollow_thread"
| "put_chunk"
| "register_poll_vote"
| "register_proposal_vote"
| "register_proposal_vote_v2"
| "toggle_mute_notifications" => true,
_ => false,
}
} else {
state.data.get_invitation(caller).is_some() && method_name == "decline_invitation"
};
let is_valid = state.data.get_member(caller).is_some()
|| state.data.get_invitation(caller).is_some() && method_name == "decline_invitation";

if is_valid {
ic_cdk::api::call::accept_message();
Expand Down

0 comments on commit 2f16e62

Please sign in to comment.