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

Channel's subscriptions to onMessageAdded and onMessageDeleted not called on iOS #31

Open
hugomc92 opened this issue Jul 2, 2024 · 8 comments

Comments

@hugomc92
Copy link

hugomc92 commented Jul 2, 2024

It's working fine on Android but on Android it doesn't call the flutter implementation when listen to them

Version 1.1.7+9

Example:

channel.onMessageAdded?.listen((message) async {
        console.log('_generateConversation channel.onMessageAdded', channel.sid);

        // Not being called on iOS
}),

channel.onMessageDeleted?.listen((message) async {
        console.log('_generateConversation channel.onMessageDeleted', channel.sid);

        // Not being called on iOS
}),
@asmodeoux
Copy link
Contributor

Should be solved in a 2.0.1 quickfix, closing

@hugomc92
Copy link
Author

hugomc92 commented Jul 4, 2024

Hello @asmodeoux

It's not completely fixed yet.

Now it's being called sometimes and others no, same code, same circumstances, so I can't know why sometimes the listeners are being called and others not.

Thanks in advance for your review

@asmodeoux asmodeoux reopened this Jul 4, 2024
@martintrollip
Copy link
Contributor

martintrollip commented Jul 7, 2024

@hugomc92, you can try to add this and listen for the channel to be synchronized on IOS

/// Listen to Twilio client synchronization events
client.onClientSynchronization?.listen((status) {
      if (_isSynced(status)) {
           /// subscribe to channel.onMessageAdded and channel.onMessageDeleted
      }
}

bool _isSynced(ChatClientSynchronizationStatus status) {
    return status == ChatClientSynchronizationStatus.CONVERSATIONS_COMPLETED ||
        (status == ChatClientSynchronizationStatus.COMPLETED && client.channelsInitialized());
}

@hugomc92
Copy link
Author

hugomc92 commented Jul 8, 2024

Hello @martintrollip

I'm going to give it a try and I'll subscribe to the listeners after the client synchronization are completed.

However, the client.channelsInitialized is not defined in ChatClient and I didn't found anything similar to it into that class:

Captura de pantalla 2024-07-08 a las 18 01 49

Thanks in advance for your answer!

EDIT: I've tried with this function to ensure the client is initialized:

bool _isClientSynced(ChatClientSynchronizationStatus? status) {
    return status == ChatClientSynchronizationStatus.CONVERSATIONS_COMPLETED;
}

But when I print the ChatClientSynchronizationStatus current status it always is ChatClientSynchronizationStatus.COMPLETED and don't change to ChatClientSynchronizationStatus.CONVERSATIONS_COMPLETED never

@martintrollip
Copy link
Contributor

For the channelsInitialized you can check that the client channels is not null.

client?.channels != null

From the example code, it looks like Android and IOS handles initialization slightly differently,

See the example in subscriptions_middleware.dart:

store.state.chatClient?.onClientSynchronization?.listen((event) async {
        // in Android there is a separate event to identify when fully initialized
        // in iOS we do check manually
        if (event == ChatClientSynchronizationStatus.CONVERSATIONS_COMPLETED ||
            (event == ChatClientSynchronizationStatus.COMPLETED &&
                store.state.chatClient?.channels != null)) {
                    ....
        }

@hugomc92
Copy link
Author

hugomc92 commented Jul 9, 2024

Hello @martintrollip

Thanks for your reply. I was actually checking the channels was not null before subscribing.

Anyways I tried your full solution and the problem still persists. There’re sometimes the listeners are being fired and other not on iOS. On Android it works perfect.

Thanks for your replies

@martintrollip
Copy link
Contributor

martintrollip commented Jul 15, 2024

Hi @hugomc92,

We only used this during initialisation:

  1. final client = await TwilioConversationsClient.create(token, Properties());
  2. client?.onClientSynchronization?.listen(....) (as above)

Any other checks and listeners on channels / messages will only happen once the client sent the synchronisation status.

Other than this I'm not sure how to reproduce the issue for further investigations

@jullicer
Copy link

jullicer commented Nov 15, 2024

Any update to this bug? i have issue with the LAST_CONSUMED_MESSAGE_INDEX either from channel or member update.

The logs are shown from console but my listener callback isn't called. But on the onMessageAdded it is working fine.

` twilioSub.add(client!.onChannelUpdated!.listen((channelUpdate) {
print("LAST_CONSUMED_MESSAGE_INDEX $channelUpdate");

    /// check if reason is LAST_CONSUMED_MESSAGE_INDEX
    if (channelUpdate.reason == ChannelUpdateReason.LAST_CONSUMED_MESSAGE_INDEX) {
      onLastMessageIndexChanged(channelUpdate.channel.lastMessageIndex!);
    }
  }));`

ChannelListener.onMemberUpdated => memberSid = MBd47ae420b5764ab4b7581a54ceb880ee, reason = LAST_READ_MESSAGE_INDEX D/TwilioInfo(14167): ChannelListener.onMemberUpdated => memberSid = MBd47ae420b5764ab4b7581a54ceb880ee, reason = LAST_READ_MESSAGE_INDEX D/TwilioInfo(14167): ChannelListener.onMemberUpdated => memberSid = MBd47ae420b5764ab4b7581a54ceb880ee, reason = LAST_READ_MESSAGE_INDEX D/TwilioInfo(14167): ChannelListener.onMemberUpdated => memberSid = MBd47ae420b5764ab4b7581a54ceb880ee, reason = LAST_READ_MESSAGE_INDEX D/TwilioInfo(14167): ChannelListener.onMemberUpdated => memberSid = MBd47ae420b5764ab4b7581a54ceb880ee, reason = LAST_READ_MESSAGE_INDEX D/TwilioInfo(14167): ChannelListener.onMemberUpdated => memberSid = MBd47ae420b5764ab4b7581a54ceb880ee, reason = LAST_READ_MESSAGE_INDEX D/TwilioInfo(14167): ChannelListener.onMemberUpdated => memberSid = MBd47ae420b5764ab4b7581a54ceb880ee, reason = LAST_READ_MESSAGE_INDEX

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

No branches or pull requests

4 participants