Something went wrong. Try again.
A live media wall for your Bluesky follows
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354import type { MediaItem } from './feed.js';import type { InteractionController } from './interaction-controller.js';import { mediaAssetKey } from './media-identity.js';
export const POST_CONTEXT = Symbol('post-controls');export type PostAction = 'like' | 'bookmark' | 'repost';export type PostActionResult = 'activated' | 'deactivated' | 'ignored';export type PostControls = { enabled: boolean; pending: ReadonlySet<string>; errors: ReadonlyMap<string, string>; change(item: MediaItem, action: PostAction): Promise<PostActionResult>;};
export function postActionKey(uri: string, action: PostAction) { return `${action}:${uri}`;}
export function postActionTarget(item: MediaItem) { return JSON.stringify([item.uri, item.post?.cid, mediaAssetKey(item)]);}
export async function writePostAction( controller: Pick< InteractionController, 'like' | 'unlike' | 'repost' | 'unrepost' | 'bookmark' | 'unbookmark' >, uri: string, state: NonNullable<MediaItem['post']>, action: PostAction): Promise<'activated' | 'deactivated'> { const post = { uri, cid: state.cid }; if (action === 'like') { if (state.likeUri) { await controller.unlike(post, state.likeUri); return 'deactivated'; } await controller.like(post); } else if (action === 'repost') { if (state.repostUri) { await controller.unrepost(post, state.repostUri); return 'deactivated'; } await controller.repost(post); } else { if (state.bookmarked) { await controller.unbookmark(post); return 'deactivated'; } await controller.bookmark(post); } return 'activated';}