Changeset fb30b5d in Klonkt for test/c2s-inbox.test.js


Ignore:
Timestamp:
07/21/2026 11:10:32 PM (7 weeks ago)
Author:
Robin Genis <roboburr@…>
Branches:
main
Children:
4c70ecb
Parents:
e2ea5c4
Message:

C2S inbox carries friends' media as AS2 attachments

Shaer showed images on own posts (outbox serialises attachment) but not on
friends' posts: the C2S inbox GET built its Create(Note) items without the
stored media. The timeline rows already keep media_json ([{url, type}],
written on the inbound Create); it just never reached the wire. A new pure
helper maps it to an AS2 attachment array so clients render friends' images
and audio exactly like own outbox posts.

Changed files:
src/services/ActivityPubService.js

  • timelineAttachments(mediaJson): media_json -> AS2 attachment array (Document + mediaType + url); empty or malformed JSON yields undefined and never blocks the item
  • exported alongside getTimeline

src/routes/activitypub.js

  • inbox GET: object.attachment = AP.timelineAttachments(t.media_json)

test/c2s-inbox.test.js

  • covers the mapping, the unknown-mediaType case, dropped rows without url, and malformed media_json (148 tests total, all green)

Alt text is not in media_json yet, so attachment.name stays empty for now.

-robo
Co-Authored-By: Claude Opus 4.8 <noreply@…>

File:
1 edited

Legend:

Unmodified
Added
Removed
  • test/c2s-inbox.test.js

    re2ea5c4 rfb30b5d  
    2626  assert.ok(t.published);
    2727});
     28
     29// Friends' media must reach the client: media_json ([{url, type}]) becomes the
     30// AS2 attachment array on the inbox item, like own outbox posts (Shaer P2).
     31test('media_json maps to AS2 attachments', () => {
     32  const rows = AP.timelineAttachments(JSON.stringify([
     33    { url: 'https://r.test/m/p.png', type: 'image/png' },
     34    { url: 'https://r.test/m/a.mp3', type: 'audio/mpeg' },
     35  ]));
     36  assert.equal(rows.length, 2);
     37  assert.deepEqual(rows[0], { type: 'Document', mediaType: 'image/png', url: 'https://r.test/m/p.png' });
     38  assert.deepEqual(rows[1], { type: 'Document', mediaType: 'audio/mpeg', url: 'https://r.test/m/a.mp3' });
     39});
     40
     41test('unknown mediaType stays undefined, bad rows drop', () => {
     42  const rows = AP.timelineAttachments(JSON.stringify([
     43    { url: 'https://r.test/m/x.bin', type: '' },
     44    { type: 'image/png' },              // no url -> dropped
     45  ]));
     46  assert.equal(rows.length, 1);
     47  assert.equal(rows[0].mediaType, undefined);
     48});
     49
     50test('empty or malformed media_json yields undefined and never throws', () => {
     51  assert.equal(AP.timelineAttachments(null), undefined);
     52  assert.equal(AP.timelineAttachments('[]'), undefined);
     53  assert.equal(AP.timelineAttachments('not json'), undefined);
     54  assert.equal(AP.timelineAttachments('{"not":"a list"}'), undefined);
     55});
Note: See TracChangeset for help on using the changeset viewer.