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

Function moveMessageToChannel

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

Source from the content-addressed store, hash-verified

46 };
47
48 const moveMessageToChannel = ({
49 messageId,
50 channelId,
51 }: {
52 messageId: string;
53 channelId: string;
54 }) => {
55 const messages = [...threads.map((thread) => thread.messages)].flat();
56 const message = messages.find(({ id }) => id === messageId);
57 if (!message) {
58 return;
59 }
60 const imitation =
61 currentChannel.id === channelId
62 ? createThreadImitation({
63 message: message.body,
64 files: message.attachments.map((attachment) => {
65 return {
66 id: attachment.name,
67 url: attachment.url,
68 };
69 }),
70 author: message.author as SerializedUser,
71 mentions: allUsers,
72 channel: currentChannel,
73 })
74 : null;
75
76 const result = threads.map((thread) => {
77 const ids = thread.messages.map(({ id }) => id);
78 if (ids.includes(messageId)) {
79 return {
80 ...thread,
81 messages: thread.messages.filter(({ id }) => id !== messageId),
82 };
83 }
84
85 return thread;
86 });
87
88 setThreads([...result, ...(imitation ? [imitation] : [])]);
89
90 return api
91 .moveMessageToChannelRequest({
92 messageId,
93 channelId,
94 communityId: currentCommunity.id,
95 })
96 .then((thread: SerializedThread) => {
97 setThreads(
98 threads.map((current) => {
99 if (current.id === imitation?.id) {
100 return thread;
101 }
102 return current;
103 })
104 );
105 });

Callers 1

OnChannelDropFunction · 0.70

Calls 3

createThreadImitationFunction · 0.90
mapMethod · 0.80
findMethod · 0.45

Tested by

no test coverage detected