@@ -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
0 commit comments