normalizeAccount(): normalize Pleroma legacy fields
This commit is contained in:
@ -16,4 +16,24 @@ describe('normalizeAccount()', () => {
|
||||
|
||||
expect(result.get('birthday')).toEqual('1993-07-03');
|
||||
});
|
||||
|
||||
it('normalizes Pleroma legacy fields', () => {
|
||||
const account = fromJS(require('soapbox/__fixtures__/pleroma-2.2.2-account.json'));
|
||||
const result = normalizeAccount(account);
|
||||
|
||||
expect(result.getIn(['pleroma', 'is_active'])).toBe(true);
|
||||
expect(result.getIn(['pleroma', 'is_confirmed'])).toBe(true);
|
||||
expect(result.getIn(['pleroma', 'is_approved'])).toBe(true);
|
||||
|
||||
expect(result.hasIn(['pleroma', 'confirmation_pending'])).toBe(false);
|
||||
});
|
||||
|
||||
it('prefers new Pleroma fields', () => {
|
||||
const account = fromJS(require('soapbox/__fixtures__/pleroma-account.json'));
|
||||
const result = normalizeAccount(account);
|
||||
|
||||
expect(result.getIn(['pleroma', 'is_active'])).toBe(true);
|
||||
expect(result.getIn(['pleroma', 'is_confirmed'])).toBe(true);
|
||||
expect(result.getIn(['pleroma', 'is_approved'])).toBe(true);
|
||||
});
|
||||
});
|
||||
|
||||
@ -1,4 +1,25 @@
|
||||
export const normalizeAccount = account => {
|
||||
import { Map as ImmutableMap } from 'immutable';
|
||||
|
||||
import { mergeDefined } from 'soapbox/utils/normalizers';
|
||||
|
||||
// https://gitlab.com/soapbox-pub/soapbox-fe/-/issues/549
|
||||
const normalizePleromaLegacyFields = account => {
|
||||
return account.update('pleroma', ImmutableMap(), pleroma => {
|
||||
return pleroma.withMutations(pleroma => {
|
||||
const legacy = ImmutableMap({
|
||||
is_active: !pleroma.get('deactivated'),
|
||||
is_confirmed: !pleroma.get('confirmation_pending'),
|
||||
is_approved: !pleroma.get('approval_pending'),
|
||||
});
|
||||
|
||||
pleroma.mergeWith(mergeDefined, legacy);
|
||||
pleroma.deleteAll(['deactivated', 'confirmation_pending', 'approval_pending']);
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
// Normalize Pleroma/Fedibird birthday
|
||||
const normalizeBirthday = account => {
|
||||
const birthday = [
|
||||
account.getIn(['pleroma', 'birthday']),
|
||||
account.getIn(['other_settings', 'birthday']),
|
||||
@ -6,3 +27,10 @@ export const normalizeAccount = account => {
|
||||
|
||||
return account.set('birthday', birthday);
|
||||
};
|
||||
|
||||
export const normalizeAccount = account => {
|
||||
return account.withMutations(account => {
|
||||
normalizePleromaLegacyFields(account);
|
||||
normalizeBirthday(account);
|
||||
});
|
||||
};
|
||||
|
||||
@ -1,6 +1,7 @@
|
||||
import { Map as ImmutableMap } from 'immutable';
|
||||
|
||||
import { parseVersion, PLEROMA } from 'soapbox/utils/features';
|
||||
import { mergeDefined } from 'soapbox/utils/normalizers';
|
||||
import { isNumber } from 'soapbox/utils/numbers';
|
||||
|
||||
// Use Mastodon defaults
|
||||
@ -36,9 +37,6 @@ const pleromaToMastodonConfig = instance => {
|
||||
});
|
||||
};
|
||||
|
||||
// Use new value only if old value is undefined
|
||||
const mergeDefined = (oldVal, newVal) => oldVal === undefined ? newVal : oldVal;
|
||||
|
||||
// Get the software's default attachment limit
|
||||
const getAttachmentLimit = software => software === PLEROMA ? Infinity : 4;
|
||||
|
||||
|
||||
@ -1,6 +1,7 @@
|
||||
import { Map as ImmutableMap, List as ImmutableList } 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({
|
||||
@ -40,9 +41,6 @@ const basePoll = ImmutableMap({
|
||||
votes_count: 0,
|
||||
});
|
||||
|
||||
// Merger function for only overriding undefined values
|
||||
const mergeDefined = (oldVal, newVal) => oldVal === undefined ? newVal : oldVal;
|
||||
|
||||
// Merge base status
|
||||
const mergeBase = status => {
|
||||
return status.mergeDeepWith(mergeDefined, baseStatus);
|
||||
|
||||
Reference in New Issue
Block a user