stream-chat
Advanced tools
Comparing version 8.40.7 to 8.40.8
@@ -72,3 +72,3 @@ import type { Channel } from './channel'; | ||
private subscribeRepliesRead; | ||
private subscribeReplyDeleted; | ||
private subscribeMessageDeleted; | ||
private subscribeMessageUpdated; | ||
@@ -83,3 +83,5 @@ unregisterSubscriptions: () => void; | ||
}) => void; | ||
updateParentMessageLocally: (message: MessageResponse<SCG>) => void; | ||
updateParentMessageLocally: ({ message }: { | ||
message: MessageResponse<SCG>; | ||
}) => void; | ||
updateParentMessageOrReplyLocally: (message: MessageResponse<SCG>) => void; | ||
@@ -86,0 +88,0 @@ markAsRead: ({ force }?: { |
{ | ||
"name": "stream-chat", | ||
"version": "8.40.7", | ||
"version": "8.40.8", | ||
"description": "JS SDK for the Stream Chat API", | ||
@@ -5,0 +5,0 @@ "author": "GetStream", |
@@ -7,2 +7,3 @@ import type { Channel } from './channel'; | ||
DefaultGenerics, | ||
EventTypes, | ||
ExtendableGenerics, | ||
@@ -83,2 +84,8 @@ FormatMessageResponse, | ||
// For when read object is undefined and due to that unreadMessageCount for | ||
// the current user isn't being incremented on message.new | ||
const placeholderReadResponse: ReadResponse[] = client.userID | ||
? [{ user: { id: client.userID }, unread_messages: 0, last_read: new Date().toISOString() }] | ||
: []; | ||
this.state = new StateStore<ThreadState<SCG>>({ | ||
@@ -94,3 +101,5 @@ active: false, | ||
participants: threadData.thread_participants, | ||
read: formatReadState(threadData.read ?? []), | ||
read: formatReadState( | ||
!threadData.read || threadData.read.length === 0 ? placeholderReadResponse : threadData.read, | ||
), | ||
replies: threadData.latest_replies.map(formatMessage), | ||
@@ -188,3 +197,3 @@ replyCount: threadData.reply_count ?? 0, | ||
this.unsubscribeFunctions.add(this.subscribeRepliesRead()); | ||
this.unsubscribeFunctions.add(this.subscribeReplyDeleted()); | ||
this.unsubscribeFunctions.add(this.subscribeMessageDeleted()); | ||
this.unsubscribeFunctions.add(this.subscribeMessageUpdated()); | ||
@@ -301,16 +310,26 @@ }; | ||
private subscribeReplyDeleted = () => | ||
private subscribeMessageDeleted = () => | ||
this.client.on('message.deleted', (event) => { | ||
if (event.message?.parent_id !== this.id) return; | ||
if (!event.message) return; | ||
if (event.hard_delete) { | ||
this.deleteReplyLocally({ message: event.message }); | ||
} else { | ||
// Handle soft delete (updates deleted_at timestamp) | ||
this.upsertReplyLocally({ message: event.message }); | ||
// Deleted message is a reply of this thread | ||
if (event.message.parent_id === this.id) { | ||
if (event.hard_delete) { | ||
this.deleteReplyLocally({ message: event.message }); | ||
} else { | ||
// Handle soft delete (updates deleted_at timestamp) | ||
this.upsertReplyLocally({ message: event.message }); | ||
} | ||
} | ||
// Deleted message is parent message of this thread | ||
if (event.message.id === this.id) { | ||
this.updateParentMessageLocally({ message: event.message }); | ||
} | ||
}).unsubscribe; | ||
private subscribeMessageUpdated = () => { | ||
const unsubscribeFunctions = ['message.updated', 'reaction.new', 'reaction.deleted'].map( | ||
const eventTypes: EventTypes[] = ['message.updated', 'reaction.new', 'reaction.deleted', 'reaction.updated']; | ||
const unsubscribeFunctions = eventTypes.map( | ||
(eventType) => | ||
@@ -383,3 +402,3 @@ this.client.on(eventType, (event) => { | ||
public updateParentMessageLocally = (message: MessageResponse<SCG>) => { | ||
public updateParentMessageLocally = ({ message }: { message: MessageResponse<SCG> }) => { | ||
if (message.id !== this.id) { | ||
@@ -392,3 +411,3 @@ throw new Error('Message does not belong to this thread'); | ||
const newData: typeof current = { | ||
return { | ||
...current, | ||
@@ -399,9 +418,2 @@ deletedAt: formattedMessage.deleted_at, | ||
}; | ||
// update channel on channelData change (unlikely but handled anyway) | ||
if (message.channel) { | ||
newData['channel'] = this.client.channel(message.channel.type, message.channel.id, message.channel); | ||
} | ||
return newData; | ||
}); | ||
@@ -416,3 +428,3 @@ }; | ||
if (!message.parent_id && message.id === this.id) { | ||
this.updateParentMessageLocally(message); | ||
this.updateParentMessageLocally({ message }); | ||
} | ||
@@ -419,0 +431,0 @@ }; |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
6846310
71112