revoltchat / backend

Monorepo for Revolt backend services.
https://developers.revolt.chat/api/
Other
1.14k stars 125 forks source link

bug: API does not return a mentions field when a message is edited to contain a mention #317

Closed Asudox closed 4 months ago

Asudox commented 5 months ago

What happened?

When a user sends a message and then edits the message to include a mention, the API does not return a mentions field containing the mention in the message object. Furthermore, when a message with a mention gets a new mention via editing, the new mention is completely ignored and the mention before the new mention was edited in is included in the mentions field. Regardless, the new mention is visible in the content field.

API response of a message without a mention:

{
  "_id": "01HV4C9ERCNDP0MXTW1N3NG6HQ",
  "nonce": "01HV4C9EEZ3ZD01WRKXN3GYAYR",
  "channel": "01HV4BMSR5WNJ5H5HBBBZ7B87W",
  "author": "01HTD2B8QN4NZCAXABYWZP1YH8",
  "content": "test"
}

API response of the same but edited message that has a mention in it:

{
  "_id": "01HV4C9ERCNDP0MXTW1N3NG6HQ",
  "nonce": "01HV4C9EEZ3ZD01WRKXN3GYAYR",
  "channel": "01HV4BMSR5WNJ5H5HBBBZ7B87W",
  "author": "01HTD2B8QN4NZCAXABYWZP1YH8",
  "content": "test <@01HTD2B8QN4NZCAXABYWZP1YH8> ",
  "edited": "2024-04-10T16:09:46.064Z",
  "embeds": []
}

As you can see above, the mention is visible in the content field, but no mentions field is supplied with the API response.

API response of a message with a mention:

{
  "_id": "01HV4CH5BRSJA0NN2HGKS22AG0",
  "nonce": "01HV4CH5ADMD8CC8VPST5YQM5W",
  "channel": "01HV4BMSR5WNJ5H5HBBBZ7B87W",
  "author": "01HTD2B8QN4NZCAXABYWZP1YH8",
  "content": "test <@01HTD2B8QN4NZCAXABYWZP1YH8>",
  "mentions": [
    "01HTD2B8QN4NZCAXABYWZP1YH8"
  ]
}

API response of the same but edited message that now has another mention in it:

{
  "_id": "01HV4CH5BRSJA0NN2HGKS22AG0",
  "nonce": "01HV4CH5ADMD8CC8VPST5YQM5W",
  "channel": "01HV4BMSR5WNJ5H5HBBBZ7B87W",
  "author": "01HTD2B8QN4NZCAXABYWZP1YH8",
  "content": "test <@01HTD2B8QN4NZCAXABYWZP1YH8> <@01HTDCMKX8XMCFC8ZFT2ZH90YH>",
  "edited": "2024-04-10T16:14:45.082Z",
  "embeds": [],
  "mentions": [
    "01HTD2B8QN4NZCAXABYWZP1YH8"
  ]
}

The new mention is visible in the content field but the mentions field is not updated to contain the new mention.

Expected Result: The API should return a mentions field that contains all mentions present in the message, including those added after the initial message was sent.

insertish commented 4 months ago

This is intentional behaviour as the 'mentions' field is meant to be interpreted as the users that the message notified at the time of sending. Calculating the current mentions list should be relatively cheap for the receiving client if necessary.

I'm going to close this out unless if others chime in and agree this should be changed, I would probably recommend proposing this change as an RFC for further discussion if there is interest.