Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Impl group_index::c2c_report_message + add variant #4723

Merged
merged 3 commits into from
Nov 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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:?}")),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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:?}")),
Expand Down
1 change: 1 addition & 0 deletions backend/canisters/group_index/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,5 @@ pub struct Args {
pub enum Response {
Success,
AlreadyReported,
InternalError(String),
}
8 changes: 8 additions & 0 deletions backend/canisters/group_index/impl/src/guards.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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())
}
}
Original file line number Diff line number Diff line change
@@ -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:?}")),
}
}
1 change: 1 addition & 0 deletions backend/canisters/group_index/impl/src/updates/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Loading