From 3095ee5db1a91123ec44a15720cd1fb512c1ec73 Mon Sep 17 00:00:00 2001 From: Alex Gleason Date: Sun, 27 Feb 2022 22:22:08 -0600 Subject: [PATCH 1/2] normalizeAccount(): normalize "verified" field --- app/soapbox/__fixtures__/mk.json | 123 ++++++++++++++++++ app/soapbox/__fixtures__/realDonaldTrump.json | 26 ++++ .../normalizers/__tests__/account-test.js | 18 +++ app/soapbox/normalizers/account.js | 13 +- app/soapbox/utils/accounts.js | 4 +- 5 files changed, 180 insertions(+), 4 deletions(-) create mode 100644 app/soapbox/__fixtures__/mk.json create mode 100644 app/soapbox/__fixtures__/realDonaldTrump.json diff --git a/app/soapbox/__fixtures__/mk.json b/app/soapbox/__fixtures__/mk.json new file mode 100644 index 000000000..a7c841f1e --- /dev/null +++ b/app/soapbox/__fixtures__/mk.json @@ -0,0 +1,123 @@ +{ + "acct": "mk", + "avatar": "https://media.spinster.xyz/4043b9fb3f9d468aa48a8d68294f338914d9d54b2816aa1c789f548efe6c6239.jpg", + "avatar_static": "https://media.spinster.xyz/4043b9fb3f9d468aa48a8d68294f338914d9d54b2816aa1c789f548efe6c6239.jpg", + "bot": false, + "created_at": "2019-08-01T22:06:30.000Z", + "display_name": "M. K. Fain", + "emojis": [ + { + "shortcode": "4w", + "static_url": "https://spinster.xyz/emoji/custom/4w.png", + "url": "https://spinster.xyz/emoji/custom/4w.png", + "visible_in_picker": false + }, + { + "shortcode": "spinster", + "static_url": "https://spinster.xyz/emoji/custom/spinster.png", + "url": "https://spinster.xyz/emoji/custom/spinster.png", + "visible_in_picker": false + } + ], + "fields": [ + { + "name": "Website", + "value": "https://marykatefain.com" + }, + { + "name": "Twitter", + "value": "https://twitter.com/mkay_fain" + }, + { + "name": "Patreon", + "value": "https://www.patreon.com/mkfain" + }, + { + "name": "Paypal", + "value": "https://www.paypal.com/donate?hosted_button_id=NYXHYFQ6CRWJJ" + }, + { + "name": "Facebook", + "value": "https://www.facebook.com/M-K-Fain-102559968375112" + }, + { + "name": "Dog Pics", + "value": "https://www.instagram.com/mmkaayyy92" + }, + { + "name": "$BTC", + "value": "bc1q7fp347muhnuxrtu0pft6eswn0e7pldhssdg8py" + } + ], + "followers_count": 5687, + "following_count": 18017, + "fqn": "mk@spinster.xyz", + "header": "https://media.spinster.xyz/3a5f9d5ef06940d0c319f8f0135b1153a8a42cefd10eace97378875c0347da71.png", + "header_static": "https://media.spinster.xyz/3a5f9d5ef06940d0c319f8f0135b1153a8a42cefd10eace97378875c0347da71.png", + "id": "9y4BZYXEDuQ6K1zW9g", + "last_status_at": "2022-02-27T01:58:21", + "locked": false, + "note": ":spinster: Admin of @spinster
:4w: Editor of @4WPub

Sorry I didn't reply to you.

Boost ≠ agree. All opinions my own.", + "pleroma": { + "accepts_chat_messages": true, + "also_known_as": [], + "ap_id": "https://spinster.xyz/users/mk", + "background_image": null, + "favicon": "https://spinster.xyz/favicon.png", + "hide_favorites": true, + "hide_followers": false, + "hide_followers_count": false, + "hide_follows": false, + "hide_follows_count": false, + "is_admin": true, + "is_confirmed": true, + "is_moderator": false, + "is_suggested": true, + "relationship": {}, + "skip_thread_containment": false, + "tags": [ + "verified" + ] + }, + "source": { + "fields": [ + { + "name": "Website", + "value": "https://marykatefain.com" + }, + { + "name": "Twitter", + "value": "https://twitter.com/mkay_fain" + }, + { + "name": "Patreon", + "value": "https://www.patreon.com/mkfain" + }, + { + "name": "Paypal", + "value": "https://www.paypal.com/donate?hosted_button_id=NYXHYFQ6CRWJJ" + }, + { + "name": "Facebook", + "value": "https://www.facebook.com/M-K-Fain-102559968375112" + }, + { + "name": "Dog Pics", + "value": "https://www.instagram.com/mmkaayyy92" + }, + { + "name": "$BTC", + "value": "bc1q7fp347muhnuxrtu0pft6eswn0e7pldhssdg8py" + } + ], + "note": ":spinster: Admin of @spinster\r\n:4w: Editor of @4WPub\r\n\r\nSorry I didn't reply to you.\r\n\r\nBoost ≠ agree. All opinions my own.", + "pleroma": { + "actor_type": "Person", + "discoverable": false + }, + "sensitive": false + }, + "statuses_count": 9580, + "url": "https://spinster.xyz/users/mk", + "username": "mk" +} diff --git a/app/soapbox/__fixtures__/realDonaldTrump.json b/app/soapbox/__fixtures__/realDonaldTrump.json new file mode 100644 index 000000000..c9cf20076 --- /dev/null +++ b/app/soapbox/__fixtures__/realDonaldTrump.json @@ -0,0 +1,26 @@ +{ + "id": "107780257626128497", + "username": "realDonaldTrump", + "acct": "realDonaldTrump", + "display_name": "Donald J. Trump", + "locked": false, + "bot": false, + "discoverable": null, + "group": false, + "created_at": "2022-02-11T00:00:00.000Z", + "note": "

45th President of the United States of America

", + "url": "https://truthsocial.com/@realDonaldTrump", + "avatar": "https://static-assets.truthsocial.com/tmtg:prime-truth-social-assets/accounts/avatars/107/780/257/626/128/497/original/573cf5cc8281e7e9.jpeg", + "avatar_static": "https://static-assets.truthsocial.com/tmtg:prime-truth-social-assets/accounts/avatars/107/780/257/626/128/497/original/573cf5cc8281e7e9.jpeg", + "header": "https://static-assets.truthsocial.com/tmtg:prime-truth-social-assets/accounts/headers/107/780/257/626/128/497/original/3c1acf607b065ded.jpeg", + "header_static": "https://static-assets.truthsocial.com/tmtg:prime-truth-social-assets/accounts/headers/107/780/257/626/128/497/original/3c1acf607b065ded.jpeg", + "followers_count": 51507, + "following_count": 1, + "statuses_count": 1, + "last_status_at": "2022-02-14", + "verified": true, + "location": "", + "website": "", + "emojis": [], + "fields": [] +} diff --git a/app/soapbox/normalizers/__tests__/account-test.js b/app/soapbox/normalizers/__tests__/account-test.js index d6584f96b..f00dd57c5 100644 --- a/app/soapbox/normalizers/__tests__/account-test.js +++ b/app/soapbox/normalizers/__tests__/account-test.js @@ -36,4 +36,22 @@ describe('normalizeAccount()', () => { expect(result.getIn(['pleroma', 'is_confirmed'])).toBe(true); expect(result.getIn(['pleroma', 'is_approved'])).toBe(true); }); + + it('normalizes a verified Pleroma user', () => { + const account = fromJS(require('soapbox/__fixtures__/mk.json')); + const result = normalizeAccount(account); + expect(result.get('verified')).toBe(true); + }); + + it('normalizes an unverified Pleroma user', () => { + const account = fromJS(require('soapbox/__fixtures__/pleroma-account.json')); + const result = normalizeAccount(account); + expect(result.get('verified')).toBe(false); + }); + + it('normalizes a verified Truth Social user', () => { + const account = fromJS(require('soapbox/__fixtures__/realDonaldTrump.json')); + const result = normalizeAccount(account); + expect(result.get('verified')).toBe(true); + }); }); diff --git a/app/soapbox/normalizers/account.js b/app/soapbox/normalizers/account.js index da942473f..aa49f647f 100644 --- a/app/soapbox/normalizers/account.js +++ b/app/soapbox/normalizers/account.js @@ -1,4 +1,4 @@ -import { Map as ImmutableMap } from 'immutable'; +import { Map as ImmutableMap, List as ImmutableList } from 'immutable'; import { mergeDefined } from 'soapbox/utils/normalizers'; @@ -28,9 +28,20 @@ const normalizeBirthday = account => { return account.set('birthday', birthday); }; +// Normalize Truth Social/Pleroma verified +const normalizeVerified = account => { + return account.update('verified', verified => { + return [ + verified === true, + account.getIn(['pleroma', 'tags'], ImmutableList()).includes('verified'), + ].some(Boolean); + }); +}; + export const normalizeAccount = account => { return account.withMutations(account => { normalizePleromaLegacyFields(account); + normalizeVerified(account); normalizeBirthday(account); }); }; diff --git a/app/soapbox/utils/accounts.js b/app/soapbox/utils/accounts.js index 3cf2c7cd5..af6dfdbbb 100644 --- a/app/soapbox/utils/accounts.js +++ b/app/soapbox/utils/accounts.js @@ -64,9 +64,7 @@ export const isLocal = account => { export const isRemote = account => !isLocal(account); -export const isVerified = account => ( - account.getIn(['pleroma', 'tags'], ImmutableList()).includes('verified') -); +export const isVerified = account => account.get('verified') === true; export const accountToMention = account => { return ImmutableMap({ From d86eac4c1af88939e87a4b9819d9d781e8eed400 Mon Sep 17 00:00:00 2001 From: Alex Gleason Date: Sun, 27 Feb 2022 22:25:23 -0600 Subject: [PATCH 2/2] Remove isVerified() function --- app/soapbox/components/display_name.js | 3 +-- app/soapbox/features/account/components/header.js | 3 +-- .../features/edit_profile/components/profile_preview.js | 4 ++-- app/soapbox/features/edit_profile/index.js | 3 +-- app/soapbox/features/ui/components/profile_info_panel.js | 4 ++-- app/soapbox/features/ui/components/user_panel.js | 4 ++-- app/soapbox/utils/accounts.js | 2 -- 7 files changed, 9 insertions(+), 14 deletions(-) diff --git a/app/soapbox/components/display_name.js b/app/soapbox/components/display_name.js index eca526679..87947af46 100644 --- a/app/soapbox/components/display_name.js +++ b/app/soapbox/components/display_name.js @@ -4,7 +4,6 @@ import ImmutablePropTypes from 'react-immutable-proptypes'; import { connect } from 'react-redux'; import HoverRefWrapper from 'soapbox/components/hover_ref_wrapper'; -import { isVerified } from 'soapbox/utils/accounts'; import { displayFqn } from 'soapbox/utils/state'; import { getAcct } from '../utils/accounts'; @@ -38,7 +37,7 @@ class DisplayName extends React.PureComponent { const { account, displayFqn, others, children, withDate } = this.props; let displayName, suffix; - const verified = isVerified(account); + const verified = account.get('verified'); const createdAt = account.get('created_at'); diff --git a/app/soapbox/features/account/components/header.js b/app/soapbox/features/account/components/header.js index 8b5a5f258..4881d6b7d 100644 --- a/app/soapbox/features/account/components/header.js +++ b/app/soapbox/features/account/components/header.js @@ -27,7 +27,6 @@ import { isStaff, isAdmin, isModerator, - isVerified, isLocal, isRemote, getDomain, @@ -451,7 +450,7 @@ class Header extends ImmutablePureComponent { } } - if (isVerified(account)) { + if (account.get('verified')) { menu.push({ text: intl.formatMessage(messages.unverifyUser, { name: account.get('username') }), action: this.props.onUnverifyUser, diff --git a/app/soapbox/features/edit_profile/components/profile_preview.js b/app/soapbox/features/edit_profile/components/profile_preview.js index 3b73e48f8..ad1db11ed 100644 --- a/app/soapbox/features/edit_profile/components/profile_preview.js +++ b/app/soapbox/features/edit_profile/components/profile_preview.js @@ -6,7 +6,7 @@ import { Link } from 'react-router-dom'; import StillImage from 'soapbox/components/still_image'; import VerificationBadge from 'soapbox/components/verification_badge'; -import { getAcct, isVerified } from 'soapbox/utils/accounts'; +import { getAcct } from 'soapbox/utils/accounts'; import { displayFqn } from 'soapbox/utils/state'; const mapStateToProps = state => ({ @@ -28,7 +28,7 @@ const ProfilePreview = ({ account, displayFqn }) => ( {account.get('display_name')} - {isVerified(account) && } + {account.get('verified') && } @{getAcct(account, displayFqn)} diff --git a/app/soapbox/features/edit_profile/index.js b/app/soapbox/features/edit_profile/index.js index 5205f4eb6..300d965a7 100644 --- a/app/soapbox/features/edit_profile/index.js +++ b/app/soapbox/features/edit_profile/index.js @@ -25,7 +25,6 @@ import { SimpleTextarea, } from 'soapbox/features/forms'; import { makeGetAccount } from 'soapbox/selectors'; -import { isVerified } from 'soapbox/utils/accounts'; import { getFeatures } from 'soapbox/utils/features'; import resizeImage from 'soapbox/utils/resize_image'; @@ -263,7 +262,7 @@ class EditProfile extends ImmutablePureComponent { render() { const { intl, maxFields, account, verifiedCanEditName, supportsBirthdays, supportsEmailList } = this.props; - const verified = isVerified(account); + const verified = account.get('verified'); const canEditName = verifiedCanEditName || !verified; return ( diff --git a/app/soapbox/features/ui/components/profile_info_panel.js b/app/soapbox/features/ui/components/profile_info_panel.js index bb0db2677..72e033e1e 100644 --- a/app/soapbox/features/ui/components/profile_info_panel.js +++ b/app/soapbox/features/ui/components/profile_info_panel.js @@ -15,7 +15,7 @@ import Icon from 'soapbox/components/icon'; import VerificationBadge from 'soapbox/components/verification_badge'; import BundleContainer from 'soapbox/features/ui/containers/bundle_container'; import { CryptoAddress } from 'soapbox/features/ui/util/async-components'; -import { getAcct, isAdmin, isModerator, isLocal, isVerified } from 'soapbox/utils/accounts'; +import { getAcct, isAdmin, isModerator, isLocal } from 'soapbox/utils/accounts'; import { displayFqn } from 'soapbox/utils/state'; import ProfileStats from './profile_stats'; @@ -147,7 +147,7 @@ class ProfileInfoPanel extends ImmutablePureComponent { 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 = isVerified(account); + const verified = account.get('verified'); const badges = this.getBadges(); return ( diff --git a/app/soapbox/features/ui/components/user_panel.js b/app/soapbox/features/ui/components/user_panel.js index 9bf52c4da..36a48ce56 100644 --- a/app/soapbox/features/ui/components/user_panel.js +++ b/app/soapbox/features/ui/components/user_panel.js @@ -9,7 +9,7 @@ import { Link } from 'react-router-dom'; import Avatar from 'soapbox/components/avatar'; import StillImage from 'soapbox/components/still_image'; import VerificationBadge from 'soapbox/components/verification_badge'; -import { getAcct, isVerified } from 'soapbox/utils/accounts'; +import { getAcct } from 'soapbox/utils/accounts'; import { shortNumberFormat } from 'soapbox/utils/numbers'; import { displayFqn } from 'soapbox/utils/state'; @@ -51,7 +51,7 @@ class UserPanel extends ImmutablePureComponent {

- {isVerified(account) && } + {account.get('verified') && } @{getAcct(account, displayFqn)}

diff --git a/app/soapbox/utils/accounts.js b/app/soapbox/utils/accounts.js index af6dfdbbb..b72b4b97c 100644 --- a/app/soapbox/utils/accounts.js +++ b/app/soapbox/utils/accounts.js @@ -64,8 +64,6 @@ export const isLocal = account => { export const isRemote = account => !isLocal(account); -export const isVerified = account => account.get('verified') === true; - export const accountToMention = account => { return ImmutableMap({ id: account.get('id'),