From 16c8b7dd710ffad067018b2b8f2418ce66d838d7 Mon Sep 17 00:00:00 2001 From: balzack Date: Mon, 31 Oct 2022 00:32:27 -0700 Subject: [PATCH] add reporting of users and content required by android --- app/mobile/src/api/addFlag.js | 14 +++++++ app/mobile/src/context/useCardContext.hook.js | 9 ++++ .../src/context/useChannelContext.hook.js | 9 ++++ .../context/useConversationContext.hook.js | 22 ++++++++++ app/mobile/src/session/contact/Contact.jsx | 33 +++++++++++++++ .../src/session/contact/useContact.hook.js | 4 ++ .../src/session/conversation/Conversation.jsx | 3 +- .../conversation/topicItem/TopicItem.jsx | 41 +++++++++++++++++-- .../conversation/useConversation.hook.js | 3 ++ app/mobile/src/session/details/Details.jsx | 32 +++++++++++++++ .../src/session/details/useDetails.hook.js | 3 ++ 11 files changed, 168 insertions(+), 5 deletions(-) create mode 100644 app/mobile/src/api/addFlag.js diff --git a/app/mobile/src/api/addFlag.js b/app/mobile/src/api/addFlag.js new file mode 100644 index 00000000..14141ec2 --- /dev/null +++ b/app/mobile/src/api/addFlag.js @@ -0,0 +1,14 @@ +import { checkResponse, fetchWithTimeout } from './fetchUtil'; + +export async function addFlag(server, guid, channel, topic) { + if (channel) { + const param = topic ? `&topic=${topic}` : ''; + const flag = await fetchWithTimeout(`https://${server}/account/flag/${guid}?channel=${channel}${param}`, { method: 'POST' } ); + checkResponse(flag); + } + else { + const flag = await fetchWithTimeout(`https://${server}/account/flag/${guid}`, { method: 'POST' } ); + checkResponse(flag); + } +} + diff --git a/app/mobile/src/context/useCardContext.hook.js b/app/mobile/src/context/useCardContext.hook.js index fe36a78e..5b547e39 100644 --- a/app/mobile/src/context/useCardContext.hook.js +++ b/app/mobile/src/context/useCardContext.hook.js @@ -1,6 +1,7 @@ import { useState, useRef, useContext } from 'react'; import { StoreContext } from 'context/StoreContext'; import { UploadContext } from 'context/UploadContext'; +import { addFlag } from 'api/addFlag'; import { getCard } from 'api/getCard'; import { getCards } from 'api/getCards'; import { getCardProfile } from 'api/getCardProfile'; @@ -567,6 +568,14 @@ export function useCardContext() { const { detail, profile } = getCardEntry(cardId); return await removeContactChannelTopic(profile.node, `${profile.guid}.${detail.token}`, channelId, topicId); }, + addChannelReport: async (cardId, channelId) => { + const { detail, profile } = getCardEntry(cardId); + return await addFlag(profile.node, profile.guid, channelId); + }, + addChannelTopicReport: async (cardId, channelId, topicId) => { + const { detail, profile } = getCardEntry(cardId); + return await addFlag(profile.node, profile.guid, channelId, topicId); + }, resync: (cardId) => { resync.current.push(cardId); sync(); diff --git a/app/mobile/src/context/useChannelContext.hook.js b/app/mobile/src/context/useChannelContext.hook.js index 09cd56c3..df2522b9 100644 --- a/app/mobile/src/context/useChannelContext.hook.js +++ b/app/mobile/src/context/useChannelContext.hook.js @@ -15,6 +15,7 @@ import { getChannelTopicAssetUrl } from 'api/getChannelTopicAssetUrl'; import { setChannelSubject } from 'api/setChannelSubject'; import { setChannelCard } from 'api/setChannelCard'; import { clearChannelCard } from 'api/clearChannelCard'; +import { addFlag } from 'api/addFlag'; export function useChannelContext() { const [state, setState] = useState({ @@ -280,6 +281,14 @@ export function useChannelContext() { const { server, appToken } = session.current; return await removeChannelTopic(server, appToken, channelId, topicId); }, + addReport: async (channelId) => { + const { server, guid } = session.current; + return await addFlag(server, guid, channelId); + }, + addTopicReport: async (channelId, topicId) => { + const { server, guid } = session.current; + return await addFlag(server, guid, channelId, topicId); + }, setCard: async (channelId, cardId) => { const { server, appToken } = session.current; return await setChannelCard(server, appToken, channelId, cardId); diff --git a/app/mobile/src/context/useConversationContext.hook.js b/app/mobile/src/context/useConversationContext.hook.js index ec2b090b..b7e72982 100644 --- a/app/mobile/src/context/useConversationContext.hook.js +++ b/app/mobile/src/context/useConversationContext.hook.js @@ -454,6 +454,28 @@ export function useConversationContext() { await channel.actions.clearCard(channelId, id); } }, + addReport: async () => { + if (conversationId.current) { + const { cardId, channelId } = conversationId.current; + if (cardId) { + return await card.actions.addChannelReport(cardId, channelId); + } + else { + return await channel.actions.addReport(channelId); + } + } + }, + addTopicReport: async(topicId) => { + if (conversationId.current) { + const { cardId, channelId } = conversationId.current; + if (cardId) { + return await card.actions.addChannelTopicReport(cardId, channelId, topicId); + } + else { + return await channel.actions.addTopicReport(channelId, topicId); + } + } + }, setBlocked: async () => { if (conversationId.current) { const { cardId, channelId } = conversationId.current; diff --git a/app/mobile/src/session/contact/Contact.jsx b/app/mobile/src/session/contact/Contact.jsx index 591fb28b..e27ea539 100644 --- a/app/mobile/src/session/contact/Contact.jsx +++ b/app/mobile/src/session/contact/Contact.jsx @@ -154,6 +154,21 @@ export function Contact({ contact, closeContact }) { ); } + const reportContact = () => { + Alert.alert( + "Report Contact", + "Confirm?", + [ + { text: "Cancel", + onPress: () => {}, + }, + { text: "Report", onPress: () => { + setContact(actions.reportContact); + }} + ] + ); + } + const connectContact = () => { setContact(actions.connectContact); } @@ -194,6 +209,9 @@ export function Contact({ contact, closeContact }) { Block Contact + + Report Contact + )} { state.status === 'connecting' && ( @@ -207,6 +225,9 @@ export function Contact({ contact, closeContact }) { Block Contact + + Report Contact + )} { state.status === 'confirmed' && ( @@ -220,6 +241,9 @@ export function Contact({ contact, closeContact }) { Block Contact + + Report Contact + )} { state.status === 'pending' && ( @@ -236,6 +260,9 @@ export function Contact({ contact, closeContact }) { Block Contact + + Report Contact + )} { state.status === 'requested' && ( @@ -255,6 +282,9 @@ export function Contact({ contact, closeContact }) { Block Contact + + Report Contact + )} { state.status == null && ( @@ -265,6 +295,9 @@ export function Contact({ contact, closeContact }) { Save Contact + + Report Contact + )} diff --git a/app/mobile/src/session/contact/useContact.hook.js b/app/mobile/src/session/contact/useContact.hook.js index fe7101ba..ebdf1bfa 100644 --- a/app/mobile/src/session/contact/useContact.hook.js +++ b/app/mobile/src/session/contact/useContact.hook.js @@ -3,6 +3,7 @@ import { useNavigate } from 'react-router-dom'; import { CardContext } from 'context/CardContext'; import { useWindowDimensions } from 'react-native' import { getListingMessage } from 'api/getListingMessage'; +import { addFlag } from 'api/addFlag'; import config from 'constants/Config'; export function useContact(contact, close) { @@ -177,6 +178,9 @@ export function useContact(contact, close) { close(); }); }, + reportContact: async () => { + await addFlag(state.node, state.guid); + }, resync: () => { card.actions.resync(contact.card); }, diff --git a/app/mobile/src/session/conversation/Conversation.jsx b/app/mobile/src/session/conversation/Conversation.jsx index 7c6700e1..f470403e 100644 --- a/app/mobile/src/session/conversation/Conversation.jsx +++ b/app/mobile/src/session/conversation/Conversation.jsx @@ -83,7 +83,8 @@ export function ConversationBody() { inverted={true} renderItem={({item}) => actions.setFocus(item.topicId)} hosting={state.host == null} - remove={actions.removeTopic} update={actions.editTopic} block={actions.blockTopic} />} + remove={actions.removeTopic} update={actions.editTopic} block={actions.blockTopic} + report={actions.reportTopic} />} keyExtractor={item => item.topicId} /> { !state.init && ( diff --git a/app/mobile/src/session/conversation/topicItem/TopicItem.jsx b/app/mobile/src/session/conversation/topicItem/TopicItem.jsx index 2a614ff5..c20ff7f3 100644 --- a/app/mobile/src/session/conversation/topicItem/TopicItem.jsx +++ b/app/mobile/src/session/conversation/topicItem/TopicItem.jsx @@ -15,7 +15,7 @@ import Carousel from 'react-native-snap-carousel'; import GestureRecognizer from 'react-native-swipe-gestures'; import avatar from 'images/avatar.png'; -export function TopicItem({ item, focused, focus, hosting, remove, update, block }) { +export function TopicItem({ item, focused, focus, hosting, remove, update, block, report }) { const { state, actions } = useTopicItem(item, hosting); @@ -45,6 +45,32 @@ export function TopicItem({ item, focused, focus, hosting, remove, update, block ); } + const reportMessage = () => { + Alert.alert( + "Report Message", + "Confirm?", + [ + { text: "Cancel", + onPress: () => {}, + }, + { text: "Report", + onPress: async () => { + try { + await report(item.topicId); + } + catch (err) { + console.log(err); + Alert.alert( + 'Failed to Report Message', + 'Please try again.' + ) + } + }, + } + ] + ); + } + const hideMessage = () => { Alert.alert( "Blocking Message", @@ -155,9 +181,16 @@ export function TopicItem({ item, focused, focus, hosting, remove, update, block )} - - - + { !state.editable && ( + + + + )} + { !state.editable && ( + + + + )} { state.deletable && ( diff --git a/app/mobile/src/session/conversation/useConversation.hook.js b/app/mobile/src/session/conversation/useConversation.hook.js index 331e935d..b3999906 100644 --- a/app/mobile/src/session/conversation/useConversation.hook.js +++ b/app/mobile/src/session/conversation/useConversation.hook.js @@ -89,6 +89,9 @@ export function useConversation() { blockTopic: async (topicId) => { await conversation.actions.blockTopic(topicId); }, + reportTopic: async (topicId) => { + await conversation.actions.addTopicReport(topicId); + }, resync: () => { conversation.actions.resync(); }, diff --git a/app/mobile/src/session/details/Details.jsx b/app/mobile/src/session/details/Details.jsx index c1123dd4..3a067f12 100644 --- a/app/mobile/src/session/details/Details.jsx +++ b/app/mobile/src/session/details/Details.jsx @@ -82,6 +82,33 @@ export function DetailsBody({ channel, clearConversation }) { ); } + + const report = () => { + Alert.alert( + "Report Topic", + "Confirm?", + [ + { text: "Cancel", + onPress: () => {}, + }, + { text: "Report", + onPress: async () => { + try { + await actions.report(); + } + catch (err) { + console.log(err); + Alert.alert( + 'Failed to Report Topic', + 'Please try again.' + ) + } + }, + } + ] + ); + } + return ( @@ -112,6 +139,11 @@ export function DetailsBody({ channel, clearConversation }) { Block Topic + { state.hostId && ( + + Report Topic + + )} { !state.hostId && ( Edit Membership diff --git a/app/mobile/src/session/details/useDetails.hook.js b/app/mobile/src/session/details/useDetails.hook.js index 1d3ab2e2..c3f5772c 100644 --- a/app/mobile/src/session/details/useDetails.hook.js +++ b/app/mobile/src/session/details/useDetails.hook.js @@ -61,6 +61,9 @@ export function useDetails() { block: async() => { await conversation.actions.setBlocked(); }, + report: async() => { + await conversation.actions.addReport(); + }, }; return { state, actions };