(iOS/Swift) Using SBSMChannelCollectionDelegate when I receive a new message it updated twice the channel when the app is on foreground, the first time with the correct data, correct number of unread messages, etc. the second time it updates it has 0 new messages, but moving to background or closing and opening the app, fixes the channel data.
thought updating the SDK would fix the issue but it didn’t. SDK before Update
func collection(_ collection: SBSMChannelCollection, didReceiveEvent action: SBSMChannelEventAction, channels: [SBDGroupChannel]) {
switch (action) {
case .insert:
break
case .update:
// This is getting called/triggered twice the first time with the correct data, second time it is like the channel was marked as read.
break
case .remove:
break
case .move:
break
case .clear:
break
case .none:
break;
}
}
Hi Woo, I originally thought that was the issue, and I checked an placed breakpoints in the only place we call markAsRead but the channel is not being marked as read, just moving the app to the background and bringing it back to the foreground shows the correct channel data with the correct number of unread messages and everything, so when the event in collection: case .update: gets called twice the first time it has the correct data, the second time it is like if it was markAsRead but it wasn’t, and sending it to the background fixes the data in the channel.
How do you handle messages when .update action was called, specifically how did you display your cell with? you said that it was called twice, first with correct message and second with no message. Can you see if any difference on channel objects in those two calls?
when .update is called we replace/update the channel object in our channel array, the first time channel object is correct with all the data(correct number of unread messages, etc.), second time it gets called the channel object has 0 unread messages even if they where not marked as read.
First Call channel: <channel url: 4b68e, created at: 1585589464, last message: Test unread messages, msg created at: 1592437888703>
Last Message Optional(0x600002e38c40 - Message: Test unread messages, ID: 4613012829, Sender: Bdbdjdjjwnw Jdjdjd jdjdjd, Timestamp: 1592437888703)
channel unread Messages 1
Second Call
channel <channel url: 4b68e, created at: 1585589464, last message: Test unread messages, msg created at: 1592437888703>
Last Message Optional(0x600002e38c40 - Message: Test unread messages, ID: 4613012829, Sender: Bdbdjdjjwnw Jdjdjd jdjdjd, Timestamp: 1592437888703)
channel unread Messages 0
after a while, managerSync will update correctly, or when moving it to background which forces manager sync to update/sync the channels which will cause channel unread Messages to increase to 1
I wrote a test case that simulated the situation you described. Unfortunately, I was not able to reproduce the same result. Can you provide the code snippet that shows how you use SyncManager? Also, from the video, it seems like your app was foreground yet you receive push notification. Is this intentional?
thanks!!, is there someone we can contact or anyone who can help out fix this issue, since we have multiple projects with sendbird, and this one is being delayed by this issue.
@Cris_Warren are you sure .update event calls twice? I just tested it and it seems like the delegate get called twice but .move and .update respectively