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

Function eventNewMessage

apps/web/services/events/eventNewMessage.ts:31–103  ·  view source on GitHub ↗
({
  channelId,
  messageId,
  threadId,
  imitationId,
  mentions = [],
  mentionNodes = [],
  communityId,
  message,
  userId,
  isLinenMessage,
}: NewMessageEvent)

Source from the content-addressed store, hash-verified

29};
30
31export async function eventNewMessage({
32 channelId,
33 messageId,
34 threadId,
35 imitationId,
36 mentions = [],
37 mentionNodes = [],
38 communityId,
39 message,
40 userId,
41 isLinenMessage,
42}: NewMessageEvent) {
43 const event = {
44 channelId,
45 messageId,
46 threadId,
47 imitationId,
48 isThread: false,
49 isReply: true,
50 message,
51 };
52
53 const channel = await ChannelsService.getChannelAndMembersWithAuth(channelId);
54
55 const promises: Promise<any>[] = [
56 eventNewMentions({
57 mentions,
58 mentionNodes,
59 channelId,
60 threadId,
61 authorId: userId,
62 }),
63 ...resolvePush({ channel, userId, event, communityId }),
64 ];
65
66 if (isLinenMessage) {
67 promises.push(
68 ...[
69 createNotificationJob(messageId, {
70 ...event,
71 communityId,
72 mentions,
73 mentionNodes,
74 }),
75 createTwoWaySyncJob({ ...event, event: 'newMessage', id: messageId }),
76 matrixNewMessage(event),
77 ThreadsServices.updateMetrics({ messageId, threadId }),
78 UserThreadStatusService.markAsUnread(threadId, userId),
79 UserThreadStatusService.markAsUnmutedForMentionedUsers(
80 threadId,
81 mentions.map((mention) => mention.usersId)
82 ),
83 ]
84 );
85 if (channel?.type === ChannelType.DM) {
86 promises.push(
87 ChannelsService.unarchiveChannel({ channelId: channel.id })
88 );

Callers 2

createMethod · 0.90
addMessageFunction · 0.90

Calls 13

eventNewMentionsFunction · 0.90
resolvePushFunction · 0.90
createNotificationJobFunction · 0.90
createTwoWaySyncJobFunction · 0.90
matrixNewMessageFunction · 0.90
updateMetricsMethod · 0.80
markAsUnreadMethod · 0.80
mapMethod · 0.80
unarchiveChannelMethod · 0.80

Tested by

no test coverage detected