Skip to content

Commit d441e7b

Browse files
Fixed online indicator updates in the header view
1 parent b9a6751 commit d441e7b

File tree

3 files changed

+29
-8
lines changed

3 files changed

+29
-8
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
99
### 🔄 Changed
1010
- Reactions popup disabled if channel is frozen
1111

12+
### 🐞 Fixed
13+
- Online indicator updates in the header view
14+
1215
# [4.35.1](https://github.com/GetStream/stream-chat-swiftui/releases/tag/4.35.1)
1316
_August 10, 2023_
1417

Sources/StreamChatSwiftUI/ChatChannel/ChatChannelViewModel.swift

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ open class ChatChannelViewModel: ObservableObject, MessagesDataSource {
3737
private var lastMessageRead: String?
3838
private var disableDateIndicator = false
3939
private var channelName = ""
40+
private var onlineIndicatorShown = false
4041

4142
public var channelController: ChatChannelController
4243
public var messageController: ChatMessageController?
@@ -274,6 +275,7 @@ open class ChatChannelViewModel: ObservableObject, MessagesDataSource {
274275
checkReadIndicators(for: channel)
275276
checkTypingIndicator()
276277
checkHeaderType()
278+
checkOnlineIndicator()
277279
}
278280

279281
public func showReactionOverlay(for view: AnyView) {
@@ -380,13 +382,29 @@ open class ChatChannelViewModel: ObservableObject, MessagesDataSource {
380382
}
381383

382384
if nameChanged {
383-
// Toolbar is not updated unless there's a state change.
384-
// Therefore, we manually need to update the state for a short period of time.
385-
let headerType = channelHeaderType
386-
channelHeaderType = .typingIndicator
387-
DispatchQueue.main.asyncAfter(deadline: .now() + 0.1) { [weak self] in
388-
self?.channelHeaderType = headerType
389-
}
385+
triggerHeaderChange()
386+
}
387+
}
388+
389+
private func checkOnlineIndicator() {
390+
guard let channel else { return }
391+
let updated = !channel.lastActiveMembers.filter { member in
392+
member.id != chatClient.currentUserId && member.isOnline
393+
}.isEmpty
394+
395+
if updated != onlineIndicatorShown {
396+
onlineIndicatorShown = updated
397+
triggerHeaderChange()
398+
}
399+
}
400+
401+
private func triggerHeaderChange() {
402+
// Toolbar is not updated unless there's a state change.
403+
// Therefore, we manually need to update the state for a short period of time.
404+
let headerType = channelHeaderType
405+
channelHeaderType = .typingIndicator
406+
DispatchQueue.main.asyncAfter(deadline: .now() + 0.1) { [weak self] in
407+
self?.channelHeaderType = headerType
390408
}
391409
}
392410

StreamChatSwiftUITests/Tests/ChatChannelList/MoreChannelActionsView_Tests.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,6 @@ class MoreChannelActionsView_Tests: StreamChatTestCase {
2929
.applyDefaultSize()
3030

3131
// Then
32-
assertSnapshot(matching: view, as: .image)
32+
assertSnapshot(matching: view, as: .image(perceptualPrecision: 0.98))
3333
}
3434
}

0 commit comments

Comments
 (0)