mirror of
https://github.com/TeamPiped/Piped.git
synced 2025-12-17 05:28:17 +00:00
Merge pull request #3346 from Bnyro/subscribe-channel-on-fly
feat: support for subscribing to channels in search results
This commit is contained in:
35
src/main.js
35
src/main.js
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user