kopia lustrzana https://gitlab.com/soapbox-pub/soapbox
Merge branch 'records' into 'develop'
Records: Status, Account, Instance See merge request soapbox-pub/soapbox-fe!1083next-old
commit
cd6fd8c0db
|
@ -116,7 +116,7 @@ class EditProfile extends ImmutablePureComponent {
|
|||
const birthday = account.get('birthday');
|
||||
const showBirthday = account.getIn(['source', 'pleroma', 'show_birthday']);
|
||||
|
||||
const initialState = account.withMutations(map => {
|
||||
const initialState = ImmutableMap(account).withMutations(map => {
|
||||
map.merge(map.get('source'));
|
||||
map.delete('source');
|
||||
map.set('fields', normalizeFields(map.get('fields'), Math.min(maxFields, 4)));
|
||||
|
|
|
@ -4,25 +4,60 @@ import { normalizeInstance } from '../instance';
|
|||
|
||||
describe('normalizeInstance()', () => {
|
||||
it('normalizes an empty Map', () => {
|
||||
const expected = ImmutableMap({
|
||||
description_limit: 1500,
|
||||
configuration: ImmutableMap({
|
||||
statuses: ImmutableMap({
|
||||
max_characters: 500,
|
||||
max_media_attachments: 4,
|
||||
}),
|
||||
polls: ImmutableMap({
|
||||
const expected = {
|
||||
approval_required: false,
|
||||
contact_account: {},
|
||||
configuration: {
|
||||
media_attachments: {
|
||||
image_size_limit: 10485760,
|
||||
image_matrix_limit: 16777216,
|
||||
video_size_limit: 41943040,
|
||||
video_frame_rate_limit: 60,
|
||||
video_matrix_limit: 2304000,
|
||||
},
|
||||
polls: {
|
||||
max_options: 4,
|
||||
max_characters_per_option: 25,
|
||||
min_expiration: 300,
|
||||
max_expiration: 2629746,
|
||||
}),
|
||||
}),
|
||||
},
|
||||
statuses: {
|
||||
max_characters: 500,
|
||||
max_media_attachments: 4,
|
||||
},
|
||||
},
|
||||
description: '',
|
||||
description_limit: 1500,
|
||||
email: '',
|
||||
fedibird_capabilities: [],
|
||||
invites_enabled: false,
|
||||
languages: [],
|
||||
pleroma: {
|
||||
metadata: {
|
||||
account_activation_required: false,
|
||||
birthday_min_age: 0,
|
||||
birthday_required: false,
|
||||
features: [],
|
||||
federation: {
|
||||
enabled: true,
|
||||
exclusions: false,
|
||||
},
|
||||
},
|
||||
stats: {},
|
||||
},
|
||||
registrations: false,
|
||||
rules: [],
|
||||
short_description: '',
|
||||
stats: {},
|
||||
title: '',
|
||||
thumbnail: '',
|
||||
uri: '',
|
||||
urls: {},
|
||||
version: '0.0.0',
|
||||
});
|
||||
};
|
||||
|
||||
const result = normalizeInstance(ImmutableMap());
|
||||
expect(result).toEqual(expected);
|
||||
expect(result.toJS()).toEqual(expected);
|
||||
});
|
||||
|
||||
it('normalizes Pleroma instance with Mastodon configuration format', () => {
|
||||
|
@ -104,10 +139,10 @@ describe('normalizeInstance()', () => {
|
|||
const result = normalizeInstance(instance);
|
||||
|
||||
// Sets description_limit
|
||||
expect(result.get('description_limit')).toEqual(1500);
|
||||
expect(result.description_limit).toEqual(1500);
|
||||
|
||||
// But otherwise, it's the same
|
||||
expect(result.delete('description_limit')).toEqual(instance);
|
||||
// Preserves fedibird_capabilities
|
||||
expect(result.fedibird_capabilities).toEqual(instance.get('fedibird_capabilities'));
|
||||
});
|
||||
|
||||
it('normalizes Mitra instance', () => {
|
||||
|
|
|
@ -1,7 +1,45 @@
|
|||
import { Map as ImmutableMap, List as ImmutableList } from 'immutable';
|
||||
import { Map as ImmutableMap, List as ImmutableList, Record } from 'immutable';
|
||||
|
||||
import { mergeDefined } from 'soapbox/utils/normalizers';
|
||||
|
||||
const AccountRecord = Record({
|
||||
acct: '',
|
||||
avatar: '',
|
||||
avatar_static: '',
|
||||
birthday: undefined,
|
||||
bot: false,
|
||||
created_at: new Date(),
|
||||
display_name: '',
|
||||
emojis: ImmutableList(),
|
||||
fields: ImmutableList(),
|
||||
followers_count: 0,
|
||||
following_count: 0,
|
||||
fqn: '',
|
||||
header: '',
|
||||
header_static: '',
|
||||
id: '',
|
||||
last_status_at: new Date(),
|
||||
location: '',
|
||||
locked: false,
|
||||
moved: null,
|
||||
note: '',
|
||||
pleroma: ImmutableMap(),
|
||||
source: ImmutableMap(),
|
||||
statuses_count: 0,
|
||||
uri: '',
|
||||
url: '',
|
||||
username: '',
|
||||
verified: false,
|
||||
|
||||
// Internal fields
|
||||
display_name_html: '',
|
||||
note_emojified: '',
|
||||
note_plain: '',
|
||||
patron: ImmutableMap(),
|
||||
relationship: ImmutableList(),
|
||||
should_refetch: false,
|
||||
});
|
||||
|
||||
// https://gitlab.com/soapbox-pub/soapbox-fe/-/issues/549
|
||||
const normalizePleromaLegacyFields = account => {
|
||||
return account.update('pleroma', ImmutableMap(), pleroma => {
|
||||
|
@ -49,10 +87,12 @@ const normalizeLocation = account => {
|
|||
};
|
||||
|
||||
export const normalizeAccount = account => {
|
||||
return account.withMutations(account => {
|
||||
normalizePleromaLegacyFields(account);
|
||||
normalizeVerified(account);
|
||||
normalizeBirthday(account);
|
||||
normalizeLocation(account);
|
||||
});
|
||||
return AccountRecord(
|
||||
account.withMutations(account => {
|
||||
normalizePleromaLegacyFields(account);
|
||||
normalizeVerified(account);
|
||||
normalizeBirthday(account);
|
||||
normalizeLocation(account);
|
||||
}),
|
||||
);
|
||||
};
|
||||
|
|
|
@ -1,16 +1,20 @@
|
|||
import { Map as ImmutableMap } from 'immutable';
|
||||
import { Map as ImmutableMap, List as ImmutableList, Record } from 'immutable';
|
||||
|
||||
import { parseVersion, PLEROMA } from 'soapbox/utils/features';
|
||||
import { mergeDefined } from 'soapbox/utils/normalizers';
|
||||
import { isNumber } from 'soapbox/utils/numbers';
|
||||
|
||||
// Use Mastodon defaults
|
||||
const baseInstance = ImmutableMap({
|
||||
description_limit: 1500,
|
||||
const InstanceRecord = Record({
|
||||
approval_required: false,
|
||||
contact_account: ImmutableMap(),
|
||||
configuration: ImmutableMap({
|
||||
statuses: ImmutableMap({
|
||||
max_characters: 500,
|
||||
max_media_attachments: 4,
|
||||
media_attachments: ImmutableMap({
|
||||
image_size_limit: 10485760,
|
||||
image_matrix_limit: 16777216,
|
||||
video_size_limit: 41943040,
|
||||
video_frame_rate_limit: 60,
|
||||
video_matrix_limit: 2304000,
|
||||
}),
|
||||
polls: ImmutableMap({
|
||||
max_options: 4,
|
||||
|
@ -18,7 +22,38 @@ const baseInstance = ImmutableMap({
|
|||
min_expiration: 300,
|
||||
max_expiration: 2629746,
|
||||
}),
|
||||
statuses: ImmutableMap({
|
||||
max_characters: 500,
|
||||
max_media_attachments: 4,
|
||||
}),
|
||||
}),
|
||||
description: '',
|
||||
description_limit: 1500,
|
||||
email: '',
|
||||
fedibird_capabilities: ImmutableList(),
|
||||
invites_enabled: false,
|
||||
languages: ImmutableList(),
|
||||
pleroma: ImmutableMap({
|
||||
metadata: ImmutableMap({
|
||||
account_activation_required: false,
|
||||
birthday_min_age: 0,
|
||||
birthday_required: false,
|
||||
features: ImmutableList(),
|
||||
federation: ImmutableMap({
|
||||
enabled: true,
|
||||
exclusions: false,
|
||||
}),
|
||||
}),
|
||||
stats: ImmutableMap(),
|
||||
}),
|
||||
registrations: false,
|
||||
rules: ImmutableList(),
|
||||
short_description: '',
|
||||
stats: ImmutableMap(),
|
||||
title: '',
|
||||
thumbnail: '',
|
||||
uri: '',
|
||||
urls: ImmutableMap(),
|
||||
version: '0.0.0',
|
||||
});
|
||||
|
||||
|
@ -45,19 +80,21 @@ export const normalizeInstance = instance => {
|
|||
const { software } = parseVersion(instance.get('version'));
|
||||
const mastodonConfig = pleromaToMastodonConfig(instance);
|
||||
|
||||
return instance.withMutations(instance => {
|
||||
// Merge configuration
|
||||
instance.update('configuration', ImmutableMap(), configuration => (
|
||||
configuration.mergeDeepWith(mergeDefined, mastodonConfig)
|
||||
));
|
||||
return InstanceRecord(
|
||||
instance.withMutations(instance => {
|
||||
// Merge configuration
|
||||
instance.update('configuration', ImmutableMap(), configuration => (
|
||||
configuration.mergeDeepWith(mergeDefined, mastodonConfig)
|
||||
));
|
||||
|
||||
// If max attachments isn't set, check the backend software
|
||||
instance.updateIn(['configuration', 'statuses', 'max_media_attachments'], value => {
|
||||
return isNumber(value) ? value : getAttachmentLimit(software);
|
||||
});
|
||||
// If max attachments isn't set, check the backend software
|
||||
instance.updateIn(['configuration', 'statuses', 'max_media_attachments'], value => {
|
||||
return isNumber(value) ? value : getAttachmentLimit(software);
|
||||
});
|
||||
|
||||
// Merge defaults & cleanup
|
||||
instance.mergeDeepWith(mergeDefined, baseInstance);
|
||||
instance.deleteAll(['max_toot_chars', 'poll_limits']);
|
||||
});
|
||||
// Merge defaults & cleanup
|
||||
instance.mergeDeepWith(mergeDefined, InstanceRecord());
|
||||
instance.deleteAll(['max_toot_chars', 'poll_limits']);
|
||||
}),
|
||||
);
|
||||
};
|
||||
|
|
|
@ -1,32 +1,45 @@
|
|||
import { Map as ImmutableMap, List as ImmutableList } from 'immutable';
|
||||
import { Map as ImmutableMap, List as ImmutableList, Record } from 'immutable';
|
||||
|
||||
import { accountToMention } from 'soapbox/utils/accounts';
|
||||
import { mergeDefined } from 'soapbox/utils/normalizers';
|
||||
|
||||
// Some backends can return null, or omit these required fields
|
||||
const baseStatus = ImmutableMap({
|
||||
const StatusRecord = Record({
|
||||
account: ImmutableMap(),
|
||||
application: null,
|
||||
bookmarked: false,
|
||||
card: null,
|
||||
content: '',
|
||||
created_at: new Date(),
|
||||
emojis: ImmutableList(),
|
||||
favourited: false,
|
||||
favourites_count: 0,
|
||||
in_reply_to_account_id: null,
|
||||
in_reply_to_id: null,
|
||||
id: '',
|
||||
language: null,
|
||||
media_attachments: ImmutableList(),
|
||||
mentions: ImmutableList(),
|
||||
muted: false,
|
||||
pinned: false,
|
||||
pleroma: ImmutableMap(),
|
||||
poll: null,
|
||||
quote: null,
|
||||
reblog: null,
|
||||
reblogged: false,
|
||||
reblogs_count: 0,
|
||||
replies_count: 0,
|
||||
sensitive: false,
|
||||
spoiler_text: '',
|
||||
tags: ImmutableList(),
|
||||
uri: '',
|
||||
url: '',
|
||||
visibility: 'public',
|
||||
|
||||
// Internal fields
|
||||
contentHtml: '',
|
||||
hidden: false,
|
||||
search_index: '',
|
||||
spoilerHtml: '',
|
||||
});
|
||||
|
||||
const basePollOption = ImmutableMap({ title: '', votes_count: 0 });
|
||||
|
@ -41,11 +54,6 @@ const basePoll = ImmutableMap({
|
|||
votes_count: 0,
|
||||
});
|
||||
|
||||
// Merge base status
|
||||
const mergeBase = status => {
|
||||
return status.mergeDeepWith(mergeDefined, baseStatus);
|
||||
};
|
||||
|
||||
// Ensure attachments have required fields
|
||||
// https://docs.joinmastodon.org/entities/attachment/
|
||||
const normalizeAttachment = attachment => {
|
||||
|
@ -147,13 +155,14 @@ const fixQuote = status => {
|
|||
};
|
||||
|
||||
export const normalizeStatus = status => {
|
||||
return status.withMutations(status => {
|
||||
mergeBase(status);
|
||||
normalizeAttachments(status);
|
||||
normalizeMentions(status);
|
||||
normalizePoll(status);
|
||||
fixMentionsOrder(status);
|
||||
addSelfMention(status);
|
||||
fixQuote(status);
|
||||
});
|
||||
return StatusRecord(
|
||||
status.withMutations(status => {
|
||||
normalizeAttachments(status);
|
||||
normalizeMentions(status);
|
||||
normalizePoll(status);
|
||||
fixMentionsOrder(status);
|
||||
addSelfMention(status);
|
||||
fixQuote(status);
|
||||
}),
|
||||
);
|
||||
};
|
||||
|
|
|
@ -1,4 +1,6 @@
|
|||
import { Map as ImmutableMap } from 'immutable';
|
||||
import { Map as ImmutableMap, Record } from 'immutable';
|
||||
|
||||
import { ACCOUNT_IMPORT } from 'soapbox/actions/importer';
|
||||
|
||||
import reducer from '../accounts';
|
||||
// import * as actions from 'soapbox/actions/importer';
|
||||
|
@ -10,6 +12,16 @@ describe('accounts reducer', () => {
|
|||
expect(reducer(undefined, {})).toEqual(ImmutableMap());
|
||||
});
|
||||
|
||||
describe('ACCOUNT_IMPORT', () => {
|
||||
it('parses the account as a Record', () => {
|
||||
const account = require('soapbox/__fixtures__/pleroma-account.json');
|
||||
const action = { type: ACCOUNT_IMPORT, account };
|
||||
const result = reducer(undefined, action).get('9v5bmRalQvjOy0ECcC');
|
||||
|
||||
expect(Record.isRecord(result)).toBe(true);
|
||||
});
|
||||
});
|
||||
|
||||
// fails to add normalized accounts to state
|
||||
// it('should handle ACCOUNT_IMPORT', () => {
|
||||
// const state = ImmutableMap({ });
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
import { Map as ImmutableMap } from 'immutable';
|
||||
import { Record } from 'immutable';
|
||||
|
||||
import { INSTANCE_REMEMBER_SUCCESS } from 'soapbox/actions/instance';
|
||||
|
||||
|
@ -6,22 +6,27 @@ import reducer from '../instance';
|
|||
|
||||
describe('instance reducer', () => {
|
||||
it('should return the initial state', () => {
|
||||
expect(reducer(undefined, {})).toEqual(ImmutableMap({
|
||||
const result = reducer(undefined, {});
|
||||
|
||||
const expected = {
|
||||
description_limit: 1500,
|
||||
configuration: ImmutableMap({
|
||||
statuses: ImmutableMap({
|
||||
configuration: {
|
||||
statuses: {
|
||||
max_characters: 500,
|
||||
max_media_attachments: 4,
|
||||
}),
|
||||
polls: ImmutableMap({
|
||||
},
|
||||
polls: {
|
||||
max_options: 4,
|
||||
max_characters_per_option: 25,
|
||||
min_expiration: 300,
|
||||
max_expiration: 2629746,
|
||||
}),
|
||||
}),
|
||||
},
|
||||
},
|
||||
version: '0.0.0',
|
||||
}));
|
||||
};
|
||||
|
||||
expect(Record.isRecord(result)).toBe(true);
|
||||
expect(result.toJS()).toMatchObject(expected);
|
||||
});
|
||||
|
||||
describe('INSTANCE_REMEMBER_SUCCESS', () => {
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
import { Map as ImmutableMap, fromJS } from 'immutable';
|
||||
import { Map as ImmutableMap, Record, fromJS } from 'immutable';
|
||||
|
||||
import { STATUS_IMPORT } from 'soapbox/actions/importer';
|
||||
import {
|
||||
|
@ -14,6 +14,14 @@ describe('statuses reducer', () => {
|
|||
});
|
||||
|
||||
describe('STATUS_IMPORT', () => {
|
||||
it('parses the status as a Record', () => {
|
||||
const status = require('soapbox/__fixtures__/pleroma-quote-post.json');
|
||||
const action = { type: STATUS_IMPORT, status };
|
||||
const result = reducer(undefined, action).get('AFmFMSpITT9xcOJKcK');
|
||||
|
||||
expect(Record.isRecord(result)).toBe(true);
|
||||
});
|
||||
|
||||
it('fixes the order of mentions', () => {
|
||||
const status = require('soapbox/__fixtures__/status-unordered-mentions.json');
|
||||
const action = { type: STATUS_IMPORT, status };
|
||||
|
|
|
@ -40,17 +40,8 @@ import {
|
|||
|
||||
const initialState = ImmutableMap();
|
||||
|
||||
const minifyAccount = account => {
|
||||
return account.deleteAll([
|
||||
'followers_count',
|
||||
'following_count',
|
||||
'statuses_count',
|
||||
'source',
|
||||
]);
|
||||
};
|
||||
|
||||
const fixAccount = (state, account) => {
|
||||
const normalized = minifyAccount(normalizeAccount(fromJS(account)));
|
||||
const normalized = normalizeAccount(fromJS(account));
|
||||
return state.set(account.id, normalized);
|
||||
};
|
||||
|
||||
|
@ -125,20 +116,15 @@ const removePermission = (state, accountIds, permissionGroup) => {
|
|||
});
|
||||
};
|
||||
|
||||
const buildAccount = adminUser => fromJS({
|
||||
const buildAccount = adminUser => normalizeAccount(fromJS({
|
||||
id: adminUser.get('id'),
|
||||
username: adminUser.get('nickname').split('@')[0],
|
||||
acct: adminUser.get('nickname'),
|
||||
display_name: adminUser.get('display_name'),
|
||||
display_name_html: adminUser.get('display_name'),
|
||||
note: '',
|
||||
url: adminUser.get('url'),
|
||||
avatar: adminUser.get('avatar'),
|
||||
avatar_static: adminUser.get('avatar'),
|
||||
header: '',
|
||||
header_static: '',
|
||||
emojis: [],
|
||||
fields: [],
|
||||
created_at: adminUser.get('created_at'),
|
||||
pleroma: {
|
||||
is_active: adminUser.get('is_active'),
|
||||
|
@ -153,7 +139,7 @@ const buildAccount = adminUser => fromJS({
|
|||
},
|
||||
},
|
||||
should_refetch: true,
|
||||
});
|
||||
}));
|
||||
|
||||
const mergeAdminUser = (account, adminUser) => {
|
||||
return account.withMutations(account => {
|
||||
|
|
|
@ -89,8 +89,7 @@ const fixQuote = (status, oldStatus) => {
|
|||
const fixStatus = (state, status, expandSpoilers) => {
|
||||
const oldStatus = state.get(status.get('id'));
|
||||
|
||||
return status.withMutations(status => {
|
||||
normalizeStatus(status);
|
||||
return normalizeStatus(status).withMutations(status => {
|
||||
fixQuote(status, oldStatus);
|
||||
calculateStatus(status, oldStatus, expandSpoilers);
|
||||
minifyStatus(status);
|
||||
|
|
Ładowanie…
Reference in New Issue