Fix at mention that triggers ephemeral message (#6458)

* Fix at mention that triggers ephemeral message

* Properly handle failed posts
This commit is contained in:
Daniel Espino García
2022-07-07 12:12:31 +02:00
committed by GitHub
parent 6a3c600c8a
commit e481c07630
4 changed files with 57 additions and 37 deletions

View File

@@ -130,30 +130,9 @@ export async function createPost(serverUrl: string, post: Partial<Post>, files:
const isCRTEnabled = await getIsCRTEnabled(database);
let created;
try {
const created = await client.createPost(newPost);
const models = await operator.handlePosts({
actionType: ActionType.POSTS.RECEIVED_NEW,
order: [created.id],
posts: [created],
prepareRecordsOnly: true,
});
const isCrtReply = isCRTEnabled && created.root_id !== '';
if (!isCrtReply) {
const {member} = await updateLastPostAt(serverUrl, created.channel_id, created.create_at, true);
if (member) {
models.push(member);
}
}
if (isCRTEnabled) {
const {models: threadModels} = await createThreadFromNewPost(serverUrl, created, true);
if (threadModels?.length) {
models.push(...threadModels);
}
}
await operator.batchRecords(models);
newPost = created;
created = await client.createPost(newPost);
} catch (error: any) {
const errorPost = {
...newPost,
@@ -187,8 +166,33 @@ export async function createPost(serverUrl: string, post: Partial<Post>, files:
}
await operator.batchRecords(models);
}
return {data: true};
}
const models = await operator.handlePosts({
actionType: ActionType.POSTS.RECEIVED_NEW,
order: [created.id],
posts: [created],
prepareRecordsOnly: true,
});
const isCrtReply = isCRTEnabled && created.root_id !== '';
if (!isCrtReply) {
const {member} = await updateLastPostAt(serverUrl, created.channel_id, created.create_at, true);
if (member) {
models.push(member);
}
}
if (isCRTEnabled) {
const {models: threadModels} = await createThreadFromNewPost(serverUrl, created, true);
if (threadModels?.length) {
models.push(...threadModels);
}
}
await operator.batchRecords(models);
newPost = created;
return {data: true};
}