stream-chat-swift
stream-chat-swift copied to clipboard
Unread count is broken in stream-chat
What did you do?
We found out the channels read count is broken. So the way stream works, a channel has a structure read info, which is held at channel level, for each user that is part of the channel. When we receive a message, we get the unread count from the channel to display it in the UI. This unread count, starts do display random values: 1,2,4,8,11,14 when the real numbers were 1,2,3,4,5,6. We read the unread count in 2 situations: when a message is received, or when the channel is updated. When a message is received, the count is wrong, but when the channel is updated, the count is correct. We can also see in the push notifications logs the unread count as a control number, so definetly the SDK has a bug again.
GetStream Environment
**GetStream Chat version:4.21.2 **iOS version:15.7 **Swift version:5. **Xcode version:14 **Device:iPhone 11 Pro
Additional context
Hi @Crysis21,
First of all, could you please share a video so that we fully understand when and how those counters are changing? Also, do you mean that these unread counts that act weirdly are per channel, or is it a global counter?
We are shipping this fix in the following release, which might be of your interest if the issue is with per-channel counters: https://github.com/GetStream/stream-chat-swift/pull/2288
Hi @Crysis21 , could you please confirm if the changes shared above fix the issue?
hey @polqf , no the changes above don't fix the issue. The problem appears when you have 2 devices for the same account connected and they receive messages. Seems like a backend issue. Not happening when using only one device per account.
Ho @Crysis21, we are sorry to hear that.
Could you please share a video or any other info where we can see it happening? It would help us to reproduce it.
Hi @Crysis21!
Can you please share a code snippet where are you reading the unread counts from the messages update?
Thank you, Nuno
Closing this one for inactivity.
Feel free to re-open when you have more details.
Best, Nuno
hey @nuno-vieira and @polqf, the issue is there, but you guys didn't check.
Unread counts jump or display random values. This happens due to 2 getstream factors:
-
ContentHandler for notifications, which tries to keep the channel in sync. Internally, when a new message is received, it increses a counter, without fetching the latest information from the backend.
-
A while back they prompted us to upgrade push notification and change notifications mode from offline, to online mode. This means that push notifications are broadcasted all the time, regardless of the websocket connection status. Due to this change, NotificationService is executed for every message, while the application is also running. The result is that getsream is increasing the counter twice, one in NotificationService and once in the main application, which results in the app having random jumps in the notitication counter.
@nuno-vieira when I break the NotificationService in debugger, for every message that I receive, there are 2 events in the queue to be processed.
Hi @Crysis21,
Without a good description of the issue, it is hard to understand what you mean. Only now it is clear that you are talking about the notification badge count. Either way, a video recording would be more helpful to understand the behaviour.
I just recorded one myself, with the app open, and with the notifications being displayed. It is noticeable that sometimes the badgeCount grows faster than the push notifications, but this is normal. The web socket is much faster than the push notifications. But in the end, the badge count will always be correct.
Video:
https://user-images.githubusercontent.com/12814114/199527933-92dfa2ca-56cd-4156-ace9-3bd9f66a1240.mov
Hey guys,
@nuno-vieira I am not talking about the badge count. I am talking that the ChatChannel.reads, at various points in time gets broken. We display the info from that, into the conversations list. If happens especially if you abuse it. Our app just prints the information straight from the ChatChannel reads information.
https://user-images.githubusercontent.com/777169/199708790-16eb0286-5480-417e-a021-2b8ee15006d6.MP4
Hey guys! I wish I could show you the video recording of this issue on our app. We have been this issue having for a month now! I'm glad thought that I found this ticket. Thanks!
From our QA ticket (project list and project details have both the badge counts):
Test Loop:
----
WEB APP:
Send a chat message
----
iOS APP
Go to next screen:
If on project list → go to project details
If on project details → go to chat screen
If on chat screen <- go back to project details
If on project details ← go back to project list
Check badge count
Hi @glennposadas,
Yes, this looks like a real issue. We are tracking this in our Support ZenDesk channel. But for visibility, we will re-open the issue here too.
We will let you know once we have more details about this.
Best, Nuno
@nuno-vieira any chance we can get a fix for this? There are plenty of offline synchronization issues with the iOS SDK and we're seeing very little progress on them. It's been almost 2 months since I reported this one.
Hi @Crysis21,
Unfortunately, I can't provide an ETA yet. We have limited capacity and we need to prioritise all the issues. Right now we have other important things to tackle. Also, you reported this 2 months ago, but you were 1month inactive where you didn't provide the full details of the issue.
Same issue here, we cannot use the badgeCount, the number is wrong.
Hi @Crysis21,
Unfortunately, I can't provide an ETA yet. We have limited capacity and we need to prioritise all the issues. Right now we have other important things to tackle. Also, you reported this 2 months ago, but you were 1month inactive where you didn't provide the full details of the issue.
We provided enough details for the bugs. We also opened a ton of issues on Zendesk where we provided constant feedback and tried to help as much as possible.
@Crysis21 I'm not aware of those, but either way, as I said, we have to prioritise our issues, so it is normal that some issues take more time to be solved. We are planning on picking this one up in the next week. We will keep you posted.
Best, Nuno
Hello @nuno-vieira, I've the same bug. I'm using Notification Service Extension too in order to custom push notifications as mentionned in the documentation. The property unread count has wrong value. Any update on this issue? Thanks!
Hi @vjard33,
Not yet. Unfortunately with the newest crash reports, we are focusing on those. We will post here when we have updates on this one.
Best, Nuno
hey @nuno-vieira, any news on this?
Hi @Crysis21,
We currently have the backend investigating as well, since there were some similar issues on Android. But right now we don't know the root cause of the issue yet.
Best, Nuno
@vjard33 Could you also share the exact steps to reproduce this on your side? On our DemoApp this is quite hard to reproduce, so maybe there is a better way to reproduce this.
Thanks!
Bump. Thanks all for the hard work. I hope we get the fix by January?
@nuno-vieira @polqf Still have the problem on SDK 4.25.0 Pay attention to the badge count on ChannelViewController. there is +1 at the end on the third message (4 instead of 3).
https://user-images.githubusercontent.com/99725306/208922524-e410df44-ad52-46a8-a7e1-addd5853d420.mp4
Hi @vjard33,
4.25.0, does not mention it fixes this issue. We also didn't close it yet as well. The team is still investigating it.
Best, Nuno
Bumped. Happy new year to y'all.
hey guys, any update for an actual fix for this issue?
Hi @glennposadas , @Crysis21 , @vjard33 We believe to have fixed it in this PR: https://github.com/GetStream/stream-chat-swift/pull/2433
Would be amazing if you can give it a try
This fix is now available in the 4.26.0 release.
Thank you for your patience.
Best, Nuno
Hey guys,
@polqf @nuno-vieira this is not working. I tried to see if your sample app works, but push notifications are not delivered in your sample. the device token is registered, but I don't get anything. Also, in configuration->Push Configuration does nothing (you have a break in code, so you might as well remove that misleading option.
The problem is again, your synchronization with the NotificationService extension. Your code doesn't cope with the fact that there are 2 sources changing the storage info. I have the perfect sample from my application.
If in the NotifiactionService stream-chat client that I initialize, I don't pass the appGroup (which means both the app and NSE will use the same storage information), the counts are working just fine in the app. This means you avoid any concurrency problems and the code works as expected.
If I use the same AppGroupIdentifier, which should enable us to sync the local storage when we receive push notifications, the unread counts are broken again. But this time, are broken in reverse. They no longer jump as before, they actually don;t count at all. Randomly you would see an update or two, but nothing more.
Why is push not working on your sample app? Did you guys even test your code in a real-life scenario, when users have a ton of push notifications? If so, why isn't your sample app fully working in this regard? Whenever we try to plug in all the components as in documentation, and have offline storage + push notifications sync, things are broken. It's been months.
Please watch the video below to check what I am talking about. In the first part of the video, I am using the same AppGroup identififer enabled and after the app restarts, I disable it. Please observe the behavior and tell me how the unreads counts are fixed. Please note that we render the reads info from the channel, we don't do any special magic.
The conclusion is, if we want to have unread counts fixed, we need to drop support for offline synchronization from push service and vice-versa.
https://user-images.githubusercontent.com/777169/212640262-6efb105f-631c-4918-a8df-662d4d400bc5.MP4
@glennposadas @vjard33 is the issue fixed for you? Do you use the same app group identifier in notifications service extension?
Thank you.