Enable reblogging

This commit is contained in:
Nat 2021-05-22 11:45:01 -03:00
parent 1cc44eae7f
commit 1e2ec90026
3 changed files with 35 additions and 2 deletions

View File

@ -52,14 +52,14 @@ const PostActionBarJsx = (props) => {
<PostActionJsx
field = "reblogged"
pack = { icons.reblog }
reblogged = { props.reblogged }
active = { props.reblogged }
onPress = { props.onReblog }/>
<PostActionJsx
field = "bookmarked"
pack = { icons.bookmark }
last = { true }
bookmarked = { props.bookmarked }
active = { props.bookmarked }
onPress = { props.onBookmark } />
</View>
)

View File

@ -139,6 +139,7 @@ export const RawPostJsx = (props) => {
reblogged = { props.data.reblogged }
bookmarked = { false }
onFavourite = { props.onFavourite }
onReblog = { props.onReblog }
onBookmark = { props.onBookmark } />
<View style = { styles.caption }>
<Text>
@ -227,6 +228,28 @@ export const PostByDataJsx = (props) => {
});
};
const _handleReblog = async () => {
let newStatus;
if (!state.data.reblogged) {
newStatus = await requests.reblogStatus(
state.instance,
state.data.id,
state.accessToken
);
} else {
newStatus = await requests.unreblogStatus(
state.instance,
state.data.id,
state.accessToken
);
}
setState({...state,
data: newStatus,
});
};
return (
<View>
{ state.loaded ?
@ -234,6 +257,7 @@ export const PostByDataJsx = (props) => {
data = { state.data }
dimensions = { state.dimensions }
onFavourite = { _handleFavourite }
onReblog = { _handleReblog }
navigation = { props.navigation }/>
: <View></View> }
</View>

View File

@ -107,6 +107,15 @@ export async function unfavouriteStatus(domain, id, token) {
return resp.json();
}
export async function reblogStatus(domain, id, token) {
const resp = await post(`https://${domain}/api/v1/statuses/${id}/reblog`, token);
return resp.json();
}
export async function unreblogStatus(domain, id, token) {
const resp = await post(`https://${domain}/api/v1/statuses/${id}/unreblog`, token);
return resp.json();
}
export async function fetchFollowing(domain, id, token) {
const resp = await get(`https://${domain}/api/v1/accounts/${id}/following`, token);
return resp.json();