Skip to content

Commit

Permalink
Merge branch 'develop' into chore/remove-method-call
Browse files Browse the repository at this point in the history
  • Loading branch information
ggazzo authored Aug 10, 2022
2 parents 20470cb + 3c1cee7 commit 0e73eab
Show file tree
Hide file tree
Showing 122 changed files with 3,054 additions and 2,378 deletions.
785 changes: 0 additions & 785 deletions .yarn/releases/yarn-3.2.0.cjs

This file was deleted.

783 changes: 783 additions & 0 deletions .yarn/releases/yarn-3.2.2.cjs

Large diffs are not rendered by default.

16 changes: 9 additions & 7 deletions .yarnrc.yml
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
checksumBehavior: update

enableImmutableInstalls: false

nodeLinker: node-modules

plugins:
- path: .yarn/plugins/@yarnpkg/plugin-workspace-tools.cjs
spec: '@yarnpkg/plugin-workspace-tools'
spec: "@yarnpkg/plugin-workspace-tools"
- path: .yarn/plugins/@yarnpkg/plugin-interactive-tools.cjs
spec: '@yarnpkg/plugin-interactive-tools'
spec: "@yarnpkg/plugin-interactive-tools"
- path: .yarn/plugins/@yarnpkg/plugin-engines.cjs
spec: 'https://raw.githubusercontent.com/devoto13/yarn-plugin-engines/main/bundles/%40yarnpkg/plugin-engines.js'
spec: "https://raw.githubusercontent.com/devoto13/yarn-plugin-engines/main/bundles/%40yarnpkg/plugin-engines.js"
- path: .yarn/plugins/@yarnpkg/plugin-typescript.cjs
spec: '@yarnpkg/plugin-typescript'
spec: "@yarnpkg/plugin-typescript"

yarnPath: .yarn/releases/yarn-3.2.0.cjs
checksumBehavior: 'update'
enableImmutableInstalls: false
yarnPath: .yarn/releases/yarn-3.2.2.cjs
7 changes: 6 additions & 1 deletion apps/meteor/.mocharc.client.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,12 @@ Object.assign(

module.exports = {
...base, // see https://github.com/mochajs/mocha/issues/3916
require: [...base.require, './tests/setup/registerWebApiMocks.ts', './tests/setup/cleanupTestingLibrary.ts'],
require: [
...base.require,
'./tests/setup/registerWebApiMocks.ts',
'./tests/setup/hoistedReact.ts',
'./tests/setup/cleanupTestingLibrary.ts',
],
exit: false,
slow: 200,
spec: [
Expand Down
15 changes: 8 additions & 7 deletions apps/meteor/app/apps/client/gameCenter/tabBar.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
import { useMemo } from 'react';
import { useEndpoint } from '@rocket.chat/ui-contexts';
import { useQuery } from '@tanstack/react-query';

import { addAction } from '../../../../client/views/room/lib/Toolbox';
import { useEndpointData } from '../../../../client/hooks/useEndpointData';
import { AsyncStatePhase } from '../../../../client/hooks/useAsyncState';

addAction('game-center', () => {
const { value = { externalComponents: [] }, phase: state, error } = useEndpointData('/apps/externalComponents');
const getExternalComponents = useEndpoint('GET', '/apps/externalComponents');
const result = useQuery(['apps/external-components'], () => getExternalComponents(), {
staleTime: 10_000,
});

const hasExternalComponents = value && value.externalComponents.length > 0;
const hasError = !!error;
return useMemo(
() =>
state === AsyncStatePhase.RESOLVED && !hasError && hasExternalComponents
result.isSuccess && result.data.externalComponents.length > 0
? {
groups: ['channel', 'group', 'direct', 'direct_multiple', 'team'],
id: 'game-center',
Expand All @@ -21,6 +22,6 @@ addAction('game-center', () => {
order: -1,
}
: null,
[hasError, hasExternalComponents, state],
[result.data?.externalComponents.length, result.isSuccess],
);
});
18 changes: 8 additions & 10 deletions apps/meteor/app/livechat/server/api/v1/visitor.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { Meteor } from 'meteor/meteor';
import { Match, check } from 'meteor/check';
import type { ILivechatVisitorDTO, IRoom } from '@rocket.chat/core-typings';
import { LivechatVisitors as VisitorsRaw } from '@rocket.chat/models';
import { LivechatVisitors as VisitorsRaw, LivechatCustomField } from '@rocket.chat/models';

import { LivechatRooms, LivechatCustomField } from '../../../../models/server';
import { LivechatRooms } from '../../../../models/server';
import { API } from '../../../../api/server';
import { findGuest, normalizeHttpHeaderData } from '../lib/livechat';
import { Livechat } from '../../lib/Livechat';
Expand Down Expand Up @@ -40,17 +40,15 @@ API.v1.addRoute('livechat/visitor', {
const visitorId = await Livechat.registerGuest(guest as any); // TODO: Rewrite Livechat to TS

let visitor = await VisitorsRaw.findOneById(visitorId, {});
// If it's updating an existing visitor, it must also update the roomInfo
const cursor = LivechatRooms.findOpenByVisitorToken(visitor?.token);
cursor.forEach((room: IRoom) => {
if (visitor) {
Livechat.saveRoomInfo(room, visitor);
}
});
if (visitor) {
// If it's updating an existing visitor, it must also update the roomInfo
const rooms = LivechatRooms.findOpenByVisitorToken(visitor?.token).fetch();
await Promise.all(rooms.map((room: IRoom) => Livechat.saveRoomInfo(room, visitor)));
}

if (customFields && customFields instanceof Array) {
customFields.forEach((field) => {
const customField = LivechatCustomField.findOneById(field.key);
const customField = Promise.await(LivechatCustomField.findOneById(field.key));
if (!customField) {
return;
}
Expand Down
10 changes: 5 additions & 5 deletions apps/meteor/app/livechat/server/lib/Contacts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ import { check } from 'meteor/check';
import { Meteor } from 'meteor/meteor';
import s from 'underscore.string';
import type { MatchKeysAndValues, OnlyFieldsOfType } from 'mongodb';
import { LivechatVisitors, Users, LivechatRooms } from '@rocket.chat/models';
import { LivechatVisitors, Users, LivechatRooms, LivechatCustomField } from '@rocket.chat/models';
import type { ILivechatCustomField, ILivechatVisitor, IOmnichannelRoom } from '@rocket.chat/core-typings';

import { LivechatCustomField, Rooms, LivechatInquiry, Subscriptions } from '../../../models/server';
import { Rooms, LivechatInquiry, Subscriptions } from '../../../models/server';

type RegisterContactProps = {
_id?: string;
Expand Down Expand Up @@ -71,9 +71,9 @@ export const Contacts = {
}
}

const allowedCF: ILivechatCustomField['_id'][] = LivechatCustomField.find({ scope: 'visitor' }, { fields: { _id: 1 } }).map(
({ _id }: ILivechatCustomField) => _id,
);
const allowedCF = await LivechatCustomField.findByScope<Pick<ILivechatCustomField, '_id'>>('visitor', { projection: { _id: 1 } })
.map(({ _id }) => _id)
.toArray();

const livechatData = Object.keys(customFields)
.filter((key) => allowedCF.includes(key) && customFields[key] !== '' && customFields[key] !== undefined)
Expand Down
19 changes: 9 additions & 10 deletions apps/meteor/app/livechat/server/lib/Livechat.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import _ from 'underscore';
import s from 'underscore.string';
import moment from 'moment-timezone';
import UAParser from 'ua-parser-js';
import { Users as UsersRaw, LivechatVisitors, Settings } from '@rocket.chat/models';
import { Users as UsersRaw, LivechatVisitors, LivechatCustomField, Settings } from '@rocket.chat/models';

import { QueueManager } from './QueueManager';
import { RoutingManager } from './RoutingManager';
Expand All @@ -25,7 +25,6 @@ import {
Rooms,
LivechatDepartmentAgents,
LivechatDepartment,
LivechatCustomField,
LivechatInquiry,
} from '../../../models/server';
import { Logger } from '../../../logger/server';
Expand Down Expand Up @@ -392,10 +391,10 @@ export const Livechat = {
}

const customFields = {};
const fields = LivechatCustomField.find({ scope: 'visitor' });

if (!userId || hasPermission(userId, 'edit-livechat-room-customfields')) {
fields.forEach((field) => {
const fields = LivechatCustomField.findByScope('visitor');
for await (const field of fields) {
if (!livechatData.hasOwnProperty(field._id)) {
return;
}
Expand All @@ -407,7 +406,7 @@ export const Livechat = {
}
}
customFields[field._id] = value;
});
}
updateData.livechatData = customFields;
}
const ret = await LivechatVisitors.saveGuestById(_id, updateData);
Expand Down Expand Up @@ -512,7 +511,7 @@ export const Livechat = {
check(overwrite, Boolean);
Livechat.logger.debug(`Setting custom fields data for visitor with token ${token}`);

const customField = LivechatCustomField.findOneById(key);
const customField = await LivechatCustomField.findOneById(key);
if (!customField) {
throw new Meteor.Error('invalid-custom-field');
}
Expand Down Expand Up @@ -580,14 +579,14 @@ export const Livechat = {
return rcSettings;
},

saveRoomInfo(roomData, guestData, userId) {
async saveRoomInfo(roomData, guestData, userId) {
Livechat.logger.debug(`Saving room information on room ${roomData._id}`);
const { livechatData = {} } = roomData;
const customFields = {};

if (!userId || hasPermission(userId, 'edit-livechat-room-customfields')) {
const fields = LivechatCustomField.find({ scope: 'room' });
fields.forEach((field) => {
const fields = LivechatCustomField.findByScope('room');
for await (const field of fields) {
if (!livechatData.hasOwnProperty(field._id)) {
return;
}
Expand All @@ -599,7 +598,7 @@ export const Livechat = {
}
}
customFields[field._id] = value;
});
}
roomData.livechatData = customFields;
}

Expand Down
7 changes: 3 additions & 4 deletions apps/meteor/app/livechat/server/methods/getCustomFields.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import { Meteor } from 'meteor/meteor';

import { LivechatCustomField } from '../../../models/server';
import { LivechatCustomField } from '@rocket.chat/models';

Meteor.methods({
'livechat:getCustomFields'() {
return LivechatCustomField.find().fetch();
async 'livechat:getCustomFields'() {
return LivechatCustomField.find().toArray();
},
});
6 changes: 2 additions & 4 deletions apps/meteor/app/livechat/server/methods/registerGuest.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,8 @@ Meteor.methods({
});

// If it's updating an existing visitor, it must also update the roomInfo
const cursor = LivechatRooms.findOpenByVisitorToken(token);
cursor.forEach((room) => {
Livechat.saveRoomInfo(room, visitor);
});
const rooms = LivechatRooms.findOpenByVisitorToken(token).fetch();
await Promise.all(rooms.map((room) => Livechat.saveRoomInfo(room, visitor)));

if (customFields && customFields instanceof Array) {
// TODO: refactor to use normal await
Expand Down
9 changes: 4 additions & 5 deletions apps/meteor/app/livechat/server/methods/removeCustomField.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { Meteor } from 'meteor/meteor';
import { check } from 'meteor/check';
import { LivechatCustomField } from '@rocket.chat/models';

import { hasPermission } from '../../../authorization';
import { LivechatCustomField } from '../../../models/server';
import { hasPermission } from '../../../authorization/server';

Meteor.methods({
'livechat:removeCustomField'(_id) {
async 'livechat:removeCustomField'(_id) {
if (!Meteor.userId() || !hasPermission(Meteor.userId(), 'view-livechat-manager')) {
throw new Meteor.Error('error-not-allowed', 'Not allowed', {
method: 'livechat:removeCustomField',
Expand All @@ -14,8 +14,7 @@ Meteor.methods({

check(_id, String);

const customField = LivechatCustomField.findOneById(_id, { fields: { _id: 1 } });

const customField = await LivechatCustomField.findOneById(_id, { projection: { _id: 1 } });
if (!customField) {
throw new Meteor.Error('error-invalid-custom-field', 'Custom field not found', {
method: 'livechat:removeCustomField',
Expand Down
10 changes: 5 additions & 5 deletions apps/meteor/app/livechat/server/methods/saveCustomField.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { Meteor } from 'meteor/meteor';
import { Match, check } from 'meteor/check';
import { LivechatCustomField } from '@rocket.chat/models';

import { hasPermission } from '../../../authorization';
import { LivechatCustomField } from '../../../models/server';
import { hasPermission } from '../../../authorization/server';

Meteor.methods({
'livechat:saveCustomField'(_id, customFieldData) {
async 'livechat:saveCustomField'(_id, customFieldData) {
if (!Meteor.userId() || !hasPermission(Meteor.userId(), 'view-livechat-manager')) {
throw new Meteor.Error('error-not-allowed', 'Not allowed', {
method: 'livechat:saveCustomField',
Expand Down Expand Up @@ -36,7 +36,7 @@ Meteor.methods({
}

if (_id) {
const customField = LivechatCustomField.findOneById(_id);
const customField = await LivechatCustomField.findOneById(_id);
if (!customField) {
throw new Meteor.Error('error-invalid-custom-field', 'Custom Field Not found', {
method: 'livechat:saveCustomField',
Expand All @@ -45,7 +45,7 @@ Meteor.methods({
}

if (!_id) {
const customField = LivechatCustomField.findOneById(customFieldData.field);
const customField = await LivechatCustomField.findOneById(customFieldData.field);
if (customField) {
throw new Meteor.Error('error-custom-field-name-already-exists', 'Custom field name already exists', {
method: 'livechat:saveCustomField',
Expand Down
2 changes: 1 addition & 1 deletion apps/meteor/app/livechat/server/methods/saveInfo.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ Meteor.methods({
delete guestData.phone;
}

const ret = (await Livechat.saveGuest(guestData, userId)) && Livechat.saveRoomInfo(roomData, guestData, userId);
const ret = (await Livechat.saveGuest(guestData, userId)) && (await Livechat.saveRoomInfo(roomData, guestData, userId));

const user = Meteor.users.findOne({ _id: userId }, { fields: { _id: 1, username: 1 } });

Expand Down
6 changes: 3 additions & 3 deletions apps/meteor/app/livechat/server/methods/setCustomField.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { Meteor } from 'meteor/meteor';
import { LivechatVisitors } from '@rocket.chat/models';
import { LivechatVisitors, LivechatCustomField } from '@rocket.chat/models';

import { LivechatRooms, LivechatCustomField } from '../../../models/server';
import { LivechatRooms } from '../../../models/server';

Meteor.methods({
async 'livechat:setCustomField'(token, key, value, overwrite = true) {
const customField = LivechatCustomField.findOneById(key);
const customField = await LivechatCustomField.findOneById(key);
if (customField) {
if (customField.scope === 'room') {
return LivechatRooms.updateDataByToken(token, key, value, overwrite);
Expand Down
2 changes: 0 additions & 2 deletions apps/meteor/app/models/server/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import Rooms from './models/Rooms';
import Subscriptions from './models/Subscriptions';
import Users from './models/Users';
import Imports from './models/Imports';
import LivechatCustomField from './models/LivechatCustomField';
import LivechatDepartment from './models/LivechatDepartment';
import LivechatDepartmentAgents from './models/LivechatDepartmentAgents';
import LivechatRooms from './models/LivechatRooms';
Expand All @@ -27,7 +26,6 @@ export {
Subscriptions,
Users,
Imports,
LivechatCustomField,
LivechatDepartment,
LivechatDepartmentAgents,
LivechatRooms,
Expand Down
49 changes: 0 additions & 49 deletions apps/meteor/app/models/server/models/LivechatCustomField.js

This file was deleted.

Loading

0 comments on commit 0e73eab

Please sign in to comment.