({ from, to }: { from: string; to: string })
| 452 | } |
| 453 | |
| 454 | const mergeThreads = ({ from, to }: { from: string; to: string }) => { |
| 455 | const source = threads.find((thread) => thread.id === from); |
| 456 | const target = threads.find((thread) => thread.id === to); |
| 457 | |
| 458 | setThreads((threads) => { |
| 459 | if (!source || !target) { |
| 460 | return threads; |
| 461 | } |
| 462 | return threads |
| 463 | .map((thread) => { |
| 464 | if (thread.id === from) { |
| 465 | return null; |
| 466 | } |
| 467 | if (thread.id === to) { |
| 468 | return { |
| 469 | ...thread, |
| 470 | messages: [...thread.messages, ...source.messages].sort( |
| 471 | (a, b) => { |
| 472 | return ( |
| 473 | new Date(a.sentAt).getTime() - new Date(b.sentAt).getTime() |
| 474 | ); |
| 475 | } |
| 476 | ), |
| 477 | }; |
| 478 | } |
| 479 | return thread; |
| 480 | }) |
| 481 | .filter(Boolean) as SerializedThread[]; |
| 482 | }); |
| 483 | if (!source || !target) { |
| 484 | return Promise.resolve(); |
| 485 | } |
| 486 | return api.mergeThreadsRequest({ |
| 487 | from: source.id, |
| 488 | to: target.id, |
| 489 | communityId: currentCommunity.id, |
| 490 | }); |
| 491 | }; |
| 492 | |
| 493 | const moveMessageToThread = ({ |
| 494 | messageId, |
no test coverage detected