Skip to content

Commit

Permalink
Merge branch 'develop' into tc-479
Browse files Browse the repository at this point in the history
  • Loading branch information
Educg550 authored Mar 3, 2023
2 parents b566e92 + d62dec3 commit 7bb0b9c
Show file tree
Hide file tree
Showing 232 changed files with 3,547 additions and 1,838 deletions.
2 changes: 1 addition & 1 deletion apps/meteor/.eslintcache

Large diffs are not rendered by default.

15 changes: 15 additions & 0 deletions apps/meteor/app/assets/server/assets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,28 @@ const assets: IRocketChatAssets = {
order: 2,
},
},
logo_dark: {
label: 'logo - dark theme (svg, png, jpg)',
defaultUrl: 'images/logo/logo_dark.svg',
constraints: {
type: 'image',
extensions: ['svg', 'png', 'jpg', 'jpeg'],
},
},
background: {
label: 'login background (svg, png, jpg)',
constraints: {
type: 'image',
extensions: ['svg', 'png', 'jpg', 'jpeg'],
},
},
background_dark: {
label: 'login background - dark theme (svg, png, jpg)',
constraints: {
type: 'image',
extensions: ['svg', 'png', 'jpg', 'jpeg'],
},
},
favicon_ico: {
label: 'favicon (ico)',
defaultUrl: 'favicon.ico',
Expand Down
31 changes: 19 additions & 12 deletions apps/meteor/app/autotranslate/client/lib/actionButton.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
hasTranslationLanguageInAttachments,
hasTranslationLanguageInMessage,
} from '../../../../client/views/room/MessageList/lib/autoTranslate';
import { roomCoordinator } from '../../../../client/lib/rooms/roomCoordinator';

Meteor.startup(() => {
AutoTranslate.init();
Expand All @@ -33,18 +34,20 @@ Meteor.startup(() => {
const action = 'autoTranslateShowInverse' in message ? '$unset' : '$set';
Messages.update({ _id: message._id }, { [action]: { autoTranslateShowInverse: true } });
},
condition({ message, subscription, user }) {
condition({ message, subscription, user, room }) {
if (!user) {
return false;
}
const language = subscription?.autoTranslateLanguage || AutoTranslate.getLanguage(message.rid) || '';
const isLivechatRoom = roomCoordinator.isLivechatRoom(room?.t);
const isDifferentUser = message?.u && message.u._id !== user._id;
const autoTranslateEnabled = subscription?.autoTranslate || isLivechatRoom;
const hasLanguage =
hasTranslationLanguageInMessage(message, language) || hasTranslationLanguageInAttachments(message.attachments, language);

return Boolean(
(message?.u &&
message.u._id !== user._id &&
subscription?.autoTranslate &&
(message as { autoTranslateShowInverse?: boolean }).autoTranslateShowInverse) ||
(!hasTranslationLanguageInMessage(message, language) && !hasTranslationLanguageInAttachments(message.attachments, language)),
(message as { autoTranslateShowInverse?: boolean }).autoTranslateShowInverse ||
(isDifferentUser && autoTranslateEnabled && !hasLanguage),
);
},
order: 90,
Expand All @@ -65,18 +68,22 @@ Meteor.startup(() => {
const action = 'autoTranslateShowInverse' in message ? '$unset' : '$set';
Messages.update({ _id: message._id }, { [action]: { autoTranslateShowInverse: true } });
},
condition({ message, subscription, user }) {
condition({ message, subscription, user, room }) {
const language = subscription?.autoTranslateLanguage || AutoTranslate.getLanguage(message.rid) || '';
const isLivechatRoom = roomCoordinator.isLivechatRoom(room?.t);
if (!user) {
return false;
}
const isDifferentUser = message?.u && message.u._id !== user._id;
const autoTranslateEnabled = subscription?.autoTranslate || isLivechatRoom;
const hasLanguage =
hasTranslationLanguageInMessage(message, language) || hasTranslationLanguageInAttachments(message.attachments, language);

return Boolean(
message?.u &&
message.u._id !== user._id &&
subscription?.autoTranslate &&
!(message as { autoTranslateShowInverse?: boolean }).autoTranslateShowInverse &&
(hasTranslationLanguageInMessage(message, language) || hasTranslationLanguageInAttachments(message.attachments, language)),
!(message as { autoTranslateShowInverse?: boolean }).autoTranslateShowInverse &&
isDifferentUser &&
autoTranslateEnabled &&
hasLanguage,
);
},
order: 90,
Expand Down
19 changes: 15 additions & 4 deletions apps/meteor/app/federation-v2/server/Federation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ const allowedActionsInFederatedRooms: ValueOf<typeof RoomMemberActions>[] = [
RoomMemberActions.LEAVE,
];

const allowedActionsForModerators = allowedActionsInFederatedRooms.filter((action) => action !== RoomMemberActions.SET_AS_OWNER);

const allowedRoomSettingsChangesInFederatedRooms: ValueOf<typeof RoomSettingsEnum>[] = [RoomSettingsEnum.NAME, RoomSettingsEnum.TOPIC];

export class Federation {
Expand All @@ -33,10 +35,19 @@ export class Federation {
return true;
}

return Boolean(
(userSubscription.roles?.includes('owner') || userSubscription.roles?.includes('moderator')) &&
allowedActionsInFederatedRooms.includes(action),
);
if (action === RoomMemberActions.LEAVE) {
return true;
}

if (userSubscription.roles?.includes('owner')) {
return allowedActionsInFederatedRooms.includes(action);
}

if (userSubscription.roles?.includes('moderator')) {
return allowedActionsForModerators.includes(action);
}

return false;
}

public static isAFederatedUsername(username: string): boolean {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ export class FederationHooks {
callbacks.add(
'federation.beforeAddUserToARoom',
(params: { user: IUser | string; inviter?: IUser }, room: IRoom): void => {
if (!params || !params.user || !room) {
if (!params?.user || !room) {
return;
}
Promise.await(callback(params.user, room));
Expand All @@ -59,7 +59,7 @@ export class FederationHooks {
callbacks.add(
'federation.beforeAddUserToARoom',
(params: { user: IUser | string; inviter: IUser }, room: IRoom): void => {
if (!params || !params.user || !params.inviter || !room || !settings.get('Federation_Matrix_enabled')) {
if (!params?.user || !params.inviter || !room || !settings.get('Federation_Matrix_enabled')) {
return;
}

Expand Down Expand Up @@ -189,7 +189,7 @@ export class FederationHooks {
);
}

public static afterRoomRoleChanged(federationRoomService: FederationRoomServiceSender, data: Record<string, any>): void {
public static afterRoomRoleChanged(federationRoomService: FederationRoomServiceSender, data?: Record<string, any>): void {
if (!data || !settings.get('Federation_Matrix_enabled')) {
return;
}
Expand Down
14 changes: 8 additions & 6 deletions apps/meteor/app/lib/server/functions/updateMessage.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { IMessage, IMessageEdited, IUser } from '@rocket.chat/core-typings';
import type { IEditedMessage, IMessage, IUser } from '@rocket.chat/core-typings';
import { Meteor } from 'meteor/meteor';

import { Messages, Rooms } from '../../../models/server';
Expand Down Expand Up @@ -35,11 +35,13 @@ export const updateMessage = function (message: IMessage, user: IUser, originalM
Messages.cloneAndSaveAsHistoryById(message._id, user);
}

(message as IMessageEdited).editedAt = new Date();
(message as IMessageEdited).editedBy = {
_id: user._id,
username: user.username,
};
Object.assign<IMessage, Omit<IEditedMessage, keyof IMessage>>(message, {
editedAt: new Date(),
editedBy: {
_id: user._id,
username: user.username,
},
});

parseUrlsInMessage(message);

Expand Down
6 changes: 6 additions & 0 deletions apps/meteor/app/lib/server/startup/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1684,6 +1684,12 @@ settingsRegistry.addGroup('Layout', function () {
multiline: true,
public: true,
});
this.add('Layout_Sidenav_Footer_Dark', '<a href="/home"><img src="assets/logo_dark.png" alt="Home" /></a>', {
type: 'code',
code: 'text/html',
public: true,
i18nDescription: 'Layout_Sidenav_Footer_description',
});
return this.add('Layout_Sidenav_Footer', '<a href="/home"><img src="assets/logo.png" alt="Home" /></a>', {
type: 'code',
code: 'text/html',
Expand Down
3 changes: 1 addition & 2 deletions apps/meteor/app/livechat/server/api/v1/transcript.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,14 @@ import { TAPi18n } from 'meteor/rocketchat:tap-i18n';
import { isPOSTLivechatTranscriptParams } from '@rocket.chat/rest-typings';

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

API.v1.addRoute(
'livechat/transcript',
{ validateParams: isPOSTLivechatTranscriptParams },
{
async post() {
const { token, rid, email } = this.bodyParams;
// @ts-expect-error -- typings on sendtranscript are wrong
if (!(await Livechat.sendTranscript({ token, rid, email }))) {
return API.v1.failure({ message: TAPi18n.__('Error_sending_livechat_transcript') });
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,7 @@ import { RoutingManager } from '../lib/RoutingManager';
callbacks.add(
'afterSaveMessage',
(message, room) => {
if (!isOmnichannelRoom(room)) {
return message;
}

// skip callback if message was edited
if (isEditedMessage(message)) {
if (!isOmnichannelRoom(room) || isEditedMessage(message) || message.t) {
return message;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { isOmnichannelRoom } from '@rocket.chat/core-typings';
import { LivechatRooms } from '@rocket.chat/models';

import { callbacks } from '../../../../lib/callbacks';
import { Livechat } from '../lib/Livechat';
import { Livechat } from '../lib/LivechatTyped';
import type { CloseRoomParams } from '../lib/LivechatTyped.d';

type LivechatCloseCallbackParams = {
Expand Down
86 changes: 0 additions & 86 deletions apps/meteor/app/livechat/server/lib/Livechat.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import { Match, check } from 'meteor/check';
import { Random } from 'meteor/random';
import { TAPi18n } from 'meteor/rocketchat:tap-i18n';
import { HTTP } from 'meteor/http';
import moment from 'moment-timezone';
import UAParser from 'ua-parser-js';
import {
Users as UsersRaw,
Expand All @@ -27,7 +26,6 @@ import { QueueManager } from './QueueManager';
import { RoutingManager } from './RoutingManager';
import { Analytics } from './Analytics';
import { settings } from '../../../settings/server';
import { getTimezone } from '../../../utils/server/lib/getTimezone';
import { callbacks } from '../../../../lib/callbacks';
import {
Users,
Expand Down Expand Up @@ -1096,90 +1094,6 @@ export const Livechat = {
});
},

async sendTranscript({ token, rid, email, subject, user }) {
check(rid, String);
check(email, String);
Livechat.logger.debug(`Sending conversation transcript of room ${rid} to user with token ${token}`);

const room = LivechatRooms.findOneById(rid);

const visitor = await LivechatVisitors.getVisitorByToken(token, {
projection: { _id: 1, token: 1, language: 1, username: 1, name: 1 },
});

if (!visitor) {
throw new Meteor.Error('error-invalid-token', 'Invalid token');
}

const userLanguage = (visitor && visitor.language) || settings.get('Language') || 'en';
const timezone = getTimezone(user);
Livechat.logger.debug(`Transcript will be sent using ${timezone} as timezone`);

// allow to only user to send transcripts from their own chats
if (!room || room.t !== 'l' || !room.v || room.v.token !== token) {
throw new Meteor.Error('error-invalid-room', 'Invalid room');
}

const showAgentInfo = settings.get('Livechat_show_agent_info');
const ignoredMessageTypes = [
'livechat_navigation_history',
'livechat_transcript_history',
'command',
'livechat-close',
'livechat-started',
'livechat_video_call',
];
const messages = Messages.findVisibleByRoomIdNotContainingTypes(rid, ignoredMessageTypes, {
sort: { ts: 1 },
});

let html = '<div> <hr>';
messages.forEach((message) => {
let author;
if (message.u._id === visitor._id) {
author = TAPi18n.__('You', { lng: userLanguage });
} else {
author = showAgentInfo ? message.u.name || message.u.username : TAPi18n.__('Agent', { lng: userLanguage });
}

const datetime = moment.tz(message.ts, timezone).locale(userLanguage).format('LLL');
const singleMessage = `
<p><strong>${author}</strong> <em>${datetime}</em></p>
<p>${message.msg}</p>
`;
html += singleMessage;
});

html = `${html}</div>`;

let fromEmail = settings.get('From_Email').match(/\b[A-Z0-9._%+-]+@(?:[A-Z0-9-]+\.)+[A-Z]{2,4}\b/i);

if (fromEmail) {
fromEmail = fromEmail[0];
} else {
fromEmail = settings.get('From_Email');
}

const mailSubject = subject || TAPi18n.__('Transcript_of_your_livechat_conversation', { lng: userLanguage });

this.sendEmail(fromEmail, email, fromEmail, mailSubject, html);

Meteor.defer(() => {
callbacks.run('livechat.sendTranscript', messages, email);
});

let type = 'user';
if (!user) {
user = Users.findOneById('rocket.cat', { fields: { _id: 1, username: 1, name: 1 } });
type = 'visitor';
}

Messages.createTranscriptHistoryWithRoomIdMessageAndUser(room._id, '', user, {
requestData: { type, visitor, user },
});
return true;
},

getRoomMessages({ rid }) {
check(rid, String);

Expand Down
Loading

0 comments on commit 7bb0b9c

Please sign in to comment.