-
Notifications
You must be signed in to change notification settings - Fork 10.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
refactor: move system message calls from sendMessage to saveSystemMessage #32842
refactor: move system message calls from sendMessage to saveSystemMessage #32842
Conversation
Looks like this PR is not ready to merge, because of the following issues:
Please fix the issues and try again If you have any trouble, please check the PR guidelines |
|
77e3364
to
7d6f676
Compare
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## develop #32842 +/- ##
===========================================
- Coverage 59.40% 59.40% -0.01%
===========================================
Files 2541 2541
Lines 63176 63171 -5
Branches 14220 14218 -2
===========================================
- Hits 37527 37524 -3
+ Misses 22934 22933 -1
+ Partials 2715 2714 -1
Flags with carried forward coverage won't be shown. Click here to find out more. |
12dabab
to
f95aca7
Compare
// TODO: replace with `Message.saveSystemMessage` | ||
|
||
await sendMessage(guest, { t: 'livechat-started', msg: '', groupable: false, token: guest.token }, room); | ||
await Message.saveSystemMessageAndNotifyUser('livechat-started', rid, '', { _id, username }, { groupable: false }); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
looks like you removed token
for some reason.. I'm suggesting removing groupable
since saveSystemMessageAndNotifyUser
already adds it
await Message.saveSystemMessageAndNotifyUser('livechat-started', rid, '', { _id, username }, { groupable: false }); | |
await Message.saveSystemMessageAndNotifyUser('livechat-started', rid, '', { _id, username }, { token: guest.token }); |
await Message.saveSystemMessageAndNotifyUser('livechat-close', rid, comment ?? '', closeData.closedBy, { | ||
groupable: false, | ||
transcriptRequested, | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
await Message.saveSystemMessageAndNotifyUser('livechat-close', rid, comment ?? '', closeData.closedBy, { | |
groupable: false, | |
transcriptRequested, | |
}); | |
await Message.saveSystemMessageAndNotifyUser('livechat-close', rid, comment ?? '', closeData.closedBy, { | |
transcriptRequested, | |
...(isRoomClosedByVisitorParams(params) && { token: chatCloser.token }), | |
}); |
t: 'livechat_transfer_history', | ||
rid: room._id, | ||
ts: new Date(), | ||
msg: '', | ||
u: { | ||
_id, | ||
username, | ||
}, | ||
...(transferData.transferredBy.userType === 'visitor' && { token: room.v.token }), | ||
groupable: false, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
all these properties are already set inside of saveSystemMessageAndNotifyUser
so we don't need to pass them
t: 'livechat_transfer_history', | |
rid: room._id, | |
ts: new Date(), | |
msg: '', | |
u: { | |
_id, | |
username, | |
}, | |
...(transferData.transferredBy.userType === 'visitor' && { token: room.v.token }), | |
groupable: false, | |
...(transferData.transferredBy.userType === 'visitor' && { token: room.v.token }), |
throw new Error('Failed to find the created message.'); | ||
} | ||
|
||
void notifyOnMessageChange({ id: createdMessage._id }); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
since you just fetched the inserted message, we can optimize by passing the data to notifyOnMessageChange
otherwise it will fetch it from DB again
void notifyOnMessageChange({ id: createdMessage._id }); | |
void notifyOnMessageChange({ id: createdMessage._id, data: createdMessage }); |
…sage (#32842) Co-authored-by: Guilherme Gazzo <[email protected]>
As per OPI-19, some use cases that send internal live chat messages have been updated. These messages now use the
saveSystemMessage
method instead ofsendMessage
. This change maintains the same outcome but bypasses certain validations that increase execution time.We believe these validations are unnecessary since internal messages are typically predefined (often hardcoded) and do not violate server message rules.