MCPcopy Create free account
hub / github.com/Linen-dev/linen.dev / moveMessageToChannel

Function moveMessageToChannel

apps/web/ui/ChannelView/index.tsx:542–608  ·  view source on GitHub ↗
({
    messageId,
    channelId,
  }: {
    messageId: string;
    channelId: string;
  })

Source from the content-addressed store, hash-verified

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) {

Callers 1

onThreadDropFunction · 0.70

Calls 3

createThreadImitationFunction · 0.90
mapMethod · 0.80
findMethod · 0.45

Tested by

no test coverage detected