Share every bot and workspace picture with everyone signed in

A bot's or workspace's picture was only shared when its media row carried
the bot-image or workspace-image paradigm. A picture set before pictures
were copied into their own row points at the chat upload itself, so only
its uploader could load it and everyone else saw the default icon. A
picture is now shared because a bot or workspace points at it, whatever
its paradigm; profile photos still have to be the user's primary one.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
2026-10-25 04:08:16 +01:00
co-authored by Claude Opus 5.5
parent d542b4e9ad
commit feec69adca
2 changed files with 31 additions and 21 deletions
@@ -13,28 +13,29 @@ type Params = {
*
* - a member's current profile photo (their primary `user-profile-image`,
* the one `grabUsers` reports as `profile_media_id`),
* - a bot's picture (`bots.image_media_id`),
* - a workspace's picture (`workspaces.image_media_id`).
* - a bot's picture (whatever `bots.image_media_id` points at),
* - a workspace's picture (whatever `workspaces.image_media_id` points at).
*
* Bots and workspaces belong to the install, and people know each other by
* their photo, so a picture is never limited to whoever happens to reach
* its owner. It does have to be one still in use: the paradigm alone is not
* enough, since a removed picture leaves its paradigm row behind.
* its owner. It does have to be one still in use: a profile photo's
* paradigm alone is not enough, since a removed photo leaves its paradigm
* row behind. A bot's or workspace's picture is shared because the bot or
* workspace points at it, not by its paradigm: a picture set before
* pictures were copied into their own `bot-image`/`workspace-image` row is
* the chat upload itself, and it is still the face everyone sees.
*/
export default function sharedPictureMediaSql({ alias = "m" }: Params = {}): SqlCondition {
return {
sql: `EXISTS (
SELECT 1 FROM media_paradigms mp
WHERE mp.media_id = ${alias}.id
AND (
(mp.media_paradigm = 'user-profile-image' AND ${alias}.is_primary = 1)
OR (mp.media_paradigm = 'bot-image' AND EXISTS (
SELECT 1 FROM bots b WHERE b.image_media_id = ${alias}.id
))
OR (mp.media_paradigm = 'workspace-image' AND EXISTS (
SELECT 1 FROM workspaces w WHERE w.image_media_id = ${alias}.id
))
)
sql: `(
EXISTS (
SELECT 1 FROM media_paradigms mp
WHERE mp.media_id = ${alias}.id
AND mp.media_paradigm = 'user-profile-image'
AND ${alias}.is_primary = 1
)
OR EXISTS (SELECT 1 FROM bots b WHERE b.image_media_id = ${alias}.id)
OR EXISTS (SELECT 1 FROM workspaces w WHERE w.image_media_id = ${alias}.id)
)`,
values: [],
};