sforkowany z mirror/soapbox
Merge branch 'account-normalizer' into 'develop'
Create account normalizer See merge request soapbox-pub/soapbox-fe!1059improve-ci
commit
2eefdbe235
|
@ -0,0 +1,35 @@
|
|||
{
|
||||
"id": "66768",
|
||||
"username": "alex",
|
||||
"acct": "alex",
|
||||
"display_name": "",
|
||||
"locked": false,
|
||||
"bot": false,
|
||||
"cat": false,
|
||||
"discoverable": false,
|
||||
"group": false,
|
||||
"created_at": "2020-01-27T00:00:00.000Z",
|
||||
"note": "<p></p>",
|
||||
"url": "https://fedibird.com/@alex",
|
||||
"avatar": "https://fedibird.com/avatars/original/missing.png",
|
||||
"avatar_static": "https://fedibird.com/avatars/original/missing.png",
|
||||
"header": "https://fedibird.com/headers/original/missing.png",
|
||||
"header_static": "https://fedibird.com/headers/original/missing.png",
|
||||
"followers_count": 1,
|
||||
"following_count": 1,
|
||||
"subscribing_count": 0,
|
||||
"statuses_count": 5,
|
||||
"last_status_at": "2022-02-20",
|
||||
"emojis": [],
|
||||
"fields": [],
|
||||
"other_settings": {
|
||||
"birthday": "1993-07-03",
|
||||
"location": "Texas, USA",
|
||||
"noindex": false,
|
||||
"hide_network": false,
|
||||
"hide_statuses_count": false,
|
||||
"hide_following_count": false,
|
||||
"hide_followers_count": false,
|
||||
"enable_reaction": true
|
||||
}
|
||||
}
|
|
@ -0,0 +1,19 @@
|
|||
import { fromJS } from 'immutable';
|
||||
|
||||
import { normalizeAccount } from '../account';
|
||||
|
||||
describe('normalizeAccount()', () => {
|
||||
it('normalizes Fedibird birthday', () => {
|
||||
const account = fromJS(require('soapbox/__fixtures__/fedibird-account.json'));
|
||||
const result = normalizeAccount(account);
|
||||
|
||||
expect(result.get('birthday')).toEqual('1993-07-03');
|
||||
});
|
||||
|
||||
it('normalizes Pleroma birthday', () => {
|
||||
const account = fromJS(require('soapbox/__fixtures__/pleroma-account.json'));
|
||||
const result = normalizeAccount(account);
|
||||
|
||||
expect(result.get('birthday')).toEqual('1993-07-03');
|
||||
});
|
||||
});
|
|
@ -0,0 +1,8 @@
|
|||
export const normalizeAccount = account => {
|
||||
const birthday = [
|
||||
account.getIn(['pleroma', 'birthday']),
|
||||
account.getIn(['other_settings', 'birthday']),
|
||||
].find(Boolean);
|
||||
|
||||
return account.set('birthday', birthday);
|
||||
};
|
|
@ -30,6 +30,7 @@ import {
|
|||
import { CHATS_FETCH_SUCCESS, CHATS_EXPAND_SUCCESS, CHAT_FETCH_SUCCESS } from 'soapbox/actions/chats';
|
||||
import { normalizeAccount as normalizeAccount2 } from 'soapbox/actions/importer/normalizer';
|
||||
import { STREAMING_CHAT_UPDATE } from 'soapbox/actions/streaming';
|
||||
import { normalizeAccount } from 'soapbox/normalizers/account';
|
||||
import { normalizePleromaUserFields } from 'soapbox/utils/pleroma';
|
||||
|
||||
import {
|
||||
|
@ -47,7 +48,7 @@ const normalizePleroma = account => {
|
|||
return account;
|
||||
};
|
||||
|
||||
const normalizeAccount = (state, account) => {
|
||||
const fixAccount = (state, account) => {
|
||||
const normalized = fromJS(normalizePleroma(account)).withMutations(account => {
|
||||
account.deleteAll([
|
||||
'followers_count',
|
||||
|
@ -55,19 +56,14 @@ const normalizeAccount = (state, account) => {
|
|||
'statuses_count',
|
||||
'source',
|
||||
]);
|
||||
account.set(
|
||||
'birthday',
|
||||
account.getIn(['pleroma', 'birthday'], account.getIn(['other_settings', 'birthday'])),
|
||||
);
|
||||
});
|
||||
|
||||
|
||||
return state.set(account.id, normalized);
|
||||
return state.set(account.id, normalizeAccount(normalized));
|
||||
};
|
||||
|
||||
const normalizeAccounts = (state, accounts) => {
|
||||
accounts.forEach(account => {
|
||||
state = normalizeAccount(state, account);
|
||||
state = fixAccount(state, account);
|
||||
});
|
||||
|
||||
return state;
|
||||
|
@ -75,7 +71,7 @@ const normalizeAccounts = (state, accounts) => {
|
|||
|
||||
const importAccountFromChat = (state, chat) =>
|
||||
// TODO: Fix this monstrosity
|
||||
normalizeAccount(state, normalizeAccount2(chat.account));
|
||||
fixAccount(state, normalizeAccount2(chat.account));
|
||||
|
||||
const importAccountsFromChats = (state, chats) =>
|
||||
state.withMutations(mutable =>
|
||||
|
@ -209,7 +205,7 @@ const setSuggested = (state, accountIds, isSuggested) => {
|
|||
export default function accounts(state = initialState, action) {
|
||||
switch(action.type) {
|
||||
case ACCOUNT_IMPORT:
|
||||
return normalizeAccount(state, action.account);
|
||||
return fixAccount(state, action.account);
|
||||
case ACCOUNTS_IMPORT:
|
||||
return normalizeAccounts(state, action.accounts);
|
||||
case ACCOUNT_FETCH_FAIL_FOR_USERNAME_LOOKUP:
|
||||
|
|
|
@ -119,7 +119,7 @@ describe('isModerator', () => {
|
|||
|
||||
describe('accountToMention', () => {
|
||||
it('converts the account to a mention', () => {
|
||||
const account = fromJS(require('soapbox/__fixtures__/alex.json'));
|
||||
const account = fromJS(require('soapbox/__fixtures__/pleroma-account.json'));
|
||||
|
||||
const expected = fromJS({
|
||||
id: '9v5bmRalQvjOy0ECcC',
|
||||
|
|
Ładowanie…
Reference in New Issue