feat: populate quotedCids when publishing replies with quote references

Parse reply content for >>{postNumber} references, resolve post numbers to CIDs via usePostNumberStore, and include resolved CIDs in publishCommentOptions when publishing. Extracted quote handling into reply-quote-utils.ts for testability and clarity.
This commit is contained in:
plebeius
2026-02-11 16:07:01 +08:00
parent e9558a618a
commit 9f14a63268
2 changed files with 32 additions and 2 deletions
+23
View File
@@ -0,0 +1,23 @@
import { QUOTE_NUMBER_REGEX } from './url-utils';
export const getQuotedCidsFromContent = (content: string | undefined, numberToCid: Record<number, string>) => {
if (!content) return undefined;
const cids = new Set<string>();
for (const match of content.matchAll(new RegExp(QUOTE_NUMBER_REGEX.source, 'g'))) {
const num = parseInt(match[1], 10);
const cid = numberToCid[num];
if (cid) cids.add(cid);
}
return cids.size > 0 ? [...cids] : undefined;
};
export const mergeQuotedCids = (publishCommentOptions: Record<string, any> | undefined, quotedCids: string[] | undefined) => {
if (!publishCommentOptions || !quotedCids?.length) return publishCommentOptions;
const currentQuotedCids = publishCommentOptions.quotedCids ?? [];
const mergedQuotedCids = [...new Set([...currentQuotedCids, ...quotedCids])];
return {
...publishCommentOptions,
quotedCids: mergedQuotedCids,
};
};