From 669e311e9dd8ec7c50c149d631865d3bcd8d1d46 Mon Sep 17 00:00:00 2001 From: Hamish Peebles Date: Tue, 15 Oct 2024 18:31:41 +0100 Subject: [PATCH] Concatenate `members` and `basic_members` (#6590) --- .../src/services/common/chatMappersV2.ts | 18 +++++++++++-- .../src/services/community/mappersV2.ts | 19 ++++---------- frontend/openchat-agent/src/typebox.ts | 2 ++ frontend/openchat-agent/src/utils/caching.ts | 26 +++++++++++++++++-- ...nitySelectedChannelInitialSuccessResult.ts | 2 +- .../CommunitySelectedInitialSuccessResult.ts | 2 +- tsBindings/types.d.ts | 4 +-- 7 files changed, 51 insertions(+), 22 deletions(-) diff --git a/frontend/openchat-agent/src/services/common/chatMappersV2.ts b/frontend/openchat-agent/src/services/common/chatMappersV2.ts index cd320e1b5d..e3a4fa5342 100644 --- a/frontend/openchat-agent/src/services/common/chatMappersV2.ts +++ b/frontend/openchat-agent/src/services/common/chatMappersV2.ts @@ -2483,9 +2483,23 @@ export function groupDetailsResponse( } if ("Success" in value) { const members = - "participants" in value.Success ? value.Success.participants : value.Success.members; + ("participants" in value.Success ? value.Success.participants : value.Success.members).map(member); + + const basicMembers = "basic_members" in value.Success ? value.Success.basic_members : []; + const membersSet = new Set(); + members.forEach((m) => membersSet.add(m.userId)); + for (const id of basicMembers) { + const userId = principalBytesToString(id); + if (membersSet.add(userId)) { + members.push({ + role: "member", + userId, + displayName: undefined, + }); + } + } return { - members: members.map(member), + members, blockedUsers: new Set(value.Success.blocked_users.map(principalBytesToString)), invitedUsers: new Set(value.Success.invited_users.map(principalBytesToString)), pinnedMessages: new Set(value.Success.pinned_messages), diff --git a/frontend/openchat-agent/src/services/community/mappersV2.ts b/frontend/openchat-agent/src/services/community/mappersV2.ts index 08733f3fb8..be6730a52a 100644 --- a/frontend/openchat-agent/src/services/community/mappersV2.ts +++ b/frontend/openchat-agent/src/services/community/mappersV2.ts @@ -450,19 +450,6 @@ export function apiMemberRole(domain: MemberRole): TGroupRole { return "Participant"; } } -// -// export function communityRole(candid: ApiCommunityRole): MemberRole { -// if ("Member" in candid) { -// return "member"; -// } -// if ("Admin" in candid) { -// return "admin"; -// } -// if ("Owner" in candid) { -// return "owner"; -// } -// throw new UnsupportedValueError("Unknown community role", candid); -// } export function apiCommunityRole(newRole: MemberRole): TCommunityRole { switch (newRole) { @@ -504,7 +491,11 @@ export function communityDetailsResponse( role: memberRole(m.role), userId: principalBytesToString(m.user_id), displayName: m.display_name, - })), + })).concat(value.Success.basic_members.map((id) => ({ + role: "member", + userId: principalBytesToString(id), + displayName: undefined + }))), blockedUsers: new Set(value.Success.blocked_users.map(principalBytesToString)), invitedUsers: new Set(value.Success.invited_users.map(principalBytesToString)), rules: value.Success.chat_rules, diff --git a/frontend/openchat-agent/src/typebox.ts b/frontend/openchat-agent/src/typebox.ts index e679718009..f2ea9a8105 100644 --- a/frontend/openchat-agent/src/typebox.ts +++ b/frontend/openchat-agent/src/typebox.ts @@ -4912,6 +4912,7 @@ export const CommunitySelectedInitialSuccessResult = Type.Object({ last_updated: Type.BigInt(), latest_event_index: EventIndex, members: Type.Array(CommunityMember), + basic_members: Type.Array(UserId), blocked_users: Type.Array(UserId), invited_users: Type.Array(UserId), chat_rules: VersionedRules, @@ -6367,6 +6368,7 @@ export const CommunitySelectedChannelInitialSuccessResult = Type.Object({ last_updated: Type.BigInt(), latest_event_index: EventIndex, members: Type.Array(GroupMember), + basic_members: Type.Array(UserId), blocked_users: Type.Array(UserId), invited_users: Type.Array(UserId), pinned_messages: Type.Array(MessageIndex), diff --git a/frontend/openchat-agent/src/utils/caching.ts b/frontend/openchat-agent/src/utils/caching.ts index 6b961d77f6..45cb417ca1 100644 --- a/frontend/openchat-agent/src/utils/caching.ts +++ b/frontend/openchat-agent/src/utils/caching.ts @@ -51,7 +51,7 @@ import type { CryptocurrencyContent } from "openchat-shared"; import type { PrizeContent } from "openchat-shared"; import type { P2PSwapContent } from "openchat-shared"; -const CACHE_VERSION = 115; +const CACHE_VERSION = 116; const EARLIEST_SUPPORTED_MIGRATION = 115; const MAX_INDEX = 9999999999; @@ -150,6 +150,22 @@ type MigrationFunction = ( // await tx.objectStore("chats").clear(); // } +async function clearGroupDetailsStore( + _db: IDBPDatabase, + _principal: Principal, + tx: IDBPTransaction[], "versionchange">, +) { + await tx.objectStore("group_details").clear(); +} + +async function clearCommunityDetailsStore( + _db: IDBPDatabase, + _principal: Principal, + tx: IDBPTransaction[], "versionchange">, +) { + await tx.objectStore("community_details").clear(); +} + async function clearEverything( db: IDBPDatabase, _principal: Principal, @@ -159,7 +175,13 @@ async function clearEverything( } const migrations: Record> = { - 114: clearEverything, + 115: clearEverything, + 116: async (db, principal, transaction) => { + await Promise.all([ + clearGroupDetailsStore(db, principal, transaction), + clearCommunityDetailsStore(db, principal, transaction) + ]) + }, }; async function migrate( diff --git a/tsBindings/community/selectedChannelInitial/CommunitySelectedChannelInitialSuccessResult.ts b/tsBindings/community/selectedChannelInitial/CommunitySelectedChannelInitialSuccessResult.ts index e64b63adf8..9a49ab3d3d 100644 --- a/tsBindings/community/selectedChannelInitial/CommunitySelectedChannelInitialSuccessResult.ts +++ b/tsBindings/community/selectedChannelInitial/CommunitySelectedChannelInitialSuccessResult.ts @@ -5,4 +5,4 @@ import type { MessageIndex } from "../../shared/MessageIndex"; import type { UserId } from "../../shared/UserId"; import type { VersionedRules } from "../../shared/VersionedRules"; -export type CommunitySelectedChannelInitialSuccessResult = { timestamp: bigint, last_updated: bigint, latest_event_index: EventIndex, members: Array, blocked_users: Array, invited_users: Array, pinned_messages: Array, chat_rules: VersionedRules, }; +export type CommunitySelectedChannelInitialSuccessResult = { timestamp: bigint, last_updated: bigint, latest_event_index: EventIndex, members: Array, basic_members: Array, blocked_users: Array, invited_users: Array, pinned_messages: Array, chat_rules: VersionedRules, }; diff --git a/tsBindings/community/selectedInitial/CommunitySelectedInitialSuccessResult.ts b/tsBindings/community/selectedInitial/CommunitySelectedInitialSuccessResult.ts index 3623721218..a3e8981fff 100644 --- a/tsBindings/community/selectedInitial/CommunitySelectedInitialSuccessResult.ts +++ b/tsBindings/community/selectedInitial/CommunitySelectedInitialSuccessResult.ts @@ -5,4 +5,4 @@ import type { UserGroupDetails } from "../../shared/UserGroupDetails"; import type { UserId } from "../../shared/UserId"; import type { VersionedRules } from "../../shared/VersionedRules"; -export type CommunitySelectedInitialSuccessResult = { timestamp: bigint, last_updated: bigint, latest_event_index: EventIndex, members: Array, blocked_users: Array, invited_users: Array, chat_rules: VersionedRules, user_groups: Array, referrals: Array, }; +export type CommunitySelectedInitialSuccessResult = { timestamp: bigint, last_updated: bigint, latest_event_index: EventIndex, members: Array, basic_members: Array, blocked_users: Array, invited_users: Array, chat_rules: VersionedRules, user_groups: Array, referrals: Array, }; diff --git a/tsBindings/types.d.ts b/tsBindings/types.d.ts index 60336bd243..3565b99565 100644 --- a/tsBindings/types.d.ts +++ b/tsBindings/types.d.ts @@ -522,7 +522,7 @@ export type CommunityAddMembersToChannelArgs = { channel_id: bigint, user_ids: A export type CommunityAddMembersToChannelPartialSuccessResult = { users_added: Array, users_already_in_channel: Array, users_limit_reached: Array, users_failed_with_error: Array, }; export type CommunityAddMembersToChannelFailedResult = { users_already_in_channel: Array, users_limit_reached: Array, users_failed_with_error: Array, }; export type CommunityChangeChannelRoleArgs = { channel_id: bigint, user_id: UserId, new_role: GroupRole, }; -export type CommunitySelectedInitialSuccessResult = { timestamp: bigint, last_updated: bigint, latest_event_index: EventIndex, members: Array, blocked_users: Array, invited_users: Array, chat_rules: VersionedRules, user_groups: Array, referrals: Array, }; +export type CommunitySelectedInitialSuccessResult = { timestamp: bigint, last_updated: bigint, latest_event_index: EventIndex, members: Array, basic_members: Array, blocked_users: Array, invited_users: Array, chat_rules: VersionedRules, user_groups: Array, referrals: Array, }; export type CommunityBlockUserArgs = { user_id: UserId, }; export type CommunityCreateChannelResponse = { "Success": CommunityCreateChannelSuccessResult } | { "NameTooShort": FieldTooShortResult } | { "NameTooLong": FieldTooLongResult } | "NameReserved" | { "DescriptionTooLong": FieldTooLongResult } | { "RulesTooShort": FieldTooShortResult } | { "RulesTooLong": FieldTooLongResult } | { "AvatarTooBig": FieldTooLongResult } | "AccessGateInvalid" | { "MaxChannelsCreated": number } | "NameTaken" | "UserSuspended" | "NotAuthorized" | "CommunityFrozen" | "ExternalUrlInvalid" | { "InternalError": string } | "UserLapsed"; export type CommunitySelectedUpdatesSuccessResult = { timestamp: bigint, last_updated: bigint, members_added_or_updated: Array, members_removed: Array, blocked_users_added: Array, blocked_users_removed: Array, invited_users?: Array | undefined, chat_rules?: VersionedRules | undefined, user_groups: Array, user_groups_deleted: Array, referrals_added: Array, referrals_removed: Array, }; @@ -678,7 +678,7 @@ export type LocalUserIndexChatEventsEventsArgs = { context: LocalUserIndexChatEv export type LocalUserIndexInviteUsersToChannelResponse = "Success" | { "PartialSuccess": LocalUserIndexInviteUsersToChannelPartialSuccessResult } | { "Failed": LocalUserIndexInviteUsersToChannelFailedResult } | "CommunityFrozen" | "UserNotInCommunity" | "ChannelNotFound" | "UserNotInChannel" | "UserSuspended" | "NotAuthorized" | { "TooManyInvites": number } | { "InternalError": string }; export type LocalUserIndexReportMessageArgs = { chat_id: MultiUserChat, thread_root_message_index?: MessageIndex | undefined, event_index: EventIndex, reason_code: number, notes?: string | undefined, }; export type CommunitySelectedChannelUpdatesResponse = { "Success": SelectedGroupUpdates } | { "SuccessNoUpdates": bigint } | "PrivateCommunity" | "ChannelNotFound" | "PrivateChannel"; -export type CommunitySelectedChannelInitialSuccessResult = { timestamp: bigint, last_updated: bigint, latest_event_index: EventIndex, members: Array, blocked_users: Array, invited_users: Array, pinned_messages: Array, chat_rules: VersionedRules, }; +export type CommunitySelectedChannelInitialSuccessResult = { timestamp: bigint, last_updated: bigint, latest_event_index: EventIndex, members: Array, basic_members: Array, blocked_users: Array, invited_users: Array, pinned_messages: Array, chat_rules: VersionedRules, }; export type CommunityCommunityMembersResponse = { "Success": CommunityCommunityMembersSuccessResult } | "PrivateCommunity"; export type CommunityAddMembersToChannelResponse = "Success" | { "PartialSuccess": CommunityAddMembersToChannelPartialSuccessResult } | { "Failed": CommunityAddMembersToChannelFailedResult } | "CommunityFrozen" | "CommunityPublic" | "UserSuspended" | "UserLapsed" | "UserNotInCommunity" | "UserNotInChannel" | "ChannelNotFound" | { "UserLimitReached": number } | "NotAuthorized" | { "InternalError": string }; export type CommunitySelectedInitialResponse = { "Success": CommunitySelectedInitialSuccessResult } | "PrivateCommunity";