GetStream / stream-chat-react-native

💬 React-Native Chat SDK ➜ Stream Chat. Includes a tutorial on building your own chat app experience using React-Native, React-Navigation and Stream
https://getstream.io/chat/sdk/react-native/
Other
955 stars 321 forks source link

Under poor network conditions, sometimes channel.sendMessage() will return an error, when it is actually successful #2245

Open derekchan916 opened 1 year ago

derekchan916 commented 1 year ago

I'll try to be as descriptive as possible, and please let me know if this is my issue. Attached is a video of what happens in the UI. I am using react-native. (Versions will be listed below).

Problem

https://github.com/GetStream/stream-chat-js/assets/12720511/d641acfc-bd21-4493-92b6-1fcd282deea2 Please take a look starting at the 10 second mark. There are a couple of key points here:

Here is the code below, it is the default code from stream chat react native

In Channel.tsx:

  const sendMessageRequest = async (
    message: MessageResponse<StreamChatGenerics>,
    retrying?: boolean,
  ) => {
    try {
      const updatedMessage = await uploadPendingAttachments(message);
      const {
       // ...default code
        user,
        ...extraFields
      } = updatedMessage;
      if (!channel.id) {
        return;
      }

      const mentionedUserIds = mentioned_users?.map(user => user.id) || [];

      const messageData = {
        attachments,
        id,
        mentioned_users: mentionedUserIds,
        parent_id,
        text: patchMessageTextCommand(text ?? '', mentionedUserIds),
        ...extraFields,
      } as StreamMessage<StreamChatGenerics>;

      let messageResponse = {} as SendMessageAPIResponse<StreamChatGenerics>;
      if (doSendMessageRequest) {
         // ...default code
      } else if (channel) {
        messageResponse = await channel.sendMessage(messageData);
      }

      if (messageResponse.message) {
        // ...default code, it doesn't reach here
      }
    } catch (err) {
      console.log(err) // THIS IS WHERE THE ERROR MESSAGE IS
      message.status = MessageStatusTypes.FAILED;
      updateMessage({...message, cid: channel.cid});

      if (enableOfflineSupport) {
       // ...default code
    }
  };

My package versions:

{
  "stream-chat": "^8.10.1",
  "react-native": "0.71.11",
}

The stream-chat-react-native code is directly forked, [v5.15.0](https://github.com/GetStream/stream-chat-react-native/releases/tag/v5.15.0)

Thanks, please let me know if you need more information.

pomSense commented 11 months ago

Getting the same issue on querying.

khushal87 commented 2 months ago

Hey @derekchan916, can you try out in the latest version of the SDK and let us know if it is still a problem for you? Thanks 😄