kopia lustrzana https://gitlab.com/soapbox-pub/soapbox
Merge branch 'normalize-fqn' into 'develop'
Account: normalize fqn See merge request soapbox-pub/soapbox-fe!1110remove-makegetotheraccounts
commit
96398a61f5
|
@ -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": []
|
||||||
|
}
|
|
@ -161,4 +161,11 @@ describe('normalizeAccount()', () => {
|
||||||
expect(result.header).toEqual(HEADER_MISSING);
|
expect(result.header).toEqual(HEADER_MISSING);
|
||||||
expect(result.header_static).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');
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -14,6 +14,7 @@ import {
|
||||||
import emojify from 'soapbox/features/emoji/emoji';
|
import emojify from 'soapbox/features/emoji/emoji';
|
||||||
import { normalizeEmoji } from 'soapbox/normalizers/emoji';
|
import { normalizeEmoji } from 'soapbox/normalizers/emoji';
|
||||||
import { IAccount } from 'soapbox/types';
|
import { IAccount } from 'soapbox/types';
|
||||||
|
import { acctFull } from 'soapbox/utils/accounts';
|
||||||
import { unescapeHTML } from 'soapbox/utils/html';
|
import { unescapeHTML } from 'soapbox/utils/html';
|
||||||
import { mergeDefined, makeEmojiMap } from 'soapbox/utils/normalizers';
|
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 => {
|
export const normalizeAccount = (account: Record<string, any>): IAccount => {
|
||||||
return AccountRecord(
|
return AccountRecord(
|
||||||
ImmutableMap(fromJS(account)).withMutations(account => {
|
ImmutableMap(fromJS(account)).withMutations(account => {
|
||||||
|
@ -206,6 +211,7 @@ export const normalizeAccount = (account: Record<string, any>): IAccount => {
|
||||||
normalizeVerified(account);
|
normalizeVerified(account);
|
||||||
normalizeBirthday(account);
|
normalizeBirthday(account);
|
||||||
normalizeLocation(account);
|
normalizeLocation(account);
|
||||||
|
normalizeFqn(account);
|
||||||
fixUsername(account);
|
fixUsername(account);
|
||||||
fixDisplayName(account);
|
fixDisplayName(account);
|
||||||
addInternalFields(account);
|
addInternalFields(account);
|
||||||
|
|
|
@ -10,14 +10,14 @@ const getDomainFromURL = (account: ImmutableMap<string, any>): string => {
|
||||||
};
|
};
|
||||||
|
|
||||||
export const getDomain = (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);
|
return domain ? domain : getDomainFromURL(account);
|
||||||
};
|
};
|
||||||
|
|
||||||
export const guessFqn = (account: ImmutableMap<string, any>): string => {
|
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('@');
|
if (!domain) return [user, getDomainFromURL(account)].join('@');
|
||||||
return account.get('acct');
|
return account.get('acct', '');
|
||||||
};
|
};
|
||||||
|
|
||||||
export const getBaseURL = (account: ImmutableMap<string, any>): string => {
|
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
|
// user@domain even for local users
|
||||||
export const acctFull = (account: ImmutableMap<string, any>): string => (
|
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 => (
|
export const getAcct = (account: ImmutableMap<string, any>, displayFqn: boolean): string => (
|
||||||
|
|
Ładowanie…
Reference in New Issue