| 289 | }; |
| 290 | |
| 291 | const generateCommunityNote = (status: APITwitterStatus): string => { |
| 292 | const note = status.community_note; |
| 293 | if (!note) { |
| 294 | return ''; |
| 295 | } |
| 296 | |
| 297 | let lastToIndex = 0; |
| 298 | let result = ''; |
| 299 | |
| 300 | if ('facets' in note) { |
| 301 | const sorted = [...note.facets].sort((a, b) => a.indices[0] - b.indices[0]); |
| 302 | for (const facet of sorted) { |
| 303 | if (facet.type !== 'url') { |
| 304 | continue; |
| 305 | } |
| 306 | const [fromIndex, toIndex] = facet.indices; |
| 307 | const href = facet.replacement ?? ''; |
| 308 | const label = facet.display ?? note.text.substring(fromIndex, toIndex); |
| 309 | result += note.text.substring(lastToIndex, fromIndex); |
| 310 | result += `<a href="${href}">${label}</a>`; |
| 311 | lastToIndex = toIndex; |
| 312 | } |
| 313 | } |
| 314 | |
| 315 | result += note.text.substring(lastToIndex); |
| 316 | |
| 317 | return `<table> |
| 318 | <thead> |
| 319 | <th><b>${i18next.t('ivCommunityNoteHeader')}</b></th> |
| 320 | </thead> |
| 321 | <tbody> |
| 322 | <th>${result.replace(/\n/g, '\n<br>')}</th> |
| 323 | </tbody> |
| 324 | </table>`; |
| 325 | }; |
| 326 | |
| 327 | const generateStatus = ( |
| 328 | status: APIStatus | APIStatusTombstone, |