From 3f70b8c1ceb203b479fff93b9c998e30ecab8189 Mon Sep 17 00:00:00 2001 From: Hamish Peebles Date: Sun, 8 Oct 2023 10:45:56 +0100 Subject: [PATCH] Remove `report_message` superseded by `report_message_v2` (#4524) --- .../canisters/local_user_index/CHANGELOG.md | 4 ++ .../canisters/local_user_index/api/can.did | 9 --- .../local_user_index/api/src/main.rs | 1 - .../local_user_index/api/src/updates/mod.rs | 1 - .../api/src/updates/report_message.rs | 18 ------ .../impl/src/lifecycle/inspect_message.rs | 1 - .../local_user_index/impl/src/updates/mod.rs | 1 - .../impl/src/updates/report_message.rs | 57 ------------------- .../src/client/local_user_index.rs | 2 +- .../src/platform_moderator_tests.rs | 8 +-- .../src/services/localUserIndex/candid/idl.js | 20 ++----- .../services/localUserIndex/candid/types.d.ts | 8 --- 12 files changed, 13 insertions(+), 117 deletions(-) delete mode 100644 backend/canisters/local_user_index/api/src/updates/report_message.rs delete mode 100644 backend/canisters/local_user_index/impl/src/updates/report_message.rs diff --git a/backend/canisters/local_user_index/CHANGELOG.md b/backend/canisters/local_user_index/CHANGELOG.md index 8d750d81cb..443380b90c 100644 --- a/backend/canisters/local_user_index/CHANGELOG.md +++ b/backend/canisters/local_user_index/CHANGELOG.md @@ -5,6 +5,10 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). ## [unreleased] +### Removed + +- Remove `report_message` which has been superseded by `report_message_v2` ([#4524](https://github.com/open-chat-labs/open-chat/pull/4524)) + ### Fixed - Fix 'Report message' functionality ([#4523](https://github.com/open-chat-labs/open-chat/pull/4523)) diff --git a/backend/canisters/local_user_index/api/can.did b/backend/canisters/local_user_index/api/can.did index b4110a36a9..176d89627b 100644 --- a/backend/canisters/local_user_index/api/can.did +++ b/backend/canisters/local_user_index/api/can.did @@ -149,14 +149,6 @@ type RegisterUserResponse = variant { ReferralCodeExpired; }; -type ReportMessageArgs = record { - chat_id : ChatId; - thread_root_message_index : opt MessageIndex; - event_index : EventIndex; - reason_code : nat32; - notes : opt text; -}; - type ReportMessageV2Args = record { chat_id : MultiUserChat; thread_root_message_index : opt MessageIndex; @@ -179,5 +171,4 @@ service : { invite_users_to_group : (InviteUsersToGroupArgs) -> (InviteUsersToGroupResponse); register_user : (RegisterUserArgs) -> (RegisterUserResponse); report_message_v2 : (ReportMessageV2Args) -> (ReportMessageResponse); - report_message : (ReportMessageArgs) -> (ReportMessageResponse); }; diff --git a/backend/canisters/local_user_index/api/src/main.rs b/backend/canisters/local_user_index/api/src/main.rs index 5519198364..fd1a9f48f6 100644 --- a/backend/canisters/local_user_index/api/src/main.rs +++ b/backend/canisters/local_user_index/api/src/main.rs @@ -10,7 +10,6 @@ fn main() { generate_candid_method!(local_user_index, join_group, update); generate_candid_method!(local_user_index, register_user, update); generate_candid_method!(local_user_index, report_message_v2, update); - generate_candid_method!(local_user_index, report_message, update); candid::export_service!(); std::print!("{}", __export_service()); diff --git a/backend/canisters/local_user_index/api/src/updates/mod.rs b/backend/canisters/local_user_index/api/src/updates/mod.rs index 1fa8cc78b7..699a648e0d 100644 --- a/backend/canisters/local_user_index/api/src/updates/mod.rs +++ b/backend/canisters/local_user_index/api/src/updates/mod.rs @@ -10,5 +10,4 @@ pub mod join_channel; pub mod join_community; pub mod join_group; pub mod register_user; -pub mod report_message; pub mod report_message_v2; diff --git a/backend/canisters/local_user_index/api/src/updates/report_message.rs b/backend/canisters/local_user_index/api/src/updates/report_message.rs deleted file mode 100644 index b50ac1c675..0000000000 --- a/backend/canisters/local_user_index/api/src/updates/report_message.rs +++ /dev/null @@ -1,18 +0,0 @@ -use candid::CandidType; -use serde::{Deserialize, Serialize}; -use types::{ChatId, EventIndex, MessageIndex}; - -#[derive(CandidType, Serialize, Deserialize, Debug)] -pub struct Args { - pub chat_id: ChatId, - pub thread_root_message_index: Option, - pub event_index: EventIndex, - pub reason_code: u32, - pub notes: Option, -} - -#[derive(CandidType, Serialize, Deserialize, Debug)] -pub enum Response { - Success, - InternalError(String), -} diff --git a/backend/canisters/local_user_index/impl/src/lifecycle/inspect_message.rs b/backend/canisters/local_user_index/impl/src/lifecycle/inspect_message.rs index 6c6373f010..d2688699cb 100644 --- a/backend/canisters/local_user_index/impl/src/lifecycle/inspect_message.rs +++ b/backend/canisters/local_user_index/impl/src/lifecycle/inspect_message.rs @@ -22,7 +22,6 @@ fn accept_if_valid(state: &RuntimeState) { | "join_channel" | "join_community" | "join_group" - | "report_message" | "report_message_v2" => state.is_caller_openchat_user(), "register_user" => true, _ => false, diff --git a/backend/canisters/local_user_index/impl/src/updates/mod.rs b/backend/canisters/local_user_index/impl/src/updates/mod.rs index 893833d4fe..5c8a360d37 100644 --- a/backend/canisters/local_user_index/impl/src/updates/mod.rs +++ b/backend/canisters/local_user_index/impl/src/updates/mod.rs @@ -8,5 +8,4 @@ pub mod join_channel; pub mod join_community; pub mod join_group; pub mod register_user; -pub mod report_message; pub mod report_message_v2; diff --git a/backend/canisters/local_user_index/impl/src/updates/report_message.rs b/backend/canisters/local_user_index/impl/src/updates/report_message.rs deleted file mode 100644 index a377da6eb9..0000000000 --- a/backend/canisters/local_user_index/impl/src/updates/report_message.rs +++ /dev/null @@ -1,57 +0,0 @@ -use crate::guards::caller_is_openchat_user; -use crate::{mutate_state, read_state, RuntimeState}; -use canister_tracing_macros::trace; -use ic_cdk_macros::update; -use local_user_index_canister::report_message::{Response::*, *}; -use types::{CanisterId, ChatId, Empty, UserId}; - -#[update(guard = "caller_is_openchat_user")] -#[trace] -async fn report_message(args: Args) -> Response { - let PrepareResult { - user_id, - platform_moderators_group, - user_index_canister_id, - } = read_state(prepare); - - let platform_moderators_group = if let Some(group) = platform_moderators_group { - group - } else { - match user_index_canister_c2c_client::platform_moderators_group(user_index_canister_id, &Empty {}).await { - Ok(user_index_canister::platform_moderators_group::Response::Success(group)) => { - mutate_state(|state| state.data.platform_moderators_group = Some(group)); - group - } - Err(error) => return InternalError(format!("{error:?}")), - } - }; - - let c2c_args = group_canister::c2c_report_message::Args { - user_id, - chat_id: args.chat_id, - thread_root_message_index: args.thread_root_message_index, - event_index: args.event_index, - reason_code: args.reason_code, - notes: args.notes, - }; - match group_canister_c2c_client::c2c_report_message(platform_moderators_group.into(), &c2c_args).await { - Ok(_) => Success, - Err(error) => InternalError(format!("Failed to call 'group::c2c_report_message': {error:?}")), - } -} - -struct PrepareResult { - user_id: UserId, - platform_moderators_group: Option, - user_index_canister_id: CanisterId, -} - -fn prepare(state: &RuntimeState) -> PrepareResult { - let user_id = state.calling_user().user_id; - - PrepareResult { - user_id, - platform_moderators_group: state.data.platform_moderators_group, - user_index_canister_id: state.data.user_index_canister_id, - } -} diff --git a/backend/integration_tests/src/client/local_user_index.rs b/backend/integration_tests/src/client/local_user_index.rs index c7a096a26b..7762e23ede 100644 --- a/backend/integration_tests/src/client/local_user_index.rs +++ b/backend/integration_tests/src/client/local_user_index.rs @@ -11,7 +11,7 @@ generate_update_call!(join_channel); generate_update_call!(join_community); generate_update_call!(join_group); generate_update_call!(register_user); -generate_update_call!(report_message); +generate_update_call!(report_message_v2); pub mod happy_path { use crate::rng::random_user_principal; diff --git a/backend/integration_tests/src/platform_moderator_tests.rs b/backend/integration_tests/src/platform_moderator_tests.rs index 0bb61b1ad4..a4fc0559a7 100644 --- a/backend/integration_tests/src/platform_moderator_tests.rs +++ b/backend/integration_tests/src/platform_moderator_tests.rs @@ -5,7 +5,7 @@ use crate::{client, CanisterIds, TestEnv, User}; use candid::Principal; use ic_test_state_machine_client::StateMachine; use std::ops::Deref; -use types::{Chat, ChatEvent, ChatId, MessageContent}; +use types::{Chat, ChatEvent, ChatId, MessageContent, MultiUserChat}; #[test] fn new_platform_moderators_added_to_moderators_group() { @@ -59,12 +59,12 @@ fn report_message_succeeds() { let group_id = client::user::happy_path::create_group(env, &user2, &random_string(), true, true); - client::local_user_index::report_message( + client::local_user_index::report_message_v2( env, user2.principal, canister_ids.local_user_index, - &local_user_index_canister::report_message::Args { - chat_id: group_id, + &local_user_index_canister::report_message_v2::Args { + chat_id: MultiUserChat::Group(group_id), thread_root_message_index: None, event_index: 10.into(), reason_code: 1, diff --git a/frontend/openchat-agent/src/services/localUserIndex/candid/idl.js b/frontend/openchat-agent/src/services/localUserIndex/candid/idl.js index a8e783d6ee..6e1fcce4bf 100644 --- a/frontend/openchat-agent/src/services/localUserIndex/candid/idl.js +++ b/frontend/openchat-agent/src/services/localUserIndex/candid/idl.js @@ -689,17 +689,6 @@ export const idlFactory = ({ IDL }) => { 'ReferralCodeInvalid' : IDL.Null, 'CyclesBalanceTooLow' : IDL.Null, }); - const ReportMessageArgs = IDL.Record({ - 'notes' : IDL.Opt(IDL.Text), - 'chat_id' : ChatId, - 'reason_code' : IDL.Nat32, - 'event_index' : EventIndex, - 'thread_root_message_index' : IDL.Opt(MessageIndex), - }); - const ReportMessageResponse = IDL.Variant({ - 'Success' : IDL.Null, - 'InternalError' : IDL.Text, - }); const MultiUserChat = IDL.Variant({ 'Group' : ChatId, 'Channel' : IDL.Tuple(CommunityId, ChannelId), @@ -711,6 +700,10 @@ export const idlFactory = ({ IDL }) => { 'event_index' : EventIndex, 'thread_root_message_index' : IDL.Opt(MessageIndex), }); + const ReportMessageResponse = IDL.Variant({ + 'Success' : IDL.Null, + 'InternalError' : IDL.Text, + }); return IDL.Service({ 'invite_users_to_channel' : IDL.Func( [InviteUsersToChannelArgs], @@ -735,11 +728,6 @@ export const idlFactory = ({ IDL }) => { ), 'join_group' : IDL.Func([JoinGroupArgs], [JoinGroupResponse], []), 'register_user' : IDL.Func([RegisterUserArgs], [RegisterUserResponse], []), - 'report_message' : IDL.Func( - [ReportMessageArgs], - [ReportMessageResponse], - [], - ), 'report_message_v2' : IDL.Func( [ReportMessageV2Args], [ReportMessageResponse], diff --git a/frontend/openchat-agent/src/services/localUserIndex/candid/types.d.ts b/frontend/openchat-agent/src/services/localUserIndex/candid/types.d.ts index 114b47e70e..9e36e5709c 100644 --- a/frontend/openchat-agent/src/services/localUserIndex/candid/types.d.ts +++ b/frontend/openchat-agent/src/services/localUserIndex/candid/types.d.ts @@ -1202,13 +1202,6 @@ export interface ReplyContext { 'chat_if_other' : [] | [[Chat, [] | [MessageIndex]]], 'event_index' : EventIndex, } -export interface ReportMessageArgs { - 'notes' : [] | [string], - 'chat_id' : ChatId, - 'reason_code' : number, - 'event_index' : EventIndex, - 'thread_root_message_index' : [] | [MessageIndex], -} export type ReportMessageResponse = { 'Success' : null } | { 'InternalError' : string }; export interface ReportMessageV2Args { @@ -1377,7 +1370,6 @@ export interface _SERVICE { 'join_community' : ActorMethod<[JoinCommunityArgs], JoinCommunityResponse>, 'join_group' : ActorMethod<[JoinGroupArgs], JoinGroupResponse>, 'register_user' : ActorMethod<[RegisterUserArgs], RegisterUserResponse>, - 'report_message' : ActorMethod<[ReportMessageArgs], ReportMessageResponse>, 'report_message_v2' : ActorMethod< [ReportMessageV2Args], ReportMessageResponse