Skip to content

Commit

Permalink
Merge branch 'develop' into voip/ib_ob
Browse files Browse the repository at this point in the history
  • Loading branch information
murtaza98 committed Jun 27, 2022
2 parents a224803 + 89546dd commit 956b2a7
Show file tree
Hide file tree
Showing 77 changed files with 569 additions and 603 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build_and_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -681,7 +681,7 @@ jobs:
docker logs presence --tail=50
cd ./apps/meteor
npm run test:playwright
IS_EE=true npm run test:playwright
- name: Store playwright test trace
uses: actions/upload-artifact@v2
Expand Down
8 changes: 6 additions & 2 deletions apps/meteor/app/api/server/v1/channels.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import {
} from '@rocket.chat/rest-typings';

import { Rooms, Subscriptions, Messages } from '../../../models/server';
import { hasPermission, hasAllPermission } from '../../../authorization/server';
import { hasPermission } from '../../../authorization/server';
import { normalizeMessagesForUser } from '../../../utils/server/lib/normalizeMessagesForUser';
import { API } from '../api';
import { Team } from '../../../../server/sdk';
Expand Down Expand Up @@ -454,7 +454,7 @@ API.v1.addRoute(
},
{
async post() {
if (!hasAllPermission(this.userId, ['create-team', 'edit-room'])) {
if (!hasPermission(this.userId, 'create-team')) {
return API.v1.unauthorized();
}

Expand All @@ -464,6 +464,10 @@ API.v1.addRoute(
return API.v1.failure('The parameter "channelId" or "channelName" is required');
}

if (!hasPermission(this.userId, 'edit-room', channelId)) {
return API.v1.unauthorized();
}

const room = findChannelByIdOrName({
params: {
roomId: channelId,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,26 @@
/* eslint-disable @typescript-eslint/camelcase */
import { Meteor } from 'meteor/meteor';
import {
ise2eGetUsersOfRoomWithoutKeyParamsGET,
ise2eSetRoomKeyIDParamsPOST,
ise2eSetUserPublicAndPrivateKeysParamsPOST,
ise2eUpdateGroupKeyParamsPOST,
} from '@rocket.chat/rest-typings';
import { IUser } from '@rocket.chat/core-typings';

import { API } from '../api';

API.v1.addRoute(
'e2e.fetchMyKeys',
{ authRequired: true },
{
authRequired: true,
},
{
get() {
let result;
Meteor.runAsUser(this.userId, () => {
result = Meteor.call('e2e.fetchMyKeys');
});
const result: {
public_key: string;
private_key: string;
} = Meteor.call('e2e.fetchMyKeys');

return API.v1.success(result);
},
Expand All @@ -19,15 +29,17 @@ API.v1.addRoute(

API.v1.addRoute(
'e2e.getUsersOfRoomWithoutKey',
{ authRequired: true },
{
authRequired: true,
validateParams: ise2eGetUsersOfRoomWithoutKeyParamsGET,
},
{
get() {
const { rid } = this.queryParams;

let result;
Meteor.runAsUser(this.userId, () => {
result = Meteor.call('e2e.getUsersOfRoomWithoutKey', rid);
});
const result: {
users: IUser[];
} = Meteor.call('e2e.getUsersOfRoomWithoutKey', rid);

return API.v1.success(result);
},
Expand Down Expand Up @@ -65,16 +77,18 @@ API.v1.addRoute(
* schema:
* $ref: '#/components/schemas/ApiFailureV1'
*/

API.v1.addRoute(
'e2e.setRoomKeyID',
{ authRequired: true },
{
authRequired: true,
validateParams: ise2eSetRoomKeyIDParamsPOST,
},
{
post() {
const { rid, keyID } = this.bodyParams;

Meteor.runAsUser(this.userId, () => {
API.v1.success(Meteor.call('e2e.setRoomKeyID', rid, keyID));
});
Meteor.call('e2e.setRoomKeyID', rid, keyID);

return API.v1.success();
},
Expand Down Expand Up @@ -114,18 +128,17 @@ API.v1.addRoute(
*/
API.v1.addRoute(
'e2e.setUserPublicAndPrivateKeys',
{ authRequired: true },
{
authRequired: true,
validateParams: ise2eSetUserPublicAndPrivateKeysParamsPOST,
},
{
post() {
const { public_key, private_key } = this.bodyParams;

Meteor.runAsUser(this.userId, () => {
API.v1.success(
Meteor.call('e2e.setUserPublicAndPrivateKeys', {
public_key,
private_key,
}),
);
const { public_key, private_key } = Meteor.call('e2e.fetchMyKeys');

Meteor.call('e2e.setUserPublicAndPrivateKeys', {
public_key,
private_key,
});

return API.v1.success();
Expand Down Expand Up @@ -168,14 +181,15 @@ API.v1.addRoute(
*/
API.v1.addRoute(
'e2e.updateGroupKey',
{ authRequired: true },
{
authRequired: true,
validateParams: ise2eUpdateGroupKeyParamsPOST,
},
{
post() {
const { uid, rid, key } = this.bodyParams;

Meteor.runAsUser(this.userId, () => {
API.v1.success(Meteor.call('e2e.updateGroupKey', rid, uid, key));
});
Meteor.call('e2e.updateGroupKey', rid, uid, key);

return API.v1.success();
},
Expand Down
20 changes: 17 additions & 3 deletions apps/meteor/app/lib/server/startup/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -426,10 +426,23 @@ settingsRegistry.addGroup('Accounts', function () {
i18nLabel: 'Sort_By',
});

this.add('Accounts_Default_User_Preferences_showMessageInMainThread', false, {
type: 'boolean',
this.add('Accounts_Default_User_Preferences_alsoSendThreadToChannel', 'default', {
type: 'select',
values: [
{
key: 'default',
i18nLabel: 'Default',
},
{
key: 'always',
i18nLabel: 'Always',
},
{
key: 'never',
i18nLabel: 'Never',
},
],
public: true,
i18nLabel: 'Show_Message_In_Main_Thread',
});

this.add('Accounts_Default_User_Preferences_sidebarShowFavorites', true, {
Expand Down Expand Up @@ -457,6 +470,7 @@ settingsRegistry.addGroup('Accounts', function () {
public: true,
i18nLabel: 'Enter_Behaviour',
});

this.add('Accounts_Default_User_Preferences_messageViewMode', 0, {
type: 'select',
values: [
Expand Down
22 changes: 20 additions & 2 deletions apps/meteor/app/threads/client/flextab/thread.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,8 @@ Template.thread.helpers({
} = Template.currentData();

const showFormattingTips = settings.get('Message_ShowFormattingTips');
const alsoSendPreferenceState = getUserPreference(Meteor.userId(), 'alsoSendThreadToChannel');

return {
showFormattingTips,
tshow: instance.state.get('sendToChannel'),
Expand All @@ -85,7 +87,9 @@ Template.thread.helpers({
tmid,
onSend: (...args) => {
instance.sendToBottom();
instance.state.set('sendToChannel', false);
if (alsoSendPreferenceState === 'default') {
instance.state.set('sendToChannel', false);
}
return instance.chatMessages && instance.chatMessages.send.apply(instance.chatMessages, args);
},
onKeyUp: (...args) => instance.chatMessages && instance.chatMessages.keyup.apply(instance.chatMessages, args),
Expand Down Expand Up @@ -243,8 +247,22 @@ Template.thread.onRendered(function () {
Template.thread.onCreated(async function () {
this.Threads = new Mongo.Collection(null);

const preferenceState = getUserPreference(Meteor.userId(), 'alsoSendThreadToChannel');

let sendToChannel;
switch (preferenceState) {
case 'always':
sendToChannel = true;
break;
case 'never':
sendToChannel = false;
break;
default:
sendToChannel = !this.data.mainMessage.tcount;
}

this.state = new ReactiveDict({
sendToChannel: !this.data.mainMessage.tcount,
sendToChannel,
});

this.loadMore = async () => {
Expand Down
2 changes: 1 addition & 1 deletion apps/meteor/app/ui-message/client/message.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<template name="message">
<li id="{{templatePrefix}}{{msg._id}}" data-id="{{msg._id}}" data-own={{isOwnMessageAndNotSystem}} data-context={{actionContext}} class="message {{className}} {{ignoredClass}} {{system}} {{t}} {{own}} {{isTemp}} {{chatops}} {{collapsed}} {{customClass}}" data-username="{{msg.u.username}}" data-tmid="{{msg.tmid}}" data-groupable="{{isGroupable}}" data-date="{{date}}" data-timestamp="{{timestamp}}" data-alias="{{msg.alias}}" data-qa-type="message">
<li data-qa-id="UserMessage" id="{{templatePrefix}}{{msg._id}}" data-id="{{msg._id}}" data-own={{isOwnMessageAndNotSystem}} data-context={{actionContext}} class="message {{className}} {{ignoredClass}} {{system}} {{t}} {{own}} {{isTemp}} {{chatops}} {{collapsed}} {{customClass}}" data-username="{{msg.u.username}}" data-tmid="{{msg.tmid}}" data-groupable="{{isGroupable}}" data-date="{{date}}" data-timestamp="{{timestamp}}" data-alias="{{msg.alias}}" data-qa-type="message">
{{#if isThreadReply}}
{{> messageThread parentMessage=parentMessage msg=msg tmid=msg.tmid class=bodyClass following=msg.following}}
<div class="thread-replied js-open-thread">
Expand Down
6 changes: 2 additions & 4 deletions apps/meteor/app/ui-utils/client/lib/RoomHistoryManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import { getConfig } from '../../../../client/lib/utils/getConfig';
import { ChatMessage, ChatSubscription, ChatRoom } from '../../../models/client';
import { callWithErrorHandling } from '../../../../client/lib/utils/callWithErrorHandling';
import { filterMarkdown } from '../../../markdown/lib/markdown';
import { getUserPreference } from '../../../utils/client';
import { onClientMessageReceived } from '../../../../client/lib/onClientMessageReceived';
import {
setHighlightMessage,
Expand Down Expand Up @@ -197,8 +196,7 @@ export const RoomHistoryManager = new (class extends Emitter {
typeName = (curRoomDoc ? curRoomDoc.t : undefined) + (curRoomDoc ? curRoomDoc.name : undefined);
}

const showMessageInMainThread = getUserPreference(Meteor.userId(), 'showMessageInMainThread', false);
const result = await callWithErrorHandling('loadHistory', rid, ts, limit, ls, showMessageInMainThread);
const result = await callWithErrorHandling('loadHistory', rid, ts, limit, ls);

this.unqueue();

Expand All @@ -224,7 +222,7 @@ export const RoomHistoryManager = new (class extends Emitter {
room.loaded = 0;
}

const visibleMessages = messages.filter((msg) => !msg.tmid || showMessageInMainThread || msg.tshow);
const visibleMessages = messages.filter((msg) => !msg.tmid || msg.tshow);

room.loaded += visibleMessages.length;

Expand Down
2 changes: 0 additions & 2 deletions apps/meteor/app/ui-utils/client/lib/messageContext.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ const fields = {
'name': 1,
'username': 1,
'settings.preferences.enableNewMessageTemplate': 1,
'settings.preferences.showMessageInMainThread': 1,
'settings.preferences.autoImageLoad': 1,
'settings.preferences.saveMobileBandwidth': 1,
'settings.preferences.collapseMediaByDefault': 1,
Expand Down Expand Up @@ -115,7 +114,6 @@ export function messageContext({ rid } = Template.instance()) {
},
settings: {
translateLanguage: AutoTranslate.getLanguage(rid),
showMessageInMainThread: getUserPreference(user, 'showMessageInMainThread'),
autoImageLoad: getUserPreference(user, 'autoImageLoad'),
enableNewMessageTemplate: getUserPreference(user, 'enableNewMessageTemplate'),
saveMobileBandwidth: Meteor.Device.isPhone() && getUserPreference(user, 'saveMobileBandwidth'),
Expand Down
5 changes: 1 addition & 4 deletions apps/meteor/app/ui/client/views/app/room.js
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,6 @@ Template.roomOld.helpers({
return state.get('subscribed');
},
messagesHistory() {
const showInMainThread = getUserPreference(Meteor.userId(), 'showMessageInMainThread', false);
const { rid } = Template.instance();
const room = Rooms.findOne(rid, { fields: { sysMes: 1 } });
const hideSettings = settings.collection.findOne('Hide_System_Messages') || {};
Expand All @@ -191,9 +190,7 @@ Template.roomOld.helpers({
const query = {
rid,
_hidden: { $ne: true },
...(!showInMainThread && {
$or: [{ tmid: { $exists: 0 } }, { tshow: { $eq: true } }],
}),
$or: [{ tmid: { $exists: 0 } }, { tshow: { $eq: true } }],
};

if (hideMessagesOfType.size) {
Expand Down
2 changes: 1 addition & 1 deletion apps/meteor/client/hooks/useEndpointAction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export const useEndpointAction = <TMethod extends Method, TPath extends PathFor<

return data;
} catch (error) {
dispatchToastMessage({ type: 'error', message: String(error) });
dispatchToastMessage({ type: 'error', message: error });
throw error;
}
}, [dispatchToastMessage, params, sendData, successMessage]);
Expand Down
2 changes: 1 addition & 1 deletion apps/meteor/client/sidebar/RoomMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ const RoomMenu = ({ rid, unread, threadUnread, alert, roomOpen, type, cl, name =
aria-keyshortcuts='alt'
tabIndex={-1}
options={menuOptions}
renderItem={({ label: { label, icon }, ...props }) => <Option label={label} title={label} icon={icon} {...props} />}
renderItem={({ label: { label, icon }, ...props }): JSX.Element => <Option label={label} title={label} icon={icon} {...props} />}
/>
);
};
Expand Down
1 change: 1 addition & 0 deletions apps/meteor/client/sidebar/search/SearchList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ const shortcut = ((): string => {
return '(\u2303+K)';
})();

// eslint-disable-next-line @typescript-eslint/explicit-function-return-type
const useSpotlight = (filterText: string, usernames: string[]) => {
const expression = /(@|#)?(.*)/i;
const [, mention, name] = filterText.match(expression) || [];
Expand Down
Loading

0 comments on commit 956b2a7

Please sign in to comment.