Skip to content

Commit

Permalink
Set unread message state before updating messages because handleMessa…
Browse files Browse the repository at this point in the history
…geAppear requires it to be set
  • Loading branch information
laevandus committed Jun 28, 2024
1 parent 14516e3 commit 4140324
Showing 1 changed file with 5 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -412,6 +412,11 @@ open class ChatChannelViewModel: ObservableObject, MessagesDataSource {
return
}

// Set unread state before updating messages for ensuring the state is up to date before `handleMessageAppear` is called
if lastReadMessageId != nil && firstUnreadMessageId == nil {
firstUnreadMessageId = channelDataSource.firstUnreadMessageId
}

if shouldAnimate(changes: changes) {
withAnimation {
self.messages = messages
Expand All @@ -425,10 +430,6 @@ open class ChatChannelViewModel: ObservableObject, MessagesDataSource {
if !showScrollToLatestButton && scrolledId == nil && !loadingNextMessages {
updateScrolledIdToNewestMessage()
}

if lastReadMessageId != nil && firstUnreadMessageId == nil {
firstUnreadMessageId = channelDataSource.firstUnreadMessageId
}
}

func dataSource(
Expand Down

0 comments on commit 4140324

Please sign in to comment.