Add profile menu items for hiding/showing reposts

This commit is contained in:
silverpill 2022-02-23 00:37:48 +00:00
parent b98e2db452
commit 838f76b17d
2 changed files with 27 additions and 3 deletions

View file

@ -9,15 +9,18 @@ export interface Relationship {
requested: boolean,
subscription_to: boolean,
subscription_from: boolean,
showing_reblogs: boolean,
}
export async function follow(
authToken: string,
profileId: string,
showReposts: boolean,
): Promise<Relationship> {
const url = `${BACKEND_URL}/api/v1/accounts/${profileId}/follow`
const response = await http(url, {
method: "POST",
json: { reblogs: showReposts },
authToken,
})
const data = await response.json()

View file

@ -15,7 +15,7 @@
</div>
</div>
<div
v-if="!isLocalUser() || canConnectWallet() || canConfigureSubscription() || canSubscribe()"
v-if="!isLocalUser() || canConnectWallet() || canConfigureSubscription() || canSubscribe() || canHideReposts() || canShowReposts()"
class="dropdown-menu-wrapper"
v-click-away="hideProfileMenu"
>
@ -58,6 +58,12 @@
Pay for subscription
</a>
</li>
<li v-if="canHideReposts()">
<a @click="follow(false)">Hide reposts</a>
</li>
<li v-if="canShowReposts()">
<a @click="follow(true)">Show reposts</a>
</li>
</ul>
</div>
</div>
@ -266,13 +272,28 @@ export default class ProfileView extends Vue {
return this.relationship.requested
}
async follow() {
if (!this.store.currentUser || !this.profile) {
canHideReposts(): boolean {
if (!this.relationship) {
return false
}
return (this.relationship.following || this.relationship.requested) && this.relationship.showing_reblogs
}
canShowReposts(): boolean {
if (!this.relationship) {
return false
}
return (this.relationship.following || this.relationship.requested) && !this.relationship.showing_reblogs
}
async follow(showReposts?: boolean) {
if (!this.store.currentUser || !this.profile || !this.relationship) {
return
}
this.relationship = await follow(
this.store.ensureAuthToken(),
this.profile.id,
showReposts ?? this.relationship.showing_reblogs,
)
}