Skip to content
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

Merged
merged 14 commits into from
Aug 19, 2024

Conversation

ricardogarim
Copy link
Contributor

@ricardogarim ricardogarim commented Jul 19, 2024

As per OPI-19, some use cases that send internal live chat messages have been updated. These messages now use the saveSystemMessage method instead of sendMessage. 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.

Copy link
Contributor

dionisio-bot bot commented Jul 19, 2024

Looks like this PR is not ready to merge, because of the following issues:

  • This PR is missing the 'stat: QA assured' label

Please fix the issues and try again

If you have any trouble, please check the PR guidelines

Copy link

changeset-bot bot commented Jul 19, 2024

⚠️ No Changeset found

Latest commit: 42645fc

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@ricardogarim ricardogarim force-pushed the refactor/unify-livechat-system-message-calls branch from 77e3364 to 7d6f676 Compare July 19, 2024 02:27
Copy link

codecov bot commented Jul 19, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 59.40%. Comparing base (bbdff10) to head (42645fc).
Report is 2 commits behind head on develop.

Additional details and impacted files

Impacted file tree graph

@@             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     
Flag Coverage Δ
unit 76.02% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

@ricardogarim ricardogarim marked this pull request as ready for review July 22, 2024 11:38
@ricardogarim ricardogarim requested review from a team as code owners July 22, 2024 11:38
@ricardogarim ricardogarim requested a review from a team as a code owner July 23, 2024 01:46
@ricardogarim ricardogarim modified the milestones: 6.11, 6.12 Jul 23, 2024
@ricardogarim ricardogarim marked this pull request as draft July 29, 2024 02:36
@ricardogarim ricardogarim force-pushed the refactor/unify-livechat-system-message-calls branch from 12dabab to f95aca7 Compare July 29, 2024 02:40
@ricardogarim ricardogarim marked this pull request as ready for review August 15, 2024 00:22
@ricardogarim ricardogarim requested a review from a team August 15, 2024 00:23
// 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 });
Copy link
Member

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

Suggested change
await Message.saveSystemMessageAndNotifyUser('livechat-started', rid, '', { _id, username }, { groupable: false });
await Message.saveSystemMessageAndNotifyUser('livechat-started', rid, '', { _id, username }, { token: guest.token });

Comment on lines 307 to 310
await Message.saveSystemMessageAndNotifyUser('livechat-close', rid, comment ?? '', closeData.closedBy, {
groupable: false,
transcriptRequested,
});
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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 }),
});

Comment on lines 1246 to 1255
t: 'livechat_transfer_history',
rid: room._id,
ts: new Date(),
msg: '',
u: {
_id,
username,
},
...(transferData.transferredBy.userType === 'visitor' && { token: room.v.token }),
groupable: false,
Copy link
Member

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

Suggested change
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 });
Copy link
Member

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

Suggested change
void notifyOnMessageChange({ id: createdMessage._id });
void notifyOnMessageChange({ id: createdMessage._id, data: createdMessage });

@ggazzo ggazzo merged commit 8162986 into develop Aug 19, 2024
48 checks passed
@ggazzo ggazzo deleted the refactor/unify-livechat-system-message-calls branch August 19, 2024 13:32
abhinavkrin pushed a commit that referenced this pull request Oct 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants