Account: normalize fqn

remove-makegetotheraccounts
Alex Gleason 2022-03-17 15:52:57 -05:00
rodzic e4f6b9ab9c
commit da07c9355a
Nie znaleziono w bazie danych klucza dla tego podpisu
ID klucza GPG: 7211D1F99744FBB7
4 zmienionych plików z 40 dodań i 4 usunięć

Wyświetl plik

@ -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": []
}

Wyświetl plik

@ -161,4 +161,11 @@ describe('normalizeAccount()', () => {
expect(result.header).toEqual(HEADER_MISSING);
expect(result.header_static).toEqual(HEADER_MISSING);
});
it('adds fqn to Mastodon account', () => {
const account = require('soapbox/__fixtures__/mastodon-account.json');
const result = normalizeAccount(account);
expect(result.fqn).toEqual('benis911@mastodon.social');
});
});

Wyświetl plik

@ -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<string, any>) => {
});
};
const normalizeFqn = (account: ImmutableMap<string, any>) => {
return account.set('fqn', acctFull(account));
};
export const normalizeAccount = (account: Record<string, any>): IAccount => {
return AccountRecord(
ImmutableMap(fromJS(account)).withMutations(account => {
@ -206,6 +211,7 @@ export const normalizeAccount = (account: Record<string, any>): IAccount => {
normalizeVerified(account);
normalizeBirthday(account);
normalizeLocation(account);
normalizeFqn(account);
fixUsername(account);
fixDisplayName(account);
addInternalFields(account);

Wyświetl plik

@ -10,14 +10,14 @@ const getDomainFromURL = (account: ImmutableMap<string, any>): string => {
};
export const getDomain = (account: ImmutableMap<string, any>): 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, any>): 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, any>): string => {
@ -31,7 +31,7 @@ export const getBaseURL = (account: ImmutableMap<string, any>): string => {
// user@domain even for local users
export const acctFull = (account: ImmutableMap<string, any>): string => (
account.get('fqn') || guessFqn(account)
account.get('fqn') || guessFqn(account) || ''
);
export const getAcct = (account: ImmutableMap<string, any>, displayFqn: boolean): string => (