Skip to content

Free, Open Source, Self-Hosted WhatsApp API Gateway

fix(dashboard): keep a thread pinned when archived audio arrives

Yudhi Armyndharisdc84af1f6438
diff --git a/dashboard/src/components/chats/ArchivedMediaPreview.test.ts b/dashboard/src/components/chats/ArchivedMediaPreview.test.ts
index d685f5445..7b8fd7c63 100644
--- a/dashboard/src/components/chats/ArchivedMediaPreview.test.ts
+++ b/dashboard/src/components/chats/ArchivedMediaPreview.test.ts
@@ -4,6 +4,7 @@
import '../../test-helpers/register-hooks.ts';
import { test, before, afterEach } from 'node:test';
import assert from 'node:assert/strict';
+import { readFileSync } from 'node:fs';
import { createElement } from 'react';
type RTL = typeof import('@testing-library/react');
@@ -205,3 +206,34 @@ test('the viewer downloads under the media file name, or one unique to the messa
delete anchorProto.dispatchEvent;
}
});
+
+test('an archived audio placeholder reserves the height of the player that replaces it', async () => {
+ const { container } = rtl.render(
+ createElement(ArchivedMediaPreview, {
+ kind: 'audio',
+ fallback,
+ load: () => new Promise<Blob>(() => undefined),
+ }),
+ );
+ const placeholder = container.querySelector('.message-media-archived-loading');
+ assert.ok(placeholder, 'the placeholder did not render');
+ assert.ok(placeholder.classList.contains('message-media-archived-loading-audio'));
+ // The player has a fixed height, so a placeholder of that height means the bubble never grows when
+ // the bytes land (a reader scrolled up, or pinned to the bottom, would otherwise be moved by it).
+ const css = readFileSync(new URL('../../pages/Chats.css', import.meta.url), 'utf8');
+ assert.match(css, /\.message-media-archived-loading-audio\s*\{[^}]*min-height:\s*54px/);
+});
+
+test('an archived audio player reports its arrival so a bottom-pinned thread stays pinned', async () => {
+ let reports = 0;
+ const { container } = rtl.render(
+ createElement(ArchivedMediaPreview, {
+ kind: 'audio',
+ fallback,
+ load: async () => new Blob(['x']),
+ onMediaLoad: () => void (reports += 1),
+ }),
+ );
+ await rtl.waitFor(() => assert.ok(container.querySelector('audio.chat-audio-media'), 'audio did not render'));
+ assert.equal(reports, 1, 'the thread is told once that the placeholder became a player');
+});
diff --git a/dashboard/src/components/chats/ArchivedMediaPreview.tsx b/dashboard/src/components/chats/ArchivedMediaPreview.tsx
index 4c6a8542a..9b999c86f 100644
--- a/dashboard/src/components/chats/ArchivedMediaPreview.tsx
+++ b/dashboard/src/components/chats/ArchivedMediaPreview.tsx
@@ -57,6 +57,10 @@ function ArchivedMediaPreview({
useEffect(() => {
loadRef.current = load;
});
+ const onMediaLoadRef = useRef(onMediaLoad);
+ useEffect(() => {
+ onMediaLoadRef.current = onMediaLoad;
+ });
// The object URL the ready render points at. Revoked on unmount only, the phase never leaves
// `ready`, so the URL stays valid for as long as the element showing it exists.
const urlRef = useRef<string | null>(null);
@@ -113,11 +117,22 @@ function ArchivedMediaPreview({
};
}, [state.phase]);
+ // An audio player has a fixed box that does not wait for decode, so the thread grows the moment the
+ // player replaces the placeholder, before any media event could say so. Report it, so a thread pinned
+ // to the bottom stays pinned (image and video report their own load).
+ useEffect(() => {
+ if (state.phase === 'ready' && kind === 'audio') onMediaLoadRef.current?.();
+ }, [state.phase, kind]);
+
if (state.phase === 'failed') return <>{fallback}</>;
if (state.phase !== 'ready') {
return (
- <div ref={anchorRef} className="message-media-omitted message-media-archived-loading" aria-busy="true">
+ <div
+ ref={anchorRef}
+ className={`message-media-omitted message-media-archived-loading${kind === 'audio' ? ' message-media-archived-loading-audio' : ''}`}
+ aria-busy="true"
+ >
<Loader2 size={14} className="animate-spin" />
</div>
);
diff --git a/dashboard/src/pages/Chats.css b/dashboard/src/pages/Chats.css
index c645b9518..48609ff2c 100644
--- a/dashboard/src/pages/Chats.css
+++ b/dashboard/src/pages/Chats.css
@@ -996,6 +996,12 @@
text-decoration: none;
}
+/* The archived audio placeholder holds the height of the native player that replaces it, so the bubble
+ does not grow when the bytes land and move a thread that was pinned to the bottom or being read. */
+.chats-page .message-media-archived-loading-audio {
+ min-height: 54px;
+}
+
/* The map preview keeps its own modest cap, but bounded by the bubble the way every other media type
here is. As a bare pixel width it stayed 220px wide in a narrower room and ran past the panel edge. */
.chats-page .chat-location-media {