Something went wrong. Try again.
[READ-ONLY] Mirror of https://github.com/improsocial/impro
An extensible Bluesky client for web impro.social
Something went wrong. Try again.
JavaScript
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214import { hapticsImpactMedium } from "/js/haptics.js";import { showToast } from "/js/toasts.js";import { confirmModal } from "/js/modals/confirm.modal.js";import { getDisplayName } from "/js/dataHelpers.js";import "/js/components/post-notifications-dialog.js";
export class ProfileInteractionHandler { constructor(dataLayer, reportService) { this.dataLayer = dataLayer; this.reportService = reportService; this._postNotificationsDialog = null; }
async handleFollow(profile, doFollow) { if (doFollow) { try { hapticsImpactMedium(); await this.dataLayer.mutations.followProfile(profile); showToast(`Following ${getDisplayName(profile)}`); } catch (error) { console.error(error); showToast("Failed to follow account", { style: "error" }); } } else { const confirmed = await confirmModal( `Are you sure you want to unfollow ${getDisplayName(profile)}?`, { title: "Unfollow?", confirmButtonText: "Unfollow", }, ); if (!confirmed) return; try { await this.dataLayer.mutations.unfollowProfile(profile); showToast(`No longer following ${getDisplayName(profile)}`); } catch (error) { console.error(error); showToast("Failed to unfollow account", { style: "error" }); } } }
async handleMute(profile, doMute) { if (doMute) { try { await this.dataLayer.mutations.muteProfile(profile); showToast("Account muted"); } catch (error) { console.error(error); showToast("Failed to mute account", { style: "error" }); } } else { try { await this.dataLayer.mutations.unmuteProfile(profile); showToast("Account unmuted"); } catch (error) { console.error(error); showToast("Failed to unmute account", { style: "error" }); } } }
async handleBlock(profile, doBlock) { if (doBlock) { const confirmed = await confirmModal( "Blocked accounts cannot reply in your threads, mention you, or otherwise interact with you.", { title: "Block Account?", confirmButtonText: "Block", confirmButtonStyle: "danger", }, ); if (!confirmed) return; try { hapticsImpactMedium(); await this.dataLayer.mutations.blockProfile(profile); showToast("Account blocked"); } catch (error) { console.error(error); showToast("Failed to block account", { style: "error" }); } } else { try { await this.dataLayer.mutations.unblockProfile(profile); showToast("Account unblocked"); } catch (error) { console.error(error); showToast("Failed to unblock account", { style: "error" }); } } }
async handleAddToList(profile, list) { try { await this.dataLayer.mutations.addProfileToList(profile, list); showToast(`Added to ${list.name}`, { style: "success" }); } catch (error) { console.error(error); showToast("Failed to add to list", { style: "error" }); throw error; } }
async handleRemoveFromList(profile, list, membershipUri) { try { await this.dataLayer.mutations.removeProfileFromList( profile, list, membershipUri, ); showToast(`Removed from ${list.name}`, { style: "success" }); } catch (error) { console.error(error); showToast("Failed to remove from list", { style: "error" }); throw error; } }
async handleSubscribe(profile, doSubscribe, labelerInfo) { if (doSubscribe) { try { hapticsImpactMedium(); await this.dataLayer.mutations.subscribeLabeler(profile, labelerInfo); showToast("Subscribed to labeler"); } catch (error) { console.error(error); showToast("Failed to subscribe to labeler", { style: "error" }); } } else { try { await this.dataLayer.mutations.unsubscribeLabeler(profile); showToast("Unsubscribed from labeler"); } catch (error) { console.error(error); showToast("Failed to unsubscribe from labeler", { style: "error" }); } } }
async handlePostNotificationSubscription(profile) { if (this._postNotificationsDialog !== null) { return; } return new Promise((resolve) => { this._postNotificationsDialog = document.createElement( "post-notifications-dialog", ); this._postNotificationsDialog.profile = profile; this._postNotificationsDialog.activitySubscription = profile.viewer?.activitySubscription ?? null;
this._postNotificationsDialog.addEventListener( "save-subscription", async (event) => { const { activitySubscription, successCallback, errorCallback } = event.detail; try { hapticsImpactMedium(); await this.dataLayer.mutations.updatePostNotificationSubscription( profile, activitySubscription, ); const initialSub = profile.viewer?.activitySubscription; const wasSubscribed = initialSub?.post || initialSub?.reply; if (!activitySubscription.post && !activitySubscription.reply) { showToast( `You will no longer receive notifications for @${profile.handle}`, { style: "success" }, ); } else if (!wasSubscribed) { showToast( `You'll start receiving notifications for @${profile.handle}!`, { style: "success" }, ); } else { showToast("Changes saved", { style: "success" }); } successCallback(); resolve(); } catch (error) { console.error(error); showToast("Failed to save notification preferences", { style: "error", }); errorCallback(error.message || "An unexpected error occurred."); } }, );
this._postNotificationsDialog.addEventListener("dialog-closed", () => { if (this._postNotificationsDialog) { this._postNotificationsDialog.remove(); this._postNotificationsDialog = null; } resolve(); });
document.body.appendChild(this._postNotificationsDialog); this._postNotificationsDialog.open(); }); }
async handleReport(profile) { try { await this.reportService.openReportDialog({ subject: profile, subjectType: "account", }); } catch (error) { console.error(error); } }}