({
authorId,
channelId,
body,
files,
imitationId,
title,
externalThreadId,
sentAt,
accountId,
mentions,
messageFormat = MessageFormat.LINEN,
}: {
authorId: string;
channelId: string;
body: string;
files?: UploadedFile[];
imitationId?: string;
title?: string;
externalThreadId?: string;
sentAt?: Date;
accountId: string;
mentions?: { id: string }[];
messageFormat?: MessageFormat;
})
| 156 | } |
| 157 | |
| 158 | static async create({ |
| 159 | authorId, |
| 160 | channelId, |
| 161 | body, |
| 162 | files, |
| 163 | imitationId, |
| 164 | title, |
| 165 | externalThreadId, |
| 166 | sentAt, |
| 167 | accountId, |
| 168 | mentions, |
| 169 | messageFormat = MessageFormat.LINEN, |
| 170 | }: { |
| 171 | authorId: string; |
| 172 | channelId: string; |
| 173 | body: string; |
| 174 | files?: UploadedFile[]; |
| 175 | imitationId?: string; |
| 176 | title?: string; |
| 177 | externalThreadId?: string; |
| 178 | sentAt?: Date; |
| 179 | accountId: string; |
| 180 | mentions?: { id: string }[]; |
| 181 | messageFormat?: MessageFormat; |
| 182 | }) { |
| 183 | const account = await prisma.accounts.findFirst({ |
| 184 | where: { id: accountId }, |
| 185 | }); |
| 186 | if (!account) { |
| 187 | throw new Error("can't find the account"); |
| 188 | } |
| 189 | if (account.chat === ChatType.NONE) { |
| 190 | throw new Error('chat is disabled'); |
| 191 | } |
| 192 | const channel = await prisma.channels.findFirst({ |
| 193 | where: { id: channelId, accountId }, |
| 194 | }); |
| 195 | |
| 196 | if (!channel || !channel.accountId || channel.accountId !== accountId) { |
| 197 | throw new Error("can't find the channel"); |
| 198 | } |
| 199 | |
| 200 | sentAt = sentAt || new Date(); |
| 201 | |
| 202 | const tree = parse.linen(body); |
| 203 | const mentionNodes = mentions || find.mentions(tree); |
| 204 | const userIds = unique<string>( |
| 205 | mentionNodes.map(({ id }: { id: string }) => id) |
| 206 | ).filter((id) => id !== 'channel'); |
| 207 | |
| 208 | const thread = await prisma.threads.create({ |
| 209 | data: { |
| 210 | channel: { connect: { id: channelId } }, |
| 211 | sentAt: sentAt.getTime(), |
| 212 | lastReplyAt: sentAt.getTime(), |
| 213 | slug: slugify(title || body), |
| 214 | messageCount: 1, |
| 215 | title, |
no test coverage detected