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

question: Duplicate data when use API channel.getPinnedMessages #2627

Closed
vihan85 opened this issue Feb 2, 2025 · 7 comments
Closed

question: Duplicate data when use API channel.getPinnedMessages #2627

vihan85 opened this issue Feb 2, 2025 · 7 comments
Labels
question Support request

Comments

@vihan85
Copy link

vihan85 commented Feb 2, 2025

Describe the bug

Duplicate data when use API channel.getPinnedMessages

To Reproduce
https://miro.com/app/board/uXjVLlZ3HP0=/

Expected behavior
No duplicate data when get data in next page

Package version
stream-chat-react: ^12.6.0
stream-chat: "^8.40.9"

@vihan85 vihan85 added bug Something isn't working status: unconfirmed labels Feb 2, 2025
@MartinCupela
Copy link
Contributor

Hello @vihan85 , could you please provide reproduction steps? The most effective approach would be to have a functioning example in a forked sandbox

@vihan85
Copy link
Author

vihan85 commented Feb 5, 2025

Hello @vihan85 , could you please provide reproduction steps? The most effective approach would be to have a functioning example in a forked sandbox

Hi @MartinCupela

Give you my demo

Step 1: clicking button page 1 (list next page of pinned messages)
Step 2: clicking button next (list next page of pinned messages)

https://codesandbox.io/p/devbox/modest-hoover-hwgwky?file=%2Fsrc%2FApp.tsx%3A95%2C1

@MartinCupela MartinCupela added question Support request and removed bug Something isn't working status: unconfirmed pending-reply labels Feb 5, 2025
@MartinCupela MartinCupela changed the title bug: Duplicate data when use API channel.getPinnedMessages question: Duplicate data when use API channel.getPinnedMessages Feb 5, 2025
@MartinCupela
Copy link
Contributor

Hey @vihan85 , the duplication happens because of incorrect pagination parameter:

Instead of taking the newest pinned message:

const descLastMsg = pinnedMessages[pinnedMessages.length - 1];

Take the last one:

const descLastMsg = pinnedMessages[0];

You did not realize, that at the index 0, there is the oldest message as they are ordered in asc order.

@vihan85
Copy link
Author

vihan85 commented Feb 6, 2025

Hi @MartinCupela ,

@MartinCupela
Copy link
Contributor

Hey @vihan85 , by default, the pinned messages are sorted in ascending order as can be seen from the response in developer tools. What results are expected by you?

@MartinCupela
Copy link
Contributor

MartinCupela commented Feb 6, 2025

So, getPinnedMessages gets messages sorted ascending by pinned_at value. To get the next page, you will need to ask for id_gt instead of id_lt. And the id should belong to the last message in the pinnedMessages array.

const ascLastMsg = pinnedMessages[pinnedMessages.length - 1];

    if (!ascLastMsg) return;

    const pinedMessagesOtherPage = await channel.getPinnedMessages({
      limit: 2,
      id_gt: ascLastMsg!.id,
    });

@MartinCupela
Copy link
Contributor

I will update the docs

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

No branches or pull requests

2 participants