diff --git a/backend/bots/examples/group_prize_bot/impl/src/updates/join_group.rs b/backend/bots/examples/group_prize_bot/impl/src/updates/join_group.rs index 7b3563baa4..c3df30a85d 100644 --- a/backend/bots/examples/group_prize_bot/impl/src/updates/join_group.rs +++ b/backend/bots/examples/group_prize_bot/impl/src/updates/join_group.rs @@ -32,11 +32,15 @@ async fn join_group(args: Args) -> Response { } async fn lookup_local_user_index(group: CanisterId) -> Result { - let c2c_args = group_canister::local_user_index::Args {}; - match group_canister_c2c_client::local_user_index(group, &c2c_args).await { - Ok(group_canister::local_user_index::Response::Success(canister_id)) => Ok(canister_id), + let c2c_args = group_canister::public_summary::Args { invite_code: None }; + match group_canister_c2c_client::public_summary(group, &c2c_args).await { + Ok(group_canister::public_summary::Response::Success(result)) => Ok(result.summary.local_user_index_canister_id), + Ok(_) => { + error!(%group, "Group not public"); + Err(GroupNotFound) + } Err(error) => { - error!(?error, ?group, "Group not found"); + error!(?error, %group, "Group not found"); Err(GroupNotFound) } } diff --git a/backend/canisters/community/CHANGELOG.md b/backend/canisters/community/CHANGELOG.md index e187002d6b..28342bacae 100644 --- a/backend/canisters/community/CHANGELOG.md +++ b/backend/canisters/community/CHANGELOG.md @@ -5,6 +5,10 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). ## [unreleased] +### Removed + +- Removed `local_user_index` endpoint since that is now included in the summary ([#4977](https://github.com/open-chat-labs/open-chat/pull/4977)) + ## [[2.0.965](https://github.com/open-chat-labs/open-chat/releases/tag/v2.0.965-community)] - 2023-12-07 ### Fixed diff --git a/backend/canisters/community/api/can.did b/backend/canisters/community/api/can.did index 63f9fde97b..46c4c6620c 100644 --- a/backend/canisters/community/api/can.did +++ b/backend/canisters/community/api/can.did @@ -80,10 +80,6 @@ type InviteCodeResponse = variant { NotAuthorized; }; -type LocalUserIndexResponse = variant { - Success : CanisterId; -}; - type MessagesByMessageIndexArgs = record { channel_id : ChannelId; thread_root_message_index : opt MessageIndex; @@ -954,7 +950,6 @@ service : { events_window : (EventsWindowArgs) -> (EventsResponse) query; explore_channels : (ExploreChannelsArgs) -> (ExploreChannelsResponse) query; invite_code : (EmptyArgs) -> (InviteCodeResponse) query; - local_user_index : (EmptyArgs) -> (LocalUserIndexResponse) query; messages_by_message_index : (MessagesByMessageIndexArgs) -> (MessagesByMessageIndexResponse) query; search_channel : (SearchChannelArgs) -> (SearchChannelResponse) query; selected_channel_initial : (SelectedChannelInitialArgs) -> (SelectedChannelInitialResponse) query; diff --git a/backend/canisters/community/api/src/main.rs b/backend/canisters/community/api/src/main.rs index 606ad7a900..0301253ccd 100644 --- a/backend/canisters/community/api/src/main.rs +++ b/backend/canisters/community/api/src/main.rs @@ -10,7 +10,6 @@ fn main() { generate_candid_method!(community, events, query); generate_candid_method!(community, explore_channels, query); generate_candid_method!(community, invite_code, query); - generate_candid_method!(community, local_user_index, query); generate_candid_method!(community, messages_by_message_index, query); generate_candid_method!(community, search_channel, query); generate_candid_method!(community, selected_channel_initial, query); diff --git a/backend/canisters/community/api/src/queries/local_user_index.rs b/backend/canisters/community/api/src/queries/local_user_index.rs deleted file mode 100644 index 91c8faf6ff..0000000000 --- a/backend/canisters/community/api/src/queries/local_user_index.rs +++ /dev/null @@ -1,10 +0,0 @@ -use candid::CandidType; -use serde::{Deserialize, Serialize}; -use types::{CanisterId, Empty}; - -pub type Args = Empty; - -#[derive(CandidType, Serialize, Deserialize, Debug)] -pub enum Response { - Success(CanisterId), -} diff --git a/backend/canisters/community/api/src/queries/mod.rs b/backend/canisters/community/api/src/queries/mod.rs index 67f68f9214..c2484ffbb1 100644 --- a/backend/canisters/community/api/src/queries/mod.rs +++ b/backend/canisters/community/api/src/queries/mod.rs @@ -10,7 +10,6 @@ pub mod events_by_index; pub mod events_window; pub mod explore_channels; pub mod invite_code; -pub mod local_user_index; pub mod messages_by_message_index; pub mod search_channel; pub mod selected_channel_initial; diff --git a/backend/canisters/community/impl/src/queries/local_user_index.rs b/backend/canisters/community/impl/src/queries/local_user_index.rs deleted file mode 100644 index 10b7e4d0b4..0000000000 --- a/backend/canisters/community/impl/src/queries/local_user_index.rs +++ /dev/null @@ -1,12 +0,0 @@ -use crate::{read_state, RuntimeState}; -use community_canister::local_user_index::{Response::*, *}; -use ic_cdk_macros::query; - -#[query] -fn local_user_index(_args: Args) -> Response { - read_state(local_user_index_impl) -} - -fn local_user_index_impl(state: &RuntimeState) -> Response { - Success(state.data.local_user_index_canister_id) -} diff --git a/backend/canisters/community/impl/src/queries/mod.rs b/backend/canisters/community/impl/src/queries/mod.rs index 5bfd0a0df0..5379b40a1c 100644 --- a/backend/canisters/community/impl/src/queries/mod.rs +++ b/backend/canisters/community/impl/src/queries/mod.rs @@ -10,7 +10,6 @@ mod events_window; mod explore_channels; mod http_request; mod invite_code; -mod local_user_index; mod messages_by_message_index; mod search_channel; mod selected_channel_initial; diff --git a/backend/canisters/group/CHANGELOG.md b/backend/canisters/group/CHANGELOG.md index d283f9c0e4..71abfd87f1 100644 --- a/backend/canisters/group/CHANGELOG.md +++ b/backend/canisters/group/CHANGELOG.md @@ -5,6 +5,10 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). ## [unreleased] +### Removed + +- Removed `local_user_index` endpoint since that is now included in the summary ([#4977](https://github.com/open-chat-labs/open-chat/pull/4977)) + ## [[2.0.966](https://github.com/open-chat-labs/open-chat/releases/tag/v2.0.966-group)] - 2023-12-07 ### Fixed diff --git a/backend/canisters/group/api/can.did b/backend/canisters/group/api/can.did index 79adcac171..2434e246e9 100644 --- a/backend/canisters/group/api/can.did +++ b/backend/canisters/group/api/can.did @@ -425,12 +425,6 @@ type EventsResponse = variant { ReplicaNotUpToDateV2 : TimestampMillis; }; -type LocalUserIndexArgs = record {}; - -type LocalUserIndexResponse = variant { - Success : CanisterId; -}; - type MessagesByMessageIndexArgs = record { thread_root_message_index : opt MessageIndex; messages : vec MessageIndex; @@ -647,7 +641,6 @@ service : { events : (EventsArgs) -> (EventsResponse) query; events_by_index : (EventsByIndexArgs) -> (EventsResponse) query; events_window : (EventsWindowArgs) -> (EventsResponse) query; - local_user_index : (LocalUserIndexArgs) -> (LocalUserIndexResponse) query; messages_by_message_index : (MessagesByMessageIndexArgs) -> (MessagesByMessageIndexResponse) query; thread_previews : (ThreadPreviewsArgs) -> (ThreadPreviewsResponse) query; deleted_message : (DeletedMessageArgs) -> (DeletedMessageResponse) query; diff --git a/backend/canisters/group/api/src/main.rs b/backend/canisters/group/api/src/main.rs index 76c8e6ac30..1452a099d1 100644 --- a/backend/canisters/group/api/src/main.rs +++ b/backend/canisters/group/api/src/main.rs @@ -7,7 +7,6 @@ fn main() { generate_candid_method!(group, events_by_index, query); generate_candid_method!(group, events_window, query); generate_candid_method!(group, invite_code, query); - generate_candid_method!(group, local_user_index, query); generate_candid_method!(group, messages_by_message_index, query); generate_candid_method!(group, thread_previews, query); generate_candid_method!(group, public_summary, query); diff --git a/backend/canisters/group/api/src/queries/local_user_index.rs b/backend/canisters/group/api/src/queries/local_user_index.rs deleted file mode 100644 index 91c8faf6ff..0000000000 --- a/backend/canisters/group/api/src/queries/local_user_index.rs +++ /dev/null @@ -1,10 +0,0 @@ -use candid::CandidType; -use serde::{Deserialize, Serialize}; -use types::{CanisterId, Empty}; - -pub type Args = Empty; - -#[derive(CandidType, Serialize, Deserialize, Debug)] -pub enum Response { - Success(CanisterId), -} diff --git a/backend/canisters/group/api/src/queries/mod.rs b/backend/canisters/group/api/src/queries/mod.rs index 6b68f12244..b091557c54 100644 --- a/backend/canisters/group/api/src/queries/mod.rs +++ b/backend/canisters/group/api/src/queries/mod.rs @@ -10,7 +10,6 @@ pub mod events; pub mod events_by_index; pub mod events_window; pub mod invite_code; -pub mod local_user_index; pub mod messages_by_message_index; pub mod public_summary; pub mod rules; diff --git a/backend/canisters/group/c2c_client/src/lib.rs b/backend/canisters/group/c2c_client/src/lib.rs index fddfcc9612..f5952ccc9d 100644 --- a/backend/canisters/group/c2c_client/src/lib.rs +++ b/backend/canisters/group/c2c_client/src/lib.rs @@ -13,7 +13,6 @@ generate_c2c_call!(public_summary); generate_candid_c2c_call!(events); generate_candid_c2c_call!(invite_code); -generate_candid_c2c_call!(local_user_index); generate_candid_c2c_call!(selected_initial); // Updates diff --git a/backend/canisters/group/client/src/lib.rs b/backend/canisters/group/client/src/lib.rs index da08ef99c3..a35cf390b4 100644 --- a/backend/canisters/group/client/src/lib.rs +++ b/backend/canisters/group/client/src/lib.rs @@ -4,7 +4,6 @@ use group_canister::*; // Queries generate_query_call!(events); generate_query_call!(events_by_index); -generate_query_call!(local_user_index); generate_query_call!(selected_initial); generate_query_call!(selected_updates_v2); diff --git a/backend/canisters/group/impl/src/queries/local_user_index.rs b/backend/canisters/group/impl/src/queries/local_user_index.rs deleted file mode 100644 index 1ea2681c9f..0000000000 --- a/backend/canisters/group/impl/src/queries/local_user_index.rs +++ /dev/null @@ -1,12 +0,0 @@ -use crate::{read_state, RuntimeState}; -use group_canister::local_user_index::{Response::*, *}; -use ic_cdk_macros::query; - -#[query] -fn local_user_index(_args: Args) -> Response { - read_state(local_user_index_impl) -} - -fn local_user_index_impl(state: &RuntimeState) -> Response { - Success(state.data.local_user_index_canister_id) -} diff --git a/backend/canisters/group/impl/src/queries/mod.rs b/backend/canisters/group/impl/src/queries/mod.rs index 671001fa80..561d2bd3d4 100644 --- a/backend/canisters/group/impl/src/queries/mod.rs +++ b/backend/canisters/group/impl/src/queries/mod.rs @@ -9,7 +9,6 @@ mod events_by_index; mod events_window; mod http_request; mod invite_code; -mod local_user_index; mod messages_by_message_index; mod public_summary; mod rules; diff --git a/frontend/app/src/components/register/Register.svelte b/frontend/app/src/components/register/Register.svelte index e4ef07df4e..443aa52fdc 100644 --- a/frontend/app/src/components/register/Register.svelte +++ b/frontend/app/src/components/register/Register.svelte @@ -66,12 +66,6 @@ error.set("register.usernameTooLong"); } else if (resp.kind === "username_invalid") { error.set("register.usernameInvalid"); - } else if (resp.kind === "display_name_too_short") { - error.set("register.displayNameTooShort"); - } else if (resp.kind === "display_name_too_long") { - error.set("register.displayNameTooLong"); - } else if (resp.kind === "display_name_invalid") { - error.set("register.displayNameInvalid"); } else if (resp.kind === "user_limit_reached") { error.set("register.userLimitReached"); } else if (resp.kind === "internal_error") { diff --git a/frontend/app/src/stores/community.ts b/frontend/app/src/stores/community.ts index eaaa1d4565..aaf0985bf9 100644 --- a/frontend/app/src/stores/community.ts +++ b/frontend/app/src/stores/community.ts @@ -44,5 +44,6 @@ export function createCandidateCommunity(id: string, index: number): CommunitySu primaryLanguage: "en", metrics: emptyChatMetrics(), userGroups: new Map(), + localUserIndex: "", }; } diff --git a/frontend/openchat-agent/src/services/common/chatMappers.ts b/frontend/openchat-agent/src/services/common/chatMappers.ts index fcc586c460..9235b7b33b 100644 --- a/frontend/openchat-agent/src/services/common/chatMappers.ts +++ b/frontend/openchat-agent/src/services/common/chatMappers.ts @@ -1521,6 +1521,7 @@ export function groupChatSummary(candid: ApiGroupCanisterGroupChatSummary): Grou archived: false, rulesAccepted: candid.rules_accepted, }, + localUserIndex: candid.local_user_index_canister_id.toString(), }; } @@ -1565,6 +1566,7 @@ export function communitySummary(candid: ApiCommunityCanisterCommunitySummary): channels: candid.channels.map((c) => communityChannelSummary(c, communityId)), primaryLanguage: candid.primary_language, userGroups: new Map(candid.user_groups.map(userGroup)), + localUserIndex: candid.local_user_index_canister_id.toString(), }; } diff --git a/frontend/openchat-agent/src/services/common/publicSummaryMapper.ts b/frontend/openchat-agent/src/services/common/publicSummaryMapper.ts index c55643e77d..92d67382e3 100644 --- a/frontend/openchat-agent/src/services/common/publicSummaryMapper.ts +++ b/frontend/openchat-agent/src/services/common/publicSummaryMapper.ts @@ -56,6 +56,7 @@ export function publicGroupSummary(candid: ApiPublicGroupSummary): GroupChatSumm gate: optional(candid.gate, accessGate) ?? { kind: "no_gate" }, level: "group", membership: nullMembership(), + localUserIndex: candid.local_user_index_canister_id.toString(), }; } diff --git a/frontend/openchat-agent/src/services/community/candid/idl.d.ts b/frontend/openchat-agent/src/services/community/candid/idl.d.ts index b7f160b27f..a9d92d6cd0 100644 --- a/frontend/openchat-agent/src/services/community/candid/idl.d.ts +++ b/frontend/openchat-agent/src/services/community/candid/idl.d.ts @@ -24,7 +24,6 @@ import { InviteCodeResponse, JoinChannelResponse, LeaveChannelResponse, - LocalUserIndexResponse, MakeChannelPrivateResponse, MessagesByMessageIndexResponse, OptionalCommunityPermissions, @@ -101,7 +100,6 @@ export { InviteCodeResponse as ApiInviteCodeResponse, JoinChannelResponse as ApiJoinChannelResponse, LeaveChannelResponse as ApiLeaveChannelResponse, - LocalUserIndexResponse as ApiLocalUserIndexResponse, MakeChannelPrivateResponse as ApiMakeChannelPrivateResponse, MessagesByMessageIndexResponse as ApiMessagesByMessageIndexResponse, OptionalCommunityPermissions as ApiOptionalCommunityPermissions, diff --git a/frontend/openchat-agent/src/services/community/candid/idl.js b/frontend/openchat-agent/src/services/community/candid/idl.js index b6d5a1f26d..9a1caddf82 100644 --- a/frontend/openchat-agent/src/services/community/candid/idl.js +++ b/frontend/openchat-agent/src/services/community/candid/idl.js @@ -1510,6 +1510,7 @@ export const idlFactory = ({ IDL }) => { 'user_groups' : IDL.Vec(UserGroup), 'avatar_id' : IDL.Opt(IDL.Nat), 'membership' : IDL.Opt(CommunityMembership), + 'local_user_index_canister_id' : CanisterId, 'frozen' : IDL.Opt(FrozenGroupInfo), 'latest_event_index' : EventIndex, 'banner_id' : IDL.Opt(IDL.Nat), diff --git a/frontend/openchat-agent/src/services/community/candid/types.d.ts b/frontend/openchat-agent/src/services/community/candid/types.d.ts index 10a3768afd..668b7d5ce2 100644 --- a/frontend/openchat-agent/src/services/community/candid/types.d.ts +++ b/frontend/openchat-agent/src/services/community/candid/types.d.ts @@ -381,6 +381,7 @@ export interface CommunityCanisterCommunitySummary { 'user_groups' : Array, 'avatar_id' : [] | [bigint], 'membership' : [] | [CommunityMembership], + 'local_user_index_canister_id' : CanisterId, 'frozen' : [] | [FrozenGroupInfo], 'latest_event_index' : EventIndex, 'banner_id' : [] | [bigint], @@ -830,6 +831,7 @@ export interface GroupCanisterGroupChatSummary { 'avatar_id' : [] | [bigint], 'rules_accepted' : boolean, 'membership' : [] | [GroupMembership], + 'local_user_index_canister_id' : CanisterId, 'latest_threads' : Array, 'frozen' : [] | [FrozenGroupInfo], 'latest_event_index' : EventIndex, @@ -902,6 +904,7 @@ export interface GroupChatSummary { 'joined' : TimestampMillis, 'avatar_id' : [] | [bigint], 'rules_accepted' : boolean, + 'local_user_index_canister_id' : CanisterId, 'latest_threads' : Array, 'frozen' : [] | [FrozenGroupInfo], 'latest_event_index' : EventIndex, @@ -1490,6 +1493,7 @@ export interface PublicGroupSummary { 'events_ttl' : [] | [Milliseconds], 'last_updated' : TimestampMillis, 'avatar_id' : [] | [bigint], + 'local_user_index_canister_id' : CanisterId, 'frozen' : [] | [FrozenGroupInfo], 'latest_event_index' : EventIndex, 'history_visible_to_new_joiners' : boolean, diff --git a/frontend/openchat-agent/src/services/community/community.client.ts b/frontend/openchat-agent/src/services/community/community.client.ts index c81610e7bf..d2ac1a353b 100644 --- a/frontend/openchat-agent/src/services/community/community.client.ts +++ b/frontend/openchat-agent/src/services/community/community.client.ts @@ -7,7 +7,6 @@ import type { AgentConfig } from "../../config"; import { addMembersToChannelResponse, blockUserResponse, - localUserIndexResponse, messagesByMessageIndexResponse, removeMemberResponse, removeMemberFromChannelResponse, @@ -636,10 +635,6 @@ export class CommunityClient extends CandidService { ); } - localUserIndex(): Promise { - return this.handleResponse(this.service.local_user_index({}), localUserIndexResponse); - } - messagesByMessageIndex( chatId: ChannelIdentifier, messageIndexes: number[], diff --git a/frontend/openchat-agent/src/services/community/mappers.ts b/frontend/openchat-agent/src/services/community/mappers.ts index ccf82fcc7a..84b4188348 100644 --- a/frontend/openchat-agent/src/services/community/mappers.ts +++ b/frontend/openchat-agent/src/services/community/mappers.ts @@ -41,7 +41,6 @@ import type { ApiAddMembersToChannelResponse, ApiBlockUserResponse, ApiChangeRoleResponse, - ApiLocalUserIndexResponse, ApiMessagesByMessageIndexResponse, ApiRemoveMemberResponse, ApiRemoveMemberFromChannelResponse, @@ -215,10 +214,6 @@ export function changeRoleResponse(candid: ApiChangeRoleResponse): ChangeCommuni } } -export function localUserIndexResponse(candid: ApiLocalUserIndexResponse): string { - return candid.Success.toString(); -} - export async function messagesByMessageIndexResponse( principal: Principal, candid: ApiMessagesByMessageIndexResponse, diff --git a/frontend/openchat-agent/src/services/group/candid/idl.js b/frontend/openchat-agent/src/services/group/candid/idl.js index b3dc7fac71..2476c99892 100644 --- a/frontend/openchat-agent/src/services/group/candid/idl.js +++ b/frontend/openchat-agent/src/services/group/candid/idl.js @@ -842,6 +842,7 @@ export const idlFactory = ({ IDL }) => { 'events_ttl' : IDL.Opt(Milliseconds), 'last_updated' : TimestampMillis, 'avatar_id' : IDL.Opt(IDL.Nat), + 'local_user_index_canister_id' : CanisterId, 'frozen' : IDL.Opt(FrozenGroupInfo), 'latest_event_index' : EventIndex, 'history_visible_to_new_joiners' : IDL.Bool, @@ -1135,6 +1136,7 @@ export const idlFactory = ({ IDL }) => { 'avatar_id' : IDL.Opt(IDL.Nat), 'rules_accepted' : IDL.Bool, 'membership' : IDL.Opt(GroupMembership), + 'local_user_index_canister_id' : CanisterId, 'latest_threads' : IDL.Vec(GroupCanisterThreadDetails), 'frozen' : IDL.Opt(FrozenGroupInfo), 'latest_event_index' : EventIndex, diff --git a/frontend/openchat-agent/src/services/group/candid/types.d.ts b/frontend/openchat-agent/src/services/group/candid/types.d.ts index d770e84999..630dd9e245 100644 --- a/frontend/openchat-agent/src/services/group/candid/types.d.ts +++ b/frontend/openchat-agent/src/services/group/candid/types.d.ts @@ -312,6 +312,7 @@ export interface CommunityCanisterCommunitySummary { 'user_groups' : Array, 'avatar_id' : [] | [bigint], 'membership' : [] | [CommunityMembership], + 'local_user_index_canister_id' : CanisterId, 'frozen' : [] | [FrozenGroupInfo], 'latest_event_index' : EventIndex, 'banner_id' : [] | [bigint], @@ -695,6 +696,7 @@ export interface GroupCanisterGroupChatSummary { 'avatar_id' : [] | [bigint], 'rules_accepted' : boolean, 'membership' : [] | [GroupMembership], + 'local_user_index_canister_id' : CanisterId, 'latest_threads' : Array, 'frozen' : [] | [FrozenGroupInfo], 'latest_event_index' : EventIndex, @@ -767,6 +769,7 @@ export interface GroupChatSummary { 'joined' : TimestampMillis, 'avatar_id' : [] | [bigint], 'rules_accepted' : boolean, + 'local_user_index_canister_id' : CanisterId, 'latest_threads' : Array, 'frozen' : [] | [FrozenGroupInfo], 'latest_event_index' : EventIndex, @@ -1334,6 +1337,7 @@ export interface PublicGroupSummary { 'events_ttl' : [] | [Milliseconds], 'last_updated' : TimestampMillis, 'avatar_id' : [] | [bigint], + 'local_user_index_canister_id' : CanisterId, 'frozen' : [] | [FrozenGroupInfo], 'latest_event_index' : EventIndex, 'history_visible_to_new_joiners' : boolean, diff --git a/frontend/openchat-agent/src/services/group/group.client.ts b/frontend/openchat-agent/src/services/group/group.client.ts index 6067e66e3b..d22e23801c 100644 --- a/frontend/openchat-agent/src/services/group/group.client.ts +++ b/frontend/openchat-agent/src/services/group/group.client.ts @@ -845,13 +845,6 @@ export class GroupClient extends CandidService { ); } - localUserIndex(): Promise { - return this.handleQueryResponse( - () => this.groupService.local_user_index({}), - (resp) => resp.Success.toString(), - ); - } - declineInvitation(): Promise { return this.handleResponse( this.groupService.decline_invitation({}), diff --git a/frontend/openchat-agent/src/services/group/mappers.ts b/frontend/openchat-agent/src/services/group/mappers.ts index e26ba24dae..a6b8d48ef7 100644 --- a/frontend/openchat-agent/src/services/group/mappers.ts +++ b/frontend/openchat-agent/src/services/group/mappers.ts @@ -131,6 +131,7 @@ function groupChatSummary(candid: ApiGroupCanisterGroupChatSummary): GroupCanist rulesAccepted: candid.rules_accepted, eventsTTL: optional(candid.events_ttl, identity), eventsTtlLastUpdated: candid.events_ttl_last_updated, + localUserIndex: candid.local_user_index_canister_id.toString(), }; } diff --git a/frontend/openchat-agent/src/services/groupIndex/candid/idl.js b/frontend/openchat-agent/src/services/groupIndex/candid/idl.js index 44d827ffd1..28b4cae340 100644 --- a/frontend/openchat-agent/src/services/groupIndex/candid/idl.js +++ b/frontend/openchat-agent/src/services/groupIndex/candid/idl.js @@ -553,6 +553,7 @@ export const idlFactory = ({ IDL }) => { 'events_ttl' : IDL.Opt(Milliseconds), 'last_updated' : TimestampMillis, 'avatar_id' : IDL.Opt(IDL.Nat), + 'local_user_index_canister_id' : CanisterId, 'frozen' : IDL.Opt(FrozenGroupInfo), 'latest_event_index' : EventIndex, 'history_visible_to_new_joiners' : IDL.Bool, diff --git a/frontend/openchat-agent/src/services/groupIndex/candid/types.d.ts b/frontend/openchat-agent/src/services/groupIndex/candid/types.d.ts index d7bd59f133..451cdf13e3 100644 --- a/frontend/openchat-agent/src/services/groupIndex/candid/types.d.ts +++ b/frontend/openchat-agent/src/services/groupIndex/candid/types.d.ts @@ -278,6 +278,7 @@ export interface CommunityCanisterCommunitySummary { 'user_groups' : Array, 'avatar_id' : [] | [bigint], 'membership' : [] | [CommunityMembership], + 'local_user_index_canister_id' : CanisterId, 'frozen' : [] | [FrozenGroupInfo], 'latest_event_index' : EventIndex, 'banner_id' : [] | [bigint], @@ -659,6 +660,7 @@ export interface GroupCanisterGroupChatSummary { 'avatar_id' : [] | [bigint], 'rules_accepted' : boolean, 'membership' : [] | [GroupMembership], + 'local_user_index_canister_id' : CanisterId, 'latest_threads' : Array, 'frozen' : [] | [FrozenGroupInfo], 'latest_event_index' : EventIndex, @@ -731,6 +733,7 @@ export interface GroupChatSummary { 'joined' : TimestampMillis, 'avatar_id' : [] | [bigint], 'rules_accepted' : boolean, + 'local_user_index_canister_id' : CanisterId, 'latest_threads' : Array, 'frozen' : [] | [FrozenGroupInfo], 'latest_event_index' : EventIndex, @@ -1273,6 +1276,7 @@ export interface PublicGroupSummary { 'events_ttl' : [] | [Milliseconds], 'last_updated' : TimestampMillis, 'avatar_id' : [] | [bigint], + 'local_user_index_canister_id' : CanisterId, 'frozen' : [] | [FrozenGroupInfo], 'latest_event_index' : EventIndex, 'history_visible_to_new_joiners' : boolean, diff --git a/frontend/openchat-agent/src/services/localUserIndex/candid/idl.js b/frontend/openchat-agent/src/services/localUserIndex/candid/idl.js index c296fb6af8..146df9628b 100644 --- a/frontend/openchat-agent/src/services/localUserIndex/candid/idl.js +++ b/frontend/openchat-agent/src/services/localUserIndex/candid/idl.js @@ -596,6 +596,7 @@ export const idlFactory = ({ IDL }) => { 'user_groups' : IDL.Vec(UserGroup), 'avatar_id' : IDL.Opt(IDL.Nat), 'membership' : IDL.Opt(CommunityMembership), + 'local_user_index_canister_id' : CanisterId, 'frozen' : IDL.Opt(FrozenGroupInfo), 'latest_event_index' : EventIndex, 'banner_id' : IDL.Opt(IDL.Nat), @@ -685,6 +686,7 @@ export const idlFactory = ({ IDL }) => { 'avatar_id' : IDL.Opt(IDL.Nat), 'rules_accepted' : IDL.Bool, 'membership' : IDL.Opt(GroupMembership), + 'local_user_index_canister_id' : CanisterId, 'latest_threads' : IDL.Vec(GroupCanisterThreadDetails), 'frozen' : IDL.Opt(FrozenGroupInfo), 'latest_event_index' : EventIndex, @@ -714,7 +716,6 @@ export const idlFactory = ({ IDL }) => { const RegisterUserArgs = IDL.Record({ 'username' : IDL.Text, 'public_key' : IDL.Vec(IDL.Nat8), - 'display_name' : IDL.Opt(IDL.Text), 'referral_code' : IDL.Opt(IDL.Text), }); const RegisterUserResponse = IDL.Variant({ @@ -722,14 +723,11 @@ export const idlFactory = ({ IDL }) => { 'UsernameInvalid' : IDL.Null, 'AlreadyRegistered' : IDL.Null, 'UserLimitReached' : IDL.Null, - 'DisplayNameInvalid' : IDL.Null, 'UsernameTooLong' : IDL.Nat16, 'Success' : IDL.Record({ 'icp_account' : AccountIdentifier, 'user_id' : UserId, }), - 'DisplayNameTooLong' : IDL.Nat16, - 'DisplayNameTooShort' : IDL.Nat16, 'PublicKeyInvalid' : IDL.Text, 'ReferralCodeAlreadyClaimed' : IDL.Null, 'ReferralCodeExpired' : IDL.Null, 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 6f81dda4f8..ef5d5b336e 100644 --- a/frontend/openchat-agent/src/services/localUserIndex/candid/types.d.ts +++ b/frontend/openchat-agent/src/services/localUserIndex/candid/types.d.ts @@ -258,6 +258,7 @@ export interface CommunityCanisterCommunitySummary { 'user_groups' : Array, 'avatar_id' : [] | [bigint], 'membership' : [] | [CommunityMembership], + 'local_user_index_canister_id' : CanisterId, 'frozen' : [] | [FrozenGroupInfo], 'latest_event_index' : EventIndex, 'banner_id' : [] | [bigint], @@ -549,6 +550,7 @@ export interface GroupCanisterGroupChatSummary { 'avatar_id' : [] | [bigint], 'rules_accepted' : boolean, 'membership' : [] | [GroupMembership], + 'local_user_index_canister_id' : CanisterId, 'latest_threads' : Array, 'frozen' : [] | [FrozenGroupInfo], 'latest_event_index' : EventIndex, @@ -621,6 +623,7 @@ export interface GroupChatSummary { 'joined' : TimestampMillis, 'avatar_id' : [] | [bigint], 'rules_accepted' : boolean, + 'local_user_index_canister_id' : CanisterId, 'latest_threads' : Array, 'frozen' : [] | [FrozenGroupInfo], 'latest_event_index' : EventIndex, @@ -1255,6 +1258,7 @@ export interface PublicGroupSummary { 'events_ttl' : [] | [Milliseconds], 'last_updated' : TimestampMillis, 'avatar_id' : [] | [bigint], + 'local_user_index_canister_id' : CanisterId, 'frozen' : [] | [FrozenGroupInfo], 'latest_event_index' : EventIndex, 'history_visible_to_new_joiners' : boolean, @@ -1272,18 +1276,14 @@ export type Reaction = string; export interface RegisterUserArgs { 'username' : string, 'public_key' : Uint8Array | number[], - 'display_name' : [] | [string], 'referral_code' : [] | [string], } export type RegisterUserResponse = { 'UsernameTooShort' : number } | { 'UsernameInvalid' : null } | { 'AlreadyRegistered' : null } | { 'UserLimitReached' : null } | - { 'DisplayNameInvalid' : null } | { 'UsernameTooLong' : number } | { 'Success' : { 'icp_account' : AccountIdentifier, 'user_id' : UserId } } | - { 'DisplayNameTooLong' : number } | - { 'DisplayNameTooShort' : number } | { 'PublicKeyInvalid' : string } | { 'ReferralCodeAlreadyClaimed' : null } | { 'ReferralCodeExpired' : null } | diff --git a/frontend/openchat-agent/src/services/localUserIndex/localUserIndex.client.ts b/frontend/openchat-agent/src/services/localUserIndex/localUserIndex.client.ts index 1a6fb0d72a..bc7b68da8e 100644 --- a/frontend/openchat-agent/src/services/localUserIndex/localUserIndex.client.ts +++ b/frontend/openchat-agent/src/services/localUserIndex/localUserIndex.client.ts @@ -48,7 +48,6 @@ export class LocalUserIndexClient extends CandidService { return this.handleResponse( this.localUserIndexService.register_user({ username, - display_name: [], referral_code: apiOptional(identity, referralCode), public_key: new Uint8Array((this.identity as SignIdentity).getPublicKey().toDer()), }), diff --git a/frontend/openchat-agent/src/services/localUserIndex/mappers.ts b/frontend/openchat-agent/src/services/localUserIndex/mappers.ts index 6dcb055ef5..7bd4010803 100644 --- a/frontend/openchat-agent/src/services/localUserIndex/mappers.ts +++ b/frontend/openchat-agent/src/services/localUserIndex/mappers.ts @@ -21,7 +21,7 @@ import { export function joinChannelResponse( candid: ApiJoinChannelResponse, - communityId: string + communityId: string, ): JoinGroupResponse { if ("Success" in candid) { return { kind: "success", group: communityChannelSummary(candid.Success, communityId) }; @@ -66,15 +66,6 @@ export function registerUserResponse(candid: ApiRegisterUserResponse): RegisterU if ("UsernameInvalid" in candid) { return { kind: "username_invalid" }; } - if ("DisplayNameTooShort" in candid) { - return { kind: "display_name_too_short" }; - } - if ("DisplayNameTooLong" in candid) { - return { kind: "display_name_too_long" }; - } - if ("DisplayNameInvalid" in candid) { - return { kind: "display_name_invalid" }; - } if ("AlreadyRegistered" in candid) { return { kind: "already_registered" }; } @@ -107,7 +98,7 @@ export function registerUserResponse(candid: ApiRegisterUserResponse): RegisterU } export function inviteUsersResponse( - candid: ApiInviteUsersResponse | ApiInviteUsersToChannelResponse + candid: ApiInviteUsersResponse | ApiInviteUsersToChannelResponse, ): InviteUsersResponse { if ("Success" in candid) { return "success"; diff --git a/frontend/openchat-agent/src/services/notifications/candid/types.d.ts b/frontend/openchat-agent/src/services/notifications/candid/types.d.ts index 9898b14391..512fa5b682 100644 --- a/frontend/openchat-agent/src/services/notifications/candid/types.d.ts +++ b/frontend/openchat-agent/src/services/notifications/candid/types.d.ts @@ -258,6 +258,7 @@ export interface CommunityCanisterCommunitySummary { 'user_groups' : Array, 'avatar_id' : [] | [bigint], 'membership' : [] | [CommunityMembership], + 'local_user_index_canister_id' : CanisterId, 'frozen' : [] | [FrozenGroupInfo], 'latest_event_index' : EventIndex, 'banner_id' : [] | [bigint], @@ -549,6 +550,7 @@ export interface GroupCanisterGroupChatSummary { 'avatar_id' : [] | [bigint], 'rules_accepted' : boolean, 'membership' : [] | [GroupMembership], + 'local_user_index_canister_id' : CanisterId, 'latest_threads' : Array, 'frozen' : [] | [FrozenGroupInfo], 'latest_event_index' : EventIndex, @@ -621,6 +623,7 @@ export interface GroupChatSummary { 'joined' : TimestampMillis, 'avatar_id' : [] | [bigint], 'rules_accepted' : boolean, + 'local_user_index_canister_id' : CanisterId, 'latest_threads' : Array, 'frozen' : [] | [FrozenGroupInfo], 'latest_event_index' : EventIndex, @@ -1160,6 +1163,7 @@ export interface PublicGroupSummary { 'events_ttl' : [] | [Milliseconds], 'last_updated' : TimestampMillis, 'avatar_id' : [] | [bigint], + 'local_user_index_canister_id' : CanisterId, 'frozen' : [] | [FrozenGroupInfo], 'latest_event_index' : EventIndex, 'history_visible_to_new_joiners' : boolean, diff --git a/frontend/openchat-agent/src/services/online/candid/types.d.ts b/frontend/openchat-agent/src/services/online/candid/types.d.ts index 5187144c61..2eb801d940 100644 --- a/frontend/openchat-agent/src/services/online/candid/types.d.ts +++ b/frontend/openchat-agent/src/services/online/candid/types.d.ts @@ -258,6 +258,7 @@ export interface CommunityCanisterCommunitySummary { 'user_groups' : Array, 'avatar_id' : [] | [bigint], 'membership' : [] | [CommunityMembership], + 'local_user_index_canister_id' : CanisterId, 'frozen' : [] | [FrozenGroupInfo], 'latest_event_index' : EventIndex, 'banner_id' : [] | [bigint], @@ -549,6 +550,7 @@ export interface GroupCanisterGroupChatSummary { 'avatar_id' : [] | [bigint], 'rules_accepted' : boolean, 'membership' : [] | [GroupMembership], + 'local_user_index_canister_id' : CanisterId, 'latest_threads' : Array, 'frozen' : [] | [FrozenGroupInfo], 'latest_event_index' : EventIndex, @@ -621,6 +623,7 @@ export interface GroupChatSummary { 'joined' : TimestampMillis, 'avatar_id' : [] | [bigint], 'rules_accepted' : boolean, + 'local_user_index_canister_id' : CanisterId, 'latest_threads' : Array, 'frozen' : [] | [FrozenGroupInfo], 'latest_event_index' : EventIndex, @@ -1170,6 +1173,7 @@ export interface PublicGroupSummary { 'events_ttl' : [] | [Milliseconds], 'last_updated' : TimestampMillis, 'avatar_id' : [] | [bigint], + 'local_user_index_canister_id' : CanisterId, 'frozen' : [] | [FrozenGroupInfo], 'latest_event_index' : EventIndex, 'history_visible_to_new_joiners' : boolean, diff --git a/frontend/openchat-agent/src/services/openchatAgent.ts b/frontend/openchat-agent/src/services/openchatAgent.ts index e9845b33a7..5ab6cf638a 100644 --- a/frontend/openchat-agent/src/services/openchatAgent.ts +++ b/frontend/openchat-agent/src/services/openchatAgent.ts @@ -574,6 +574,7 @@ export class OpenChatAgent extends EventTarget { async inviteUsersToCommunity( id: CommunityIdentifier, + localUserIndex: string, userIds: string[], ): Promise { if (!userIds.length) { @@ -582,8 +583,7 @@ export class OpenChatAgent extends EventTarget { if (offline()) return Promise.resolve("failure"); - const communityLocalUserIndex = await this.communityClient(id.communityId).localUserIndex(); - return this.createLocalUserIndexClient(communityLocalUserIndex).inviteUsersToCommunity( + return this.createLocalUserIndexClient(localUserIndex).inviteUsersToCommunity( id.communityId, userIds, ); @@ -591,6 +591,7 @@ export class OpenChatAgent extends EventTarget { async inviteUsers( chatId: MultiUserChatIdentifier, + localUserIndex: string, userIds: string[], ): Promise { if (!userIds.length) { @@ -599,22 +600,17 @@ export class OpenChatAgent extends EventTarget { if (offline()) return Promise.resolve("failure"); + const localUserIndexClient = this.createLocalUserIndexClient(localUserIndex); + switch (chatId.kind) { case "group_chat": - const groupLocalUserIndex = await this.getGroupClient( - chatId.groupId, - ).localUserIndex(); - return this.createLocalUserIndexClient(groupLocalUserIndex).inviteUsersToGroup( - chatId.groupId, - userIds, - ); + return localUserIndexClient.inviteUsersToGroup(chatId.groupId, userIds); case "channel": - const communityLocalUserIndex = await this.communityClient( + return localUserIndexClient.inviteUsersToChannel( chatId.communityId, - ).localUserIndex(); - return this.createLocalUserIndexClient( - communityLocalUserIndex, - ).inviteUsersToChannel(chatId.communityId, chatId.channelId, userIds); + chatId.channelId, + userIds, + ); } } @@ -1819,40 +1815,31 @@ export class OpenChatAgent extends EventTarget { async joinGroup( chatId: MultiUserChatIdentifier, + localUserIndex: string, _credential?: string, ): Promise { if (offline()) return Promise.resolve(CommonResponses.offline()); + const localUserIndexClient = this.createLocalUserIndexClient(localUserIndex); + switch (chatId.kind) { case "group_chat": const groupInviteCode = this.getProvidedGroupInviteCode(chatId); - const groupLocalUserIndex = await this.getGroupClient( - chatId.groupId, - ).localUserIndex(); - return this.createLocalUserIndexClient(groupLocalUserIndex).joinGroup( - chatId.groupId, - groupInviteCode, - ); + return localUserIndexClient.joinGroup(chatId.groupId, groupInviteCode); case "channel": const communityInviteCode = this.getProvidedCommunityInviteCode(chatId.communityId); - const communityLocalIndex = await this.communityClient( - chatId.communityId, - ).localUserIndex(); - return this.createLocalUserIndexClient(communityLocalIndex).joinChannel( - chatId, - communityInviteCode, - ); + return localUserIndexClient.joinChannel(chatId, communityInviteCode); } } async joinCommunity( id: CommunityIdentifier, + localUserIndex: string, _credential?: string, ): Promise { if (offline()) return Promise.resolve(CommonResponses.offline()); const inviteCode = this.getProvidedCommunityInviteCode(id.communityId); - const localUserIndex = await this.communityClient(id.communityId).localUserIndex(); return this.createLocalUserIndexClient(localUserIndex).joinCommunity( id.communityId, inviteCode, @@ -2863,16 +2850,24 @@ export class OpenChatAgent extends EventTarget { return this._dexesAgent.canSwap(tokenLedgers); } - getTokenSwaps(inputTokenLedger: string, outputTokenLedgers: string[]): Promise> { - return this._dexesAgent.getSwapPools(inputTokenLedger, new Set(outputTokenLedgers)).then((pools) => { - return pools.reduce(swapReducer, {} as Record) - }); + getTokenSwaps( + inputTokenLedger: string, + outputTokenLedgers: string[], + ): Promise> { + return this._dexesAgent + .getSwapPools(inputTokenLedger, new Set(outputTokenLedgers)) + .then((pools) => { + return pools.reduce(swapReducer, {} as Record); + }); - function swapReducer(result: Record, pool: TokenSwapPool): Record { + function swapReducer( + result: Record, + pool: TokenSwapPool, + ): Record { const outputTokenLedger = inputTokenLedger === pool.token0 ? pool.token1 : pool.token0; - return { - ...result, - [outputTokenLedger]: [...(result[outputTokenLedger] || []), pool.dex] + return { + ...result, + [outputTokenLedger]: [...(result[outputTokenLedger] || []), pool.dex], }; } } @@ -2882,13 +2877,18 @@ export class OpenChatAgent extends EventTarget { outputTokenLedger: string, amountIn: bigint, ): Promise<[DexId, bigint][]> { - return this._dexesAgent.quoteSwap(inputTokenLedger, outputTokenLedger, amountIn).then((quotes) => { - // Sort the quotes by amount descending so the first quote is the best - quotes.sort(compare); - return quotes; - }); + return this._dexesAgent + .quoteSwap(inputTokenLedger, outputTokenLedger, amountIn) + .then((quotes) => { + // Sort the quotes by amount descending so the first quote is the best + quotes.sort(compare); + return quotes; + }); - function compare([_dexA, amountA]: [DexId, bigint], [_dexB, amountB]: [DexId, bigint]): number { + function compare( + [_dexA, amountA]: [DexId, bigint], + [_dexB, amountB]: [DexId, bigint], + ): number { if (amountA > amountB) { return -1; } @@ -2910,12 +2910,16 @@ export class OpenChatAgent extends EventTarget { return this._dexesAgent .getSwapPools(inputTokenDetails.ledger, new Set([outputTokenDetails.ledger])) .then((pools) => { - const pool = pools.find((p) => p.dex === dex && p.token0 === inputTokenDetails.ledger || p.token0 === outputTokenDetails.ledger); + const pool = pools.find( + (p) => + (p.dex === dex && p.token0 === inputTokenDetails.ledger) || + p.token0 === outputTokenDetails.ledger, + ); if (pool === undefined) { return Promise.reject("Cannot find a matching pool"); } - + const exchangeArgs: ExchangeTokenSwapArgs = { dex, swapCanisterId: pool.canisterId, @@ -2929,7 +2933,7 @@ export class OpenChatAgent extends EventTarget { amountIn, minAmountOut, exchangeArgs, - ); + ); }); } diff --git a/frontend/openchat-agent/src/services/proposalsBot/candid/types.d.ts b/frontend/openchat-agent/src/services/proposalsBot/candid/types.d.ts index b2b6e761b8..9e216ab6a1 100644 --- a/frontend/openchat-agent/src/services/proposalsBot/candid/types.d.ts +++ b/frontend/openchat-agent/src/services/proposalsBot/candid/types.d.ts @@ -258,6 +258,7 @@ export interface CommunityCanisterCommunitySummary { 'user_groups' : Array, 'avatar_id' : [] | [bigint], 'membership' : [] | [CommunityMembership], + 'local_user_index_canister_id' : CanisterId, 'frozen' : [] | [FrozenGroupInfo], 'latest_event_index' : EventIndex, 'banner_id' : [] | [bigint], @@ -549,6 +550,7 @@ export interface GroupCanisterGroupChatSummary { 'avatar_id' : [] | [bigint], 'rules_accepted' : boolean, 'membership' : [] | [GroupMembership], + 'local_user_index_canister_id' : CanisterId, 'latest_threads' : Array, 'frozen' : [] | [FrozenGroupInfo], 'latest_event_index' : EventIndex, @@ -621,6 +623,7 @@ export interface GroupChatSummary { 'joined' : TimestampMillis, 'avatar_id' : [] | [bigint], 'rules_accepted' : boolean, + 'local_user_index_canister_id' : CanisterId, 'latest_threads' : Array, 'frozen' : [] | [FrozenGroupInfo], 'latest_event_index' : EventIndex, @@ -1160,6 +1163,7 @@ export interface PublicGroupSummary { 'events_ttl' : [] | [Milliseconds], 'last_updated' : TimestampMillis, 'avatar_id' : [] | [bigint], + 'local_user_index_canister_id' : CanisterId, 'frozen' : [] | [FrozenGroupInfo], 'latest_event_index' : EventIndex, 'history_visible_to_new_joiners' : boolean, diff --git a/frontend/openchat-agent/src/services/registry/candid/types.d.ts b/frontend/openchat-agent/src/services/registry/candid/types.d.ts index 8cc2583fc2..09b63a750b 100644 --- a/frontend/openchat-agent/src/services/registry/candid/types.d.ts +++ b/frontend/openchat-agent/src/services/registry/candid/types.d.ts @@ -258,6 +258,7 @@ export interface CommunityCanisterCommunitySummary { 'user_groups' : Array, 'avatar_id' : [] | [bigint], 'membership' : [] | [CommunityMembership], + 'local_user_index_canister_id' : CanisterId, 'frozen' : [] | [FrozenGroupInfo], 'latest_event_index' : EventIndex, 'banner_id' : [] | [bigint], @@ -549,6 +550,7 @@ export interface GroupCanisterGroupChatSummary { 'avatar_id' : [] | [bigint], 'rules_accepted' : boolean, 'membership' : [] | [GroupMembership], + 'local_user_index_canister_id' : CanisterId, 'latest_threads' : Array, 'frozen' : [] | [FrozenGroupInfo], 'latest_event_index' : EventIndex, @@ -621,6 +623,7 @@ export interface GroupChatSummary { 'joined' : TimestampMillis, 'avatar_id' : [] | [bigint], 'rules_accepted' : boolean, + 'local_user_index_canister_id' : CanisterId, 'latest_threads' : Array, 'frozen' : [] | [FrozenGroupInfo], 'latest_event_index' : EventIndex, @@ -1169,6 +1172,7 @@ export interface PublicGroupSummary { 'events_ttl' : [] | [Milliseconds], 'last_updated' : TimestampMillis, 'avatar_id' : [] | [bigint], + 'local_user_index_canister_id' : CanisterId, 'frozen' : [] | [FrozenGroupInfo], 'latest_event_index' : EventIndex, 'history_visible_to_new_joiners' : boolean, diff --git a/frontend/openchat-agent/src/services/storageBucket/candid/types.d.ts b/frontend/openchat-agent/src/services/storageBucket/candid/types.d.ts index 01237ace20..b1c201a400 100644 --- a/frontend/openchat-agent/src/services/storageBucket/candid/types.d.ts +++ b/frontend/openchat-agent/src/services/storageBucket/candid/types.d.ts @@ -258,6 +258,7 @@ export interface CommunityCanisterCommunitySummary { 'user_groups' : Array, 'avatar_id' : [] | [bigint], 'membership' : [] | [CommunityMembership], + 'local_user_index_canister_id' : CanisterId, 'frozen' : [] | [FrozenGroupInfo], 'latest_event_index' : EventIndex, 'banner_id' : [] | [bigint], @@ -579,6 +580,7 @@ export interface GroupCanisterGroupChatSummary { 'avatar_id' : [] | [bigint], 'rules_accepted' : boolean, 'membership' : [] | [GroupMembership], + 'local_user_index_canister_id' : CanisterId, 'latest_threads' : Array, 'frozen' : [] | [FrozenGroupInfo], 'latest_event_index' : EventIndex, @@ -651,6 +653,7 @@ export interface GroupChatSummary { 'joined' : TimestampMillis, 'avatar_id' : [] | [bigint], 'rules_accepted' : boolean, + 'local_user_index_canister_id' : CanisterId, 'latest_threads' : Array, 'frozen' : [] | [FrozenGroupInfo], 'latest_event_index' : EventIndex, @@ -1190,6 +1193,7 @@ export interface PublicGroupSummary { 'events_ttl' : [] | [Milliseconds], 'last_updated' : TimestampMillis, 'avatar_id' : [] | [bigint], + 'local_user_index_canister_id' : CanisterId, 'frozen' : [] | [FrozenGroupInfo], 'latest_event_index' : EventIndex, 'history_visible_to_new_joiners' : boolean, diff --git a/frontend/openchat-agent/src/services/storageIndex/candid/types.d.ts b/frontend/openchat-agent/src/services/storageIndex/candid/types.d.ts index 2efda037fa..6d1885cbba 100644 --- a/frontend/openchat-agent/src/services/storageIndex/candid/types.d.ts +++ b/frontend/openchat-agent/src/services/storageIndex/candid/types.d.ts @@ -288,6 +288,7 @@ export interface CommunityCanisterCommunitySummary { 'user_groups' : Array, 'avatar_id' : [] | [bigint], 'membership' : [] | [CommunityMembership], + 'local_user_index_canister_id' : CanisterId, 'frozen' : [] | [FrozenGroupInfo], 'latest_event_index' : EventIndex, 'banner_id' : [] | [bigint], @@ -579,6 +580,7 @@ export interface GroupCanisterGroupChatSummary { 'avatar_id' : [] | [bigint], 'rules_accepted' : boolean, 'membership' : [] | [GroupMembership], + 'local_user_index_canister_id' : CanisterId, 'latest_threads' : Array, 'frozen' : [] | [FrozenGroupInfo], 'latest_event_index' : EventIndex, @@ -651,6 +653,7 @@ export interface GroupChatSummary { 'joined' : TimestampMillis, 'avatar_id' : [] | [bigint], 'rules_accepted' : boolean, + 'local_user_index_canister_id' : CanisterId, 'latest_threads' : Array, 'frozen' : [] | [FrozenGroupInfo], 'latest_event_index' : EventIndex, @@ -1196,6 +1199,7 @@ export interface PublicGroupSummary { 'events_ttl' : [] | [Milliseconds], 'last_updated' : TimestampMillis, 'avatar_id' : [] | [bigint], + 'local_user_index_canister_id' : CanisterId, 'frozen' : [] | [FrozenGroupInfo], 'latest_event_index' : EventIndex, 'history_visible_to_new_joiners' : boolean, diff --git a/frontend/openchat-agent/src/services/user/candid/idl.js b/frontend/openchat-agent/src/services/user/candid/idl.js index f38257b7b2..2dcad85ae5 100644 --- a/frontend/openchat-agent/src/services/user/candid/idl.js +++ b/frontend/openchat-agent/src/services/user/candid/idl.js @@ -855,6 +855,7 @@ export const idlFactory = ({ IDL }) => { 'community_id' : CommunityId, 'channels' : IDL.Vec(UserCanisterChannelSummary), 'pinned' : IDL.Vec(ChannelId), + 'local_user_index_canister_id' : CanisterId, 'index' : IDL.Nat32, 'archived' : IDL.Bool, }); @@ -866,6 +867,7 @@ export const idlFactory = ({ IDL }) => { 'pinned' : IDL.Vec(Chat), }); const UserCanisterGroupChatSummary = IDL.Record({ + 'local_user_index_canister_id' : CanisterId, 'read_by_me_up_to' : IDL.Opt(MessageIndex), 'chat_id' : ChatId, 'date_read_pinned' : IDL.Opt(TimestampMillis), @@ -955,6 +957,7 @@ export const idlFactory = ({ IDL }) => { 'joined' : TimestampMillis, 'avatar_id' : IDL.Opt(IDL.Nat), 'rules_accepted' : IDL.Bool, + 'local_user_index_canister_id' : CanisterId, 'latest_threads' : IDL.Vec(ThreadSyncDetails), 'frozen' : IDL.Opt(FrozenGroupInfo), 'latest_event_index' : EventIndex, diff --git a/frontend/openchat-agent/src/services/user/candid/types.d.ts b/frontend/openchat-agent/src/services/user/candid/types.d.ts index 3516783f38..5ea7a51c25 100644 --- a/frontend/openchat-agent/src/services/user/candid/types.d.ts +++ b/frontend/openchat-agent/src/services/user/candid/types.d.ts @@ -331,6 +331,7 @@ export interface CommunityCanisterCommunitySummary { 'user_groups' : Array, 'avatar_id' : [] | [bigint], 'membership' : [] | [CommunityMembership], + 'local_user_index_canister_id' : CanisterId, 'frozen' : [] | [FrozenGroupInfo], 'latest_event_index' : EventIndex, 'banner_id' : [] | [bigint], @@ -779,6 +780,7 @@ export interface GroupCanisterGroupChatSummary { 'avatar_id' : [] | [bigint], 'rules_accepted' : boolean, 'membership' : [] | [GroupMembership], + 'local_user_index_canister_id' : CanisterId, 'latest_threads' : Array, 'frozen' : [] | [FrozenGroupInfo], 'latest_event_index' : EventIndex, @@ -851,6 +853,7 @@ export interface GroupChatSummary { 'joined' : TimestampMillis, 'avatar_id' : [] | [bigint], 'rules_accepted' : boolean, + 'local_user_index_canister_id' : CanisterId, 'latest_threads' : Array, 'frozen' : [] | [FrozenGroupInfo], 'latest_event_index' : EventIndex, @@ -1506,6 +1509,7 @@ export interface PublicGroupSummary { 'events_ttl' : [] | [Milliseconds], 'last_updated' : TimestampMillis, 'avatar_id' : [] | [bigint], + 'local_user_index_canister_id' : CanisterId, 'frozen' : [] | [FrozenGroupInfo], 'latest_event_index' : EventIndex, 'history_visible_to_new_joiners' : boolean, @@ -1990,6 +1994,7 @@ export interface UserCanisterCommunitySummary { 'community_id' : CommunityId, 'channels' : Array, 'pinned' : Array, + 'local_user_index_canister_id' : CanisterId, 'index' : number, 'archived' : boolean, } @@ -2001,6 +2006,7 @@ export interface UserCanisterCommunitySummaryUpdates { 'archived' : [] | [boolean], } export interface UserCanisterGroupChatSummary { + 'local_user_index_canister_id' : CanisterId, 'read_by_me_up_to' : [] | [MessageIndex], 'chat_id' : ChatId, 'date_read_pinned' : [] | [TimestampMillis], diff --git a/frontend/openchat-agent/src/services/user/mappers.ts b/frontend/openchat-agent/src/services/user/mappers.ts index e34e520726..bb9024d3de 100644 --- a/frontend/openchat-agent/src/services/user/mappers.ts +++ b/frontend/openchat-agent/src/services/user/mappers.ts @@ -867,6 +867,7 @@ function groupChatSummary(candid: ApiGroupChatSummary): GroupChatSummary { archived: candid.archived, rulesAccepted: candid.rules_accepted, }, + localUserIndex: candid.local_user_index_canister_id.toString(), }; } @@ -1191,7 +1192,9 @@ function result(candid: { Ok: T } | { Err: string }): Result { }; } -function resultOfResult(candid: { Ok: { Ok: T; } | { Err: string; }; } | { Err: string; }): Result> { +function resultOfResult( + candid: { Ok: { Ok: T } | { Err: string } } | { Err: string }, +): Result> { if ("Ok" in candid) { return { kind: "ok", @@ -1204,7 +1207,9 @@ function resultOfResult(candid: { Ok: { Ok: T; } | { Err: string; }; } | { Er }; } -export function approveTransferResponse(candid: ApiApproveTransferResponse): ApproveTransferResponse { +export function approveTransferResponse( + candid: ApiApproveTransferResponse, +): ApproveTransferResponse { if ("Success" in candid) { return { kind: "success" }; } diff --git a/frontend/openchat-agent/src/services/userIndex/candid/types.d.ts b/frontend/openchat-agent/src/services/userIndex/candid/types.d.ts index bd94e95aac..acd9f71913 100644 --- a/frontend/openchat-agent/src/services/userIndex/candid/types.d.ts +++ b/frontend/openchat-agent/src/services/userIndex/candid/types.d.ts @@ -280,6 +280,7 @@ export interface CommunityCanisterCommunitySummary { 'user_groups' : Array, 'avatar_id' : [] | [bigint], 'membership' : [] | [CommunityMembership], + 'local_user_index_canister_id' : CanisterId, 'frozen' : [] | [FrozenGroupInfo], 'latest_event_index' : EventIndex, 'banner_id' : [] | [bigint], @@ -601,6 +602,7 @@ export interface GroupCanisterGroupChatSummary { 'avatar_id' : [] | [bigint], 'rules_accepted' : boolean, 'membership' : [] | [GroupMembership], + 'local_user_index_canister_id' : CanisterId, 'latest_threads' : Array, 'frozen' : [] | [FrozenGroupInfo], 'latest_event_index' : EventIndex, @@ -673,6 +675,7 @@ export interface GroupChatSummary { 'joined' : TimestampMillis, 'avatar_id' : [] | [bigint], 'rules_accepted' : boolean, + 'local_user_index_canister_id' : CanisterId, 'latest_threads' : Array, 'frozen' : [] | [FrozenGroupInfo], 'latest_event_index' : EventIndex, @@ -1244,6 +1247,7 @@ export interface PublicGroupSummary { 'events_ttl' : [] | [Milliseconds], 'last_updated' : TimestampMillis, 'avatar_id' : [] | [bigint], + 'local_user_index_canister_id' : CanisterId, 'frozen' : [] | [FrozenGroupInfo], 'latest_event_index' : EventIndex, 'history_visible_to_new_joiners' : boolean, diff --git a/frontend/openchat-agent/src/utils/caching.ts b/frontend/openchat-agent/src/utils/caching.ts index 7d37906822..b7a2b29c70 100644 --- a/frontend/openchat-agent/src/utils/caching.ts +++ b/frontend/openchat-agent/src/utils/caching.ts @@ -41,7 +41,7 @@ import { } from "openchat-shared"; import type { Principal } from "@dfinity/principal"; -const CACHE_VERSION = 91; +const CACHE_VERSION = 92; const MAX_INDEX = 9999999999; export type Database = Promise>; diff --git a/frontend/openchat-agent/src/utils/chat.ts b/frontend/openchat-agent/src/utils/chat.ts index 64a873b310..6857d59901 100644 --- a/frontend/openchat-agent/src/utils/chat.ts +++ b/frontend/openchat-agent/src/utils/chat.ts @@ -270,6 +270,7 @@ export function mergeGroupChatUpdates( archived: u?.archived ?? c.membership.archived, rulesAccepted: g?.rulesAccepted ?? c.membership.rulesAccepted, }, + localUserIndex: c.localUserIndex, }; }); } @@ -323,6 +324,7 @@ export function mergeGroupChats( archived: u?.archived ?? false, rulesAccepted: g.rulesAccepted, }, + localUserIndex: g.localUserIndex, }; }); } diff --git a/frontend/openchat-agent/src/utils/community.ts b/frontend/openchat-agent/src/utils/community.ts index 1634ad8dc0..be7403c387 100644 --- a/frontend/openchat-agent/src/utils/community.ts +++ b/frontend/openchat-agent/src/utils/community.ts @@ -147,6 +147,7 @@ export function mergeCommunityUpdates( c?.userGroups ?? [], c?.userGroupsDeleted ?? new Set(), ), + localUserIndex: community.localUserIndex, }; }); } diff --git a/frontend/openchat-client/src/openchat.ts b/frontend/openchat-client/src/openchat.ts index c54ead1255..67cb12ef9d 100644 --- a/frontend/openchat-client/src/openchat.ts +++ b/frontend/openchat-client/src/openchat.ts @@ -1213,7 +1213,17 @@ export class OpenChat extends OpenChatAgentWorker { return "gate_check_failed"; } - return this.sendRequest({ kind: "joinGroup", chatId: chat.id, credential }) + const localUserIndex = + chat.kind === "group_chat" + ? chat.localUserIndex + : this.localUserIndexForCommunity(chat.id.communityId); + + return this.sendRequest({ + kind: "joinGroup", + chatId: chat.id, + localUserIndex, + credential, + }) .then((resp) => { if (resp.kind === "success") { localChatSummaryUpdates.markAdded(resp.group); @@ -3930,7 +3940,8 @@ export class OpenChat extends OpenChatAgentWorker { inviteUsers(chatId: MultiUserChatIdentifier, userIds: string[]): Promise { this.inviteUsersLocally(chatId, userIds); - return this.sendRequest({ kind: "inviteUsers", chatId, userIds }) + const localUserIndex = this.localUserIndexForChat(chatId); + return this.sendRequest({ kind: "inviteUsers", chatId, localUserIndex, userIds }) .then((resp) => { if (resp !== "success") { this.uninviteUsersLocally(chatId, userIds); @@ -3959,7 +3970,8 @@ export class OpenChat extends OpenChatAgentWorker { userIds: string[], ): Promise { this.inviteUsersToCommunityLocally(id, userIds); - return this.sendRequest({ kind: "inviteUsersToCommunity", id, userIds }) + const localUserIndex = this.localUserIndexForCommunity(id.communityId); + return this.sendRequest({ kind: "inviteUsersToCommunity", id, localUserIndex, userIds }) .then((resp) => { if (resp !== "success") { this.uninviteUsersToCommunityLocally(id, userIds); @@ -5383,6 +5395,24 @@ export class OpenChat extends OpenChatAgentWorker { }); } + private localUserIndexForChat(chatId: MultiUserChatIdentifier): string { + const chat = this._liveState.allChats.get(chatId); + if (chat?.kind === "group_chat") { + return chat.localUserIndex; + } else if (chat?.kind === "channel") { + return this.localUserIndexForCommunity(chat.id.communityId); + } + throw new Error("Chat not found"); + } + + private localUserIndexForCommunity(communityId: string): string { + const community = this._liveState.communities.get({ kind: "community", communityId }); + if (community === undefined) { + throw new Error("Community not found"); + } + return community.localUserIndex; + } + // **** Communities Stuff // takes a list of communities that may contain communities that we are a member of and/or preview communities @@ -5502,7 +5532,12 @@ export class OpenChat extends OpenChatAgentWorker { return "gate_check_failed"; } - return this.sendRequest({ kind: "joinCommunity", id: community.id, credential }) + return this.sendRequest({ + kind: "joinCommunity", + id: community.id, + localUserIndex: community.localUserIndex, + credential, + }) .then((resp) => { if (resp.kind === "success") { // Make the community appear at the top of the list diff --git a/frontend/openchat-client/src/utils/chat.spec.ts b/frontend/openchat-client/src/utils/chat.spec.ts index 0f2f155c85..4b25611ee7 100644 --- a/frontend/openchat-client/src/utils/chat.spec.ts +++ b/frontend/openchat-client/src/utils/chat.spec.ts @@ -78,6 +78,7 @@ const defaultGroupChat: GroupChatSummary = { }, ], }, + localUserIndex: "", }; function createUser(userId: string, username: string): UserSummary { diff --git a/frontend/openchat-shared/src/domain/chat/chat.ts b/frontend/openchat-shared/src/domain/chat/chat.ts index ecefca6c6a..b2102d7c8f 100644 --- a/frontend/openchat-shared/src/domain/chat/chat.ts +++ b/frontend/openchat-shared/src/domain/chat/chat.ts @@ -1233,6 +1233,7 @@ export type GroupChatSummary = DataContent & previewed: boolean; dateLastPinned: bigint | undefined; dateReadPinned: bigint | undefined; + localUserIndex: string; }; export function nullMembership(): ChatMembership { @@ -1296,6 +1297,7 @@ export type GroupCanisterGroupChatSummary = AccessControlled & rulesAccepted: boolean; eventsTTL?: bigint; eventsTtlLastUpdated: bigint; + localUserIndex: string; }; export type UpdatedEvent = { diff --git a/frontend/openchat-shared/src/domain/community/index.ts b/frontend/openchat-shared/src/domain/community/index.ts index 13b5ccdbc5..44c5115ceb 100644 --- a/frontend/openchat-shared/src/domain/community/index.ts +++ b/frontend/openchat-shared/src/domain/community/index.ts @@ -73,6 +73,7 @@ export type CommunitySummary = AccessControlled & channels: ChannelSummary[]; // TODO - this might be better as a ChatMap - but that would have some serialisation complications primaryLanguage: string; userGroups: Map; + localUserIndex: string; }; export type DefaultChannel = { diff --git a/frontend/openchat-shared/src/domain/user/user.ts b/frontend/openchat-shared/src/domain/user/user.ts index da23a18ee4..340ec574f1 100644 --- a/frontend/openchat-shared/src/domain/user/user.ts +++ b/frontend/openchat-shared/src/domain/user/user.ts @@ -217,9 +217,6 @@ export type RegisterUserResponse = | { kind: "username_too_short" } | { kind: "username_too_long" } | { kind: "username_invalid" } - | { kind: "display_name_too_short" } - | { kind: "display_name_too_long" } - | { kind: "display_name_invalid" } | { kind: "public_key_invalid" } | { kind: "referral_code_invalid" } | { kind: "referral_code_already_claimed" } diff --git a/frontend/openchat-shared/src/domain/worker.ts b/frontend/openchat-shared/src/domain/worker.ts index eebf495064..a69bae5ca9 100644 --- a/frontend/openchat-shared/src/domain/worker.ts +++ b/frontend/openchat-shared/src/domain/worker.ts @@ -596,12 +596,14 @@ type RemoveMember = { type InviteUsers = { chatId: MultiUserChatIdentifier; + localUserIndex: string; userIds: string[]; kind: "inviteUsers"; }; type InviteUsersToCommunity = { id: CommunityIdentifier; + localUserIndex: string; userIds: string[]; kind: "inviteUsersToCommunity"; }; @@ -737,12 +739,14 @@ type UpdateGroup = { type JoinGroup = { chatId: MultiUserChatIdentifier; + localUserIndex: string; kind: "joinGroup"; credential?: string; }; type JoinCommunity = { id: CommunityIdentifier; + localUserIndex: string; kind: "joinCommunity"; credential?: string; }; diff --git a/frontend/openchat-worker/src/worker.ts b/frontend/openchat-worker/src/worker.ts index e966ea3c44..988f43aa8e 100644 --- a/frontend/openchat-worker/src/worker.ts +++ b/frontend/openchat-worker/src/worker.ts @@ -393,7 +393,7 @@ self.addEventListener("message", (msg: MessageEvent) => executeThenReply( payload, correlationId, - agent.joinGroup(payload.chatId, payload.credential), + agent.joinGroup(payload.chatId, payload.localUserIndex, payload.credential), ); break; @@ -401,7 +401,7 @@ self.addEventListener("message", (msg: MessageEvent) => executeThenReply( payload, correlationId, - agent.joinCommunity(payload.id, payload.credential), + agent.joinCommunity(payload.id, payload.localUserIndex, payload.credential), ); break; @@ -601,7 +601,7 @@ self.addEventListener("message", (msg: MessageEvent) => executeThenReply( payload, correlationId, - agent.inviteUsers(payload.chatId, payload.userIds), + agent.inviteUsers(payload.chatId, payload.localUserIndex, payload.userIds), ); break; @@ -609,7 +609,11 @@ self.addEventListener("message", (msg: MessageEvent) => executeThenReply( payload, correlationId, - agent.inviteUsersToCommunity(payload.id, payload.userIds), + agent.inviteUsersToCommunity( + payload.id, + payload.localUserIndex, + payload.userIds, + ), ); break; @@ -1362,11 +1366,7 @@ self.addEventListener("message", (msg: MessageEvent) => break; case "canSwap": - executeThenReply( - payload, - correlationId, - agent.canSwap(payload.tokenLedgers), - ); + executeThenReply(payload, correlationId, agent.canSwap(payload.tokenLedgers)); break; case "getTokenSwaps": @@ -1381,7 +1381,11 @@ self.addEventListener("message", (msg: MessageEvent) => executeThenReply( payload, correlationId, - agent.getTokenSwapQuotes(payload.inputTokenLedger, payload.outputTokenLedger, payload.amountIn), + agent.getTokenSwapQuotes( + payload.inputTokenLedger, + payload.outputTokenLedger, + payload.amountIn, + ), ); break;