Skip to content

Commit

Permalink
Add localUserIndex to group and community summaries (#4977)
Browse files Browse the repository at this point in the history
  • Loading branch information
hpeebles authored Dec 11, 2023
1 parent 72486fb commit 95cb75d
Show file tree
Hide file tree
Showing 57 changed files with 204 additions and 179 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,15 @@ async fn join_group(args: Args) -> Response {
}

async fn lookup_local_user_index(group: CanisterId) -> Result<CanisterId, Response> {
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)
}
}
Expand Down
4 changes: 4 additions & 0 deletions backend/canisters/community/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 0 additions & 5 deletions backend/canisters/community/api/can.did
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
1 change: 0 additions & 1 deletion backend/canisters/community/api/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
10 changes: 0 additions & 10 deletions backend/canisters/community/api/src/queries/local_user_index.rs

This file was deleted.

1 change: 0 additions & 1 deletion backend/canisters/community/api/src/queries/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
12 changes: 0 additions & 12 deletions backend/canisters/community/impl/src/queries/local_user_index.rs

This file was deleted.

1 change: 0 additions & 1 deletion backend/canisters/community/impl/src/queries/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
4 changes: 4 additions & 0 deletions backend/canisters/group/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 0 additions & 7 deletions backend/canisters/group/api/can.did
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
1 change: 0 additions & 1 deletion backend/canisters/group/api/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
10 changes: 0 additions & 10 deletions backend/canisters/group/api/src/queries/local_user_index.rs

This file was deleted.

1 change: 0 additions & 1 deletion backend/canisters/group/api/src/queries/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
1 change: 0 additions & 1 deletion backend/canisters/group/c2c_client/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 0 additions & 1 deletion backend/canisters/group/client/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
12 changes: 0 additions & 12 deletions backend/canisters/group/impl/src/queries/local_user_index.rs

This file was deleted.

1 change: 0 additions & 1 deletion backend/canisters/group/impl/src/queries/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
6 changes: 0 additions & 6 deletions frontend/app/src/components/register/Register.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -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") {
Expand Down
1 change: 1 addition & 0 deletions frontend/app/src/stores/community.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,5 +44,6 @@ export function createCandidateCommunity(id: string, index: number): CommunitySu
primaryLanguage: "en",
metrics: emptyChatMetrics(),
userGroups: new Map(),
localUserIndex: "",
};
}
2 changes: 2 additions & 0 deletions frontend/openchat-agent/src/services/common/chatMappers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1521,6 +1521,7 @@ export function groupChatSummary(candid: ApiGroupCanisterGroupChatSummary): Grou
archived: false,
rulesAccepted: candid.rules_accepted,
},
localUserIndex: candid.local_user_index_canister_id.toString(),
};
}

Expand Down Expand Up @@ -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(),
};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ import {
InviteCodeResponse,
JoinChannelResponse,
LeaveChannelResponse,
LocalUserIndexResponse,
MakeChannelPrivateResponse,
MessagesByMessageIndexResponse,
OptionalCommunityPermissions,
Expand Down Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -381,6 +381,7 @@ export interface CommunityCanisterCommunitySummary {
'user_groups' : Array<UserGroup>,
'avatar_id' : [] | [bigint],
'membership' : [] | [CommunityMembership],
'local_user_index_canister_id' : CanisterId,
'frozen' : [] | [FrozenGroupInfo],
'latest_event_index' : EventIndex,
'banner_id' : [] | [bigint],
Expand Down Expand Up @@ -830,6 +831,7 @@ export interface GroupCanisterGroupChatSummary {
'avatar_id' : [] | [bigint],
'rules_accepted' : boolean,
'membership' : [] | [GroupMembership],
'local_user_index_canister_id' : CanisterId,
'latest_threads' : Array<GroupCanisterThreadDetails>,
'frozen' : [] | [FrozenGroupInfo],
'latest_event_index' : EventIndex,
Expand Down Expand Up @@ -902,6 +904,7 @@ export interface GroupChatSummary {
'joined' : TimestampMillis,
'avatar_id' : [] | [bigint],
'rules_accepted' : boolean,
'local_user_index_canister_id' : CanisterId,
'latest_threads' : Array<ThreadSyncDetails>,
'frozen' : [] | [FrozenGroupInfo],
'latest_event_index' : EventIndex,
Expand Down Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import type { AgentConfig } from "../../config";
import {
addMembersToChannelResponse,
blockUserResponse,
localUserIndexResponse,
messagesByMessageIndexResponse,
removeMemberResponse,
removeMemberFromChannelResponse,
Expand Down Expand Up @@ -636,10 +635,6 @@ export class CommunityClient extends CandidService {
);
}

localUserIndex(): Promise<string> {
return this.handleResponse(this.service.local_user_index({}), localUserIndexResponse);
}

messagesByMessageIndex(
chatId: ChannelIdentifier,
messageIndexes: number[],
Expand Down
5 changes: 0 additions & 5 deletions frontend/openchat-agent/src/services/community/mappers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ import type {
ApiAddMembersToChannelResponse,
ApiBlockUserResponse,
ApiChangeRoleResponse,
ApiLocalUserIndexResponse,
ApiMessagesByMessageIndexResponse,
ApiRemoveMemberResponse,
ApiRemoveMemberFromChannelResponse,
Expand Down Expand Up @@ -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,
Expand Down
2 changes: 2 additions & 0 deletions frontend/openchat-agent/src/services/group/candid/idl.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down
4 changes: 4 additions & 0 deletions frontend/openchat-agent/src/services/group/candid/types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,7 @@ export interface CommunityCanisterCommunitySummary {
'user_groups' : Array<UserGroup>,
'avatar_id' : [] | [bigint],
'membership' : [] | [CommunityMembership],
'local_user_index_canister_id' : CanisterId,
'frozen' : [] | [FrozenGroupInfo],
'latest_event_index' : EventIndex,
'banner_id' : [] | [bigint],
Expand Down Expand Up @@ -695,6 +696,7 @@ export interface GroupCanisterGroupChatSummary {
'avatar_id' : [] | [bigint],
'rules_accepted' : boolean,
'membership' : [] | [GroupMembership],
'local_user_index_canister_id' : CanisterId,
'latest_threads' : Array<GroupCanisterThreadDetails>,
'frozen' : [] | [FrozenGroupInfo],
'latest_event_index' : EventIndex,
Expand Down Expand Up @@ -767,6 +769,7 @@ export interface GroupChatSummary {
'joined' : TimestampMillis,
'avatar_id' : [] | [bigint],
'rules_accepted' : boolean,
'local_user_index_canister_id' : CanisterId,
'latest_threads' : Array<ThreadSyncDetails>,
'frozen' : [] | [FrozenGroupInfo],
'latest_event_index' : EventIndex,
Expand Down Expand Up @@ -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,
Expand Down
7 changes: 0 additions & 7 deletions frontend/openchat-agent/src/services/group/group.client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -845,13 +845,6 @@ export class GroupClient extends CandidService {
);
}

localUserIndex(): Promise<string> {
return this.handleQueryResponse(
() => this.groupService.local_user_index({}),
(resp) => resp.Success.toString(),
);
}

declineInvitation(): Promise<DeclineInvitationResponse> {
return this.handleResponse(
this.groupService.decline_invitation({}),
Expand Down
Loading

0 comments on commit 95cb75d

Please sign in to comment.