Skip to content

Commit

Permalink
Merge branch 'feat/apps-toast-message' of github.com:RocketChat/Rocke…
Browse files Browse the repository at this point in the history
…t.Chat into feat/apps-toast-message
  • Loading branch information
tiagoevanp committed Aug 30, 2023
2 parents 53cf322 + 00f333d commit 7f28a8f
Show file tree
Hide file tree
Showing 322 changed files with 6,350 additions and 2,382 deletions.
7 changes: 7 additions & 0 deletions .changeset/bright-carpets-fly.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
'@rocket.chat/core-typings': minor
'@rocket.chat/rest-typings': minor
'@rocket.chat/meteor': minor
---

new: ring mobile users on direct conference calls
9 changes: 9 additions & 0 deletions .changeset/bright-snakes-vanish.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
---
"@rocket.chat/meteor": patch
---

Fixed an issue causing `queue time` to be calculated from current time when a room was closed without being served.
Now:
- For served rooms: queue time = servedBy time - queuedAt
- For not served, but open rooms = now - queuedAt
- For not served and closed rooms = closedAt - queuedAt
5 changes: 5 additions & 0 deletions .changeset/cool-students-tan.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@rocket.chat/meteor": patch
---

feat(apps): `ActionManagerBusyState` component for apps `ui.interaction`
6 changes: 6 additions & 0 deletions .changeset/eighty-kids-jog.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'@rocket.chat/livechat': minor
'@rocket.chat/meteor': minor
---

Added new Omnichannel's trigger condition "After starting a chat".
5 changes: 5 additions & 0 deletions .changeset/many-icons-provide.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@rocket.chat/meteor': patch
---

Don't allow to report self messages
6 changes: 6 additions & 0 deletions .changeset/pretty-bees-give.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@rocket.chat/meteor": minor
"@rocket.chat/rest-typings": minor
---

Add option to select what URL previews should be generated for each message.
8 changes: 8 additions & 0 deletions .changeset/serious-geckos-drive.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
'@rocket.chat/core-typings': minor
'@rocket.chat/rest-typings': minor
'@rocket.chat/ui-client': minor
'@rocket.chat/meteor': minor
---

Added Reports Metrics Dashboard to Omnichannel
5 changes: 5 additions & 0 deletions .changeset/short-cobras-tell.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@rocket.chat/meteor": minor
---

Reorganized the message menu
5 changes: 5 additions & 0 deletions .changeset/stale-roses-knock.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@rocket.chat/meteor": patch
---

fix: User timezone not being respected on Current Chat's filter
6 changes: 6 additions & 0 deletions .changeset/tricky-years-swim.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@rocket.chat/meteor": patch
"@rocket.chat/rest-typings": patch
---

Deprecate `livechat:getOverviewData` and `livechat:getAgentOverviewData` methods and create API endpoints `livechat/analytics/overview` and `livechat/analytics/agent-overview` to fetch analytics data
5 changes: 5 additions & 0 deletions .changeset/wise-ways-fetch.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@rocket.chat/meteor": patch
---

fixed the unread messages mark not showing
6 changes: 4 additions & 2 deletions apps/meteor/app/api/server/v1/chat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import { hasPermissionAsync } from '../../../authorization/server/functions/hasP
import { deleteMessageValidatingPermission } from '../../../lib/server/functions/deleteMessage';
import { processWebhookMessage } from '../../../lib/server/functions/processWebhookMessage';
import { executeSendMessage } from '../../../lib/server/methods/sendMessage';
import { executeUpdateMessage } from '../../../lib/server/methods/updateMessage';
import { executeSetReaction } from '../../../reactions/server/setReaction';
import { settings } from '../../../settings/server';
import { normalizeMessagesForUser } from '../../../utils/server/lib/normalizeMessagesForUser';
Expand Down Expand Up @@ -215,7 +216,7 @@ API.v1.addRoute(
throw new Meteor.Error('error-invalid-params', 'The "message" parameter must be provided.');
}

const sent = await executeSendMessage(this.userId, this.bodyParams.message as Pick<IMessage, 'rid'>);
const sent = await executeSendMessage(this.userId, this.bodyParams.message as Pick<IMessage, 'rid'>, this.bodyParams.previewUrls);
const [message] = await normalizeMessagesForUser([sent], this.userId);

return API.v1.success({
Expand Down Expand Up @@ -310,6 +311,7 @@ API.v1.addRoute(
roomId: String,
msgId: String,
text: String, // Using text to be consistant with chat.postMessage
previewUrls: Match.Maybe([String]),
}),
);

Expand All @@ -325,7 +327,7 @@ API.v1.addRoute(
}

// Permission checks are already done in the updateMessage method, so no need to duplicate them
await Meteor.callAsync('updateMessage', { _id: msg._id, msg: this.bodyParams.text, rid: msg.rid });
await executeUpdateMessage(this.userId, { _id: msg._id, msg: this.bodyParams.text, rid: msg.rid }, this.bodyParams.previewUrls);

const updatedMessage = await Messages.findOneById(msg._id);
const [message] = await normalizeMessagesForUser(updatedMessage ? [updatedMessage] : [], this.userId);
Expand Down
2 changes: 2 additions & 0 deletions apps/meteor/app/autotranslate/client/lib/actionButton.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ Meteor.startup(() => {
icon: 'language',
label: 'Translate',
context: ['message', 'message-mobile', 'threads'],
type: 'interaction',
action(_, props) {
const { message = messageArgs(this).msg } = props;
const language = AutoTranslate.getLanguage(message.rid);
Expand Down Expand Up @@ -58,6 +59,7 @@ Meteor.startup(() => {
icon: 'language',
label: 'View_original',
context: ['message', 'message-mobile', 'threads'],
type: 'interaction',
action(_, props) {
const { message = messageArgs(this).msg } = props;
const language = AutoTranslate.getLanguage(message.rid);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ Meteor.startup(() => {
id: 'start-discussion',
icon: 'discussion',
label: 'Discussion_start',
type: 'communication',
context: ['message', 'message-mobile', 'videoconf'],
async action(_, props) {
const { message = messageArgs(this).msg, room } = props;
Expand Down
2 changes: 1 addition & 1 deletion apps/meteor/app/e2e/client/rocketchat.e2e.ts
Original file line number Diff line number Diff line change
Expand Up @@ -466,7 +466,7 @@ class E2E extends Emitter {

await Promise.all(
urls.map(async (url) => {
if (!url.includes(Meteor.absoluteUrl())) {
if (!url.includes(settings.get('Site_Url'))) {
return;
}

Expand Down
13 changes: 8 additions & 5 deletions apps/meteor/app/lib/server/functions/parseUrlsInMessage.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import type { IMessage } from '@rocket.chat/core-typings';
import type { IMessage, AtLeast } from '@rocket.chat/core-typings';

import { getMessageUrlRegex } from '../../../../lib/getMessageUrlRegex';
import { Markdown } from '../../../markdown/server';
import { settings } from '../../../settings/server';

export const parseUrlsInMessage = (message: IMessage & { parseUrls?: boolean }): IMessage => {
export const parseUrlsInMessage = (message: AtLeast<IMessage, 'msg'> & { parseUrls?: boolean }, previewUrls?: string[]) => {
if (message.parseUrls === false) {
return message;
}
Expand All @@ -13,13 +14,15 @@ export const parseUrlsInMessage = (message: IMessage & { parseUrls?: boolean }):

const urls = message.html?.match(getMessageUrlRegex()) || [];
if (urls) {
message.urls = [...new Set(urls)].map((url) => ({ url, meta: {} }));
message.urls = [...new Set(urls)].map((url) => ({
url,
meta: {},
...(previewUrls && !previewUrls.includes(url) && !url.includes(settings.get('Site_Url')) && { ignoreParse: true }),
}));
}

message = Markdown.mountTokensBack(message, false);
message.msg = message.html || message.msg;
delete message.html;
delete message.tokens;

return message;
};
13 changes: 11 additions & 2 deletions apps/meteor/app/lib/server/functions/sendMessage.js
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,16 @@ function cleanupMessageObject(message) {
['customClass'].forEach((field) => delete message[field]);
}

export const sendMessage = async function (user, message, room, upsert = false) {
/**
* Validates and sends the message object.
* @param {IUser} user
* @param {AtLeast<IMessage, 'rid'>} message
* @param {IRoom} room
* @param {boolean} [upsert=false]
* @param {string[]} [previewUrls]
* @returns {Promise<IMessage>}
*/
export const sendMessage = async function (user, message, room, upsert = false, previewUrls = undefined) {
if (!user || !message || !room._id) {
return false;
}
Expand Down Expand Up @@ -236,7 +245,7 @@ export const sendMessage = async function (user, message, room, upsert = false)

cleanupMessageObject(message);

parseUrlsInMessage(message);
parseUrlsInMessage(message, previewUrls);

message = await callbacks.run('beforeSaveMessage', message, room);
if (message) {
Expand Down
13 changes: 9 additions & 4 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 { IEditedMessage, IMessage, IUser } from '@rocket.chat/core-typings';
import type { IEditedMessage, IMessage, IUser, AtLeast } from '@rocket.chat/core-typings';
import { Messages, Rooms } from '@rocket.chat/models';
import { Meteor } from 'meteor/meteor';

Expand All @@ -7,7 +7,12 @@ import { callbacks } from '../../../../lib/callbacks';
import { settings } from '../../../settings/server';
import { parseUrlsInMessage } from './parseUrlsInMessage';

export const updateMessage = async function (message: IMessage, user: IUser, originalMsg?: IMessage): Promise<void> {
export const updateMessage = async function (
message: AtLeast<IMessage, '_id' | 'rid' | 'msg'>,
user: IUser,
originalMsg?: IMessage,
previewUrls?: string[],
): Promise<void> {
const originalMessage = originalMsg || (await Messages.findOneById(message._id));

// For the Rocket.Chat Apps :)
Expand All @@ -33,15 +38,15 @@ export const updateMessage = async function (message: IMessage, user: IUser, ori
await Messages.cloneAndSaveAsHistoryById(message._id, user as Required<Pick<IUser, '_id' | 'username' | 'name'>>);
}

Object.assign<IMessage, Omit<IEditedMessage, keyof IMessage>>(message, {
Object.assign<AtLeast<IMessage, '_id' | 'rid' | 'msg'>, Omit<IEditedMessage, keyof IMessage>>(message, {
editedAt: new Date(),
editedBy: {
_id: user._id,
username: user.username,
},
});

parseUrlsInMessage(message);
parseUrlsInMessage(message, previewUrls);

message = await callbacks.run('beforeSaveMessage', message);

Expand Down
10 changes: 5 additions & 5 deletions apps/meteor/app/lib/server/methods/sendMessage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import { settings } from '../../../settings/server';
import { sendMessage } from '../functions/sendMessage';
import { RateLimiter } from '../lib';

export async function executeSendMessage(uid: IUser['_id'], message: AtLeast<IMessage, 'rid'>) {
export async function executeSendMessage(uid: IUser['_id'], message: AtLeast<IMessage, 'rid'>, previewUrls?: string[]) {
if (message.tshow && !message.tmid) {
throw new Meteor.Error('invalid-params', 'tshow provided but missing tmid', {
method: 'sendMessage',
Expand Down Expand Up @@ -82,7 +82,7 @@ export async function executeSendMessage(uid: IUser['_id'], message: AtLeast<IMe
const room = await canSendMessageAsync(rid, { uid, username: user.username, type: user.type });

metrics.messagesSent.inc(); // TODO This line needs to be moved to it's proper place. See the comments on: https://github.com/RocketChat/Rocket.Chat/pull/5736
return sendMessage(user, message, room, false);
return sendMessage(user, message, room, false, previewUrls);
} catch (err: any) {
SystemLogger.error({ msg: 'Error sending message:', err });

Expand All @@ -102,12 +102,12 @@ export async function executeSendMessage(uid: IUser['_id'], message: AtLeast<IMe
declare module '@rocket.chat/ui-contexts' {
// eslint-disable-next-line @typescript-eslint/naming-convention
interface ServerMethods {
sendMessage(message: AtLeast<IMessage, '_id' | 'rid' | 'msg'>): any;
sendMessage(message: AtLeast<IMessage, '_id' | 'rid' | 'msg'>, previewUrls?: string[]): any;
}
}

Meteor.methods<ServerMethods>({
sendMessage(message) {
sendMessage(message, previewUrls) {
check(message, Object);

const uid = Meteor.userId();
Expand All @@ -118,7 +118,7 @@ Meteor.methods<ServerMethods>({
}

try {
return executeSendMessage(uid, message);
return executeSendMessage(uid, message, previewUrls);
} catch (error: any) {
if ((error.error || error.message) === 'error-not-allowed') {
throw new Meteor.Error(error.error || error.message, error.reason, {
Expand Down
Loading

0 comments on commit 7f28a8f

Please sign in to comment.