-
Notifications
You must be signed in to change notification settings - Fork 13.7k
feat: Adds setting to ignore automatic messages on metrics #34274
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
Merged
Changes from 22 commits
Commits
Show all changes
30 commits
Select commit
Hold shift + click to select a range
4d837ad
feat: adds new setting to ignore automatic messages
lucas-a-pelegrino 90852de
feat: adds logic to skip metrics for automatic messages
lucas-a-pelegrino 6fe8e5b
Merge branch 'develop' into CORE-668
lucas-a-pelegrino 2bb55d2
refactor: improves logic for isMessageFromBot method
lucas-a-pelegrino ed8facd
tests: adds unit test for isMessageFromBot method
lucas-a-pelegrino e0fff07
refactor: inverts order of if statement validation to avoid unnecessa…
lucas-a-pelegrino 3d1a785
refactor: adds validation for null returns from Users.findOneById
lucas-a-pelegrino 15f46d1
test: adds e2e test to validate bot messages are ignored when setting…
lucas-a-pelegrino 6eb89ab
test: adds unit test to check for setting and bot message on markRoom…
lucas-a-pelegrino b45e411
fix: merge conflicts en.i18n.json
lucas-a-pelegrino 8139644
Merge branch 'develop' of github.com:RocketChat/Rocket.Chat into CORE…
lucas-a-pelegrino 297a649
test: fixes e2e and unit tests
lucas-a-pelegrino b47ad58
test: fixes mocks used in the unit tests
lucas-a-pelegrino 1f77cd8
docs: adds changeset
lucas-a-pelegrino 67ee91f
chore: updates number of total conversations testing
lucas-a-pelegrino 2bb0522
Merge branch 'CORE-668' of github.com:RocketChat/Rocket.Chat into COR…
lucas-a-pelegrino 3ef8969
tests: fixes setting logic at saveAnalyticsData
lucas-a-pelegrino 9fe3e3b
fix: updates Open_conversations expected values
lucas-a-pelegrino 0857b09
Merge branch 'develop' of github.com:RocketChat/Rocket.Chat into CORE…
lucas-a-pelegrino cfc9ddb
fix: updates Conversations_per_day value
lucas-a-pelegrino 58158b0
chore: updates en.i18n with setting label
lucas-a-pelegrino 1d4bfbb
Merge branch 'develop' into CORE-668
lucas-a-pelegrino c70ec88
chore: updates .changeset/funny-turtles-hunt.md
lucas-a-pelegrino bc84edf
fix: readds labels mistakenly removed
lucas-a-pelegrino 803da66
fix: readds labels mistakenly removed
lucas-a-pelegrino 6089fee
Merge branch 'CORE-668' of github.com:RocketChat/Rocket.Chat into COR…
lucas-a-pelegrino 10abc1a
refactor: moves setting update to before/after tests
lucas-a-pelegrino 4221773
refactor: replaces Users.findOne for Users.isUserInRole
lucas-a-pelegrino 741c929
Merge branch 'develop' into CORE-668
kodiakhq[bot] 20e4ecd
Merge branch 'develop' into CORE-668
kodiakhq[bot] File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| --- | ||
| "@rocket.chat/meteor": patch | ||
| "@rocket.chat/i18n": patch | ||
| --- | ||
|
|
||
| Adds a new setting that if enabled, will not count bot messages in the average response time metrics | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| import type { IMessage, IUser } from '@rocket.chat/core-typings'; | ||
| import { Users } from '@rocket.chat/models'; | ||
|
|
||
| export async function isMessageFromBot(message: IMessage): Promise<boolean> { | ||
|
MarcosSpessatto marked this conversation as resolved.
|
||
| const user = await Users.findOneById<Pick<IUser, 'roles'>>(message.u._id, { projection: { roles: 1 } }); | ||
|
|
||
| if (!user) { | ||
| throw new Error('User not found'); | ||
| } | ||
|
|
||
| return !!user.roles.includes('bot'); | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 43 additions & 0 deletions
43
apps/meteor/tests/unit/app/livechat/server/lib/isMessageFromBot.spec.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,43 @@ | ||
| import { expect } from 'chai'; | ||
| import p from 'proxyquire'; | ||
| import sinon from 'sinon'; | ||
|
|
||
| import { createFakeMessage, createFakeUser } from '../../../../../mocks/data'; | ||
|
|
||
| const modelsMock = { | ||
| Users: { | ||
| findOneById: sinon.stub(), | ||
| }, | ||
| }; | ||
|
|
||
| const { isMessageFromBot } = p.noCallThru().load('../../../../../../app/livechat/server/lib/isMessageFromBot', { | ||
| '@rocket.chat/models': modelsMock, | ||
| }); | ||
|
|
||
| describe('isMessageFromBot', () => { | ||
|
lucas-a-pelegrino marked this conversation as resolved.
|
||
| const mockUser = createFakeUser({ roles: ['bot'] }); | ||
| const mockMessage = createFakeMessage(); | ||
|
|
||
| beforeEach(() => { | ||
| modelsMock.Users.findOneById.reset(); | ||
| }); | ||
|
|
||
| it('Should return true if user has bot role', async () => { | ||
| modelsMock.Users.findOneById.resolves(mockUser); | ||
| const result = await isMessageFromBot(mockMessage); | ||
| expect(result).to.be.true; | ||
| }); | ||
|
|
||
| it('Should return false if user does not have bot role', async () => { | ||
| mockUser.roles = ['user']; | ||
| modelsMock.Users.findOneById.resolves(mockUser); | ||
| const result = await isMessageFromBot(mockMessage); | ||
| expect(result).to.be.false; | ||
| }); | ||
|
|
||
| it('Should throw error when user is not found', async () => { | ||
| modelsMock.Users.findOneById.resolves(null); | ||
|
|
||
| await expect(isMessageFromBot(mockMessage)).to.be.rejectedWith(Error, 'User not found'); | ||
| }); | ||
| }); | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.