Skip to content

Overall unread messages counter not updating in 1:1 chats #662

@oleg-hf

Description

@oleg-hf

What did you do?

Added subscription for unreadCountPublisher in the ChatManager object.

    func subscribeToUnreadChatMessages() {
        Observable<Int>.create { [weak self] observer in
            let subscription = self?.chatClient.currentUserController()
                .unreadCountPublisher
                .sink(
                    receiveCompletion: { _ in },
                    receiveValue: { unreadCount in
                        observer.onNext(unreadCount.messages)
                    }
                )
            return Disposables.create {
                subscription?.cancel()
            }
        }
        .catchErrorJustReturn(0) // Emit 0 in case of error
        .bind(to: unreadChatMessages)
        .disposed(by: disposeBag)
    }

What did you expect to happen?

The unreadChatMessages value should increase when a new message is sent in any channel, whether it's a group or a 1:1 chat.

What happened instead?

The unreadChatMessages value increases only for channels with three or more members. When a new message is sent in 1:1 channels, the unreadChatMessages value does not increase. Although the unread count red badge in the channel list increases, it disappears after closing and reopening the chat. The unread count red badge value is not related to the unreadChatMessages value bound to unreadCountPublisher.

GetStream Environment

GetStream Chat version:
4.63.0

GetStream Chat frameworks: StreamChat, StreamChatSwiftUI
4.63.0

iOS version:
17.5, 16.4

Swift version:
5

Xcode version:
Version 16.1 (16B40)

Device:
iPhone 13, 14

Additional context

It would be helpful to know if there are other publishers that emit values for 1:1 chats and why the unread count badge disappears when reopening the channel list. I want to emphasize that the badge in the list and the unreadCountPublisher's value for messages in group chats work as expected.

Both group chats and 1:1 chats are created using the same method:

func makeChannelController() throws {
        guard let instanceId = self.instanceId else { return }
        let selectedUserIds = Set(selectedUsers.map(\.id))

        channelController = try chatClient.channelController(
            createDirectMessageChannelWith: selectedUserIds,
            type: .team,
            team: instanceId,
            extraData: [:]
        )

        guard let channelController else { return }

        channelController.synchronize { [weak self] error in
            guard let self else { return }
            if error == nil {
                self.selectedUsers = []
                self.makeChannelInfo()
                self.state = .channel
            } else {
                self.state = .error
            }
        }
    }

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions