Merge pull request #3346 from Bnyro/subscribe-channel-on-fly

feat: support for subscribing to channels in search results
This commit is contained in:
Bnyro
2024-02-10 10:24:17 +01:00
committed by GitHub
4 changed files with 96 additions and 82 deletions

View File

@@ -550,6 +550,41 @@ const mixin = {
});
});
},
async fetchSubscriptionStatus(channelId) {
if (!this.authenticated) {
return this.isSubscribedLocally(channelId);
}
const response = await this.fetchJson(
this.authApiUrl() + "/subscribed",
{
channelId: channelId,
},
{
headers: {
Authorization: this.getAuthToken(),
},
},
);
return response?.subscribed;
},
async toggleSubscriptionState(channelId, subscribed) {
if (!this.authenticated) return this.handleLocalSubscriptions(channelId);
const resp = await this.fetchJson(this.authApiUrl() + (subscribed ? "/unsubscribe" : "/subscribe"), null, {
method: "POST",
body: JSON.stringify({
channelId: channelId,
}),
headers: {
Authorization: this.getAuthToken(),
"Content-Type": "application/json",
},
});
return !resp.error;
},
},
computed: {
authenticated(_this) {