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

same message is sent multiple times to the receiver #49

Open
keanyee opened this issue Oct 9, 2022 · 4 comments
Open

same message is sent multiple times to the receiver #49

keanyee opened this issue Oct 9, 2022 · 4 comments

Comments

@keanyee
Copy link

keanyee commented Oct 9, 2022

Same message was sent multiple times to the receiver (userId 1) from sender (userId 1) even though the sender only sent it once.
You can see the local time and server time are all the same for the message.

I/flutter (30685): {from: 2, to: 1, body: {type: txt, content: u, translations: {}}, direction: rec, hasRead: false, hasReadAck: false, hasDeliverAck: false, needGroupAck: false, msgId: 1063987074572487632, conversationId: 2, chatType: 0, localTime: 1665293596977, serverTime: 1665293595422, status: 2, isThread: false}
I/flutter (30685): {from: 2, to: 1, body: {type: txt, content: u, translations: {}}, direction: rec, hasRead: false, hasReadAck: false, hasDeliverAck: false, needGroupAck: false, msgId: 1063987074572487632, conversationId: 2, chatType: 0, localTime: 1665293596977, serverTime: 1665293595422, status: 2, isThread: false}
I/flutter (30685): {from: 2, to: 1, body: {type: txt, content: u, translations: {}}, direction: rec, hasRead: false, hasReadAck: false, hasDeliverAck: false, needGroupAck: false, msgId: 1063987074572487632, conversationId: 2, chatType: 0, localTime: 1665293596977, serverTime: 1665293595422, status: 2, isThread: false}
I/flutter (30685): {from: 2, to: 1, body: {type: txt, content: u, translations: {}}, direction: rec, hasRead: false, hasReadAck: false, hasDeliverAck: false, needGroupAck: false, msgId: 1063987074572487632, conversationId: 2, chatType: 0, localTime: 1665293596977, serverTime: 1665293595422, status: 2, isThread: false}
I/flutter (30685): {from: 2, to: 1, body: {type: txt, content: u, translations: {}}, direction: rec, hasRead: false, hasReadAck: false, hasDeliverAck: false, needGroupAck: false, msgId: 1063987074572487632, conversationId: 2, chatType: 0, localTime: 1665293596977, serverTime: 1665293595422, status: 2, isThread: false}
I/flutter (30685): {from: 2, to: 1, body: {type: txt, content: u, translations: {}}, direction: rec, hasRead: false, hasReadAck: false, hasDeliverAck: false, needGroupAck: false, msgId: 1063987074572487632, conversationId: 2, chatType: 0, localTime: 1665293596977, serverTime: 1665293595422, status: 2, isThread: false}

@dujiepeng
Copy link
Contributor

@keanyee Do you add the listener multiple times, for example by writing the add listener to the build method?

@keanyee
Copy link
Author

keanyee commented Oct 11, 2022

@dujiepeng only once.

  @override
  void initState() {
    super.initState();
    _initSDK();
    _login();
    _addChatListener();
  }
  
  void _addChatListener() {
    ChatClient.getInstance.chatManager.addEventHandler(
        chatUniqueHandlerID,
        ChatEventHandler(onMessagesReceived: onMessagesReceived)
    );
  }
  
 void _sendMessage(String message) async {
    var msg = ChatMessage.createTxtSendMessage(
      targetId: '1',
      content: message,
    );
    msg.setMessageStatusCallBack(
        MessageStatusCallBack(
          onSuccess: () {},
          onError: (e) {
            print(e);
            final errorMessage = "Send message failed, code: ${e.code}, desc: ${e.description}";
            print(errorMessage);
          },
        )
    );
    await ChatClient.getInstance.chatManager.sendMessage(msg);
  }

the onMessagesReceived function is from the flutter example .

@dujiepeng
Copy link
Contributor

@keanyee
this is the only page that has ever executed addEventHandler operation? If there are more than one EMChatEventHandler, all EMChatEventHandler are executed. When dispose of a page, use chatUniqueHandlerID to remove EMChatEventHandler.

@darshil123332
Copy link

Add below line in dispose method.

ChatClient.getInstance.chatManager.clearEventHandlers();

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

3 participants