From f24e1c99296a756b15be4d088a7f37128b4e5a49 Mon Sep 17 00:00:00 2001 From: Alex Gleason Date: Mon, 18 Jan 2021 13:59:24 -0600 Subject: [PATCH] Normalize Pleroma user fields, fixes #549 --- app/soapbox/features/account/components/header.js | 2 +- .../features/ui/components/profile_info_panel.js | 2 +- app/soapbox/reducers/accounts.js | 9 ++++++++- app/soapbox/reducers/admin.js | 4 +++- app/soapbox/utils/pleroma.js | 10 ++++++++++ 5 files changed, 23 insertions(+), 4 deletions(-) create mode 100644 app/soapbox/utils/pleroma.js diff --git a/app/soapbox/features/account/components/header.js b/app/soapbox/features/account/components/header.js index 444cb5272..116b43565 100644 --- a/app/soapbox/features/account/components/header.js +++ b/app/soapbox/features/account/components/header.js @@ -224,7 +224,7 @@ class Header extends ImmutablePureComponent { const headerMissing = (account.get('header').indexOf('/headers/original/missing.png') > -1); const avatarSize = isSmallScreen ? 90 : 200; - const deactivated = account.getIn(['pleroma', 'deactivated'], false); + const deactivated = !account.getIn(['pleroma', 'is_active'], true); return (
diff --git a/app/soapbox/features/ui/components/profile_info_panel.js b/app/soapbox/features/ui/components/profile_info_panel.js index 7d2da3c99..efc5cb63c 100644 --- a/app/soapbox/features/ui/components/profile_info_panel.js +++ b/app/soapbox/features/ui/components/profile_info_panel.js @@ -59,7 +59,7 @@ class ProfileInfoPanel extends ImmutablePureComponent { const lockedIcon = account.get('locked') ? () : ''; const content = { __html: account.get('note_emojified') }; const fields = account.get('fields'); - const deactivated = account.getIn(['pleroma', 'deactivated'], false); + const deactivated = !account.getIn(['pleroma', 'is_active'], true); const displayNameHtml = deactivated ? { __html: intl.formatMessage(messages.deactivated) } : { __html: account.get('display_name_html') }; const memberSinceDate = intl.formatDate(account.get('created_at'), { month: 'long', year: 'numeric' }); const verified = account.getIn(['pleroma', 'tags'], ImmutableList()).includes('verified'); diff --git a/app/soapbox/reducers/accounts.js b/app/soapbox/reducers/accounts.js index b02ef763f..f8f869ad5 100644 --- a/app/soapbox/reducers/accounts.js +++ b/app/soapbox/reducers/accounts.js @@ -7,11 +7,18 @@ import { CHATS_FETCH_SUCCESS, CHAT_FETCH_SUCCESS } from 'soapbox/actions/chats'; import { STREAMING_CHAT_UPDATE } from 'soapbox/actions/streaming'; import { normalizeAccount as normalizeAccount2 } from 'soapbox/actions/importer/normalizer'; import { Map as ImmutableMap, fromJS } from 'immutable'; +import { normalizePleromaUserFields } from 'soapbox/utils/pleroma'; const initialState = ImmutableMap(); +const normalizePleroma = account => { + if (!account.pleroma) return account; + account.pleroma = normalizePleromaUserFields(account.pleroma); + return account; +}; + const normalizeAccount = (state, account) => { - const normalized = fromJS(account).deleteAll([ + const normalized = fromJS(normalizePleroma(account)).deleteAll([ 'followers_count', 'following_count', 'statuses_count', diff --git a/app/soapbox/reducers/admin.js b/app/soapbox/reducers/admin.js index 9f6000ec8..960df70f6 100644 --- a/app/soapbox/reducers/admin.js +++ b/app/soapbox/reducers/admin.js @@ -15,6 +15,7 @@ import { OrderedSet as ImmutableOrderedSet, fromJS, } from 'immutable'; +import { normalizePleromaUserFields } from 'soapbox/utils/pleroma'; const initialState = ImmutableMap({ reports: ImmutableMap(), @@ -28,7 +29,8 @@ const initialState = ImmutableMap({ function importUsers(state, users) { return state.withMutations(state => { users.forEach(user => { - if (user.approval_pending) { + user = normalizePleromaUserFields(user); + if (!user.is_approved) { state.update('awaitingApproval', orderedSet => orderedSet.add(user.nickname)); } state.setIn(['users', user.nickname], fromJS(user)); diff --git a/app/soapbox/utils/pleroma.js b/app/soapbox/utils/pleroma.js new file mode 100644 index 000000000..dd8937938 --- /dev/null +++ b/app/soapbox/utils/pleroma.js @@ -0,0 +1,10 @@ +// https://gitlab.com/soapbox-pub/soapbox-fe/-/issues/549 +export const normalizePleromaUserFields = obj => { + obj.is_active = obj.is_active === undefined ? !obj.deactivated : obj.is_active; + obj.is_confirmed = obj.is_confirmed === undefined ? !obj.confirmation_pending : obj.is_confirmed; + obj.is_approved = obj.is_approved === undefined ? !obj.approval_pending : obj.is_approved; + delete obj.deactivated; + delete obj.confirmation_pending; + delete obj.approval_pending; + return obj; +};