MCPcopy Index your code
hub / github.com/Linen-dev/linen.dev / post

Method post

apps/web/server/routers/threads/controller.ts:83–131  ·  view source on GitHub ↗
(
    req: AuthedRequestWithTenantAndBody<postThreadType>,
    res: Response,
    next: NextFunction
  )

Source from the content-addressed store, hash-verified

81 res.json(thread);
82 }
83 static async post(
84 req: AuthedRequestWithTenantAndBody<postThreadType>,
85 res: Response,
86 next: NextFunction
87 ) {
88 if (req.tenant?.chat === ChatType.NONE) {
89 return next(new Forbidden('Community has chat disabled'));
90 }
91
92 if (
93 req.tenant?.chat === ChatType.MANAGERS &&
94 isNotManager(req.tenant_user?.role)
95 ) {
96 return next(new Forbidden('User is not allow to chat'));
97 }
98
99 const tree = parse.linen(req.body.body);
100 const mentionNodes: MentionNode[] = find.mentions(tree);
101
102 if (
103 mentionNodes.find((m) => m.id === 'channel') &&
104 isNotManager(req.tenant_user?.role)
105 ) {
106 return next(new Forbidden('User is not allow to mention a channel'));
107 }
108 const [err, _] = await to(
109 ChannelsService.isChannelUsable({
110 channelId: req.body.channelId,
111 accountId: req.tenant?.id!,
112 })
113 );
114 if (err) {
115 return next(new BadRequest(err.message));
116 }
117
118 const thread = await ThreadsServices.create({
119 accountId: req.tenant?.id!,
120 body: req.body.body,
121 channelId: req.body.channelId,
122 files: req.body.files,
123 imitationId: req.body.imitationId,
124 title: req.body.title,
125 authorId: req.tenant_user?.id!,
126 });
127
128 await trackApiEvent({ req, res }, ApiEvent.user_send_message);
129
130 res.json({ thread, imitationId: req.body.imitationId });
131 }
132 static async findTopics(
133 req: AuthedRequestWithTenantAndBody<findTopicsSchema>,
134 res: Response,

Callers 15

processNewThreadFunction · 0.45
processNewMessageFunction · 0.45
queryThreadsMethod · 0.45
server.tsFile · 0.45
index.jsFile · 0.45
ApiClientClass · 0.45
inbound.tsFile · 0.45
inbound.tsFile · 0.45
ApiClass · 0.45
findOrCreateChannelMethod · 0.45
createNewThreadMethod · 0.45
createNewMessageMethod · 0.45

Calls 6

isNotManagerFunction · 0.90
toFunction · 0.90
trackApiEventFunction · 0.90
isChannelUsableMethod · 0.80
findMethod · 0.45
createMethod · 0.45

Tested by

no test coverage detected