diff --git a/packages/core/src/lib/chat-session.ts b/packages/core/src/lib/chat-session.ts index 8a852c60..568c374c 100644 --- a/packages/core/src/lib/chat-session.ts +++ b/packages/core/src/lib/chat-session.ts @@ -33,6 +33,7 @@ export declare class StartChatSessionRequest { onMessageDeleted?: (message: Message) => void; onChannelUpdated?: (channel: Channel) => void; onMessageRead?: (message: Message, receipt: ReadReceipt) => void; + onMessageUnread?: (message: Message, receipt: ReadReceipt) => void; onMessageReactionAdded?: (message: Message, reaction: Reaction) => void; onMessageReactionRemoved?: (message: Message, reaction: Reaction) => void; onThreadMessageReceived?: (thread: Thread, message: Message) => void; diff --git a/packages/core/src/lib/chatkitty.ts b/packages/core/src/lib/chatkitty.ts index 16050ed0..33f00c40 100644 --- a/packages/core/src/lib/chatkitty.ts +++ b/packages/core/src/lib/chatkitty.ts @@ -133,7 +133,10 @@ import { SentFileMessageResult, SentTextMessageResult, TextUserMessage, - ListUsersMessagesRequest, UpdateMessagePropertiesRequest, UpdatedMessagePropertiesSucceededResult, + ListUsersMessagesRequest, + UpdateMessagePropertiesRequest, + UpdatedMessagePropertiesSucceededResult, + UnreadMessageRequest, UnreadMessageResult, UnreadMessageSucceededResult, } from './message'; import { Notification } from './notification'; import { ChatKittyObserver, ChatKittyUnsubscribe } from './observer'; @@ -836,6 +839,7 @@ export class ChatKitty { const onMessageDeleted = request.onMessageDeleted; const onChannelUpdated = request.onChannelUpdated; const onMessageRead = request.onMessageRead; + const onMessageUnread = request.onMessageUnread; const onMessageReactionAdded = request.onMessageReactionAdded; const onMessageReactionRemoved = request.onMessageReactionRemoved; const onThreadMessageReceived = request.onThreadMessageReceived; @@ -1001,6 +1005,21 @@ export class ChatKitty { }); } + if (onMessageUnread) { + messageReadUnsubscribe = this.stompX.listenForEvent({ + topic: request.channel._topics.readReceipts, + event: 'message.read_receipt.deleted', + onSuccess: (receipt) => { + this.stompX.relayResource({ + destination: receipt._relays.message, + onSuccess: (message) => { + onMessageUnread(message, receipt); + }, + }); + }, + }); + } + if (onMessageReactionAdded) { messageReactionAddedUnsubscribe = this.stompX.listenForEvent({ topic: request.channel._topics.reactions, @@ -1399,6 +1418,18 @@ export class ChatKitty { }); } + unreadMessage(request: UnreadMessageRequest): Promise { + return new Promise((resolve) => { + this.stompX.sendAction({ + destination: request.message._actions.unread, + body: {}, + onSent: () => + resolve(new UnreadMessageSucceededResult(request.message)), + onError: (error) => resolve(new ChatKittyFailedResult(error)), + }); + }); + } + retrieveLastReadMessage( request: RetrieveLastReadMessageRequest ): Promise { diff --git a/packages/core/src/lib/message.ts b/packages/core/src/lib/message.ts index 25c044e8..a8abde42 100644 --- a/packages/core/src/lib/message.ts +++ b/packages/core/src/lib/message.ts @@ -118,6 +118,7 @@ declare class MessageRelays { declare class MessageActions { read: string; + unread: string; reply: string; deleteForMe: string; delete: string; @@ -203,6 +204,10 @@ export declare class ReadMessageRequest { message: Message; } +export declare class UnreadMessageRequest { + message: Message; +} + export type ReadMessageResult = | ReadMessageSucceededResult | ChatKittyFailedResult; @@ -213,6 +218,16 @@ export class ReadMessageSucceededResult extends ChatKittySucceededResult { } } +export type UnreadMessageResult = + | UnreadMessageSucceededResult + | ChatKittyFailedResult; + +export class UnreadMessageSucceededResult extends ChatKittySucceededResult { + constructor(public message: Message) { + super(); + } +} + export declare class EditMessageRequest { message: Message; body: string;