mirror of
https://github.com/PR0M3TH3AN/bitvid.git
synced 2026-11-04 11:52:25 +00:00
Add subscription toggle helper
This commit is contained in:
1 parent
18bdf121a4
commit
06c7cf912a
2 files changed
+21
-12
No files matched your search
+2
-12
@@ -3389,13 +3389,7 @@ function setupChannelMessageControls() {
|
||||
}
|
||||
|
||||
try {
|
||||
const isSubscribed =
|
||||
subscriptions.isSubscribed(resolvedHex) === true;
|
||||
if (isSubscribed) {
|
||||
await subscriptions.removeChannel(resolvedHex, app.pubkey);
|
||||
} else {
|
||||
await subscriptions.addChannel(resolvedHex, app.pubkey);
|
||||
}
|
||||
await subscriptions.toggleChannel(resolvedHex, app.pubkey);
|
||||
} catch (error) {
|
||||
userLogger.error("Failed to toggle channel notifications:", error);
|
||||
const permissionErrorCodes = new Set([
|
||||
@@ -4218,11 +4212,7 @@ function renderSubscribeButton(channelHex) {
|
||||
return;
|
||||
}
|
||||
try {
|
||||
if (alreadySubscribed) {
|
||||
await subscriptions.removeChannel(channelHex, currentApp.pubkey);
|
||||
} else {
|
||||
await subscriptions.addChannel(channelHex, currentApp.pubkey);
|
||||
}
|
||||
await subscriptions.toggleChannel(channelHex, currentApp.pubkey);
|
||||
// Re-render the button so it toggles state
|
||||
renderSubscribeButton(channelHex);
|
||||
} catch (err) {
|
||||
|
||||
@@ -535,6 +535,25 @@ class SubscriptionsManager {
|
||||
return this.subscribedPubkeys.has(normalized);
|
||||
}
|
||||
|
||||
async toggleChannel(channelHex, userPubkey) {
|
||||
if (!userPubkey) {
|
||||
throw new Error("No user pubkey => cannot toggleChannel.");
|
||||
}
|
||||
await this.ensureLoaded(userPubkey);
|
||||
const isSubscribed = this.isSubscribed(channelHex) === true;
|
||||
try {
|
||||
if (isSubscribed) {
|
||||
await this.removeChannel(channelHex, userPubkey);
|
||||
} else {
|
||||
await this.addChannel(channelHex, userPubkey);
|
||||
}
|
||||
return { ok: true, subscribed: !isSubscribed };
|
||||
} catch (error) {
|
||||
userLogger.error("[SubscriptionsManager] Failed to toggle subscription:", error);
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
getSubscribedAuthors() {
|
||||
return Array.from(this.subscribedPubkeys);
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user