Enable hiding content, muting and blocking

See #24 for why this works conceptually but doesn't do anything in
practice
This commit is contained in:
Nat 2021-05-22 20:51:24 -03:00
parent 1afe0aadb4
commit 355782ff66
3 changed files with 71 additions and 5 deletions

View File

@ -21,6 +21,9 @@ const ViewPostJsx = ({navigation}) => {
afterDelete = { afterDelete = {
() => navigation.goBack() () => navigation.goBack()
} }
afterModerate = {
() => navigation.goBack()
}
data = { state.post } /> data = { state.post } />
</ScreenWithBackBarJsx> </ScreenWithBackBarJsx>
); );

View File

@ -118,13 +118,14 @@ export const RawPostJsx = (props) => {
</> </>
: <> : <>
<MenuOption <MenuOption
onSelect = { props.onHide }
text = "Don't show me their posts"/> text = "Don't show me their posts"/>
<MenuOption <MenuOption
onSelect = { props.onMute }
text = "Mute" /> text = "Mute" />
<MenuOption <MenuOption
onSelect = { props.onBlock }
text = "Block" /> text = "Block" />
<MenuOption
text = "Report" />
</> </>
} }
</ContextMenuJsx> </ContextMenuJsx>
@ -311,7 +312,46 @@ export const PostByDataJsx = (props) => {
deleted: true, deleted: true,
}); });
} }
};
const _handleHide = async () => {
await requests.muteAccount(
state.instance,
state.data.account.id,
state.accessToken,
// Thus, only "mute" statuses
{ notifications: false, }
);
if (props.afterModerate) {
props.afterModerate();
} }
};
const _handleMute = async () => {
await requests.muteAccount(
state.instance,
state.data.account.id,
state.accessToken,
);
if (props.afterModerate) {
props.afterModerate();
}
};
const _handleBlock = async () => {
await requests.blockAccount(
state.instance,
state.data.account.id,
state.accessToken,
);
if (props.afterModerate) {
props.afterModerate();
}
};
return ( return (
<View> <View>
@ -323,6 +363,9 @@ export const PostByDataJsx = (props) => {
onReblog = { _handleReblog } onReblog = { _handleReblog }
onBookmark = { _handleDelete } onBookmark = { _handleDelete }
onDelete = { _handleDelete } onDelete = { _handleDelete }
onHide = { _handleHide }
onMute = { _handleMute }
onBlock = { _handleBlock }
own = { state.own } own = { state.own }
navigation = { props.navigation }/> navigation = { props.navigation }/>
: <View></View> } : <View></View> }

View File

@ -39,11 +39,11 @@ export async function checkUnreadNotifications() {
} }
} }
export async function postForm(url, data, token = false) { export async function postForm(url, data = false, token = false) {
// Send a POST request with data formatted with FormData returning JSON // Send a POST request with data formatted with FormData returning JSON
const resp = await fetch(url, { const resp = await fetch(url, {
method: "POST", method: "POST",
body: objectToForm(data), body: data ? objectToForm(data): {},
headers: token headers: token
? { "Authorization": `Bearer ${token}`, } ? { "Authorization": `Bearer ${token}`, }
: {}, : {},
@ -103,6 +103,26 @@ export async function fetchAccountStatuses(domain, id, token) {
return resp.json(); return resp.json();
} }
export async function muteAccount(domain, id, token, params = false) {
const resp = await postForm(`https://${domain}/api/v1/accounts/${id}/mute`, params, token);
return resp.json();
}
export async function unmuteAccount(domain, id, token) {
const resp = await post(`https://${domain}/api/v1/accounts/${id}/unmute`, token);
return resp.json();
}
export async function blockAccount(domain, id, token) {
const resp = await post(`https://${domain}/api/v1/accounts/${id}/block`, token);
return resp.json();
}
export async function unblockAccount(domain, id, token) {
const resp = await post(`https://${domain}/api/v1/accounts/${id}/unblock`, token);
return resp.json();
}
export async function publishStatus(domain, token, params) { export async function publishStatus(domain, token, params) {
const resp = await postForm(`https://${domain}/api/v1/statuses`, params, token); const resp = await postForm(`https://${domain}/api/v1/statuses`, params, token);
return resp.json(); return resp.json();