feat(server,web,mobile,desktop): Copy thread copies a link that opens the thread #26290
Mergedjuliusmarmingemerged 5 commits into
main fromrefs/pull/26290/headmerged by juliusmarminge View on GitHubgithub-actions[bot](GitHub profile, opens in a new tab) added labelsvouch:trusted
github-actions[bot](GitHub profile, opens in a new tab) added labelssize:L
- apps/mobile/modules/t3-composer-editor/android/src/main/java/expo/modules/t3composereditor/T3ComposerEditorView.kt line 706OutdatedResolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -701,4 +701,6 @@701701 pasteContextListener?.invoke(payload)702702 return true703703 }704- return pasteImagesOrInterceptedText()704+ if (pasteImagesOrInterceptedText()) return true705+ if (T3ComposerClipboard.hasThreadLink(payload["text"].orEmpty())) {706+ pasteContextListener?.invoke(payload)@@ -91,0 +107,21 @@107+ const rewritten = replaceThreadLinks(text, (link, label) => {108+ if (link.environmentId === null) return undefined;109+ const candidates = threadLinkCandidates(link, link.environmentId);110+ const record =111+ copied.find(112+ (candidate): candidate is ThreadContextRecord =>113+ candidate.kind === "thread" &&114+ "threadId" in candidate &&115+ candidates.some(116+ (ref) =>117+ ref.environmentId === candidate.environmentId && ref.threadId === candidate.threadId,118+ ),119+ ) ??120+ candidates.flatMap((ref) => {121+ const known = title(ref);122+ return known === undefined ? [] : [threadContextRecord(ref, known)];123+ })[0] ??124+ threadContextRecord(candidates[0]!, label?.trim() || "Thread");125+ const contextId = accept(record);126+ if (contextId === undefined) return undefined;127+ records.set(record.contextId, record);packages/shared/src/threadLinks.ts line 15Resolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -2,9 +2,14 @@22 import * as Option from "effect/Option";33 import * as Schema from "effect/Schema";445+import { DEFAULT_HOSTED_APP_URL } from "./connectAuth.ts";6+57 export const THREAD_LINK_PROTOCOL = "t3-thread";68 const V1_PREFIX = `${THREAD_LINK_PROTOCOL}://v1/`;79 const V2_PREFIX = `${THREAD_LINK_PROTOCOL}://v2/`;10+const HOSTED_PREFIX = `${DEFAULT_HOSTED_APP_URL}/threads/`;11+const HOSTED_SEGMENT = "[A-Za-z0-9_%-]+";12+const HOSTED_LINK = `${HOSTED_PREFIX.replace(/[.*+?^${}()|[\]\\/]/g, "\\$&")}${HOSTED_SEGMENT}/${HOSTED_SEGMENT}`;813 // Code comes first in the alternation so a link written inside a code span or fence is skipped.9-const THREAD_LINK_OUTSIDE_CODE =10- /(?<fence>(`{3,}|~{3,})[\s\S]*?(?:\2|$))|(?<span>(`+)[^\n]*?\4)|\[(?<label>[^\]\n]*)\]\((?<href>t3-thread:\/\/v[12]\/[^\s)]+)\)|<(?<autolink>t3-thread:\/\/v[12]\/[^\s<>]+)>/g;14+const THREAD_LINK_OUTSIDE_CODE = new RegExp(15+ String.raw`(?<fence>(\`{3,}|~{3,})[\s\S]*?(?:\2|$))|(?<span>(\`+)[^\n]*?\4)|\[(?<label>[^\]\n]*)\]\((?<href>t3-thread:\/\/v[12]\/[^\s)]+|${HOSTED_LINK})\)|<(?<autolink>t3-thread:\/\/v[12]\/[^\s<>]+|${HOSTED_LINK})>|(?<bare>${HOSTED_LINK})(?![\w%/?#-])`,
github-actions[bot](GitHub profile, opens in a new tab) added labels📱 Native Change
- apps/mobile/modules/t3-composer-editor/android/src/main/java/expo/modules/t3composereditor/T3ComposerEditorView.kt lines 742 to 747OutdatedResolvedby coderabbitai[bot](GitHub profile, opens in a new tab)@@ -739,4 +739,9 @@739739 pasteContextListener?.invoke(payload)740740 return true741741 }742- return pasteImagesOrInterceptedText()742+ if (pasteImagesOrInterceptedText()) return true743+ if (T3ComposerClipboard.hasThreadLink(payload["text"].orEmpty())) {744+ pasteContextListener?.invoke(payload)745+ return true746+ }747+ return false@@ -296,5 +296,6 @@296296 Another thread can be context too. Type `@` followed by part of its title to pick one from297297 the same server, or from a machine it links to while the Linked environments beta is on; those298298 show the machine's name. On web and desktop you can also drag a thread out of the sidebar and299-drop it on the composer; a multi-selection drops together. On any client, **Copy thread** puts a300-thread on the clipboard that pastes into a composer as its chip. The chip shows the thread's299+drop it on the composer; a multi-selection drops together. On any client, **Copy thread** copies a300+link to the thread that pastes into a composer as its chip, and so does any other thread link you301+paste. The chip shows the thread's@@ -145,5 +206,5 @@145206 : written.threadId;146207 const current = title({ environmentId, threadId });147208 if (current === undefined) {148- if (groups.href !== undefined && written.environmentId === null) return source;149- return groups.label?.trim() || unknownThreadLinkLabel(written, messageEnvironmentId);209+ if (label !== undefined && written.environmentId === null) return undefined;210+ return label?.trim() || unknownThreadLinkLabel(written, messageEnvironmentId);
- @@ -735,6 +735,7 @@735735736736 private fun pasteContextOrImages(): Boolean {737737 val payload = T3ComposerClipboard.read(context)738- if (payload["html"]?.contains("data-t3-context-fragment=") == true) {739- pasteContextListener?.invoke(payload)740- return true738+ return when {739+ payload["html"]?.contains("data-t3-context-fragment=") == true -> pasteContext(payload)740+ pasteImagesOrInterceptedText() -> true741+ T3ComposerClipboard.hasThreadLink(payload["text"].orEmpty()) -> pasteContext(payload)
juliusmarminge changed the title
- @@ -591,4 +600,4 @@591600 label: client.label,592601 access: client.access,593602 linked: client.peerLink,594- ...(client.peerLink ? {} : { webOrigin: requestUrls(request).issuer }),603+ ...(client.peerLink ? {} : { hostedAppUrl }),
juliusmarminge added labelsbugfix
juliusmarminge added labelspr:needs-julius
juliusmarminge merged this251369d
juliusmarminge closed this
Sign in to join this conversation.


macroscopeapp[bot](GitHub profile, opens in a new tab) reviewed