import "/js/components/post-composer.js"; import { createEmbedFromPost } from "/js/dataHelpers.js"; import { showToast } from "/js/toasts.js"; import { html } from "/js/lib/lit-html.js"; import { linkToPostFromUri } from "/js/navigation.js"; import { hapticsImpactLight } from "/js/haptics.js"; export class PostComposerService { constructor(dataLayer, identityResolver, pluginService, { draftsEnabled }) { this.dataLayer = dataLayer; this.identityResolver = identityResolver; this.pluginService = pluginService; this.currentPostComposer = null; this.draftsEnabled = draftsEnabled; } async composePost({ currentUser, replyTo = null, replyRoot = null, quotedPost = null, }) { if (!currentUser) { console.warn("No current user"); return; } if (this.currentPostComposer !== null) { console.warn("Post composer already open"); return; } hapticsImpactLight(); return new Promise((resolve, reject) => { this.currentPostComposer = document.createElement("post-composer"); this.currentPostComposer.dataLayer = this.dataLayer; this.currentPostComposer.identityResolver = this.identityResolver; this.currentPostComposer.pluginService = this.pluginService; this.currentPostComposer.replyTo = replyTo; this.currentPostComposer.replyRoot = replyRoot; this.currentPostComposer.quotedRecord = quotedPost ? createEmbedFromPost(quotedPost) : null; this.currentPostComposer.currentUser = currentUser; this.currentPostComposer.draftsEnabled = this.draftsEnabled; this.currentPostComposer.addEventListener("send-post", async (e) => { const { posts, replyTo: sendReplyTo, replyRoot: sendReplyRoot, threadgateAllow, postgateEmbeddingRules, draft, signal, successCallback, errorCallback, settledCallback, } = e.detail; try { const res = await this.dataLayer.mutations.createThread({ posts, replyTo: sendReplyTo, replyRoot: sendReplyRoot, threadgateAllow, postgateEmbeddingRules, signal, }); let toastMessage = "Your post was sent"; if (posts.length > 1) { toastMessage = "Your posts were sent"; } else if (sendReplyTo) { toastMessage = "Your reply was sent"; } showToast( html`