Skip to content

armgit / macro

Public Imported from GitHub
0

Macro is a unified workspace for teams: email, chat, docs, tasks, agents, calls, and CRM — @-linked together with shared AI memory.

feat: pfp + channel preview downscaling (#2651)

Eric Hayes365d1dcfc112
diff --git a/js/app/packages/channel/Input/Attachments.tsx b/js/app/packages/channel/Input/Attachments.tsx
index d179252772..1aacfc2ddc 100644
--- a/js/app/packages/channel/Input/Attachments.tsx
+++ b/js/app/packages/channel/Input/Attachments.tsx
@@ -1,4 +1,7 @@
-import { staticFileIdEndpoint } from '@core/constant/servers';
+import {
+ staticFileIdEndpoint,
+ staticFileSizedEndpoint,
+} from '@core/constant/servers';
import { EntityIcon } from '@core/component/EntityIcon';
import SpinnerIcon from '@icon/bold/spinner-gap-bold.svg';
import XIcon from '@icon/regular/x.svg';
@@ -58,7 +61,10 @@ function MediaAttachmentItem(props: {
onRemove: (attachment: InputAttachmentData) => void;
onOpen?: () => void;
}) {
- const mediaSrc = () => staticFileIdEndpoint(props.attachment.id);
+ const mediaSrc = () =>
+ props.attachment.kind === 'image'
+ ? staticFileSizedEndpoint(props.attachment.id, 'medium')
+ : staticFileIdEndpoint(props.attachment.id);
return (
<div class="ph-no-capture relative group">
@@ -166,13 +172,20 @@ export function Attachments(props: AttachmentsProps) {
);
const mediaItems = createMemo((): MediaItem[] =>
- mediaAttachments().map((a) => ({
- id: a.id,
- src: staticFileIdEndpoint(a.id),
- kind: a.kind,
- width: a.width,
- height: a.height,
- }))
+ mediaAttachments().map((a) => {
+ const fullSrc = staticFileIdEndpoint(a.id);
+ return {
+ id: a.id,
+ src:
+ a.kind === 'image'
+ ? staticFileSizedEndpoint(a.id, 'medium')
+ : fullSrc,
+ fullSrc,
+ kind: a.kind,
+ width: a.width,
+ height: a.height,
+ };
+ })
);
const handleRemove = (attachment: InputAttachmentData) => {
diff --git a/js/app/packages/channel/Media/MediaViewerDialog.tsx b/js/app/packages/channel/Media/MediaViewerDialog.tsx
index 3e2abab27d..d0a769669b 100644
--- a/js/app/packages/channel/Media/MediaViewerDialog.tsx
+++ b/js/app/packages/channel/Media/MediaViewerDialog.tsx
@@ -87,7 +87,7 @@ function VideoViewerContent(props: {
controls
autoplay
playsinline
- src={props.item().src}
+ src={props.item().fullSrc}
/>
</div>
</Dialog.Content>
@@ -132,7 +132,7 @@ export function MediaViewerDialog(props: MediaViewerDialogProps) {
}
>
<Lightbox
- src={() => item().src}
+ src={() => item().fullSrc}
imageId={() => item().id}
onPrevious={hasPrevious() ? navigatePrevious : undefined}
onNext={hasNext() ? navigateNext : undefined}
diff --git a/js/app/packages/channel/Media/media-items.ts b/js/app/packages/channel/Media/media-items.ts
index 02c2dc2504..e429460f74 100644
--- a/js/app/packages/channel/Media/media-items.ts
+++ b/js/app/packages/channel/Media/media-items.ts
@@ -1,4 +1,7 @@
-import { staticFileIdEndpoint } from '@core/constant/servers';
+import {
+ staticFileIdEndpoint,
+ staticFileSizedEndpoint,
+} from '@core/constant/servers';
import {
isStaticAttachmentType,
STATIC_IMAGE,
@@ -7,7 +10,10 @@ import {
export type MediaItem = {
id: string;
+ /** Sized variant for previews (1080/ for images, original for videos) */
src: string;
+ /** Full-resolution original — used when expanding */
+ fullSrc: string;
kind: 'image' | 'video';
width?: number | null;
height?: number | null;
@@ -57,9 +63,14 @@ function mapAttachmentToMediaItem(
const kind = getMediaKind(attachment.entity_type);
if (!kind) return;
+ const fullSrc = staticFileIdEndpoint(attachment.entity_id);
return {
id: attachment.entity_id,
- src: staticFileIdEndpoint(attachment.entity_id),
+ src:
+ kind === 'image'
+ ? staticFileSizedEndpoint(attachment.entity_id, 'medium')
+ : fullSrc,
+ fullSrc,
kind,
width: attachment.width ?? undefined,
height: attachment.height ?? undefined,
@@ -85,6 +96,7 @@ function mapAttachmentsToMediaItems<T extends AttachmentWithMediaFields>(
if (
previousItem &&
previousItem.src === item.src &&
+ previousItem.fullSrc === item.fullSrc &&
previousItem.kind === item.kind &&
previousItem.width === item.width &&
previousItem.height === item.height
diff --git a/js/app/packages/core/component/ProfilePicture.tsx b/js/app/packages/core/component/ProfilePicture.tsx
index d5c6d799be..dcd1bd0eb2 100644
--- a/js/app/packages/core/component/ProfilePicture.tsx
+++ b/js/app/packages/core/component/ProfilePicture.tsx
@@ -1,7 +1,10 @@
import { cn } from '@ui/utils/classname';
import { toast } from '@core/component/Toast/Toast';
import { ENABLE_PROFILE_PICTURES } from '@core/constant/featureFlags';
-import { staticFileIdEndpoint } from '@core/constant/servers';
+import {
+ staticFileIdEndpoint,
+ staticFileSizedUrl,
+} from '@core/constant/servers';
import { internalDrag } from '@core/directive/internalDragState';
false && internalDrag;
import { useProfilePictureUrl } from '@core/signal/profilePicture';
@@ -79,20 +82,28 @@ export function ProfilePicture(props: ProfilePictureProps) {
}
keyed
>
- {(url) => (
- <div
- class={cn(
- 'flex-shrink-0 overflow-hidden rounded-full',
- props.sizeClass.container
- )}
- >
- <img
- src={url}
- class="object-cover rounded-full w-full h-full origin-[50%_20%]"
- use:internalDrag={true}
- />
- </div>
- )}
+ {(url) => {
+ const smallUrl = staticFileSizedUrl(url, 'small');
+ return (
+ <div
+ class={cn(
+ 'flex-shrink-0 overflow-hidden rounded-full',
+ props.sizeClass.container
+ )}
+ >
+ <img
+ src={smallUrl}
+ class="object-cover rounded-full w-full h-full origin-[50%_20%]"
+ use:internalDrag={true}
+ onError={(e) => {
+ if (e.currentTarget.src !== url) {
+ e.currentTarget.src = url;
+ }
+ }}
+ />
+ </div>
+ );
+ }}
</Show>
);
}
diff --git a/js/app/packages/core/constant/servers.ts b/js/app/packages/core/constant/servers.ts
index 1e45df3d7a..c1df1a1ec9 100644
--- a/js/app/packages/core/constant/servers.ts
+++ b/js/app/packages/core/constant/servers.ts
@@ -130,3 +130,21 @@ export const SYNC_PERMISSION_TOKEN_DSS_HOST =
export function staticFileIdEndpoint(id: string): string {
return `${SERVER_HOSTS['static-file']}/file/${id}`;
}
+
+type StaticFileSize = 'small' | 'medium';
+
+const staticFileSizes: Record<StaticFileSize, number> = {
+ small: 320,
+ medium: 1080,
+};
+
+export function staticFileSizedEndpoint(
+ id: string,
+ size: StaticFileSize
+): string {
+ return `${staticFileIdEndpoint(id)}?size=${staticFileSizes[size]}`;
+}
+
+export function staticFileSizedUrl(url: string, size: StaticFileSize): string {
+ return `${url}?size=${staticFileSizes[size]}`;
+}