MCPcopy Create free account
hub / github.com/dailydotdev/apps / parseMessageBody

Function parseMessageBody

packages/shared/src/features/messages/media.ts:40–64  ·  view source on GitHub ↗
(body: string)

Source from the content-addressed store, hash-verified

38};
39
40export const parseMessageBody = (body: string): DmBodyPart[] => {
41 const parts: DmBodyPart[] = [];
42 let cursor = 0;
43
44 Array.from(body.matchAll(imageMarkdownRegex)).forEach((match) => {
45 const [markdown, alt, url] = match;
46
47 if (!isTrustedImageUrl(url)) {
48 return;
49 }
50
51 parts.push(...textPart(body.slice(cursor, match.index)));
52 parts.push({
53 type: 'image',
54 url,
55 alt,
56 isGif: matchesHost(url, gifHosts),
57 });
58 cursor = match.index + markdown.length;
59 });
60
61 parts.push(...textPart(body.slice(cursor)));
62
63 return parts;
64};
65
66// What the peer's push notification shows; the API truncates to this too.
67export const DM_PUSH_PREVIEW_LENGTH = 100;

Callers 6

media.spec.tsFile · 0.90
MessageBubbleFunction · 0.90
useSendMessageFunction · 0.90
getMessagePreviewFunction · 0.85
getEditableTextFunction · 0.85
withEditedTextFunction · 0.85

Calls 4

isTrustedImageUrlFunction · 0.85
textPartFunction · 0.85
matchesHostFunction · 0.85
pushMethod · 0.80

Tested by

no test coverage detected