Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
oleg-hf opened this issue Nov 21, 2024 · 7 comments
Open

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

oleg-hf opened this issue Nov 21, 2024 · 7 comments

Comments

@oleg-hf
Copy link

oleg-hf commented Nov 21, 2024

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
            }
        }
    }
@nuno-vieira
Copy link
Member

Hi @oleg-hf,

Can you please share a video of the issue happening? Otherwise, it is difficult to understand what the actual issue is.

Thank you,
Nuno

@oleg-hf
Copy link
Author

oleg-hf commented Nov 22, 2024

Capturing the issue with unreadCountPublisher in a video is challenging because it requires multiple Xcode simulators and debugging in the background. Here's a verbal explanation:

Scenario #1 (Issue):

  1. User A and User B have a 1:1 chat. User A sends a message to User B.
  2. User B is not viewing the chat, so the message is unread.
  3. The currentUserController.unreadCountPublisher on user B's device is not emitting a new value and the unreadCount.messages for User B does not increase (verified with Xcode breakpoints).

Additional Issue for Scenario #1:

  1. User B receives a push notification and sees a red badge for 1 unread message in ChatChannelListView.
  2. After closing and reopening the chat, the badge disappears from ChatChannelListView as if the message was read, but it wasn't.

Scenario #2 (Working as Expected):

  1. User B is in a group chat with Users C and D. User D sends a new message.
  2. The currentUserController.unreadCountPublisher on User B's device updates correctly, increasing the unread count for messages.
  3. The badge on the ChatChannelListView remains visible even after closing and reopening the chat.

@nuno-vieira
Copy link
Member

nuno-vieira commented Nov 22, 2024

Hi @oleg-hf,

Thank you for the detailed description. Now it is more clear. I just did not understood this part:

After closing and reopening the chat, the badge disappears from ChatChannelListView as if the message was read, but it wasn't.

Which user, A or B? And if the user opened the chat, then it means he read the message, right? Isn't this expected?

We will investigate this a little more deeper as soon as we can. We will let you know once we have more details.

Best,
Nuno

@oleg-hf
Copy link
Author

oleg-hf commented Nov 22, 2024

Which user, A or B? And if the user opened the chat, then it means he read the message, right? Isn't this expected?

By "opening the chat" I meant opening the screen based on ChatChannelListView. User B hasn't opened the 1:1 chat yet. When user B reopens the ChatChannelListView, the unread badge disappears even if they haven't opened the 1:1 chat with user A.

@nuno-vieira
Copy link
Member

Hi @oleg-hf,

I see, we will get back to you once we investigate this one in more detail.

Thank you for the report.

@nuno-vieira
Copy link
Member

Hi @oleg-hf,

I'm not able to reproduce the issue on our Demo App.

Can you make sure that the users are not blocked or muted?

Also, you can enable WebSocket logging and see if the data is updated from the backend correctly; if not, it might be an issue on the Backend. But first make sure the users are not muted or blocked.

How to enable WS logging:

LogConfig.level = .debug
LogConfig.subsystems = .webSocket

Best,
Nuno

@ctngovan
Copy link

ctngovan commented Dec 2, 2024

Hi @nuno-vieira nu
I am encountering a similar issue. We have two users, A and B. When user A sends a regular message, user B receives the correct unread count. However, if A sends a thread message, B’s unread count does not increase, and B doesn’t receive any change events in the eventsController(_ controller: EventsController, didReceiveEvent event: Event) function either.
I have tested this on the DemoApp and found that the handling function is similar, but the issue does not occur on the DemoApp.
I have logged the process and found that the backend logs are normal.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants