Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/develop' into monorepo
Browse files Browse the repository at this point in the history
  • Loading branch information
ggazzo committed Apr 7, 2022
2 parents dca218a + 0a2c202 commit 6610a1a
Show file tree
Hide file tree
Showing 247 changed files with 5,894 additions and 1,443 deletions.
1 change: 1 addition & 0 deletions apps/meteor/.meteor/packages
Original file line number Diff line number Diff line change
Expand Up @@ -88,3 +88,4 @@ rocketchat:i18n
rocketchat:postcss
dandv:caret-position
facts-base@1.0.1
url
56 changes: 0 additions & 56 deletions apps/meteor/app/action-links/client/lib/actionLinks.js

This file was deleted.

74 changes: 74 additions & 0 deletions apps/meteor/app/action-links/client/lib/actionLinks.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
import { Meteor } from 'meteor/meteor';

import { handleError } from '../../../../client/lib/utils/handleError';
import { IMessage } from '../../../../definition/IMessage';

// Action Links namespace creation.
export const actionLinks = {
actions: new Map<string, Function>(),
register(name: string, fn: Function): void {
actionLinks.actions.set(name, fn);
},
// getMessage(name, messageId) {
// const userId = Meteor.userId();
// if (!userId) {
// throw new Meteor.Error('error-invalid-user', 'Invalid user', {
// function: 'actionLinks.getMessage',
// });
// }

// const message = Messages.findOne({ _id: messageId });
// if (!message) {
// throw new Meteor.Error('error-invalid-message', 'Invalid message', {
// function: 'actionLinks.getMessage',
// });
// }

// const subscription = Subscriptions.findOne({
// 'rid': message.rid,
// 'u._id': userId,
// });
// if (!subscription) {
// throw new Meteor.Error('error-not-allowed', 'Not allowed', {
// function: 'actionLinks.getMessage',
// });
// }

// if (!message.actionLinks || !message.actionLinks[name]) {
// throw new Meteor.Error('error-invalid-actionlink', 'Invalid action link', {
// function: 'actionLinks.getMessage',
// });
// }

// return message;
// },
run(method: string, message: IMessage, instance: undefined): void {
const actionLink = message.actionLinks && message.actionLinks.find((action) => action.method_id === method);

if (!actionLink) {
throw new Meteor.Error('error-invalid-actionlink', 'Invalid action link');
}

if (!actionLinks.actions.has(actionLink.method_id)) {
throw new Meteor.Error('error-invalid-actionlink', 'Invalid action link');
}

const fn = actionLinks.actions.get(actionLink.method_id);

let ranClient = false;

if (fn) {
// run just on client side
fn(message, actionLink.params, instance);

ranClient = true;
}

// and run on server side
Meteor.call('actionLinkHandler', name, message._id, (err: Error) => {
if (err && !ranClient) {
handleError(err);
}
});
},
};
22 changes: 11 additions & 11 deletions apps/meteor/app/apps/server/bridges/http.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import { fetch } from 'meteor/fetch';
import { HttpBridge } from '@rocket.chat/apps-engine/server/bridges/HttpBridge';
import { IHttpResponse } from '@rocket.chat/apps-engine/definition/accessors';
import { IHttpBridgeRequestInfo } from '@rocket.chat/apps-engine/server/bridges';

import { AppServerOrchestrator } from '../orchestrator';
import { getUnsafeAgent } from '../../../../server/lib/getUnsafeAgent';
import { fetch } from '../../../../server/lib/http/fetch';

const isGetOrHead = (method: string): boolean => ['GET', 'HEAD'].includes(method.toUpperCase());

Expand Down Expand Up @@ -70,15 +69,16 @@ export class AppHttpBridge extends HttpBridge {
this.orch.debugLog(`The App ${info.appId} is requesting from the outter webs:`, info);

try {
const response = await fetch(url.href, {
method,
body: content,
headers,
...(((request.hasOwnProperty('strictSSL') && !request.strictSSL) ||
(request.hasOwnProperty('rejectUnauthorized') && request.rejectUnauthorized)) && {
agent: getUnsafeAgent(url.protocol === 'https:' ? 'https:' : 'http:'),
}),
});
const response = await fetch(
url.href,
{
method,
body: content,
headers,
},
(request.hasOwnProperty('strictSSL') && !request.strictSSL) ||
(request.hasOwnProperty('rejectUnauthorized') && request.rejectUnauthorized),
);

const result: IHttpResponse = {
url: info.url,
Expand Down
2 changes: 1 addition & 1 deletion apps/meteor/app/apps/server/communication/rest.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { Meteor } from 'meteor/meteor';
import { HTTP } from 'meteor/http';
import { fetch } from 'meteor/fetch';

import { API } from '../../../api/server';
import { getUploadFormData } from '../../../api/server/lib/getUploadFormData';
Expand All @@ -12,6 +11,7 @@ import { Settings } from '../../../models/server/raw';
import { Apps } from '../orchestrator';
import { formatAppInstanceForRest } from '../../lib/misc/formatAppInstanceForRest';
import { actionButtonsHandler } from './endpoints/actionButtonsHandler';
import { fetch } from '../../../../server/lib/http/fetch';

const appsEngineVersionForMarketplace = Info.marketplaceApiVersion.replace(/-.*/g, '');
const getDefaultHeaders = () => ({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@ import { Meteor } from 'meteor/meteor';
import { Tracker } from 'meteor/tracker';

import { AutoTranslate } from './autotranslate';
import { settings } from '../../../settings';
import { hasAtLeastOnePermission } from '../../../authorization';
import { MessageAction } from '../../../ui-utils';
import { settings } from '../../../settings/client';
import { hasAtLeastOnePermission } from '../../../authorization/client';
import { MessageAction } from '../../../ui-utils/client/lib/MessageAction';
import { messageArgs } from '../../../ui-utils/client/lib/messageArgs';
import { Messages } from '../../../models';
import { Messages } from '../../../models/client';
import { isTranslatedMessage } from '../../../../definition/IMessage';

Meteor.startup(() => {
AutoTranslate.init();
Expand All @@ -18,20 +19,20 @@ Meteor.startup(() => {
icon: 'language',
label: 'Translate',
context: ['message', 'message-mobile', 'threads'],
action() {
const { msg: message } = messageArgs(this);
action(_, props) {
const { message = messageArgs(this).msg } = props;
const language = AutoTranslate.getLanguage(message.rid);
if (!message.translations || !message.translations[language]) {
if (!isTranslatedMessage(message) || !message.translations[language]) {
// } && !_.find(message.attachments, attachment => { return attachment.translations && attachment.translations[language]; })) {
AutoTranslate.messageIdsToWait[message._id] = true;
(AutoTranslate.messageIdsToWait as any)[message._id] = true;
Messages.update({ _id: message._id }, { $set: { autoTranslateFetching: true } });
Meteor.call('autoTranslate.translateMessage', message, language);
}
const action = message.autoTranslateShowInverse ? '$unset' : '$set';
const action = 'autoTranslateShowInverse' in message ? '$unset' : '$set';
Messages.update({ _id: message._id }, { [action]: { autoTranslateShowInverse: true } });
},
condition({ msg, u }) {
return msg && msg.u && msg.u._id !== u._id && msg.translations && !msg.translations.original;
condition({ message, user }) {
return Boolean(message?.u && message.u._id !== user._id && isTranslatedMessage(message) && !message.translations.original);
},
order: 90,
});
Expand All @@ -40,20 +41,20 @@ Meteor.startup(() => {
icon: 'language',
label: 'View_original',
context: ['message', 'message-mobile', 'threads'],
action() {
const { msg: message } = messageArgs(this);
action(_, props) {
const { message = messageArgs(this).msg } = props;
const language = AutoTranslate.getLanguage(message.rid);
if (!message.translations || !message.translations[language]) {
if (!isTranslatedMessage(message) || !message.translations[language]) {
// } && !_.find(message.attachments, attachment => { return attachment.translations && attachment.translations[language]; })) {
AutoTranslate.messageIdsToWait[message._id] = true;
(AutoTranslate.messageIdsToWait as any)[message._id] = true;
Messages.update({ _id: message._id }, { $set: { autoTranslateFetching: true } });
Meteor.call('autoTranslate.translateMessage', message, language);
}
const action = message.autoTranslateShowInverse ? '$unset' : '$set';
const action = 'autoTranslateShowInverse' in message ? '$unset' : '$set';
Messages.update({ _id: message._id }, { [action]: { autoTranslateShowInverse: true } });
},
condition({ msg, u }) {
return msg && msg.u && msg.u._id !== u._id && msg.translations && msg.translations.original;
condition({ message, user }) {
return Boolean(message?.u && message.u._id !== user._id && isTranslatedMessage(message) && message.translations.original);
},
order: 90,
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ Meteor.startup(function () {
icon: 'discussion',
label: 'Discussion_start',
context: ['message', 'message-mobile'],
async action() {
const { msg: message, room } = messageArgs(this);
async action(_, props) {
const { message = messageArgs(this).msg, room } = props;

imperativeModal.open({
component: CreateDiscussion,
Expand All @@ -34,16 +34,16 @@ Meteor.startup(function () {
});
},
condition({
msg: {
message: {
u: { _id: uid },
drid,
dcount,
},
room,
subscription,
u,
user,
}) {
if (drid || !isNaN(dcount)) {
if (drid || !Number.isNaN(dcount)) {
return false;
}
if (!subscription) {
Expand All @@ -54,7 +54,7 @@ Meteor.startup(function () {
return false;
}

return uid !== u._id ? hasPermission('start-discussion-other-user') : hasPermission('start-discussion');
return uid !== user._id ? hasPermission('start-discussion-other-user') : hasPermission('start-discussion');
},
order: 1,
group: 'menu',
Expand Down
24 changes: 24 additions & 0 deletions apps/meteor/app/highlight-words/client/client.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { IMessage } from '../../../definition/IMessage';
import { highlightWords, getRegexHighlight, getRegexHighlightUrl } from './helper';

// TODO: delete this file after message rewrites
export const createHighlightWordsMessageRenderer = ({
wordsToHighlight,
}: {
wordsToHighlight: string[];
}): (<T extends IMessage & { html: string }>(message: T) => T) => {
const highlights = wordsToHighlight.map((highlight) => ({
highlight,
regex: getRegexHighlight(highlight),
urlRegex: getRegexHighlightUrl(highlight),
}));

return <T extends IMessage & { html: string }>(message: T): T => {
if (!message.html?.trim()) {
return message;
}

message.html = highlightWords(message.html, highlights);
return message;
};
};
4 changes: 2 additions & 2 deletions apps/meteor/app/highlight-words/client/helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@ export const removeHighlightedUrls = (msg, highlight, urlMatches) => {
const highlightRegex = new RegExp(highlight, 'gmi');

return urlMatches.reduce((msg, match) => {
const withTemplate = match.replace(highlightRegex, `<span class="highlight-text">${highlight}</span>`);
const withTemplate = match.replace(highlightRegex, `<mark class="highlight-text">${highlight}</mark>`);
const regexWithTemplate = new RegExp(withTemplate, 'i');
return msg.replace(regexWithTemplate, match);
}, msg);
};

const highlightTemplate = '$1<span class="highlight-text">$2</span>$3';
const highlightTemplate = '$1<mark class="highlight-text">$2</mark>$3';

export const getRegexHighlight = (highlight) =>
new RegExp(
Expand Down
1 change: 1 addition & 0 deletions apps/meteor/app/highlight-words/client/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { createHighlightWordsMessageRenderer } from './client';
20 changes: 10 additions & 10 deletions apps/meteor/app/integrations/server/lib/triggerHandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import vm from 'vm';

import { Meteor } from 'meteor/meteor';
import { Random } from 'meteor/random';
import { fetch } from 'meteor/fetch';
import { HTTP } from 'meteor/http';
import _ from 'underscore';
import s from 'underscore.string';
Expand All @@ -16,7 +15,7 @@ import { settings } from '../../../settings/server';
import { getRoomByNameOrIdWithOptionToJoin, processWebhookMessage } from '../../../lib/server';
import { outgoingLogger } from '../logger';
import { integrations } from '../../lib/rocketchat';
import { getUnsafeAgent } from '../../../../server/lib/getUnsafeAgent';
import { fetch } from '../../../../server/lib/http/fetch';

export class RocketChatIntegrationHandler {
constructor() {
Expand Down Expand Up @@ -771,14 +770,15 @@ export class RocketChatIntegrationHandler {
opts.headers['Content-Type'] = 'application/json';
}

fetch(opts.url, {
method: opts.method,
headers: opts.headers,
...(settings.get('Allow_Invalid_SelfSigned_Certs') && {
agent: getUnsafeAgent(opts.url.startsWith('https:') ? 'https:' : 'http:'),
}),
...(opts.data && { body: JSON.stringify(opts.data) }),
})
fetch(
opts.url,
{
method: opts.method,
headers: opts.headers,
...(opts.data && { body: JSON.stringify(opts.data) }),
},
settings.get('Allow_Invalid_SelfSigned_Certs'),
)
.then(async (res) => {
const content = await res.text();
if (!content) {
Expand Down
Loading

0 comments on commit 6610a1a

Please sign in to comment.