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 Mastodon from "megalodon";
import { Notification } from "../types/Notification"; import { Notification } from "../types/Notification";
import { Account } from "../types/Account"; import { Account } from "../types/Account";
import { Relationship } from "../types/Relationship";
import { withSnackbar } from "notistack"; import { withSnackbar } from "notistack";
interface INotificationsPageState { interface INotificationsPageState {
@ -294,6 +295,12 @@ class NotificationsPage extends Component<any, INotificationsPageState> {
} }
followMember(acct: Account) { followMember(acct: Account) {
this.client
.get(`/accounts/relationships`, { id: acct.id })
.then((resp: any) => {
let relationship: Relationship = resp.data[0];
if (relationship.following == false) {
this.client this.client
.post(`/accounts/${acct.id}/follow`) .post(`/accounts/${acct.id}/follow`)
.then((resp: any) => { .then((resp: any) => {
@ -308,6 +315,17 @@ class NotificationsPage extends Component<any, INotificationsPageState> {
); );
console.error(err.message); console.error(err.message);
}); });
} else {
this.props.enqueueSnackbar(
"You already follow this account."
);
}
})
.catch((err: Error) => {
this.props.enqueueSnackbar("Couldn't find relationship.", {
variant: "error"
});
});
} }
render() { render() {