···
-
import { parseResourceUri, ResourceUri } from "@atcute/lexicons";
export default defineBackground({
···
console.error(`fronter write: ${resp.error}`);
// hijack timeline fronter message because when a write is made it is either on the timeline
// or its a reply to a depth === 0 post on a threaded view, which is the same as a timeline post
browser.tabs.sendMessage(sender.tab?.id!, {
···
browser.tabs.sendMessage(sender.tab?.id!, {
type: "TIMELINE_FRONTER",
···
// console.log("sent timeline fronters", results);
const handleThread = async (
-
{ data: { body } }: any,
sender: globalThis.Browser.runtime.MessageSender,
const data: any = JSON.parse(body);
const promises = (data.thread as any[]).flatMap((item) => {
return frontersCache.get(item.uri).then(async (cachedFronter) => {
···
-
return promise.then(async (fronter) => {
const parsedUri = await cacheFronter(item.uri, fronter);
if (item.depth === 0) await setTabFronter(item.uri, fronter);
···
browser.tabs.sendMessage(sender.tab?.id!, {
-
type: "THREAD_FRONTER",
// console.log("sent thread fronters", results);
···
browser.runtime.onMessage.addListener(async (message, sender) => {
if (message.type !== "RESPONSE_CAPTURED") return;
-
// console.log("handling response event", message);
switch (message.data.type as string) {
···
+
parseCanonicalResourceUri,
+
} from "@atcute/lexicons";
export default defineBackground({
···
console.error(`fronter write: ${resp.error}`);
+
if (results.length === 0) return;
// hijack timeline fronter message because when a write is made it is either on the timeline
// or its a reply to a depth === 0 post on a threaded view, which is the same as a timeline post
browser.tabs.sendMessage(sender.tab?.id!, {
···
+
if (results.size === 0) return;
browser.tabs.sendMessage(sender.tab?.id!, {
type: "TIMELINE_FRONTER",
···
// console.log("sent timeline fronters", results);
const handleThread = async (
+
data: { body, requestUrl, documentUrl },
+
}: { data: { body: string; requestUrl: string; documentUrl: string } },
sender: globalThis.Browser.runtime.MessageSender,
+
// check if this request was made for fetching replies
+
// if anchor is not the same as current document url, that is the case
+
// which means the depth of the returned posts are invalid to us, in the case of THREAD_FRONTER
+
// if so we will use TIMELINE_FRONTER to send it back to content script
+
let isReplyThreadFetch = false;
+
const parsedDocumentUri = parseSocialAppPostUrl(documentUrl);
+
const anchorUri = new URL(requestUrl).searchParams.get("anchor");
+
// "parsedDocumentUri",
+
if (parsedDocumentUri && anchorUri) {
+
const parsedAnchorUri = expect(parseResourceUri(anchorUri));
+
isReplyThreadFetch = parsedDocumentUri.rkey !== parsedAnchorUri.rkey;
+
// console.log("isReplyThreadFetch", isReplyThreadFetch);
const data: any = JSON.parse(body);
const promises = (data.thread as any[]).flatMap((item) => {
return frontersCache.get(item.uri).then(async (cachedFronter) => {
···
+
return promise.then(async (fronter): Promise<any> => {
const parsedUri = await cacheFronter(item.uri, fronter);
+
if (isReplyThreadFetch)
if (item.depth === 0) await setTabFronter(item.uri, fronter);
···
+
if (results.size === 0) return;
browser.tabs.sendMessage(sender.tab?.id!, {
+
type: isReplyThreadFetch ? "TIMELINE_FRONTER" : "THREAD_FRONTER",
// console.log("sent thread fronters", results);
···
browser.runtime.onMessage.addListener(async (message, sender) => {
if (message.type !== "RESPONSE_CAPTURED") return;
+
console.log("handling response", message.data);
switch (message.data.type as string) {