Normalize Attachment entities as Immutable.Record

This commit is contained in:
Alex Gleason 2022-03-10 17:15:09 -06:00
parent 4c2d9a8856
commit 9afd43a42d
No known key found for this signature in database
GPG key ID: 7211D1F99744FBB7
3 changed files with 14 additions and 2 deletions

View file

@ -66,6 +66,19 @@ const PollRecord = ImmutableRecord({
voted: false, voted: false,
}); });
// https://docs.joinmastodon.org/entities/attachment/
const AttachmentRecord = ImmutableRecord({
blurhash: undefined,
description: '',
id: '',
meta: ImmutableMap(),
pleroma: ImmutableMap(),
preview_url: '',
remote_url: null,
type: 'unknown',
url: '',
});
// Ensure attachments have required fields // Ensure attachments have required fields
// https://docs.joinmastodon.org/entities/attachment/ // https://docs.joinmastodon.org/entities/attachment/
const normalizeAttachment = (attachment: ImmutableMap<string, any>) => { const normalizeAttachment = (attachment: ImmutableMap<string, any>) => {
@ -78,10 +91,9 @@ const normalizeAttachment = (attachment: ImmutableMap<string, any>) => {
const base = ImmutableMap({ const base = ImmutableMap({
url, url,
preview_url: url, preview_url: url,
remote_url: url,
}); });
return attachment.mergeWith(mergeDefined, base); return AttachmentRecord(attachment.mergeWith(mergeDefined, base));
}; };
const normalizeAttachments = (status: ImmutableMap<string, any>) => { const normalizeAttachments = (status: ImmutableMap<string, any>) => {