Fix 'undefined' message numbers
parent
d5ea95d9e9
commit
4ecea31fd8
|
@ -213,7 +213,7 @@ class Thread {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let threadMessage = new ThreadMessage({
|
const rawThreadMessage = new ThreadMessage({
|
||||||
message_type: THREAD_MESSAGE_TYPE.TO_USER,
|
message_type: THREAD_MESSAGE_TYPE.TO_USER,
|
||||||
user_id: moderator.id,
|
user_id: moderator.id,
|
||||||
user_name: moderatorName,
|
user_name: moderatorName,
|
||||||
|
@ -222,12 +222,14 @@ class Thread {
|
||||||
role_name: roleName,
|
role_name: roleName,
|
||||||
attachments: attachmentLinks,
|
attachments: attachmentLinks,
|
||||||
});
|
});
|
||||||
|
const threadMessage = await this._addThreadMessageToDB(rawThreadMessage.getSQLProps());
|
||||||
|
|
||||||
const dmContent = formatters.formatStaffReplyDM(threadMessage);
|
const dmContent = formatters.formatStaffReplyDM(threadMessage);
|
||||||
const inboxContent = formatters.formatStaffReplyThreadMessage(threadMessage);
|
const inboxContent = formatters.formatStaffReplyThreadMessage(threadMessage);
|
||||||
|
|
||||||
// Because moderator replies have to be editable, we enforce them to fit within 1 message
|
// Because moderator replies have to be editable, we enforce them to fit within 1 message
|
||||||
if (! utils.messageContentIsWithinMaxLength(dmContent) || ! utils.messageContentIsWithinMaxLength(inboxContent)) {
|
if (! utils.messageContentIsWithinMaxLength(dmContent) || ! utils.messageContentIsWithinMaxLength(inboxContent)) {
|
||||||
|
await this._deleteThreadMessage(rawThreadMessage);
|
||||||
await this.postSystemMessage("Reply is too long! Make sure your reply is under 2000 characters total, moderator name in the reply included.");
|
await this.postSystemMessage("Reply is too long! Make sure your reply is under 2000 characters total, moderator name in the reply included.");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -237,19 +239,18 @@ class Thread {
|
||||||
try {
|
try {
|
||||||
dmMessage = await this._sendDMToUser(dmContent, files);
|
dmMessage = await this._sendDMToUser(dmContent, files);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
|
await this._deleteThreadMessage(rawThreadMessage);
|
||||||
await this.postSystemMessage(`Error while replying to user: ${e.message}`);
|
await this.postSystemMessage(`Error while replying to user: ${e.message}`);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Save the log entry
|
threadMessage.dm_message_id = dmMessage.id;
|
||||||
threadMessage = await this._addThreadMessageToDB({
|
await this._updateThreadMessage(threadMessage.id, { dm_message_id: dmMessage.id });
|
||||||
...threadMessage.getSQLProps(),
|
|
||||||
dm_message_id: dmMessage.id,
|
|
||||||
});
|
|
||||||
|
|
||||||
// Show the reply in the inbox thread
|
// Show the reply in the inbox thread
|
||||||
const inboxMessage = await this._postToThreadChannel(inboxContent, files);
|
const inboxMessage = await this._postToThreadChannel(inboxContent, files);
|
||||||
if (inboxMessage) {
|
if (inboxMessage) {
|
||||||
|
threadMessage.inbox_message_id = inboxMessage.id;
|
||||||
await this._updateThreadMessage(threadMessage.id, { inbox_message_id: inboxMessage.id });
|
await this._updateThreadMessage(threadMessage.id, { inbox_message_id: inboxMessage.id });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue