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
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233export class Declarative { constructor(derived, requests) { this.derived = derived; this.requests = requests; } async ensureCurrentUser() { let currentUser = this.derived.$currentUser.get(); if (!currentUser || currentUser.isPartial) { await this.requests.loadCurrentUser(); currentUser = this.derived.$currentUser.get(); } if (!currentUser) { throw new Error("Current user not found"); } return currentUser; }
async ensureProfile(profileDid) { const getProfile = (did) => this.derived.$hydratedDetailedProfiles.get(did) ?? this.derived.$hydratedProfiles.get(did) ?? null; let profile = getProfile(profileDid); if (!profile) { await this.requests.loadDetailedProfile(profileDid); profile = getProfile(profileDid); } if (!profile) { throw new Error("Profile not found"); } return profile; }
async ensureDetailedProfile(profileDid) { const getProfile = (did) => this.derived.$hydratedDetailedProfiles.get(did); let profile = getProfile(profileDid); if (!profile) { await this.requests.loadDetailedProfile(profileDid); profile = getProfile(profileDid); } if (!profile) { throw new Error("Profile not found"); } return profile; }
async ensureKnownFollowers(profileDid) { let knownFollowers = this.derived.$knownFollowers.get(profileDid); if (!knownFollowers) { await this.requests.loadKnownFollowers(profileDid); knownFollowers = this.derived.$knownFollowers.get(profileDid); } if (!knownFollowers) { throw new Error("Known followers not found"); } return knownFollowers; }
async ensureProfileFollows(profileDid) { let profileFollows = this.derived.$profileFollows.get(profileDid); if (!profileFollows) { await this.requests.loadProfileFollows(profileDid); profileFollows = this.derived.$profileFollows.get(profileDid); } if (!profileFollows) { throw new Error("Profile follows not found"); } return profileFollows; }
async ensureProfiles(profileDids) { const getProfile = (did) => this.derived.$hydratedDetailedProfiles.get(did) ?? this.derived.$hydratedProfiles.get(did) ?? null; const missing = profileDids.filter((did) => !getProfile(did)); if (missing.length > 0) { await this.requests.loadDetailedProfiles(missing); } return profileDids.map((did) => getProfile(did)); }
async ensureDetailedProfiles(profileDids) { const getProfile = (did) => this.derived.$hydratedDetailedProfiles.get(did); const missing = profileDids.filter((did) => !getProfile(did)); if (missing.length > 0) { await this.requests.loadDetailedProfiles(missing); } return profileDids.map((did) => getProfile(did) ?? null); }
async ensurePostThread(postURI) { let postThread = this.derived.$hydratedPostThreads.get(postURI); if (!postThread) { await this.requests.loadPostThread(postURI); postThread = this.derived.$hydratedPostThreads.get(postURI); } if (!postThread) { throw new Error("Post thread not found"); } return postThread; }
async ensurePost(postURI) { let post = this.derived.$hydratedPosts.get(postURI); if (!post) { await this.requests.loadPost(postURI); post = this.derived.$hydratedPosts.get(postURI); } if (!post) { throw new Error("Post not found"); } return post; }
async ensurePosts(postURIs) { const getPost = (uri) => this.derived.$hydratedPosts.get(uri); const missing = postURIs.filter((uri) => !getPost(uri)); if (missing.length > 0) { await this.requests.loadPosts(missing); } return postURIs.map((uri) => getPost(uri)); }
async ensureFeedGenerator(feedUri) { let feedGenerator = this.derived.$feedGenerators.get(feedUri); if (!feedGenerator) { await this.requests.loadFeedGenerator(feedUri); feedGenerator = this.derived.$feedGenerators.get(feedUri); } if (!feedGenerator) { throw new Error("Feed generator not found"); } return feedGenerator; }
async ensureList(listUri) { let list = this.derived.$lists.get(listUri); if (!list) { await this.requests.loadList(listUri); list = this.derived.$lists.get(listUri); } if (!list) { throw new Error("List not found"); } return list; }
async ensureStarterPack(starterPackUri) { let starterPack = this.derived.$starterPacks.get(starterPackUri); if (!starterPack) { await this.requests.loadStarterPack(starterPackUri); starterPack = this.derived.$starterPacks.get(starterPackUri); } if (!starterPack) { throw new Error("Starter pack not found"); } return starterPack; }
async ensurePinnedItems() { let pinnedItems = this.derived.$hydratedPinnedItems.get(); if (!pinnedItems) { await this.requests.loadPinnedItems(); pinnedItems = this.derived.$hydratedPinnedItems.get(); } if (!pinnedItems) { throw new Error("Pinned items not found"); } return pinnedItems; }
async ensureConvoList() { let convoList = this.derived.$convoList.get(); if (!convoList) { await this.requests.loadConvoList(); convoList = this.derived.$convoList.get(); } if (!convoList) { throw new Error("Conversation list not found"); } return convoList; }
async ensureConvoRequestList() { let convoRequestList = this.derived.$convoRequestList.get(); if (!convoRequestList) { await this.requests.loadConvoRequestList(); convoRequestList = this.derived.$convoRequestList.get(); } if (!convoRequestList) { throw new Error("Conversation request list not found"); } return convoRequestList; }
async ensureConvo(convoId) { let convo = this.derived.$convos.get(convoId); if (!convo) { await this.requests.loadConvo(convoId); convo = this.derived.$convos.get(convoId); } if (!convo) { throw new Error("Conversation not found"); } return convo; }
async ensureJoinLinkPreview(code) { let preview = this.derived.$joinLinkPreviewsByCode.get(code); if (!preview) { await this.requests._loadJoinLinkPreviews([code]); preview = this.derived.$joinLinkPreviewsByCode.get(code); } if (!preview) { throw new Error("Join link preview not found"); } return preview; }
async ensureConvoForProfile(profileDid) { let convo = this.derived.$convoForProfile.get(profileDid); if (!convo) { await this.requests.loadConvoForProfile(profileDid); convo = this.derived.$convoForProfile.get(profileDid); } if (!convo) { throw new Error("Conversation not found"); } return convo; }}