didChangeChannels on ListChange type .update (or backend?) marking all conversations with unread messages read
jonahhugit opened this issue · 5 comments
What did you do?
This is related to #3322 but we have more information now after further debugging. There appears to be an issue with didChangeChannels
in the delegate where ListChange
of type .update
is somehow marking unread messages as read. It's unclear to me if this is a backend issue, a CoreData store/fetch issue or something else completely unrelated. Here's the log of what happens when our app loads (and loads StreamChat) with a user that has unread messages.
Initially, it loads in the unread count correctly (3), but when didChangeChannels
with change type .update
is rendered, the unread count is erroneously set to 0. Here's the log of print outs to console:
StreamChatManager: Initializing shared ChatClient
StreamChatManager: ChatClient initialized
StreamViewModel: Initializing
StreamChatManager: Setting up StreamChat
StreamChatManager: Setting up ColorPalette
StreamChatManager: Setting up Fonts
StreamChatManager: StreamChat setup complete
StreamViewModel: Initialization complete
StreamAuthManager: Set current user ID to 2
StreamViewModel: Attempting to connect user with ID: 2
StreamAuthManager: Attempting to fetch Stream Chat token from Corgi backend
*** STREAM TOKEN Fetch - Response data: {"token":"eyJhbGciOiJIUzI1NiJ9.eyJ1c2VyX2lkIjoiMiIsImV4cCI6MTcyMTkyNjUxNn0.ujA7Jfjzlq3Evl10e5l7qSV3SBxL3XAdFswQv8UFrLM"}
*** STREAM TOKEN Fetch - Received token successfully
StreamViewModel: Successfully connected to Stream Chat
StreamViewModel: Setting up channel list controller
Stream FCM Registration: User Optional("2") w/ FCM token Optional("drYMX8OA4khQioWzVbI6Ga:APA91bEyc9eQ0_JZ1-iAtvr_x5FM46TzctMo0oQqjhvllSRhJiN1EZKUgsrRZtS3lhuX1wvhJJMahm4k-LVFfBqX-yJwKR7jAO1ruKWT0HvKIJKntSeySCgmysbNyZTo7VVs0BPuEs36")
didChangeChannels / Channel list changed
didChangeChannels / Channel inserted: messaging:!members-wTjPcfeby15F8k7KihkNiW5IdpDZYzkZy3zUZ5SvBr8 at index [0, 0]
Unread count: 3 messages, 0 mentions
didChangeChannels / Channel list changed
didChangeChannels / Channel updated: messaging:!members-wTjPcfeby15F8k7KihkNiW5IdpDZYzkZy3zUZ5SvBr8 at index [0, 0]
Unread count: 0 messages, 0 mentions
Last message at: 2024-07-24 16:54:52 +0000
Created at: 2024-07-18 05:28:56 +0000
Updated at: 2024-07-18 05:28:56 +0000
To get to this understanding, we added the following extension to the Swift SDK delegate:
extension StreamViewModel: ChatChannelListControllerDelegate {
func controller(_ controller: ChatChannelListController, didChangeChannels changes: [ListChange<ChatChannel>]) {
print("didChangeChannels / Channel list changed")
for change in changes {
switch change {
case .insert(let channel, index: let index):
print("didChangeChannels / Channel inserted: \(channel.cid) at index \(index)")
print("Unread count: \(channel.unreadCount.messages) messages, \(channel.unreadCount.mentionedMessages) mentions")
case .update(let channel, index: let index):
print("didChangeChannels / Channel updated: \(channel.cid) at index \(index)")
print("Unread count: \(channel.unreadCount.messages) messages, \(channel.unreadCount.mentionedMessages) mentions")
print("Last message at: \(channel.lastMessageAt?.description ?? "N/A")")
print("Created at: \(channel.createdAt)")
print("Updated at: \(channel.updatedAt)")
case .remove(let channel, index: let index):
print("didChangeChannels / Channel removed: \(channel.cid) at index \(index)")
case .move(let channel, fromIndex: let fromIndex, toIndex: let toIndex):
print("didChangeChannels / Channel moved: \(channel.cid) from index \(fromIndex) to \(toIndex)")
}
}
}
}
What did you expect to happen?
Unread counts should only change when the user accesses the channel. In this case, the user did not access the channel and the unread count is being reset to 0 for all channels.
What happened instead?
See above
GetStream Environment
GetStream Chat version: 4.60.0
GetStream Chat frameworks: StreamChat, StreamChatUI
iOS version: 17.5
Swift version: 5
Xcode version: 15.4
Device: iPhone 14 Pro (physical) and iPhone 15 Pro (emulator)
Additional context
Hi @jonahhugit,
We can't reproduce this in our Demo App. Aren't you calling markRead()
accidently?
To properly debug this, I recommend you use a Proxy (ex, https://proxyman.io/) to analyse the HTTP traffic and see the responses and requests your application is making.
Best,
Nuno
Hi team - here are the results of testing in Proxyman.
We have this state before we reload the iOS simulator:
This is the native interface (from the Swift UI Tutorial) with only the header modified. The channel with the 6 unread messages is cid wTjPcfeby15F8k7KihkNiW5IdpDZYzkZy3zUZ5SvBr8
Upon reloading the iOS simulator, here are the HTTP calls to Stream, in sequence from Proxyman (nothing is missing - these are all the calls on set up). It would appear that the unread count is always 0 from the /channels/
endpoint.
Call 1
https://chat.stream-io-api.com/app?api_key=REDACTED
Response:
{
"app": {
"name": "Corgi",
"async_url_enrich_enabled": true,
"auto_translation_enabled": false,
"file_upload_config": {
"allowed_file_extensions": [],
"blocked_file_extensions": [],
"allowed_mime_types": [],
"blocked_mime_types": [],
"size_limit": 0
},
"image_upload_config": {
"allowed_file_extensions": [],
"blocked_file_extensions": [],
"allowed_mime_types": [],
"blocked_mime_types": [],
"size_limit": 0
},
"video_provider": "",
"moderation_enabled": false
},
"duration": "0.48ms"
}
Call 2
wss://chat.stream-io-api.com/connect?api_key=REDACTED&json=%7B%22server_determines_connection_id%22:true,%22user_details%22:%7B%22id%22:%221%22%7D,%22user_id%22:%221%22%7D
Call 3
https://chat.stream-io-api.com/channels?api_key=REDACTED&payload=%7B%22watch%22:true,%22limit%22:20,%22message_limit%22:25,%22filter_conditions%22:%7B%22members%22:%7B%22$in%22:%5B%221%22%5D%7D%7D,%22member_limit%22:30%7D&connection_id=6669ae3d-0a1d-1cb8-0200-00000339d8b2
Response: Call3-Body.json
Channels > Read for is 0'ed out across the board
Call 4
https://chat.stream-io-api.com/sync?api_key=REDACTED
Response: Call4-Body.json
Call 5
https://chat.stream-io-api.com/channels?api_key=REDACTED&payload=%7B%22filter_conditions%22:%7B%22members%22:%7B%22$in%22:%5B%221%22%5D%7D%7D,%22member_limit%22:30,%22limit%22:20,%22message_limit%22:25,%22watch%22:true%7D&connection_id=6669ae3d-0a1d-1cb8-0200-00000339d8b2
Response: Call5-Body.json
Channels > Read for is 0'ed out across the board
Call 6
https://chat.stream-io-api.com/devices?api_key=REDACTED
Response:
{
"duration": "0.74ms"
}
Hi @jonahhugit,
I see, then this seems to be a backend issue related to your app and not an issue on the iOS SDK. So you will need to report this to customer support as well.
If you provide all this data, they should be able to check what the issue is.
Thank you for your patience!
Best,
Nuno
Thank you Nuno! New ticket submitted for the support team to route to your backend folks - under tix 53266