Skip to content

Commit

Permalink
feat(core): channel context
Browse files Browse the repository at this point in the history
  • Loading branch information
aerovulpe committed Sep 27, 2023
1 parent 602c7b6 commit b79d186
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 0 deletions.
21 changes: 21 additions & 0 deletions packages/core/src/lib/channel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ export type PrivateChannel = GroupChannel & {

declare class ChannelRelays {
self: string;
context: string;
messages: string;
messagesCount: string;
lastReceivedMessage: string;
Expand Down Expand Up @@ -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';
}
Expand Down Expand Up @@ -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;
}
Expand All @@ -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;
}
Expand Down
21 changes: 21 additions & 0 deletions packages/core/src/lib/chatkitty.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,9 @@ import {
CountUnreadChannelsRequest,
CheckChannelUnreadSucceededResult,
CheckChannelUnreadRequest,
RetrieveChannelContextRequest,
RetrieveChannelContextResult,
RetrieveChannelContextSucceededResult, ChannelContext,
} from './channel';
import {
ChatSession,
Expand Down Expand Up @@ -601,6 +604,24 @@ export class ChatKitty {
});
}

retrieveChannelContext(request: RetrieveChannelContextRequest): Promise<RetrieveChannelContextResult> {
return new Promise((resolve) => {
this.stompX.relayResource<ChannelContext>({
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<JoinChannelResult> {
const currentUser = this.currentUser;

Expand Down
1 change: 1 addition & 0 deletions packages/core/src/lib/message.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ export type FileMessage = FileSystemMessage | FileUserMessage;

export interface BaseMessage {
id: number;
cursor: number;
type: string;
channelId: number;
createdTime: string;
Expand Down
2 changes: 2 additions & 0 deletions packages/core/src/lib/stompx.ts
Original file line number Diff line number Diff line change
Expand Up @@ -534,6 +534,8 @@ export declare class StompXPageMetadata {
totalElement: number;
totalPages: number;
number: number;
start: number;
next: number;
}

export declare class StompXPageRelays {
Expand Down

0 comments on commit b79d186

Please sign in to comment.