Get relationship and evaluate before following (HD-3)

This commit is contained in:
Marquis Kurt 2019-12-12 11:44:14 -05:00
parent 927c9c06a1
commit 4185d6bad8
No known key found for this signature in database
GPG Key ID: 725636D259F5402D
1 changed files with 27 additions and 9 deletions

View File

@ -33,6 +33,7 @@ import NotificationsIcon from "@material-ui/icons/Notifications";
import Mastodon from "megalodon";
import { Notification } from "../types/Notification";
import { Account } from "../types/Account";
import { Relationship } from "../types/Relationship";
import { withSnackbar } from "notistack";
interface INotificationsPageState {
@ -295,18 +296,35 @@ class NotificationsPage extends Component<any, INotificationsPageState> {
followMember(acct: Account) {
this.client
.post(`/accounts/${acct.id}/follow`)
.get(`/accounts/relationships`, { id: acct.id })
.then((resp: any) => {
this.props.enqueueSnackbar(
"You are now following this account."
);
let relationship: Relationship = resp.data[0];
if (relationship.following == false) {
this.client
.post(`/accounts/${acct.id}/follow`)
.then((resp: any) => {
this.props.enqueueSnackbar(
"You are now following this account."
);
})
.catch((err: Error) => {
this.props.enqueueSnackbar(
"Couldn't follow account: " + err.name,
{ variant: "error" }
);
console.error(err.message);
});
} else {
this.props.enqueueSnackbar(
"You already follow this account."
);
}
})
.catch((err: Error) => {
this.props.enqueueSnackbar(
"Couldn't follow account: " + err.name,
{ variant: "error" }
);
console.error(err.message);
this.props.enqueueSnackbar("Couldn't find relationship.", {
variant: "error"
});
});
}