diff --git a/backend/canisters/community/impl/src/updates/report_message.rs b/backend/canisters/community/impl/src/updates/report_message.rs index f8df099c9d..85c6329489 100644 --- a/backend/canisters/community/impl/src/updates/report_message.rs +++ b/backend/canisters/community/impl/src/updates/report_message.rs @@ -26,6 +26,7 @@ async fn report_message(args: Args) -> Response { match result { c2c_report_message::Response::Success => Success, c2c_report_message::Response::AlreadyReported => AlreadyReported, + c2c_report_message::Response::InternalError(error) => InternalError(error), } } Err(err) => InternalError(format!("{err:?}")), diff --git a/backend/canisters/group/impl/src/updates/report_message.rs b/backend/canisters/group/impl/src/updates/report_message.rs index 4e3c261c31..86f0f3b594 100644 --- a/backend/canisters/group/impl/src/updates/report_message.rs +++ b/backend/canisters/group/impl/src/updates/report_message.rs @@ -26,6 +26,7 @@ async fn report_message(args: Args) -> Response { match result { c2c_report_message::Response::Success => Success, c2c_report_message::Response::AlreadyReported => AlreadyReported, + c2c_report_message::Response::InternalError(error) => InternalError(error), } } Err(err) => InternalError(format!("{err:?}")), diff --git a/backend/canisters/group_index/CHANGELOG.md b/backend/canisters/group_index/CHANGELOG.md index 3556c945ad..809b17c578 100644 --- a/backend/canisters/group_index/CHANGELOG.md +++ b/backend/canisters/group_index/CHANGELOG.md @@ -8,6 +8,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). ### Changed - Add `events_ttl_last_updated` to chat summaries ([#4711](https://github.com/open-chat-labs/open-chat/pull/4711)) +- Implement `group_index::c2c_report_message` ([#4723](https://github.com/open-chat-labs/open-chat/pull/4723)) ## [[2.0.926](https://github.com/open-chat-labs/open-chat/releases/tag/v2.0.926-group_index)] - 2023-11-03 diff --git a/backend/canisters/group_index/api/src/updates/c2c_report_message.rs b/backend/canisters/group_index/api/src/updates/c2c_report_message.rs index a3420293a5..141937eb1a 100644 --- a/backend/canisters/group_index/api/src/updates/c2c_report_message.rs +++ b/backend/canisters/group_index/api/src/updates/c2c_report_message.rs @@ -17,4 +17,5 @@ pub struct Args { pub enum Response { Success, AlreadyReported, + InternalError(String), } diff --git a/backend/canisters/group_index/impl/src/guards.rs b/backend/canisters/group_index/impl/src/guards.rs index 77472b9e79..c454b8bc5a 100644 --- a/backend/canisters/group_index/impl/src/guards.rs +++ b/backend/canisters/group_index/impl/src/guards.rs @@ -23,3 +23,11 @@ pub fn caller_is_community_canister() -> Result<(), String> { Err("Caller is not a community canister".to_string()) } } + +pub fn caller_is_group_or_community_canister() -> Result<(), String> { + if read_state(|state| state.is_caller_group_canister() || state.is_caller_community_canister()) { + Ok(()) + } else { + Err("Caller is not a group or community canister".to_string()) + } +} diff --git a/backend/canisters/group_index/impl/src/updates/c2c_report_message.rs b/backend/canisters/group_index/impl/src/updates/c2c_report_message.rs new file mode 100644 index 0000000000..e0b759a42e --- /dev/null +++ b/backend/canisters/group_index/impl/src/updates/c2c_report_message.rs @@ -0,0 +1,27 @@ +use crate::guards::caller_is_group_or_community_canister; +use crate::read_state; +use canister_api_macros::update_msgpack; +use canister_tracing_macros::trace; +use group_index_canister::c2c_report_message::{Response::*, *}; + +#[update_msgpack(guard = "caller_is_group_or_community_canister")] +#[trace] +async fn c2c_report_message(args: Args) -> Response { + let user_index_canister_id = read_state(|state| state.data.user_index_canister_id); + + let c2c_args = user_index_canister::c2c_report_message::Args { + chat_id: args.chat_id.into(), + reporter: args.reporter, + thread_root_message_index: args.thread_root_message_index, + message: args.message, + reason_code: args.reason_code, + notes: args.notes, + already_deleted: args.already_deleted, + }; + + match user_index_canister_c2c_client::c2c_report_message(user_index_canister_id, &c2c_args).await { + Ok(user_index_canister::c2c_report_message::Response::Success) => Success, + Ok(user_index_canister::c2c_report_message::Response::AlreadyReported) => AlreadyReported, + Err(error) => InternalError(format!("{error:?}")), + } +} diff --git a/backend/canisters/group_index/impl/src/updates/mod.rs b/backend/canisters/group_index/impl/src/updates/mod.rs index 062ff36a59..b62a0549cc 100644 --- a/backend/canisters/group_index/impl/src/updates/mod.rs +++ b/backend/canisters/group_index/impl/src/updates/mod.rs @@ -10,6 +10,7 @@ pub mod c2c_make_private; pub mod c2c_mark_active; pub mod c2c_mark_community_active; pub mod c2c_mark_group_import_complete; +pub mod c2c_report_message; pub mod c2c_start_importing_group_into_community; pub mod c2c_update_community; pub mod c2c_update_group;