Skip to content

Commit

Permalink
Merge branch 'RocketChat:develop' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
intVivek authored Sep 8, 2023
2 parents 525a2e0 + ee3815f commit b3fc116
Show file tree
Hide file tree
Showing 80 changed files with 1,295 additions and 621 deletions.
5 changes: 5 additions & 0 deletions .changeset/breezy-bugs-jam.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@rocket.chat/meteor": patch
---

fix: Managers allowed to make deactivated agent's available
5 changes: 5 additions & 0 deletions .changeset/four-parents-cheer.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@rocket.chat/meteor": patch
---

load sounds right before playing them
5 changes: 5 additions & 0 deletions .changeset/gold-moose-press.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@rocket.chat/meteor': patch
---

Fix moment timestamps language change
6 changes: 6 additions & 0 deletions .changeset/importer-progress-bar.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@rocket.chat/meteor": patch
---

Fixed Importer Progress Bar progress indicator

5 changes: 5 additions & 0 deletions .changeset/lucky-balloons-divide.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@rocket.chat/meteor": patch
---

Fix engagement dashboard not showing data
5 changes: 5 additions & 0 deletions .changeset/odd-elephants-promise.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@rocket.chat/meteor": patch
---

Fix LinkedIn OAuth broken
6 changes: 6 additions & 0 deletions .changeset/seven-jobs-tickle.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@rocket.chat/meteor": patch
"@rocket.chat/model-typings": patch
---

fix: agent role being removed upon user deactivation
5 changes: 5 additions & 0 deletions .changeset/three-birds-tickle.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@rocket.chat/meteor": patch
---

chore: Increase cache time from 5s to 10s on `getUnits` helpers. This should reduce the number of DB calls made by this method to fetch the unit limitations for a user.
7 changes: 7 additions & 0 deletions .changeset/tough-candles-heal.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
"@rocket.chat/meteor": patch
"@rocket.chat/core-typings": patch
"@rocket.chat/model-typings": patch
---

Fixes a problem where the calculated time for considering the visitor abandonment was the first message from the visitor and not the visitor's reply to the agent.
6 changes: 6 additions & 0 deletions .changeset/yellow-buttons-agree.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'@rocket.chat/ui-client': minor
'@rocket.chat/meteor': minor
---

feat: add ChangePassword field to Account/Security
3 changes: 3 additions & 0 deletions .github/workflows/ci-test-e2e.yml
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ on:
required: false
REPORTER_ROCKETCHAT_API_KEY:
required: false
CODECOV_TOKEN:
required: false

env:
MONGO_URL: mongodb://localhost:27017/rocketchat?replicaSet=rs0&directConnection=true
Expand Down Expand Up @@ -237,6 +239,7 @@ jobs:
directory: ./apps/meteor
flags: e2e
verbose: true
token: ${{ secrets.CODECOV_TOKEN }}

- name: Store e2e-ee-coverage
if: inputs.type == 'ui' && inputs.release == 'ee'
Expand Down
4 changes: 4 additions & 0 deletions .github/workflows/ci-test-unit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ on:
node-version:
required: true
type: string
secrets:
CODECOV_TOKEN:
required: false

env:
MONGO_URL: mongodb://localhost:27017/rocketchat?replicaSet=rs0&directConnection=true
Expand Down Expand Up @@ -36,3 +39,4 @@ jobs:
with:
flags: unit
verbose: true
token: ${{ secrets.CODECOV_TOKEN }}
3 changes: 3 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -337,6 +337,8 @@ jobs:
uses: ./.github/workflows/ci-test-unit.yml
with:
node-version: ${{ needs.release-versions.outputs.node-version }}
secrets:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}

test-api:
name: 🔨 Test API (CE)
Expand Down Expand Up @@ -431,6 +433,7 @@ jobs:
QASE_API_TOKEN: ${{ secrets.QASE_API_TOKEN }}
REPORTER_ROCKETCHAT_API_KEY: ${{ secrets.REPORTER_ROCKETCHAT_API_KEY }}
REPORTER_ROCKETCHAT_URL: ${{ secrets.REPORTER_ROCKETCHAT_URL }}
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}

tests-done:
name: ✅ Tests Done
Expand Down
2 changes: 1 addition & 1 deletion apps/meteor/app/custom-sounds/client/lib/CustomSounds.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class CustomSoundsClass {

const audio = document.createElement('audio');
audio.id = getCustomSoundId(sound._id);
audio.preload = 'auto';
audio.preload = 'none';
audio.appendChild(source);

document.body.appendChild(audio);
Expand Down
2 changes: 1 addition & 1 deletion apps/meteor/app/lib/server/startup/oAuthServicesUpdate.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ async function _OAuthServicesUpdate() {

if (serviceName === 'Linkedin') {
data.clientConfig = {
requestPermissions: ['r_liteprofile', 'r_emailaddress'],
requestPermissions: ['openid', 'email', 'profile'],
};
}

Expand Down
7 changes: 6 additions & 1 deletion apps/meteor/app/livechat/server/api/v1/agent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,16 +73,21 @@ API.v1.addRoute(

const agentId = inputAgentId || this.userId;

const agent = await Users.findOneAgentById<Pick<ILivechatAgent, 'status' | 'statusLivechat'>>(agentId, {
const agent = await Users.findOneAgentById<Pick<ILivechatAgent, 'status' | 'statusLivechat' | 'active'>>(agentId, {
projection: {
status: 1,
statusLivechat: 1,
active: 1,
},
});
if (!agent) {
return API.v1.notFound('Agent not found');
}

if (!agent.active) {
return API.v1.failure('error-user-deactivated');
}

const newStatus: ILivechatAgentStatus =
status ||
(agent.statusLivechat === ILivechatAgentStatus.AVAILABLE ? ILivechatAgentStatus.NOT_AVAILABLE : ILivechatAgentStatus.AVAILABLE);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
import { ILivechatAgentStatus } from '@rocket.chat/core-typings';
import type { ILivechatBusinessHour, ILivechatDepartment } from '@rocket.chat/core-typings';
import type { ILivechatAgentStatus, ILivechatBusinessHour, ILivechatDepartment } from '@rocket.chat/core-typings';
import type { ILivechatBusinessHoursModel, IUsersModel } from '@rocket.chat/model-typings';
import { LivechatBusinessHours, Users } from '@rocket.chat/models';
import moment from 'moment-timezone';
import type { UpdateFilter } from 'mongodb';

import type { IWorkHoursCronJobsWrapper } from '../../../../server/models/raw/LivechatBusinessHours';
import { businessHourLogger } from '../lib/logger';
import { filterBusinessHoursThatMustBeOpened } from './Helper';

export interface IBusinessHourBehavior {
findHoursToCreateJobs(): Promise<IWorkHoursCronJobsWrapper[]>;
Expand Down Expand Up @@ -61,29 +58,6 @@ export abstract class AbstractBusinessHourBehavior {
{ livechatStatusSystemModified: true },
);
}

async onNewAgentCreated(agentId: string): Promise<void> {
businessHourLogger.debug(`Executing onNewAgentCreated for agentId: ${agentId}`);

const defaultBusinessHour = await LivechatBusinessHours.findOneDefaultBusinessHour();
if (!defaultBusinessHour) {
businessHourLogger.debug(`No default business hour found for agentId: ${agentId}`);
return;
}

const businessHourToOpen = await filterBusinessHoursThatMustBeOpened([defaultBusinessHour]);
if (!businessHourToOpen.length) {
businessHourLogger.debug(
`No business hour to open found for agentId: ${agentId}. Default business hour is closed. Setting agentId: ${agentId} to status: ${ILivechatAgentStatus.NOT_AVAILABLE}`,
);
await Users.setLivechatStatus(agentId, ILivechatAgentStatus.NOT_AVAILABLE);
return;
}

await Users.addBusinessHourByAgentIds([agentId], defaultBusinessHour._id);

businessHourLogger.debug(`Setting agentId: ${agentId} to status: ${ILivechatAgentStatus.AVAILABLE}`);
}
}

export abstract class AbstractBusinessHourType {
Expand Down
34 changes: 32 additions & 2 deletions apps/meteor/app/livechat/server/business-hour/Single.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import { LivechatBusinessHourTypes } from '@rocket.chat/core-typings';
import { ILivechatAgentStatus, LivechatBusinessHourTypes } from '@rocket.chat/core-typings';
import { LivechatBusinessHours, Users } from '@rocket.chat/models';

import { businessHourLogger } from '../lib/logger';
import type { IBusinessHourBehavior } from './AbstractBusinessHour';
import { AbstractBusinessHourBehavior } from './AbstractBusinessHour';
import { openBusinessHourDefault } from './Helper';
import { filterBusinessHoursThatMustBeOpened, openBusinessHourDefault } from './Helper';

export class SingleBusinessHourBehavior extends AbstractBusinessHourBehavior implements IBusinessHourBehavior {
async openBusinessHoursByDayAndHour(): Promise<void> {
Expand All @@ -26,6 +27,35 @@ export class SingleBusinessHourBehavior extends AbstractBusinessHourBehavior imp
return openBusinessHourDefault();
}

async onNewAgentCreated(agentId: string): Promise<void> {
const defaultBusinessHour = await LivechatBusinessHours.findOneDefaultBusinessHour();
if (!defaultBusinessHour) {
businessHourLogger.debug('No default business hour found for agentId', {
agentId,
});
return;
}

const businessHourToOpen = await filterBusinessHoursThatMustBeOpened([defaultBusinessHour]);
if (!businessHourToOpen.length) {
businessHourLogger.debug({
msg: 'No business hours found. Moving agent to NOT_AVAILABLE status',
agentId,
newStatus: ILivechatAgentStatus.NOT_AVAILABLE,
});
await Users.setLivechatStatus(agentId, ILivechatAgentStatus.NOT_AVAILABLE);
return;
}

await Users.addBusinessHourByAgentIds([agentId], defaultBusinessHour._id);

businessHourLogger.debug({
msg: 'Business hours found. Moving agent to AVAILABLE status',
agentId,
newStatus: ILivechatAgentStatus.AVAILABLE,
});
}

afterSaveBusinessHours(): Promise<void> {
return openBusinessHourDefault();
}
Expand Down
10 changes: 7 additions & 3 deletions apps/meteor/app/livechat/server/hooks/afterUserActions.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import type { IUser } from '@rocket.chat/core-typings';
import { type IUser } from '@rocket.chat/core-typings';
import { Users } from '@rocket.chat/models';

import { callbacks } from '../../../../lib/callbacks';
import { Livechat } from '../lib/Livechat';
Expand Down Expand Up @@ -33,8 +34,11 @@ const handleAgentCreated = async (user: IUser) => {

const handleDeactivateUser = async (user: IUser) => {
if (wasAgent(user)) {
callbackLogger.debug('Removing agent', user._id);
await Livechat.removeAgent(user.username);
callbackLogger.debug({
msg: 'Removing agent extension & making agent unavailable',
userId: user._id,
});
await Users.makeAgentUnavailableAndUnsetExtension(user._id);
}
};

Expand Down
36 changes: 24 additions & 12 deletions apps/meteor/app/livechat/server/hooks/markRoomResponded.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import type { IOmnichannelRoom } from '@rocket.chat/core-typings';
import { isOmnichannelRoom, isEditedMessage } from '@rocket.chat/core-typings';
import { LivechatRooms } from '@rocket.chat/models';

Expand All @@ -15,28 +16,39 @@ callbacks.add(
return message;
}

// skips this callback if the message is a system message
if (message.t) {
return message;
}

// if the message has a token, it was sent by the visitor, so ignore it
if (message.token) {
return message;
}
if (room.responseBy) {
await LivechatRooms.setAgentLastMessageTs(room._id);
}

// check if room is yet awaiting for response
if (!(typeof room.t !== 'undefined' && room.t === 'l' && room.waitingResponse)) {
// check if room is yet awaiting for response from visitor
if (!room.waitingResponse) {
// case where agent sends second message or any subsequent message in a room before visitor responds to the first message
// in this case, we just need to update the lastMessageTs of the responseBy object
if (room.responseBy) {
await LivechatRooms.setAgentLastMessageTs(room._id);
}
return message;
}

await LivechatRooms.setResponseByRoomId(room._id, {
user: {
_id: message.u._id,
username: message.u.username,
},
});
// This is the first message from agent after visitor had last responded
const responseBy: IOmnichannelRoom['responseBy'] = room.responseBy || {
_id: message.u._id,
username: message.u.username,
firstResponseTs: new Date(message.ts),
lastMessageTs: new Date(message.ts),
};

// this unsets waitingResponse and sets responseBy object
await LivechatRooms.setResponseByRoomId(room._id, responseBy);

return message;
},
callbacks.priority.LOW,
callbacks.priority.HIGH,
'markRoomResponded',
);
2 changes: 1 addition & 1 deletion apps/meteor/app/statistics/server/lib/SAUMonitor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ export class SAUMonitorClass {
constructor() {
this._started = false;
this._dailyComputeJobName = 'aggregate-sessions';
this._dailyFinishSessionsJobName = 'aggregate-sessions';
this._dailyFinishSessionsJobName = 'finish-sessions';
}

async start(): Promise<void> {
Expand Down
2 changes: 2 additions & 0 deletions apps/meteor/client/components/GazzodownText.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ const GazzodownText = ({ mentions, channels, searchText, children }: GazzodownTe
const useEmoji = Boolean(useUserPreference('useEmojis'));
const useRealName = Boolean(useSetting('UI_Use_Real_Name'));
const ownUserId = useUserId();
const showMentionSymbol = Boolean(useUserPreference<boolean>('mentionsWithSymbol'));

const chat = useChat();

Expand Down Expand Up @@ -122,6 +123,7 @@ const GazzodownText = ({ mentions, channels, searchText, children }: GazzodownTe
useRealName,
isMobile,
ownUserId,
showMentionSymbol,
}}
>
{children}
Expand Down
1 change: 1 addition & 0 deletions apps/meteor/client/providers/TranslationProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,7 @@ const TranslationProvider = ({ children }: TranslationProviderProps): ReactEleme

useEffect(() => {
if (moment.locales().includes(language.toLowerCase())) {
moment.locale(language);
return;
}

Expand Down
3 changes: 2 additions & 1 deletion apps/meteor/client/providers/UserProvider/UserProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,8 @@ const UserProvider = ({ children }: UserProviderProps): ReactElement => {

const setUserPreferences = useEndpoint('POST', '/v1/users.setPreferences');

useCreateFontStyleElement(user?.settings?.preferences?.fontSize);
const createFontStyleElement = useCreateFontStyleElement();
createFontStyleElement(user?.settings?.preferences?.fontSize);

const loginMethod: LoginMethods = (isLdapEnabled && 'loginWithLDAP') || (isCrowdEnabled && 'loginWithCrowd') || 'loginWithPassword';

Expand Down
Loading

0 comments on commit b3fc116

Please sign in to comment.