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

Function OnChannelDrop

apps/web/ui/OnChannelDrop/index.tsx:10–125  ·  view source on GitHub ↗
({
  threads,
  setThreads,
  currentCommunity,
  api,
  currentChannel,
  allUsers,
}: {
  threads: SerializedThread[];
  setThreads(threads: SerializedThread[]): void;
  currentCommunity: SerializedAccount;
  api: ApiClient;
  currentChannel: SerializedChannel;
  allUsers: SerializedUser[];
})

Source from the content-addressed store, hash-verified

8import type { ApiClient } from '@linen/api-client';
9
10export default function OnChannelDrop({
11 threads,
12 setThreads,
13 currentCommunity,
14 api,
15 currentChannel,
16 allUsers,
17}: {
18 threads: SerializedThread[];
19 setThreads(threads: SerializedThread[]): void;
20 currentCommunity: SerializedAccount;
21 api: ApiClient;
22 currentChannel: SerializedChannel;
23 allUsers: SerializedUser[];
24}) {
25 const moveThreadToChannel = ({
26 threadId,
27 channelId,
28 }: {
29 threadId: string;
30 channelId: string;
31 }) => {
32 setThreads(
33 threads.filter((thread) => {
34 if (thread.id === threadId && thread.channelId !== channelId) {
35 return false;
36 }
37 return true;
38 })
39 );
40
41 return api.moveThreadToChannelRequest({
42 threadId,
43 channelId,
44 communityId: currentCommunity.id,
45 });
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,

Callers 1

ChannelFunction · 0.85

Calls 2

moveThreadToChannelFunction · 0.85
moveMessageToChannelFunction · 0.70

Tested by

no test coverage detected