diff --git a/app/soapbox/__fixtures__/fedibird-account.json b/app/soapbox/__fixtures__/fedibird-account.json new file mode 100644 index 000000000..07bbd7057 --- /dev/null +++ b/app/soapbox/__fixtures__/fedibird-account.json @@ -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": "

", + "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 + } +} diff --git a/app/soapbox/__fixtures__/alex.json b/app/soapbox/__fixtures__/pleroma-account.json similarity index 100% rename from app/soapbox/__fixtures__/alex.json rename to app/soapbox/__fixtures__/pleroma-account.json diff --git a/app/soapbox/normalizers/__tests__/account-test.js b/app/soapbox/normalizers/__tests__/account-test.js new file mode 100644 index 000000000..58d9b9f27 --- /dev/null +++ b/app/soapbox/normalizers/__tests__/account-test.js @@ -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'); + }); +}); diff --git a/app/soapbox/normalizers/account.js b/app/soapbox/normalizers/account.js new file mode 100644 index 000000000..eb623c803 --- /dev/null +++ b/app/soapbox/normalizers/account.js @@ -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); +}; diff --git a/app/soapbox/reducers/accounts.js b/app/soapbox/reducers/accounts.js index 4ccb82856..924360dc9 100644 --- a/app/soapbox/reducers/accounts.js +++ b/app/soapbox/reducers/accounts.js @@ -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: diff --git a/app/soapbox/utils/__tests__/accounts-test.js b/app/soapbox/utils/__tests__/accounts-test.js index d3fd6f9ba..a9a77ffe1 100644 --- a/app/soapbox/utils/__tests__/accounts-test.js +++ b/app/soapbox/utils/__tests__/accounts-test.js @@ -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',