From 57d44889f2023f646e31200eafcb88ba8cccc1c2 Mon Sep 17 00:00:00 2001 From: Alex Gleason Date: Sat, 28 Mar 2020 13:07:36 -0500 Subject: [PATCH] Handle acct_full on the frontend --- app/gabsocial/components/display_name.js | 3 ++- .../features/ui/components/profile_info_panel.js | 3 ++- .../features/ui/components/user_panel.js | 3 ++- app/gabsocial/utils/accounts.js | 16 ++++++++++++++++ public/index.html | 2 +- 5 files changed, 23 insertions(+), 4 deletions(-) create mode 100644 app/gabsocial/utils/accounts.js diff --git a/app/gabsocial/components/display_name.js b/app/gabsocial/components/display_name.js index e9f91f725..be0614140 100644 --- a/app/gabsocial/components/display_name.js +++ b/app/gabsocial/components/display_name.js @@ -2,6 +2,7 @@ import React from 'react'; import ImmutablePropTypes from 'react-immutable-proptypes'; import PropTypes from 'prop-types'; import VerificationBadge from './verification_badge'; +import { acctFull } from '../utils/accounts'; export default class DisplayName extends React.PureComponent { @@ -40,7 +41,7 @@ export default class DisplayName extends React.PureComponent { {account.get('is_verified') && } ); - suffix = @{account.get('acct_full')}; + suffix = @{acctFull(account)}; } return ( diff --git a/app/gabsocial/features/ui/components/profile_info_panel.js b/app/gabsocial/features/ui/components/profile_info_panel.js index 5078717c5..1862e06fc 100644 --- a/app/gabsocial/features/ui/components/profile_info_panel.js +++ b/app/gabsocial/features/ui/components/profile_info_panel.js @@ -14,6 +14,7 @@ import ProBadge from 'gabsocial/components/pro_badge'; import DonorBadge from 'gabsocial/components/donor_badge'; import InvestorBadge from 'gabsocial/components/investor_badge'; import { List as ImmutableList } from 'immutable'; +import { acctFull } from 'gabsocial/utils/accounts'; const messages = defineMessages({ linkVerifiedOn: { id: 'account.link_verified_on', defaultMessage: 'Ownership of this link was checked on {date}' }, @@ -73,7 +74,7 @@ class ProfileInfoPanel extends ImmutablePureComponent { {account.get('is_verified') && } {badge} - @{account.get('acct_full')} {lockedIcon} + @{acctFull(account)} {lockedIcon} diff --git a/app/gabsocial/features/ui/components/user_panel.js b/app/gabsocial/features/ui/components/user_panel.js index 9b33ad7fa..60832103a 100644 --- a/app/gabsocial/features/ui/components/user_panel.js +++ b/app/gabsocial/features/ui/components/user_panel.js @@ -9,6 +9,7 @@ import ImmutablePropTypes from 'react-immutable-proptypes'; import ImmutablePureComponent from 'react-immutable-pure-component'; import Avatar from 'gabsocial/components/avatar'; import { shortNumberFormat } from 'gabsocial/utils/numbers'; +import { acctFull } from 'gabsocial/utils/accounts'; class UserPanel extends ImmutablePureComponent { static propTypes = { @@ -42,7 +43,7 @@ class UserPanel extends ImmutablePureComponent {

- @{account.get('acct_full')} + @{acctFull(account)}

diff --git a/app/gabsocial/utils/accounts.js b/app/gabsocial/utils/accounts.js new file mode 100644 index 000000000..938475582 --- /dev/null +++ b/app/gabsocial/utils/accounts.js @@ -0,0 +1,16 @@ +const getDomain = account => { + let re = /https?:\/\/(.*?)\//i; + return re.exec(account.get('url'))[1]; +} + +// user@domain even for local users +export const acctFull = account => { + let [user, domain] = account.get('acct').split('@'); + try { + if (!domain) domain = getDomain(account); + } catch(e) { + console.error('Could not get domain for acctFull.'); + return account.get('acct'); + } + return [user, domain].join('@'); +} diff --git a/public/index.html b/public/index.html index e46b48652..f63671fdb 100644 --- a/public/index.html +++ b/public/index.html @@ -9,7 +9,7 @@ - +