Only show "followed you back" when appropriate (#4849)

* only show followed back when we should

* try/catch

* log

* Update FeedItem.tsx

* tweak
zio/stable
Hailey 2024-07-31 11:16:14 -07:00 committed by GitHub
parent 576cef88b5
commit 70ffd387e3
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 21 additions and 1 deletions

View File

@ -13,11 +13,13 @@ import {
AppBskyEmbedRecordWithMedia, AppBskyEmbedRecordWithMedia,
AppBskyFeedDefs, AppBskyFeedDefs,
AppBskyFeedPost, AppBskyFeedPost,
AppBskyGraphFollow,
moderateProfile, moderateProfile,
ModerationDecision, ModerationDecision,
ModerationOpts, ModerationOpts,
} from '@atproto/api' } from '@atproto/api'
import {AtUri} from '@atproto/api' import {AtUri} from '@atproto/api'
import {TID} from '@atproto/common-web'
import {msg, plural, Trans} from '@lingui/macro' import {msg, plural, Trans} from '@lingui/macro'
import {useLingui} from '@lingui/react' import {useLingui} from '@lingui/react'
import {useNavigation} from '@react-navigation/native' import {useNavigation} from '@react-navigation/native'
@ -184,10 +186,28 @@ let FeedItem = ({
action = _(msg`reposted your post`) action = _(msg`reposted your post`)
icon = <RepostIcon size="xl" style={{color: t.palette.positive_600}} /> icon = <RepostIcon size="xl" style={{color: t.palette.positive_600}} />
} else if (item.type === 'follow') { } else if (item.type === 'follow') {
let isFollowBack = false
if ( if (
item.notification.author.viewer?.following && item.notification.author.viewer?.following &&
gate('ungroup_follow_backs') AppBskyGraphFollow.isRecord(item.notification.record)
) { ) {
let followingTimestamp
try {
const rkey = new AtUri(item.notification.author.viewer.following).rkey
followingTimestamp = TID.fromStr(rkey).timestamp()
} catch (e) {
// For some reason the following URI was invalid. Default to it not being a follow back.
console.error('Invalid following URI')
}
if (followingTimestamp) {
const followedTimestamp =
new Date(item.notification.record.createdAt).getTime() * 1000
isFollowBack = followedTimestamp > followingTimestamp
}
}
if (isFollowBack && gate('ungroup_follow_backs')) {
action = _(msg`followed you back`) action = _(msg`followed you back`)
} else { } else {
action = _(msg`followed you`) action = _(msg`followed you`)