import React, {useMemo} from 'react' import {observer} from 'mobx-react-lite' import {Image, StyleSheet, Text, View} from 'react-native' import {AtUri} from '../../../third-party/uri' import {FontAwesomeIcon, Props} from '@fortawesome/react-native-fontawesome' import {NotificationsViewItemModel} from '../../../state/models/notifications-view' import {s, colors} from '../../lib/styles' import {ago, pluralize} from '../../lib/strings' import {UserAvatar} from '../util/UserAvatar' import {PostText} from '../post/PostText' import {Post} from '../post/Post' import {Link} from '../util/Link' const MAX_AUTHORS = 8 export const FeedItem = observer(function FeedItem({ item, }: { item: NotificationsViewItemModel }) { const itemHref = useMemo(() => { if (item.isLike || item.isRepost) { const urip = new AtUri(item.subjectUri) return `/profile/${urip.host}/post/${urip.rkey}` } else if (item.isFollow) { return `/profile/${item.author.name}` } else if (item.isReply) { const urip = new AtUri(item.uri) return `/profile/${urip.host}/post/${urip.rkey}` } return '' }, [item]) const itemTitle = useMemo(() => { if (item.isLike || item.isRepost) { return 'Post' } else if (item.isFollow) { return item.author.name } else if (item.isReply) { return 'Post' } }, [item]) if (item.isReply) { return ( ) } let action = '' let icon: Props['icon'] let iconStyle: Props['style'] = [] if (item.isLike) { action = 'liked your post' icon = ['fas', 'heart'] iconStyle = [s.blue3] } else if (item.isRepost) { action = 'reposted your post' icon = 'retweet' iconStyle = [s.blue3] } else if (item.isReply) { action = 'replied to your post' icon = ['far', 'comment'] } else if (item.isFollow) { action = 'followed you' icon = 'user-plus' iconStyle = [s.blue3] } else { return <> } let authors: {href: string; name: string; displayName?: string}[] = [ { href: `/profile/${item.author.name}`, name: item.author.name, displayName: item.author.displayName, }, ] if (item.additional?.length) { authors = authors.concat( item.additional.map(item2 => ({ href: `/profile/${item2.author.name}`, name: item2.author.name, displayName: item2.author.displayName, })), ) } return ( {authors.slice(0, MAX_AUTHORS).map(author => ( ))} {authors.length > MAX_AUTHORS ? ( +{authors.length - MAX_AUTHORS} ) : undefined} {authors[0].displayName || authors[0].name} {authors.length > 1 ? ( <> and {authors.length - 1} {pluralize(authors.length - 1, 'other')} ) : undefined} {action} {ago(item.indexedAt)} {item.isLike || item.isRepost ? ( ) : ( <> )} {item.isReply ? ( ) : ( <> )} ) }) const styles = StyleSheet.create({ outer: { backgroundColor: colors.white, padding: 10, borderRadius: 6, margin: 2, marginBottom: 0, }, outerMinimal: { backgroundColor: colors.white, borderRadius: 6, margin: 2, marginBottom: 0, }, outerUnread: { borderWidth: 1, borderColor: colors.blue2, }, layout: { flexDirection: 'row', }, layoutIcon: { width: 35, alignItems: 'flex-end', }, icon: { marginRight: 10, marginTop: 4, }, avis: { flexDirection: 'row', alignItems: 'center', }, aviExtraCount: { fontWeight: 'bold', paddingLeft: 6, color: colors.gray5, }, layoutContent: { flex: 1, }, meta: { flexDirection: 'row', paddingTop: 6, paddingBottom: 2, }, metaItem: { paddingRight: 3, }, postText: { paddingBottom: 5, }, })