Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -861,6 +861,7 @@ public class ChatChannelController: DataController, DelegateCallable, DataStoreP
updater.markRead(cid: channel.cid, userId: currentUserId) { error in
self.callback {
self.markingRead = false
self.isMarkedAsUnread = false
completion?(error)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,18 @@ struct ChannelTruncatedEventMiddleware: EventMiddleware {
}

do {
if let channelDTO = session.channel(cid: truncatedEvent.channel.cid) {
channelDTO.truncatedAt = truncatedEvent.channel.truncatedAt?.bridgeDate
} else {
throw ClientError.ChannelDoesNotExist(cid: truncatedEvent.channel.cid)
let cid = truncatedEvent.channel.cid
guard let channelDTO = session.channel(cid: cid) else {
throw ClientError.ChannelDoesNotExist(cid: cid)
}

channelDTO.truncatedAt = truncatedEvent.channel.truncatedAt?.bridgeDate

// Until BE returns valid values for user's read after truncation, we are clearing them.
if let userId = truncatedEvent.user?.id, let read = session.loadChannelRead(cid: cid, userId: userId) {
read.lastReadMessageId = nil
read.lastReadAt = truncatedEvent.channel.truncatedAt?.bridgeDate ?? DBDate()
read.unreadMessageCount = 0
}
} catch {
log.error("Failed to write the `truncatedAt` field update in the database, error: \(error)")
Expand Down
8 changes: 6 additions & 2 deletions Sources/StreamChatUI/ChatChannel/ChatChannelVC.swift
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,11 @@ open class ChatChannelVC: _ViewController,
return false
}

return hasSeenLastMessage && hasSeenFirstUnreadMessage && channelController.hasLoadedAllNextMessages && !hasMarkedMessageAsUnread
return isLastMessageVisibleOrSeen && hasSeenFirstUnreadMessage && channelController.hasLoadedAllNextMessages && !hasMarkedMessageAsUnread
}

private var isLastMessageVisibleOrSeen: Bool {
hasSeenLastMessage || isLastMessageFullyVisible
}

/// A component responsible to handle when to load new or old messages.
Expand All @@ -106,7 +110,7 @@ open class ChatChannelVC: _ViewController,
/// Determines whether first unread message has been seen
private var hasSeenFirstUnreadMessage: Bool = false

/// Determines whether last cell has been seen
/// Determines whether last cell has been seen since the last time it was marked as read
private var hasSeenLastMessage: Bool = false

/// The id of the first unread message
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1039,8 +1039,6 @@ private extension ChatMessageListVC {
self?.adjustContentOffset(oldContentOffset: oldContentOffset, oldContentSize: oldContentSize)
}

self?.updateScrollDependentButtonsVisibility()

UIView.performWithoutAnimation {
self?.scrollToBottomIfNeeded(with: changes, newestChange: newestChange)
self?.reloadMovedMessage(newestChange: newestChange)
Expand Down