Mute/Unmute controls on profiles

This commit is contained in:
Rafael Caricio 2023-04-28 17:50:27 +02:00
parent a11944ac62
commit c6c39d2ee4
Signed by: rafaelcaricio
GPG key ID: 3C86DBCE8E93C947
2 changed files with 71 additions and 0 deletions

View file

@ -11,6 +11,7 @@ export interface Relationship {
subscription_from: boolean, subscription_from: boolean,
showing_reblogs: boolean, showing_reblogs: boolean,
showing_replies: boolean, showing_replies: boolean,
muting: boolean,
} }
export async function follow( export async function follow(
@ -70,6 +71,40 @@ export async function unfollow(
} }
} }
export async function mute(
authToken: string,
accountId: string,
): Promise<Relationship> {
const url = `${BACKEND_URL}/api/v1/accounts/${accountId}/mute`
const response = await http(url, {
method: "POST",
authToken,
})
const data = await response.json()
if (response.status !== 200) {
throw new Error(data.error_description)
} else {
return data
}
}
export async function unmute(
authToken: string,
accountId: string,
): Promise<Relationship> {
const url = `${BACKEND_URL}/api/v1/accounts/${accountId}/unmute`
const response = await http(url, {
method: "POST",
authToken,
})
const data = await response.json()
if (response.status !== 200) {
throw new Error(data.error_description)
} else {
return data
}
}
interface ProfileListPage { interface ProfileListPage {
profiles: Profile[]; profiles: Profile[];
nextPageUrl: string | null; nextPageUrl: string | null;

View file

@ -27,6 +27,7 @@
<div class="badge" v-if="isFollowedBy()">Follows you</div> <div class="badge" v-if="isFollowedBy()">Follows you</div>
<div class="badge" v-if="isSubscriptionValid()">Subscription</div> <div class="badge" v-if="isSubscriptionValid()">Subscription</div>
<div class="badge" v-if="isSubscriber()">Subscriber</div> <div class="badge" v-if="isSubscriber()">Subscriber</div>
<div class="badge" v-if="isMuted()">Muted</div>
</div> </div>
</div> </div>
<div <div
@ -100,6 +101,12 @@
<li v-if="canShowReplies()"> <li v-if="canShowReplies()">
<button @click="onFollow(undefined, true)">Show replies</button> <button @click="onFollow(undefined, true)">Show replies</button>
</li> </li>
<li v-if="!isMuted()">
<button @click="onMute()">Mute</button>
</li>
<li v-if="isMuted()">
<button @click="onUnmute()">Unmute</button>
</li>
<li v-if="isAdmin()"> <li v-if="isAdmin()">
<button <button
title="Copy profile ID" title="Copy profile ID"
@ -274,6 +281,8 @@ import {
getRelationship, getRelationship,
getFollowers, getFollowers,
getFollowing, getFollowing,
mute,
unmute,
} from "@/api/relationships" } from "@/api/relationships"
import { getReceivedSubscriptions } from "@/api/subscriptions-common" import { getReceivedSubscriptions } from "@/api/subscriptions-common"
import { import {
@ -445,6 +454,13 @@ function isSubscriber(): boolean {
return relationship.subscription_from return relationship.subscription_from
} }
function isMuted(): boolean {
if (!relationship) {
return false
}
return relationship.muting
}
function canFollow(): boolean { function canFollow(): boolean {
if (!relationship) { if (!relationship) {
return false return false
@ -506,6 +522,26 @@ async function onFollow(showReposts?: boolean, showReplies?: boolean) {
) )
} }
async function onMute() {
if (!currentUser || !profile) {
return
}
relationship = await mute(
ensureAuthToken(),
profile.id,
)
}
async function onUnmute() {
if (!currentUser || !profile) {
return
}
relationship = await unmute(
ensureAuthToken(),
profile.id,
)
}
async function onUnfollow() { async function onUnfollow() {
if (!currentUser || !profile) { if (!currentUser || !profile) {
return return