Skip to content

[API Bug] chat.getPinnedMessages does not support sort parameter despite documentation #36087

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

Open
Jacksonzhang0316 opened this issue May 27, 2025 · 0 comments

Comments

@Jacksonzhang0316
Copy link

Description

The official documentation for the GET /api/v1/chat.getPinnedMessages endpoint states that a sort parameter can be passed to sort pinned messages. However, after reviewing the actual source code of the endpoint, it appears that the sort parameter is neither parsed nor passed into the internal message query function, rendering it ineffective.

Steps to Reproduce

  1. Call the chat.getPinnedMessages endpoint with a sort query parameter, e.g.:
    GET /api/v1/chat.getPinnedMessages?roomId=GENERAL&sort={"ts":-1}

(Properly URL-encoded: sort=%7B%22ts%22%3A-1%7D)

  1. The response always returns messages in the default order (likely unsorted or backend-determined), and the sort order has no effect.

Source Code Analysis

The current implementation of chat.getPinnedMessages does not parse or forward the sort parameter:

const { cursor, totalCount } = Messages.findPaginatedPinnedByRoom(roomId, {
skip: offset,
limit: count,
// missing: sort
});

Even though the internal Messages.findPaginatedPinnedByRoom method does accept a FindOptions object that includes a sort field:

findPaginatedPinnedByRoom(roomId: IMessage['rid'], options?: FindOptions<IMessage>): FindPaginated<FindCursor<IMessage>> {
  const query: Filter<IMessage> = {
    t: { $ne: 'rm' },
    _hidden: { $ne: true },
    pinned: true,
    rid: roomId,
  };

  return this.findPaginated(query, options);
}

Expected Behavior

The API should properly accept and parse the sort parameter (e.g., {"ts": -1}) from the query string and pass it to Messages.findPaginatedPinnedByRoom().

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

1 participant