cometchat / chat-sdk-react-native

Voice & Video Calling and Text Chat SDK for React Native
Other
18 stars 17 forks source link

Request builder not updating on updating tags #35

Closed jasimawan closed 4 months ago

jasimawan commented 5 months ago

Describe the problem

I am working on my client's application where we are implemented Chats using Comet chat and I am using conversation builder using this:

const conversationsRequestBuilder = useMemo(() => {
    const requestBuilder = new CometChat.ConversationsRequestBuilder()
      .setLimit(25)
      .setConversationType(ConversationTypeConstants.both)
      .withTags(true);

    const superMethod = requestBuilder.build.bind(requestBuilder);
    requestBuilder.build = () => {
      const originalBuilt = superMethod();
      const originalFetchNext = originalBuilt.fetchNext.bind(originalBuilt);
      originalBuilt.fetchNext = async () => {
        const next = inboxService.current.filterConversations(
          await originalFetchNext(),
          archived,
          searchKey,
        );

        return next.sort(customPinComparator);
      };
      return originalBuilt;
    };
    return requestBuilder;
  }, [searchKey, archived, inboxService]);

And I am using it in the <CometChatConversations conversationsRequestBuilder={inboxBuilder} />

What was the expected behavior?

So when I update some tags for my conversations, like pin/unpin. I want my CometChatConversations to be re-rendered automatically with updated tags. But its not updating and I had to reload the page completely to see my changes.

Environment

Please provide the following: Expo

cometchat-helpcenter-bot commented 5 months ago

Keagan (CometChat Team) replied:

Hello,

Thank you for reaching out and sharing your concern with us.

Please do allow us sometime to review your query and circle back with more Information at the earliest.

Regards

Keagan Ellis CometChat

cometchat-helpcenter-bot commented 5 months ago

Afroz Khan (CometChat Team) replied:

Hi,

To ensure that the CometChatConversations component re-renders automatically when you update tags such as pin/unpin, you can follow this approach:

  1. State Management: Introduce a state variable that tracks changes in tags.
  2. Update Mechanism: Modify this state variable whenever tags are updated.
  3. Re-render Trigger: Use this state variable as a key or dependency to trigger a re-render of the component.

By doing this, you can ensure that the CometChatConversations component reflects the updated tags without needing to manually reload the page. This approach forces the component to treat updates as new inputs, ensuring proper re-rendering.

Please try this method and let us know if this works for you.

Best regards

Afroz Khan CometChat