RocketChat / RocketChat/Rocket.Chat

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

Open
#36,087 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
TypeScript
Stars
46.1k
Forks
13.9k
Avg merge
3d 3h
Merged PRs (30d)
130

Description

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().

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start at the chat.getPinnedMessages endpoint and inspect how its query parameters are parsed before the call to Messages.findPaginatedPinnedByRoom(). Confirm that the URL-encoded sort value reaches the method's options, then verify that requests such as sort={"ts":-1} return pinned messages in the requested order.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
api
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
55/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.