@@ -37,6 +37,7 @@ open class ChatChannelViewModel: ObservableObject, MessagesDataSource {
37
37
private var lastMessageRead : String ?
38
38
private var disableDateIndicator = false
39
39
private var channelName = " "
40
+ private var onlineIndicatorShown = false
40
41
41
42
public var channelController : ChatChannelController
42
43
public var messageController : ChatMessageController ?
@@ -274,6 +275,7 @@ open class ChatChannelViewModel: ObservableObject, MessagesDataSource {
274
275
checkReadIndicators ( for: channel)
275
276
checkTypingIndicator ( )
276
277
checkHeaderType ( )
278
+ checkOnlineIndicator ( )
277
279
}
278
280
279
281
public func showReactionOverlay( for view: AnyView ) {
@@ -380,13 +382,29 @@ open class ChatChannelViewModel: ObservableObject, MessagesDataSource {
380
382
}
381
383
382
384
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
390
408
}
391
409
}
392
410
0 commit comments