Fix various issues with embeds on message updates
The `postHandleMessage` function is parsing links and adding them to the
EmbedCache table if necessary. In the previous implementation, message
updates would push to the embeds unconditionally.

This commit parses links from the message and:

1. Normalizes the URLs
  - Useful for deduplicating similar URLs
2. Remove embeds with matching normalized URLs
  - Leaves all embeds except for ones with a `.url` property matching
  the updated message
  - This allows embeds to be re-ordered if the URL is moved
3. If no normalized URLs are found, remove all embeds
4. Take the deduplicated + normalized URLs and add an embed to the message and
insert into the EmbedCache table (if necessary)

This enables:

1. Embeds to be re-ordered by re-ordering links
2. Embeds to be removed by removing links

and fixes:

1. Duplicate embeds being attached to a message when edited
1 parent c0f9c22 commit f9cfb46e73b2e51d0c48fe509594bc3338ed65ac
@Zane Helton Zane Helton authored on 28 Jun 2025
Madeline committed on 28 Jun 2025
Showing 3 changed files
View
src/api/util/handlers/Message.ts
View
src/util/util/Url.ts 0 → 100644
View
src/util/util/index.ts