(thread: SerializedThread, url: string)
| 6 | import { parseDate } from './utils/parseDate'; |
| 7 | |
| 8 | function buildNameText(thread: SerializedThread, url: string): Question { |
| 9 | const first = thread.messages[0]; |
| 10 | const cleanBody = normalize( |
| 11 | replaceMentions({ body: first.body, mentions: first.mentions }) |
| 12 | ).trim(); |
| 13 | |
| 14 | const suggestedAnswers = thread.messages |
| 15 | .slice(1) |
| 16 | .map((message) => { |
| 17 | return { |
| 18 | url: `${url}#${message.id}`, |
| 19 | text: normalize( |
| 20 | replaceMentions({ body: message.body, mentions: message.mentions }) |
| 21 | ).trim(), |
| 22 | author: { |
| 23 | name: message.author?.displayName || 'user', |
| 24 | }, |
| 25 | dateCreated: parseDate(message.sentAt), |
| 26 | }; |
| 27 | }) |
| 28 | .filter((m) => !!m.text); |
| 29 | |
| 30 | return { |
| 31 | name: |
| 32 | !!thread.title && !!thread.title.trim() |
| 33 | ? thread.title.trim() |
| 34 | : cleanBody.substring(0, 60), |
| 35 | text: cleanBody, |
| 36 | author: { |
| 37 | name: first.author?.displayName || 'user', |
| 38 | }, |
| 39 | upvoteCount: thread.viewCount, |
| 40 | dateCreated: parseDate(first.sentAt), |
| 41 | answerCount: suggestedAnswers.length, |
| 42 | suggestedAnswer: suggestedAnswers, |
| 43 | }; |
| 44 | } |
| 45 | |
| 46 | export function buildStructureData({ |
| 47 | thread, |
no test coverage detected