({
messageId,
channelId,
}: {
messageId: string;
channelId: string;
})
| 540 | }; |
| 541 | |
| 542 | const moveMessageToChannel = ({ |
| 543 | messageId, |
| 544 | channelId, |
| 545 | }: { |
| 546 | messageId: string; |
| 547 | channelId: string; |
| 548 | }) => { |
| 549 | const messages = [...threads.map((thread) => thread.messages)].flat(); |
| 550 | const message = messages.find(({ id }) => id === messageId); |
| 551 | if (!message) { |
| 552 | return; |
| 553 | } |
| 554 | const imitation = |
| 555 | currentChannel.id === channelId && |
| 556 | createThreadImitation({ |
| 557 | message: message.body, |
| 558 | files: message.attachments.map((attachment) => { |
| 559 | return { |
| 560 | id: attachment.name, |
| 561 | url: attachment.url, |
| 562 | }; |
| 563 | }), |
| 564 | author: message.author as SerializedUser, |
| 565 | mentions: allUsers, |
| 566 | channel: currentChannel, |
| 567 | }); |
| 568 | |
| 569 | setThreads((threads) => { |
| 570 | const result = threads.map((thread) => { |
| 571 | const ids = thread.messages.map(({ id }) => id); |
| 572 | if (ids.includes(messageId)) { |
| 573 | return { |
| 574 | ...thread, |
| 575 | messages: thread.messages.filter(({ id }) => id !== messageId), |
| 576 | }; |
| 577 | } |
| 578 | |
| 579 | return thread; |
| 580 | }); |
| 581 | |
| 582 | if (imitation) { |
| 583 | return [...result, imitation]; |
| 584 | } |
| 585 | |
| 586 | return result; |
| 587 | }); |
| 588 | |
| 589 | return api |
| 590 | .moveMessageToChannelRequest({ |
| 591 | messageId, |
| 592 | channelId, |
| 593 | communityId: currentCommunity.id, |
| 594 | }) |
| 595 | .then((thread) => { |
| 596 | setThreads((threads) => { |
| 597 | if (imitation) { |
| 598 | return threads.map((current) => { |
| 599 | if (current.id === imitation.id) { |
no test coverage detected