(
req: AuthedRequestWithTenantAndBody<postThreadType>,
res: Response,
next: NextFunction
)
| 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, |
no test coverage detected