diff --git a/app/soapbox/__fixtures__/mastodon-account.json b/app/soapbox/__fixtures__/mastodon-account.json new file mode 100644 index 0000000000..7a00340bf5 --- /dev/null +++ b/app/soapbox/__fixtures__/mastodon-account.json @@ -0,0 +1,23 @@ +{ + "id": "106801667066418367", + "username": "benis911", + "acct": "benis911", + "display_name": "", + "locked": false, + "bot": false, + "discoverable": null, + "group": false, + "created_at": "2021-08-22T00:00:00.000Z", + "note": "", + "url": "https://mastodon.social/@benis911", + "avatar": "https://mastodon.social/avatars/original/missing.png", + "avatar_static": "https://mastodon.social/avatars/original/missing.png", + "header": "https://mastodon.social/headers/original/missing.png", + "header_static": "https://mastodon.social/headers/original/missing.png", + "followers_count": 1, + "following_count": 0, + "statuses_count": 5, + "last_status_at": "2022-02-23", + "emojis": [], + "fields": [] +} diff --git a/app/soapbox/normalizers/__tests__/account-test.js b/app/soapbox/normalizers/__tests__/account-test.js index cbe45419f3..8d12a935d0 100644 Binary files a/app/soapbox/normalizers/__tests__/account-test.js and b/app/soapbox/normalizers/__tests__/account-test.js differ diff --git a/app/soapbox/normalizers/account.ts b/app/soapbox/normalizers/account.ts index a96c9ad2d0..1c536ee4ab 100644 --- a/app/soapbox/normalizers/account.ts +++ b/app/soapbox/normalizers/account.ts @@ -14,6 +14,7 @@ import { import emojify from 'soapbox/features/emoji/emoji'; import { normalizeEmoji } from 'soapbox/normalizers/emoji'; import { IAccount } from 'soapbox/types'; +import { acctFull } from 'soapbox/utils/accounts'; import { unescapeHTML } from 'soapbox/utils/html'; import { mergeDefined, makeEmojiMap } from 'soapbox/utils/normalizers'; @@ -195,6 +196,10 @@ const addInternalFields = (account: ImmutableMap) => { }); }; +const normalizeFqn = (account: ImmutableMap) => { + return account.set('fqn', acctFull(account)); +}; + export const normalizeAccount = (account: Record): IAccount => { return AccountRecord( ImmutableMap(fromJS(account)).withMutations(account => { @@ -206,6 +211,7 @@ export const normalizeAccount = (account: Record): IAccount => { normalizeVerified(account); normalizeBirthday(account); normalizeLocation(account); + normalizeFqn(account); fixUsername(account); fixDisplayName(account); addInternalFields(account); diff --git a/app/soapbox/utils/accounts.ts b/app/soapbox/utils/accounts.ts index e93138c868..a97f763389 100644 --- a/app/soapbox/utils/accounts.ts +++ b/app/soapbox/utils/accounts.ts @@ -10,14 +10,14 @@ const getDomainFromURL = (account: ImmutableMap): string => { }; export const getDomain = (account: ImmutableMap): string => { - const domain = account.get('acct').split('@')[1]; + const domain = account.get('acct', '').split('@')[1]; return domain ? domain : getDomainFromURL(account); }; export const guessFqn = (account: ImmutableMap): string => { - const [user, domain] = account.get('acct').split('@'); + const [user, domain] = account.get('acct', '').split('@'); if (!domain) return [user, getDomainFromURL(account)].join('@'); - return account.get('acct'); + return account.get('acct', ''); }; export const getBaseURL = (account: ImmutableMap): string => { @@ -31,7 +31,7 @@ export const getBaseURL = (account: ImmutableMap): string => { // user@domain even for local users export const acctFull = (account: ImmutableMap): string => ( - account.get('fqn') || guessFqn(account) + account.get('fqn') || guessFqn(account) || '' ); export const getAcct = (account: ImmutableMap, displayFqn: boolean): string => (