stream-chat-swift icon indicating copy to clipboard operation
stream-chat-swift copied to clipboard

channel 'deletedAt' state is not updating after delete channel completion

Open muaviyaijaz123 opened this issue 3 years ago • 10 comments

What did you do?

I deleted a channel and want to perform some operation on the deleted channel on the basis 'deletedAt' variable

What did you expect to happen?

I expected 'deletedAt' variable to change state

What happened instead?

The states remained the same for the variable. I have attached the below SS: Screen Shot 2022-09-28 at 4 04 56 PM

GetStream Environment

GetStream Chat version: GetStream Chat frameworks: StreamChat, StreamChatUI iOS version: Swift version: Xcode version: Device:

Additional context

muaviyaijaz123 avatar Sep 28 '22 11:09 muaviyaijaz123

Hi @muaviyaijaz123!

Currently, if you want to get the updated channel, you need to make sure you call synchronize() on the channel controller and set the delegate to observe the didUpdateChannel event. There you will be able to get the updated channel.deletedAt like so:

func channelController(_ channelController: ChatChannelController, didUpdateChannel channel: EntityChange<ChatChannel>) {
    debugPrint(channelController.channel?.deletedAt)
}

Let me know if that is enough for you.

Best, Nuno

nuno-vieira avatar Sep 28 '22 14:09 nuno-vieira

@nuno-vieira Yeah , got your point but i think i need to elaborate the problem

The main issue is when i invite another user, he receives a notification for the invite on his device. Now, i delete the channel from my end and it disappears and hide on my device which is okay but the other user still has the notification on his device for that chat and he can click on that notification for that deleted channel on his device to accept or reject.

I dont want him to have that notiifcation or notification click

muaviyaijaz123 avatar Sep 29 '22 06:09 muaviyaijaz123

Hi @muaviyaijaz123,

I don't think I'm understanding the problem. Why is the deletedAt useful to avoid that?

nuno-vieira avatar Sep 29 '22 10:09 nuno-vieira

I want that user to stop navigating to that channel on notification click based on this property

muaviyaijaz123 avatar Sep 29 '22 10:09 muaviyaijaz123

And why is the delegate not useful in this case? That part is what I'm not understanding. Why do you need the deletedAt in the completion block?

nuno-vieira avatar Sep 29 '22 12:09 nuno-vieira

@muaviyaijaz123 Meanwhile, we can improve this in the deleteChannel call, but this will only be available on the next release. So the delegate would unblock you for now.

nuno-vieira avatar Sep 29 '22 13:09 nuno-vieira

The snippet which i sent you is indicating i am deleting a channel on my device and the print statement for deletedAt is only for log purpose.

I want deletedAt for the other user 's device to which i sent request to. When he clicks on notification from background , the following code runs for him and takes him to that channel, so i want deletedAt here on "selectedChannel" indicated in the following code: Screenshot_2022-09-29_at_6 14 52_PM

And why is the delegate not useful in this case? That part is what I'm not understanding. Why do you need the deletedAt in the completion block?

muaviyaijaz123 avatar Sep 29 '22 13:09 muaviyaijaz123

You are saying you want to call deleteChannel in one user and in the other user (other device), when he clicks on the notification, do you want to get the deletedAt updated? This is not possible unless you call synchronize() and update the deleted channel with the remote server. Fixing the deleteChannel completion block has nothing to do with this flow. The deletedAt property will be available only on the device for which this was called. Keep in mind, the issue is not that deletedAt is not updated. The property is updated, and you can observe it with the delegate. The current problem in the SDK is that when the completion block is executed, it is executed before the deleteAt property is updated, but this will not have any impact on other devices.

You need to be more clear on your intent. Record a video or something, otherwise, it is hard to understand what you are trying to achieve.

nuno-vieira avatar Sep 29 '22 13:09 nuno-vieira

Video_recording.mp4.zip

@nuno-vieira Here s the video. The other user has the notification for the deleted channel and i dont want him to navigate for that deleted channel on click as he can accept or reject. Thanks for looking into it in depth!

muaviyaijaz123 avatar Sep 29 '22 14:09 muaviyaijaz123

Hi @muaviyaijaz123!

Like I said in the previous message, the issue you reported, won't solve your problem. The behaviour you are mentioning is normal, and you can also replicate it on our DemoApp. If you get a notification for a channel, and before clicking on that notification the channel is deleted, it will open the channel that it is already deleted. In our DemoApp, we don't currently do anything about it, so if you send messages, they will fail, because the channel doesn't exist anymore. But in a real app, when you open the channel view, you can observe the didUpdateChannel after syncing the channel, and if it is deleted, you should go back to the channel list and display a message that the channel was deleted, something like this.

So indeed, the completion block is fired before the deletedAt property has been updated, and the issue you reported is valid, but this won't have any impact on another device.

Best, Nuno

nuno-vieira avatar Sep 30 '22 14:09 nuno-vieira

Hi @muaviyaijaz123!

After reviewing a little more deeper, all our controllers are working like this. If you need to observe data changes, you need to call synchronize() and use the controller's delegate. You should only use the completion block to observe if the call failed. This is the current pattern in the SDK, and it does not make sense to change it for this specific case. We might improve this in the future, and change this pattern, but probably only in the major version. Right now, this is working as intended.

Hope you understand.

Best, Nuno

nuno-vieira avatar Oct 07 '22 13:10 nuno-vieira