From f8dd9910ad8ade336447940f0598de4f2cdf1389 Mon Sep 17 00:00:00 2001 From: Tasso Date: Mon, 16 Sep 2024 12:41:34 -0300 Subject: [PATCH 1/4] Remove remnant references of `Accounts_AvatarExternalProviderUrl` on client --- .changeset/strong-grapes-brake.md | 7 +++++++ apps/meteor/app/utils/client/getUserAvatarURL.ts | 5 ----- apps/meteor/app/utils/server/getUserAvatarURL.ts | 5 ----- 3 files changed, 7 insertions(+), 10 deletions(-) create mode 100644 .changeset/strong-grapes-brake.md diff --git a/.changeset/strong-grapes-brake.md b/.changeset/strong-grapes-brake.md new file mode 100644 index 000000000000..0a5bdc2e73d0 --- /dev/null +++ b/.changeset/strong-grapes-brake.md @@ -0,0 +1,7 @@ +--- +'@rocket.chat/meteor': patch +--- + +Fixed remaining direct references to external user avatar URLs + +It mainly corrects the behavior of E2E encryption messages and desktop notifications. diff --git a/apps/meteor/app/utils/client/getUserAvatarURL.ts b/apps/meteor/app/utils/client/getUserAvatarURL.ts index 1a825a44fc27..d5fdd2b2d427 100644 --- a/apps/meteor/app/utils/client/getUserAvatarURL.ts +++ b/apps/meteor/app/utils/client/getUserAvatarURL.ts @@ -1,11 +1,6 @@ -import { settings } from '../../settings/client'; import { getAvatarURL } from './getAvatarURL'; export const getUserAvatarURL = function (username: string, cache = ''): string | undefined { - const externalSource = (settings.get('Accounts_AvatarExternalProviderUrl') || '').trim().replace(/\/$/, ''); - if (externalSource !== '') { - return externalSource.replace('{username}', username); - } if (username == null) { return; } diff --git a/apps/meteor/app/utils/server/getUserAvatarURL.ts b/apps/meteor/app/utils/server/getUserAvatarURL.ts index b83efea1d842..d5fdd2b2d427 100644 --- a/apps/meteor/app/utils/server/getUserAvatarURL.ts +++ b/apps/meteor/app/utils/server/getUserAvatarURL.ts @@ -1,11 +1,6 @@ -import { settings } from '../../settings/server'; import { getAvatarURL } from './getAvatarURL'; export const getUserAvatarURL = function (username: string, cache = ''): string | undefined { - const externalSource = (settings.get('Accounts_AvatarExternalProviderUrl') || '').trim().replace(/\/$/, ''); - if (externalSource !== '') { - return externalSource.replace('{username}', username); - } if (username == null) { return; } From 817bc7e47434e9796609dafe3c91ab30f4fa0775 Mon Sep 17 00:00:00 2001 From: Tasso Date: Mon, 16 Sep 2024 15:53:05 -0300 Subject: [PATCH 2/4] Remove redundant CDN handling --- apps/meteor/client/providers/AvatarUrlProvider.tsx | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/apps/meteor/client/providers/AvatarUrlProvider.tsx b/apps/meteor/client/providers/AvatarUrlProvider.tsx index b5a92c9117f2..606da39360d5 100644 --- a/apps/meteor/client/providers/AvatarUrlProvider.tsx +++ b/apps/meteor/client/providers/AvatarUrlProvider.tsx @@ -1,4 +1,4 @@ -import { AvatarUrlContext, useSetting } from '@rocket.chat/ui-contexts'; +import { AvatarUrlContext } from '@rocket.chat/ui-contexts'; import type { ReactNode } from 'react'; import React, { useMemo } from 'react'; @@ -10,19 +10,15 @@ type AvatarUrlProviderProps = { }; const AvatarUrlProvider = ({ children }: AvatarUrlProviderProps) => { - const cdnAvatarUrl = String(useSetting('CDN_PREFIX') || ''); const contextValue = useMemo( () => ({ getUserPathAvatar: ((): ((uid: string, etag?: string) => string) => { - if (cdnAvatarUrl) { - return (uid: string, etag?: string): string => `${cdnAvatarUrl}/avatar/${uid}${etag ? `?etag=${etag}` : ''}`; - } return (uid: string, etag?: string): string => getURL(`/avatar/${uid}${etag ? `?etag=${etag}` : ''}`); })(), getRoomPathAvatar: ({ type, ...room }: any): string => roomCoordinator.getRoomDirectives(type || room.t).getAvatarPath({ username: room._id, ...room }) || '', }), - [cdnAvatarUrl], + [], ); return ; From b23ec898c069103835e73366b253039c0a537b14 Mon Sep 17 00:00:00 2001 From: gabriellsh Date: Mon, 16 Sep 2024 18:31:20 -0300 Subject: [PATCH 3/4] fix: Avatar external provider URL wrong priority --- apps/meteor/server/routes/avatar/user.js | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/apps/meteor/server/routes/avatar/user.js b/apps/meteor/server/routes/avatar/user.js index 269c2e90019a..1c92d24fe300 100644 --- a/apps/meteor/server/routes/avatar/user.js +++ b/apps/meteor/server/routes/avatar/user.js @@ -32,6 +32,13 @@ export const userAvatar = async function (req, res) { return; } + if (settings.get('Accounts_AvatarExternalProviderUrl')) { + const response = await fetch(settings.get('Accounts_AvatarExternalProviderUrl').replace('{username}', requestUsername)); + response.headers.forEach((value, key) => res.setHeader(key, value)); + response.body.pipe(res); + return; + } + const reqModifiedHeader = req.headers['if-modified-since']; const file = await Avatars.findOneByName(requestUsername); @@ -52,13 +59,6 @@ export const userAvatar = async function (req, res) { return FileUpload.get(file, req, res); } - if (settings.get('Accounts_AvatarExternalProviderUrl')) { - const response = await fetch(settings.get('Accounts_AvatarExternalProviderUrl').replace('{username}', requestUsername)); - response.headers.forEach((value, key) => res.setHeader(key, value)); - response.body.pipe(res); - return; - } - // if still using "letters fallback" if (!wasFallbackModified(reqModifiedHeader, res)) { res.writeHead(304); From bf13e15a49c36ea4eee562a7013f651a635b9865 Mon Sep 17 00:00:00 2001 From: gabriellsh <40830821+gabriellsh@users.noreply.github.com> Date: Mon, 16 Sep 2024 18:46:27 -0300 Subject: [PATCH 4/4] Update CS --- .changeset/strong-grapes-brake.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.changeset/strong-grapes-brake.md b/.changeset/strong-grapes-brake.md index 0a5bdc2e73d0..c867600a8cd2 100644 --- a/.changeset/strong-grapes-brake.md +++ b/.changeset/strong-grapes-brake.md @@ -4,4 +4,6 @@ Fixed remaining direct references to external user avatar URLs +Fixed local avatars having priority over external provider + It mainly corrects the behavior of E2E encryption messages and desktop notifications.