From 65f958c1280c5ab0fb3737ce770d915e64ef7714 Mon Sep 17 00:00:00 2001 From: Paul Frazee Date: Tue, 7 Feb 2023 18:45:41 -0600 Subject: [PATCH] Wire up ReportAccount and ReportPost (#168) --- src/state/models/shell-ui.ts | 2 +- src/view/com/modals/ReportAccount.tsx | 23 ++++++++++++++-- src/view/com/modals/ReportPost.tsx | 30 +++++++++++++++++++-- src/view/com/post-thread/PostThreadItem.tsx | 8 ++++++ src/view/com/post/Post.tsx | 4 +++ src/view/com/posts/FeedItem.tsx | 4 +++ src/view/com/util/PostCtrls.tsx | 4 +++ src/view/com/util/forms/DropdownButton.tsx | 6 ++++- 8 files changed, 75 insertions(+), 6 deletions(-) diff --git a/src/state/models/shell-ui.ts b/src/state/models/shell-ui.ts index 9fd1a851e5..d05afde5aa 100644 --- a/src/state/models/shell-ui.ts +++ b/src/state/models/shell-ui.ts @@ -39,7 +39,7 @@ export class ServerInputModal { export class ReportPostModal { name = 'report-post' - constructor(public postUrl: string) { + constructor(public postUri: string, public postCid: string) { makeAutoObservable(this) } } diff --git a/src/view/com/modals/ReportAccount.tsx b/src/view/com/modals/ReportAccount.tsx index 91ab4a3a9f..b3a564d089 100644 --- a/src/view/com/modals/ReportAccount.tsx +++ b/src/view/com/modals/ReportAccount.tsx @@ -5,11 +5,13 @@ import { TouchableOpacity, View, } from 'react-native' +import {ComAtprotoReportReasonType} from '@atproto/api' import LinearGradient from 'react-native-linear-gradient' import {useStores} from '../../../state' import {s, colors, gradients} from '../../lib/styles' import {RadioGroup, RadioGroupItem} from '../util/forms/RadioGroup' import {Text} from '../util/text/Text' +import * as Toast from '../util/Toast' import {ErrorMessage} from '../util/error/ErrorMessage' import {cleanError} from '../../../lib/strings' @@ -21,7 +23,7 @@ const ITEMS: RadioGroupItem[] = [ export const snapPoints = ['50%'] -export function Component() { +export function Component({did}: {did: string}) { const store = useStores() const [isProcessing, setIsProcessing] = useState(false) const [error, setError] = useState('') @@ -29,9 +31,26 @@ export function Component() { const onSelectIssue = (v: string) => setIssue(v) const onPress = async () => { setError('') + if (!issue) { + return + } setIsProcessing(true) try { - // TODO + // NOTE: we should update the lexicon of reasontype to include more options -prf + let reasonType = ComAtprotoReportReasonType.OTHER + if (issue === 'spam') { + reasonType = ComAtprotoReportReasonType.SPAM + } + const reason = ITEMS.find(item => item.key === issue)?.label || '' + await store.api.com.atproto.report.create({ + reasonType, + reason, + subject: { + $type: 'com.atproto.repo.repoRef', + did, + }, + }) + Toast.show("Thank you for your report! We'll look into it promptly.") store.shell.closeModal() return } catch (e: any) { diff --git a/src/view/com/modals/ReportPost.tsx b/src/view/com/modals/ReportPost.tsx index a051bf2b0d..c0c15a7ffa 100644 --- a/src/view/com/modals/ReportPost.tsx +++ b/src/view/com/modals/ReportPost.tsx @@ -5,11 +5,13 @@ import { TouchableOpacity, View, } from 'react-native' +import {ComAtprotoReportReasonType} from '@atproto/api' import LinearGradient from 'react-native-linear-gradient' import {useStores} from '../../../state' import {s, colors, gradients} from '../../lib/styles' import {RadioGroup, RadioGroupItem} from '../util/forms/RadioGroup' import {Text} from '../util/text/Text' +import * as Toast from '../util/Toast' import {ErrorMessage} from '../util/error/ErrorMessage' import {cleanError} from '../../../lib/strings' @@ -22,7 +24,13 @@ const ITEMS: RadioGroupItem[] = [ export const snapPoints = ['50%'] -export function Component() { +export function Component({ + postUri, + postCid, +}: { + postUri: string + postCid: string +}) { const store = useStores() const [isProcessing, setIsProcessing] = useState(false) const [error, setError] = useState('') @@ -30,9 +38,27 @@ export function Component() { const onSelectIssue = (v: string) => setIssue(v) const onPress = async () => { setError('') + if (!issue) { + return + } setIsProcessing(true) try { - // TODO + // NOTE: we should update the lexicon of reasontype to include more options -prf + let reasonType = ComAtprotoReportReasonType.OTHER + if (issue === 'spam') { + reasonType = ComAtprotoReportReasonType.SPAM + } + const reason = ITEMS.find(item => item.key === issue)?.label || '' + await store.api.com.atproto.report.create({ + reasonType, + reason, + subject: { + $type: 'com.atproto.repo.recordRef', + uri: postUri, + cid: postCid, + }, + }) + Toast.show("Thank you for your report! We'll look into it promptly.") store.shell.closeModal() return } catch (e: any) { diff --git a/src/view/com/post-thread/PostThreadItem.tsx b/src/view/com/post-thread/PostThreadItem.tsx index d3744e4251..a9ab08e6ea 100644 --- a/src/view/com/post-thread/PostThreadItem.tsx +++ b/src/view/com/post-thread/PostThreadItem.tsx @@ -36,6 +36,8 @@ export const PostThreadItem = observer(function PostThreadItem({ const record = item.postRecord const hasEngagement = item.post.upvoteCount || item.post.repostCount + const itemUri = item.post.uri + const itemCid = item.post.cid const itemHref = useMemo(() => { const urip = new AtUri(item.post.uri) return `/profile/${item.post.author.handle}/post/${urip.rkey}` @@ -148,6 +150,8 @@ export const PostThreadItem = observer(function PostThreadItem({ { const urip = new AtUri(item.post.uri) return `/profile/${item.post.author.handle}/post/${urip.rkey}` @@ -207,6 +209,8 @@ export const FeedItem = observer(function ({ ) : null} children?: React.ReactNode + itemUri: string + itemCid: string itemHref: string itemTitle: string isAuthor: boolean @@ -143,7 +147,7 @@ export function PostDropdownBtn({ icon: 'circle-exclamation', label: 'Report post', onPress() { - store.shell.openModal(new ReportPostModal(itemHref)) + store.shell.openModal(new ReportPostModal(itemUri, itemCid)) }, }, isAuthor