(body: string)
| 38 | }; |
| 39 | |
| 40 | export 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. |
| 67 | export const DM_PUSH_PREVIEW_LENGTH = 100; |
no test coverage detected