{body}
- {!open && !encrypted && !loading && !error && loose.length > 0 && (
+ {looseNote && (
- {looseNote(loose)}
+ {looseNote}
)}
{/* Stays mounted while an album is open, so a running send keeps its progress. */}
diff --git a/src/app/features/albums/buildAlbums.ts b/src/app/features/albums/buildAlbums.ts
index 4a09500b..5d3662e1 100644
--- a/src/app/features/albums/buildAlbums.ts
+++ b/src/app/features/albums/buildAlbums.ts
@@ -175,3 +175,10 @@ export const looseNote = (files: AlbumFile[]): string => {
files.length === 1 ? 'It is' : 'They are'
} in the Timeline.`;
};
+
+/** Where the album view stands when it decides whether to show the loose-files note. */
+export type ViewState = { open: boolean; encrypted: boolean; loading: boolean; error: boolean };
+
+/** The note for the list view only: never inside an open album, an encrypted zone, or a load that is not finished. */
+export const looseNoteFor = (files: AlbumFile[], view: ViewState): string =>
+ view.open || view.encrypted || view.loading || view.error ? '' : looseNote(files);
diff --git a/src/app/features/albums/publisherWire.test.ts b/src/app/features/albums/publisherWire.test.ts
index a63ab29c..83bddf3a 100644
--- a/src/app/features/albums/publisherWire.test.ts
+++ b/src/app/features/albums/publisherWire.test.ts
@@ -1,5 +1,5 @@
import { describe, expect, it } from 'vitest';
-import { buildAlbums, looseFiles, looseNote, TimelineEvent } from './buildAlbums';
+import { buildAlbums, looseFiles, looseNote, looseNoteFor, TimelineEvent } from './buildAlbums';
// The Commons publisher as it posted before gamecult-ops #121: loose files (no album thread), a
// flat `org.gamecult.publish.replaces` key, no info.sha256. The sender must see that, not a
@@ -62,6 +62,33 @@ describe('loose files from a poster that does not thread', () => {
});
});
+describe('where the loose-files note shows', () => {
+ const loose = looseFiles([file('$a', 'notes.md')]);
+ const list = { open: false, encrypted: false, loading: false, error: false };
+
+ it('on the album list, and only there', () => {
+ expect(looseNoteFor(loose, list)).toContain('notes.md');
+ expect(looseNoteFor(loose, { ...list, open: true })).toBe('');
+ expect(looseNoteFor(loose, { ...list, encrypted: true })).toBe('');
+ expect(looseNoteFor(loose, { ...list, loading: true })).toBe('');
+ expect(looseNoteFor(loose, { ...list, error: true })).toBe('');
+ });
+
+ it('says nothing when there are no loose files', () => {
+ expect(looseNoteFor([], list)).toBe('');
+ });
+
+ it('names m.notice and m.sticker posts as not files', () => {
+ const notice = { ...text('$n', 'hi'), content: { msgtype: 'm.notice', body: 'hi' } };
+ expect(looseFiles([notice])).toEqual([]);
+ });
+
+ it('a file with no name reads as unnamed', () => {
+ const bare: TimelineEvent = { ...file('$b', ''), content: { msgtype: 'm.file', body: '' } };
+ expect(looseNote(looseFiles([bare]))).toContain('unnamed');
+ });
+});
+
describe('the old wire shape inside an album', () => {
const root = text('$root', 'handoff/eureka');
const albumOf = (replies: TimelineEvent[]) => buildAlbums([{ root, replies }], 'gamecult.org')[0];