From ab11f206d8a14443d68408f237fd99dd33752185 Mon Sep 17 00:00:00 2001 From: Paul Frazee Date: Fri, 7 Apr 2023 11:09:25 -0500 Subject: [PATCH] Stripe checkmark emojis from display names (close #396) (#419) --- src/lib/notifee.ts | 5 ++++- src/lib/strings/display-names.ts | 12 ++++++++++++ src/view/com/composer/Composer.tsx | 5 ++++- src/view/com/notifications/FeedItem.tsx | 9 ++++++--- src/view/com/notifications/InvitedUsers.tsx | 3 ++- src/view/com/post-thread/PostThreadItem.tsx | 5 ++++- src/view/com/posts/FeedItem.tsx | 13 +++++++------ src/view/com/profile/ProfileCard.tsx | 3 ++- src/view/com/profile/ProfileHeader.tsx | 11 ++++++----- src/view/com/search/Suggestions.tsx | 5 ++++- src/view/com/util/PostMeta.tsx | 5 +++-- src/view/com/util/UserInfoText.tsx | 5 ++++- 12 files changed, 58 insertions(+), 23 deletions(-) create mode 100644 src/lib/strings/display-names.ts diff --git a/src/lib/notifee.ts b/src/lib/notifee.ts index d2e29c0a..86631903 100644 --- a/src/lib/notifee.ts +++ b/src/lib/notifee.ts @@ -3,6 +3,7 @@ import {AppBskyEmbedImages} from '@atproto/api' import {RootStoreModel} from 'state/models/root-store' import {NotificationsFeedItemModel} from 'state/models/feeds/notifications' import {enforceLen} from 'lib/strings/helpers' +import {sanitizeDisplayName} from './strings/display-names' import {resetToTab} from '../Navigation' export function init(store: RootStoreModel) { @@ -42,7 +43,9 @@ export function displayNotification( export function displayNotificationFromModel( notif: NotificationsFeedItemModel, ) { - let author = notif.author.displayName || notif.author.handle + let author = sanitizeDisplayName( + notif.author.displayName || notif.author.handle, + ) let title: string let body: string = '' if (notif.isLike) { diff --git a/src/lib/strings/display-names.ts b/src/lib/strings/display-names.ts new file mode 100644 index 00000000..5b58dec3 --- /dev/null +++ b/src/lib/strings/display-names.ts @@ -0,0 +1,12 @@ +// \u2705 = ✅ +// \u2713 = ✓ +// \u2714 = ✔ +// \u2611 = ☑ +const CHECK_MARKS_RE = /[\u2705\u2713\u2714\u2611]/gu + +export function sanitizeDisplayName(str: string): string { + if (typeof str === 'string') { + return str.replace(CHECK_MARKS_RE, '') + } + return '' +} diff --git a/src/view/com/composer/Composer.tsx b/src/view/com/composer/Composer.tsx index 10a44542..7dcd6b2c 100644 --- a/src/view/com/composer/Composer.tsx +++ b/src/view/com/composer/Composer.tsx @@ -26,6 +26,7 @@ import {useStores} from 'state/index' import * as apilib from 'lib/api/index' import {ComposerOpts} from 'state/models/ui/shell' import {s, colors, gradients} from 'lib/styles' +import {sanitizeDisplayName} from 'lib/strings/display-names' import {cleanError} from 'lib/strings/errors' import {SelectPhotoBtn} from './photos/SelectPhotoBtn' import {OpenCameraBtn} from './photos/OpenCameraBtn' @@ -265,7 +266,9 @@ export const ComposePost = observer(function ComposePost({ - {replyTo.author.displayName || replyTo.author.handle} + {sanitizeDisplayName( + replyTo.author.displayName || replyTo.author.handle, + )} {replyTo.text} diff --git a/src/view/com/notifications/FeedItem.tsx b/src/view/com/notifications/FeedItem.tsx index dab26dbf..e77eae17 100644 --- a/src/view/com/notifications/FeedItem.tsx +++ b/src/view/com/notifications/FeedItem.tsx @@ -18,6 +18,7 @@ import {NotificationsFeedItemModel} from 'state/models/feeds/notifications' import {PostThreadModel} from 'state/models/content/post-thread' import {s, colors} from 'lib/styles' import {ago} from 'lib/strings/time' +import {sanitizeDisplayName} from 'lib/strings/display-names' import {pluralize} from 'lib/strings/helpers' import {HeartIconSolid} from 'lib/icons' import {Text} from '../util/text/Text' @@ -187,7 +188,9 @@ export const FeedItem = observer(function FeedItem({ key={authors[0].href} style={[pal.text, s.bold, styles.metaItem]} href={authors[0].href} - text={authors[0].displayName || authors[0].handle} + text={sanitizeDisplayName( + authors[0].displayName || authors[0].handle, + )} /> {authors.length > 1 ? ( <> @@ -310,7 +313,7 @@ function ExpandedAuthorsList({ @@ -322,7 +325,7 @@ function ExpandedAuthorsList({ numberOfLines={1} style={pal.text} lineHeight={1.2}> - {author.displayName || author.handle} + {sanitizeDisplayName(author.displayName || author.handle)}   {author.handle} diff --git a/src/view/com/notifications/InvitedUsers.tsx b/src/view/com/notifications/InvitedUsers.tsx index 2c44eb5b..73469d2a 100644 --- a/src/view/com/notifications/InvitedUsers.tsx +++ b/src/view/com/notifications/InvitedUsers.tsx @@ -15,6 +15,7 @@ import {CenteredView} from '../util/Views.web' import {useStores} from 'state/index' import {usePalette} from 'lib/hooks/usePalette' import {s} from 'lib/styles' +import {sanitizeDisplayName} from 'lib/strings/display-names' export const InvitedUsers = observer(() => { const store = useStores() @@ -65,7 +66,7 @@ function InvitedUser({ type="md-bold" style={pal.text} href={`/profile/${profile.handle}`} - text={profile.displayName || profile.handle} + text={sanitizeDisplayName(profile.displayName || profile.handle)} />{' '} joined using your invite code! diff --git a/src/view/com/post-thread/PostThreadItem.tsx b/src/view/com/post-thread/PostThreadItem.tsx index b23bebe0..3d3647f6 100644 --- a/src/view/com/post-thread/PostThreadItem.tsx +++ b/src/view/com/post-thread/PostThreadItem.tsx @@ -16,6 +16,7 @@ import * as Toast from '../util/Toast' import {UserAvatar} from '../util/UserAvatar' import {s} from 'lib/styles' import {ago} from 'lib/strings/time' +import {sanitizeDisplayName} from 'lib/strings/display-names' import {pluralize} from 'lib/strings/helpers' import {useStores} from 'state/index' import {PostMeta} from '../util/PostMeta' @@ -151,7 +152,9 @@ export const PostThreadItem = observer(function PostThreadItem({ style={[pal.text]} numberOfLines={1} lineHeight={1.2}> - {item.post.author.displayName || item.post.author.handle} + {sanitizeDisplayName( + item.post.author.displayName || item.post.author.handle, + )} diff --git a/src/view/com/posts/FeedItem.tsx b/src/view/com/posts/FeedItem.tsx index 5ec0c43a..569d1125 100644 --- a/src/view/com/posts/FeedItem.tsx +++ b/src/view/com/posts/FeedItem.tsx @@ -22,6 +22,7 @@ import {s} from 'lib/styles' import {useStores} from 'state/index' import {usePalette} from 'lib/hooks/usePalette' import {useAnalytics} from 'lib/analytics' +import {sanitizeDisplayName} from 'lib/strings/display-names' export const FeedItem = observer(function ({ item, @@ -151,9 +152,9 @@ export const FeedItem = observer(function ({ + title={sanitizeDisplayName( + item.reasonRepost.by.displayName || item.reasonRepost.by.handle, + )}> diff --git a/src/view/com/profile/ProfileCard.tsx b/src/view/com/profile/ProfileCard.tsx index 339e535a..dfbc2ddb 100644 --- a/src/view/com/profile/ProfileCard.tsx +++ b/src/view/com/profile/ProfileCard.tsx @@ -9,6 +9,7 @@ import {s} from 'lib/styles' import {usePalette} from 'lib/hooks/usePalette' import {useStores} from 'state/index' import {FollowButton} from './FollowButton' +import {sanitizeDisplayName} from 'lib/strings/display-names' export function ProfileCard({ testID, @@ -57,7 +58,7 @@ export function ProfileCard({ style={[s.bold, pal.text]} numberOfLines={1} lineHeight={1.2}> - {displayName || handle} + {sanitizeDisplayName(displayName || handle)} @{handle} diff --git a/src/view/com/profile/ProfileHeader.tsx b/src/view/com/profile/ProfileHeader.tsx index 36aadb9e..47281c45 100644 --- a/src/view/com/profile/ProfileHeader.tsx +++ b/src/view/com/profile/ProfileHeader.tsx @@ -18,6 +18,7 @@ import {useStores} from 'state/index' import {ProfileImageLightbox} from 'state/models/ui/shell' import {pluralize} from 'lib/strings/helpers' import {toShareUrl} from 'lib/strings/url-helpers' +import {sanitizeDisplayName} from 'lib/strings/display-names' import {s, colors} from 'lib/styles' import {DropdownButton, DropdownItem} from '../util/forms/DropdownButton' import * as Toast from '../util/Toast' @@ -58,7 +59,7 @@ export const ProfileHeader = observer( - {view.displayName || view.handle} + {sanitizeDisplayName(view.displayName || view.handle)} @@ -108,9 +109,9 @@ const ProfileHeaderLoaded = observer(function ProfileHeaderLoaded({ view?.toggleFollowing().then( () => { Toast.show( - `${view.viewer.following ? 'Following' : 'No longer following'} ${ - view.displayName || view.handle - }`, + `${ + view.viewer.following ? 'Following' : 'No longer following' + } ${sanitizeDisplayName(view.displayName || view.handle)}`, ) }, err => store.log.error('Failed to toggle follow', err), @@ -266,7 +267,7 @@ const ProfileHeaderLoaded = observer(function ProfileHeaderLoaded({ testID="profileHeaderDisplayName" type="title-2xl" style={[pal.text, styles.title]}> - {view.displayName || view.handle} + {sanitizeDisplayName(view.displayName || view.handle)} diff --git a/src/view/com/search/Suggestions.tsx b/src/view/com/search/Suggestions.tsx index 5231faea..e9999e1d 100644 --- a/src/view/com/search/Suggestions.tsx +++ b/src/view/com/search/Suggestions.tsx @@ -5,6 +5,7 @@ import {FoafsModel} from 'state/models/discovery/foafs' import {SuggestedActorsModel} from 'state/models/discovery/suggested-actors' import {SuggestedFollows} from 'view/com/discover/SuggestedFollows' import {ProfileCardFeedLoadingPlaceholder} from 'view/com/util/LoadingPlaceholder' +import {sanitizeDisplayName} from 'lib/strings/display-names' export const Suggestions = observer( ({ @@ -43,7 +44,9 @@ export const Suggestions = observer( return ( diff --git a/src/view/com/util/PostMeta.tsx b/src/view/com/util/PostMeta.tsx index cebab59c..5202b81a 100644 --- a/src/view/com/util/PostMeta.tsx +++ b/src/view/com/util/PostMeta.tsx @@ -9,6 +9,7 @@ import {UserAvatar} from './UserAvatar' import {observer} from 'mobx-react-lite' import {FollowButton} from '../profile/FollowButton' import {FollowState} from 'state/models/cache/my-follows' +import {sanitizeDisplayName} from 'lib/strings/display-names' interface PostMetaOpts { authorAvatar?: string @@ -52,7 +53,7 @@ export const PostMeta = observer(function (opts: PostMetaOpts) { style={pal.text} numberOfLines={1} lineHeight={1.2} - text={displayName} + text={sanitizeDisplayName(displayName)} href={`/profile/${opts.authorHandle}`} /> @@ -103,7 +104,7 @@ export const PostMeta = observer(function (opts: PostMetaOpts) { lineHeight={1.2} text={ <> - {displayName} + {sanitizeDisplayName(displayName)}  {handle} diff --git a/src/view/com/util/UserInfoText.tsx b/src/view/com/util/UserInfoText.tsx index 4753c9b0..b8f6e082 100644 --- a/src/view/com/util/UserInfoText.tsx +++ b/src/view/com/util/UserInfoText.tsx @@ -6,6 +6,7 @@ import {Text} from './text/Text' import {LoadingPlaceholder} from './LoadingPlaceholder' import {useStores} from 'state/index' import {TypographyVariant} from 'lib/ThemeContext' +import {sanitizeDisplayName} from 'lib/strings/display-names' export function UserInfoText({ type = 'md', @@ -68,7 +69,9 @@ export function UserInfoText({ lineHeight={1.2} numberOfLines={1} href={`/profile/${profile.handle}`} - text={`${prefix || ''}${profile[attr] || profile.handle}`} + text={`${prefix || ''}${sanitizeDisplayName( + profile[attr] || profile.handle, + )}`} /> ) } else {