From b79d186048b6159c1ed46249f56807c2e8834569 Mon Sep 17 00:00:00 2001 From: Aaron Nwabuoku Date: Wed, 27 Sep 2023 00:31:11 -0400 Subject: [PATCH] feat(core): channel context --- packages/core/src/lib/channel.ts | 21 +++++++++++++++++++++ packages/core/src/lib/chatkitty.ts | 21 +++++++++++++++++++++ packages/core/src/lib/message.ts | 1 + packages/core/src/lib/stompx.ts | 2 ++ 4 files changed, 45 insertions(+) diff --git a/packages/core/src/lib/channel.ts b/packages/core/src/lib/channel.ts index c3599658..c48057a2 100644 --- a/packages/core/src/lib/channel.ts +++ b/packages/core/src/lib/channel.ts @@ -42,6 +42,7 @@ export type PrivateChannel = GroupChannel & { declare class ChannelRelays { self: string; + context: string; messages: string; messagesCount: string; lastReceivedMessage: string; @@ -85,6 +86,10 @@ declare class ChannelStreams { messages: string; } +export declare class ChannelContext { + readBy: { [key: string]: number[] }; +} + export function isDirectChannel(channel: Channel): channel is DirectChannel { return channel.type === 'DIRECT'; } @@ -152,6 +157,12 @@ export declare class ListUnreadChannelsFilter { export type CountUnreadChannelsRequest = ListUnreadChannelsRequest; +export declare class RetrieveChannelContextRequest { + channel: Channel; + startCursor: number; + endCursor: number; +} + export declare class RetrieveChannelUnreadRequest { channel: Channel; } @@ -176,6 +187,16 @@ export class RetrieveChannelSucceededResult extends ChatKittySucceededResult { } } +export type RetrieveChannelContextResult = + | RetrieveChannelContextSucceededResult + | ChatKittyFailedResult; + +export class RetrieveChannelContextSucceededResult extends ChatKittySucceededResult { + constructor(public context: ChannelContext) { + super(); + } +} + export declare class CheckChannelUnreadRequest { channel: Channel; } diff --git a/packages/core/src/lib/chatkitty.ts b/packages/core/src/lib/chatkitty.ts index 33f00c40..ca924775 100644 --- a/packages/core/src/lib/chatkitty.ts +++ b/packages/core/src/lib/chatkitty.ts @@ -58,6 +58,9 @@ import { CountUnreadChannelsRequest, CheckChannelUnreadSucceededResult, CheckChannelUnreadRequest, + RetrieveChannelContextRequest, + RetrieveChannelContextResult, + RetrieveChannelContextSucceededResult, ChannelContext, } from './channel'; import { ChatSession, @@ -601,6 +604,24 @@ export class ChatKitty { }); } + retrieveChannelContext(request: RetrieveChannelContextRequest): Promise { + return new Promise((resolve) => { + this.stompX.relayResource({ + destination: request.channel._relays.context, + parameters: { + startCursor: request.startCursor, + endCursor: request.endCursor, + }, + onSuccess: (context) => { + resolve(new RetrieveChannelContextSucceededResult(context)); + }, + onError: (error) => { + resolve(new ChatKittyFailedResult(error)); + }, + }); + }); + } + joinChannel(request: JoinChannelRequest): Promise { const currentUser = this.currentUser; diff --git a/packages/core/src/lib/message.ts b/packages/core/src/lib/message.ts index a8abde42..49c27f14 100644 --- a/packages/core/src/lib/message.ts +++ b/packages/core/src/lib/message.ts @@ -23,6 +23,7 @@ export type FileMessage = FileSystemMessage | FileUserMessage; export interface BaseMessage { id: number; + cursor: number; type: string; channelId: number; createdTime: string; diff --git a/packages/core/src/lib/stompx.ts b/packages/core/src/lib/stompx.ts index 386fb425..a042cc9f 100644 --- a/packages/core/src/lib/stompx.ts +++ b/packages/core/src/lib/stompx.ts @@ -534,6 +534,8 @@ export declare class StompXPageMetadata { totalElement: number; totalPages: number; number: number; + start: number; + next: number; } export declare class StompXPageRelays {