Skip to content

Commit

Permalink
Merge branch 'develop' into improve/videoconf-first-phase
Browse files Browse the repository at this point in the history
  • Loading branch information
dougfabris committed Jul 19, 2022
2 parents 22ed6e9 + 67318f1 commit a437539
Show file tree
Hide file tree
Showing 93 changed files with 2,423 additions and 3,854 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/build_and_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -370,7 +370,7 @@ jobs:
done
cd ./apps/meteor
npm run test:playwright
npm run test:e2e
- name: Store playwright test trace
uses: actions/upload-artifact@v2
Expand Down Expand Up @@ -683,7 +683,7 @@ jobs:
docker logs presence --tail=50
cd ./apps/meteor
IS_EE=true npm run test:playwright
IS_EE=true npm run test:e2e
- name: Store playwright test trace
uses: actions/upload-artifact@v2
Expand Down
1 change: 0 additions & 1 deletion apps/meteor/.eslintignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ data/
tests/e2e/test-failures/
packages/autoupdate/
packages/meteor-streams/
packages/meteor-timesync/
app/emoji-emojione/generateEmojiIndex.js
packages/rocketchat-livechat/assets/rocketchat-livechat.min.js
packages/rocketchat-livechat/assets/rocket-livechat.js
Expand Down
1 change: 0 additions & 1 deletion apps/meteor/.meteor/packages
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ jalik:ufs-local@1.0.4

jparker:gravatar
kadira:flow-router
mizzao:timesync
mrt:reactive-store
mystor:device-detection
rocketchat:restivus
Expand Down
1 change: 0 additions & 1 deletion apps/meteor/.meteor/versions
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,6 @@ meteorhacks:inject-initial@1.0.5
minifier-css@1.6.0
minifier-js@2.7.4
minimongo@1.8.0
mizzao:timesync@0.3.4
mobile-experience@1.1.0
mobile-status-bar@1.1.0
modern-browsers@0.1.8
Expand Down
4 changes: 2 additions & 2 deletions apps/meteor/.mocharc.api.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ module.exports = {
file: 'tests/end-to-end/teardown.js',
spec: [
'tests/unit/app/api/server/v1/**/*.spec.ts',
'tests/end-to-end/api/*.js',
'tests/end-to-end/api/*.ts',
'tests/end-to-end/api/**/*.js',
'tests/end-to-end/api/**/*.ts',
'tests/end-to-end/apps/*.js',
'tests/end-to-end/apps/*.ts',
],
Expand Down
8 changes: 1 addition & 7 deletions apps/meteor/app/e2e/client/rocketchat.e2e.room.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import { Base64 } from 'meteor/base64';
import { EJSON } from 'meteor/ejson';
import { Random } from 'meteor/random';
import { Session } from 'meteor/session';
import { TimeSync } from 'meteor/mizzao:timesync';
import { Emitter } from '@rocket.chat/emitter';

import { e2e } from './rocketchat.e2e';
Expand Down Expand Up @@ -395,12 +394,7 @@ export class E2ERoom extends Emitter {

// Helper function for encryption of messages
encrypt(message) {
let ts;
if (isNaN(TimeSync.serverOffset())) {
ts = new Date();
} else {
ts = new Date(Date.now() + TimeSync.serverOffset());
}
const ts = new Date();

const data = new TextEncoder('UTF-8').encode(
EJSON.stringify({
Expand Down
3 changes: 1 addition & 2 deletions apps/meteor/app/lib/client/methods/sendMessage.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { Meteor } from 'meteor/meteor';
import { TimeSync } from 'meteor/mizzao:timesync';
import s from 'underscore.string';

import { ChatMessage, Rooms } from '../../../models/client';
Expand All @@ -19,7 +18,7 @@ Meteor.methods({
return dispatchToastMessage({ type: 'error', message: t('Message_Already_Sent') });
}
const user = Meteor.user();
message.ts = isNaN(TimeSync.serverOffset()) ? new Date() : new Date(Date.now() + TimeSync.serverOffset());
message.ts = new Date();
message.u = {
_id: Meteor.userId(),
username: user.username,
Expand Down
4 changes: 2 additions & 2 deletions apps/meteor/app/livechat/server/api/lib/users.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { escapeRegExp } from '@rocket.chat/string-helpers';
import { Users } from '@rocket.chat/models';

import { hasAllPermissionAsync } from '../../../../authorization/server/functions/hasPermission';
import { hasAllPermissionAsync, hasAtLeastOnePermissionAsync } from '../../../../authorization/server/functions/hasPermission';

/**
* @param {IRole['_id']} role the role id
Expand Down Expand Up @@ -41,7 +41,7 @@ async function findUsers({ role, text, pagination: { offset, count, sort } }) {
};
}
export async function findAgents({ userId, text, pagination: { offset, count, sort } }) {
if (!(await hasAllPermissionAsync(userId, ['view-l-room', 'transfer-livechat-guest']))) {
if (!(await hasAtLeastOnePermissionAsync(userId, ['manage-livechat-agents', 'transfer-livechat-guest', 'edit-omnichannel-contact']))) {
throw new Error('error-not-authorized');
}

Expand Down
2 changes: 1 addition & 1 deletion apps/meteor/app/livechat/server/api/rest.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@ import './v1/customField.js';
import './v1/room.js';
import './v1/videoCall.js';
import './v1/transfer.js';
import './v1/contact.js';
import './v1/contact';
77 changes: 0 additions & 77 deletions apps/meteor/app/livechat/server/api/v1/contact.js

This file was deleted.

70 changes: 70 additions & 0 deletions apps/meteor/app/livechat/server/api/v1/contact.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
import { Match, check } from 'meteor/check';
import { Meteor } from 'meteor/meteor';
import { LivechatVisitors } from '@rocket.chat/models';

import { API } from '../../../../api/server';
import { Contacts } from '../../lib/Contacts';

API.v1.addRoute(
'omnichannel/contact',
{ authRequired: true },
{
async post() {
check(this.bodyParams, {
_id: Match.Maybe(String),
token: String,
name: String,
email: Match.Maybe(String),
phone: Match.Maybe(String),
username: Match.Maybe(String),
customFields: Match.Maybe(Object),
contactManager: Match.Maybe({
username: String,
}),
});

const contact = await Contacts.registerContact(this.bodyParams);

return API.v1.success({ contact });
},
async get() {
check(this.queryParams, {
contactId: String,
});

const contact = await LivechatVisitors.findOneById(this.queryParams.contactId);

return API.v1.success({ contact });
},
},
);

API.v1.addRoute(
'omnichannel/contact.search',
{ authRequired: true },
{
async get() {
check(this.queryParams, {
email: Match.Maybe(String),
phone: Match.Maybe(String),
});

const { email, phone } = this.queryParams;

if (!email && !phone) {
throw new Meteor.Error('error-invalid-params');
}

const query = Object.assign(
{},
{
...(email && { visitorEmails: { address: email } }),
...(phone && { phone: { phoneNumber: phone } }),
},
);

const contact = await LivechatVisitors.findOne(query);
return API.v1.success({ contact });
},
},
);
Original file line number Diff line number Diff line change
@@ -1,12 +1,35 @@
import { check } from 'meteor/check';
import { Meteor } from 'meteor/meteor';
import s from 'underscore.string';
import { LivechatVisitors, LivechatRooms, Users } from '@rocket.chat/models';
import { MatchKeysAndValues, OnlyFieldsOfType } from 'mongodb';
import { LivechatVisitors, Users, LivechatRooms } from '@rocket.chat/models';
import { ILivechatCustomField, ILivechatVisitor, IOmnichannelRoom } from '@rocket.chat/core-typings';

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

type RegisterContactProps = {
_id?: string;
token: string;
name: string;
username?: string;
email?: string;
phone?: string;
customFields?: Record<string, unknown | string>;
contactManager?: {
username: string;
};
};

export const Contacts = {
async registerContact({ token, name, email, phone, username, customFields = {}, contactManager = {} } = {}) {
async registerContact({
token,
name,
email = '',
phone,
username,
customFields = {},
contactManager,
}: RegisterContactProps): Promise<string> {
check(token, String);

const visitorEmail = s.trim(email).toLowerCase();
Expand All @@ -23,11 +46,6 @@ export const Contacts = {
}

let contactId;
const updateUser = {
$set: {
token,
},
};

const user = await LivechatVisitors.getVisitorByToken(token, { projection: { _id: 1 } });

Expand All @@ -46,31 +64,39 @@ export const Contacts = {
const userData = {
username,
ts: new Date(),
token,
};

contactId = await LivechatVisitors.insertOne(userData);
contactId = (await LivechatVisitors.insertOne(userData)).insertedId;
}
}

updateUser.$set.name = name;
updateUser.$set.phone = (phone && [{ phoneNumber: phone }]) || null;
updateUser.$set.visitorEmails = (visitorEmail && [{ address: visitorEmail }]) || null;

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

const livechatData = Object.keys(customFields)
.filter((key) => allowedCF.includes(key) && customFields[key] !== '' && customFields[key] !== undefined)
.reduce((obj, key) => {
.reduce((obj: Record<string, unknown | string>, key) => {
obj[key] = customFields[key];
return obj;
}, {});

updateUser.$set.livechatData = livechatData;
updateUser.$set.contactManager = (contactManager?.username && { username: contactManager.username }) || null;
const updateUser: { $set: MatchKeysAndValues<ILivechatVisitor>; $unset?: OnlyFieldsOfType<ILivechatVisitor> } = {
$set: {
token,
name,
livechatData,
...(phone && { phone: [{ phoneNumber: phone }] }),
...(visitorEmail && { visitorEmails: [{ address: visitorEmail }] }),
...(contactManager?.username && { contactManager: { username: contactManager.username } }),
},
...(!contactManager?.username && { $unset: { contactManager: 1 } }),
};

await LivechatVisitors.updateById(contactId, updateUser);
await LivechatVisitors.updateOne({ _id: contactId }, updateUser);

const rooms = await LivechatRooms.findByVisitorId(contactId).toArray();
const rooms: IOmnichannelRoom[] = await LivechatRooms.findByVisitorId(contactId, {}).toArray();

rooms?.length &&
rooms.forEach((room) => {
Expand Down
8 changes: 1 addition & 7 deletions apps/meteor/app/otr/client/rocketchat.otr.room.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import { Random } from 'meteor/random';
import { EJSON } from 'meteor/ejson';
import { Tracker } from 'meteor/tracker';
import { TAPi18n } from 'meteor/rocketchat:tap-i18n';
import { TimeSync } from 'meteor/mizzao:timesync';
import _ from 'underscore';

import { OTR } from './rocketchat.otr';
Expand Down Expand Up @@ -219,12 +218,7 @@ OTR.Room = class {
}

encrypt(message) {
let ts;
if (isNaN(TimeSync.serverOffset())) {
ts = new Date();
} else {
ts = new Date(Date.now() + TimeSync.serverOffset());
}
const ts = new Date();

const data = new TextEncoder('UTF-8').encode(
EJSON.stringify({
Expand Down
Loading

0 comments on commit a437539

Please sign in to comment.