Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 15 additions & 2 deletions app/lib/server/functions/notifications/email.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { settings } from '../../../../settings';
import { roomTypes } from '../../../../utils';
import { metrics } from '../../../../metrics';
import { callbacks } from '../../../../callbacks';
import { getURL } from '../../../../utils/server';

let advice = '';
let goToMessage = '';
Expand Down Expand Up @@ -94,6 +95,19 @@ function getEmailContent({ message, user, room }) {
return header;
}

const getButtonUrl = (room, subscription, message) => {
const path = `${ s.ltrim(roomTypes.getRelativePath(room.t, subscription), '/') }?msg=${ message._id }`;
return getURL(path, {
full: true,
cloud: settings.get('Offline_Message_Use_DeepLink'),
cloud_route: 'room',
cloud_params: {
rid: room._id,
mid: message._id,
},
});
};

export function sendEmail({ message, user, subscription, room, emailAddress, hasMentionToUser }) {
const username = settings.get('UI_Use_Real_Name') ? message.u.name || message.u.username : message.u.username;
let subjectKey = 'Offline_Mention_All_Email';
Expand All @@ -114,8 +128,7 @@ export function sendEmail({ message, user, subscription, room, emailAddress, has
room,
});

const room_path = roomTypes.getURL(room.t, subscription);

const room_path = getButtonUrl(room, subscription, message);
const email = {
to: emailAddress,
subject: emailSubject,
Expand Down
5 changes: 5 additions & 0 deletions app/lib/server/startup/email.js
Original file line number Diff line number Diff line change
Expand Up @@ -406,6 +406,11 @@ settings.addGroup('Email', function() {
});
});

this.section('Offline_Message', function() {
this.add('Offline_Message_Use_DeepLink', true, {
type: 'boolean',
});
});

this.section('Invitation', function() {
this.add('Invitation_Subject', '{Invitation_Subject_Default}', {
Expand Down
6 changes: 6 additions & 0 deletions app/lib/server/startup/settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -831,6 +831,12 @@ settings.addGroup('General', function() {
],
public: true,
});

this.add('DeepLink_Url', 'https://go.rocket.chat', {
type: 'string',
public: true,
});

this.add('CDN_PREFIX', '', {
type: 'string',
public: true,
Expand Down
2 changes: 2 additions & 0 deletions app/markdown/tests/client.mocks.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ mock('../../settings', {
settings: {
get(setting) {
switch (setting) {
case 'DeepLink_Url':
return 'https://go.rocket.chat';
case 'Markdown_SupportSchemesForLink':
return 'http,https';
case 'Markdown_Parser':
Expand Down
4 changes: 4 additions & 0 deletions app/utils/lib/RoomTypesCommon.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,10 @@ export class RoomTypesCommon {
return FlowRouter.url(this.roomTypes[roomType].route.name, routeData);
}

getRelativePath(roomType, subData) {
return this.getRouteLink(roomType, subData).replace(Meteor.absoluteUrl(), '');
}

getRouteData(roomType, subData) {
if (!this.roomTypes[roomType]) {
return false;
Expand Down
24 changes: 17 additions & 7 deletions app/utils/lib/getURL.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,30 @@ import s from 'underscore.string';
import { isURL } from './isURL';
import { settings } from '../../settings';

function getCloudUrl(path, _site_url, cloudRoute) {
function getCloudUrl(path, _site_url, cloudRoute, cloudParams = {}) {
const cloudBaseUrl = (settings.get('DeepLink_Url') || '').replace(/\/+$/, '');

const siteUrl = s.rtrim(_site_url, '/');

// Remove the protocol
const host = siteUrl.replace(/https?\:\/\//i, '');
path = s.ltrim(path, '/');
const url = `https://go.rocket.chat/${ cloudRoute }?host=${ encodeURIComponent(host) }&path=${ encodeURIComponent(path) }`;

Object.assign(cloudParams, {
host,
path,
});

if (siteUrl.includes('http://')) {
return `${ url }&secure=no`;
cloudParams.secure = 'no';
}

return url;
const params = Object.entries(cloudParams).map(([key, value]) => `${ key }=${ encodeURIComponent(value) }`).join('&');

return `${ cloudBaseUrl }/${ cloudRoute }?${ params }`;
}

export const _getURL = (path, { cdn, full, cloud, cloud_route, _cdn_prefix, _root_url_path_prefix, _site_url }) => {
export const _getURL = (path, { cdn, full, cloud, cloud_route, cloud_params, _cdn_prefix, _root_url_path_prefix, _site_url }) => {
if (isURL(path)) {
return path;
}
Expand All @@ -37,7 +45,8 @@ export const _getURL = (path, { cdn, full, cloud, cloud_route, _cdn_prefix, _roo
const url = s.rtrim(`${ pathPrefix }/${ finalPath }`, '/') + query;

if (cloud) {
return getCloudUrl(url, siteUrl, cloudRoute);
const cloudParams = cloud_params || {};
return getCloudUrl(url, siteUrl, cloudRoute, cloudParams);
}

if (cdn && cdnPrefix !== '') {
Expand All @@ -51,11 +60,12 @@ export const _getURL = (path, { cdn, full, cloud, cloud_route, _cdn_prefix, _roo
return url;
};

export const getURL = (path, { cdn = true, full = false, cloud = false, cloud_route = '' } = {}) => _getURL(path, {
export const getURL = (path, { cdn = true, full = false, cloud = false, cloud_route = '', cloud_params = {} } = {}) => _getURL(path, {
cdn,
full,
cloud,
cloud_route,
cloud_params,
_cdn_prefix: settings.get('CDN_PREFIX'),
_root_url_path_prefix: __meteor_runtime_config__.ROOT_URL_PATH_PREFIX,
_site_url: settings.get('Site_Url'),
Expand Down
2 changes: 2 additions & 0 deletions packages/rocketchat-i18n/i18n/en.i18n.json
Original file line number Diff line number Diff line change
Expand Up @@ -2497,6 +2497,8 @@
"Offline_form": "Offline form",
"Offline_form_unavailable_message": "Offline Form Unavailable Message",
"Offline_Link_Message": "GO TO MESSAGE",
"Offline_Message": "Offline Message",
"Offline_Message_Use_DeepLink": "Use Deep Link URL Format",
"Offline_Mention_All_Email": "Mention All Email Subject",
"Offline_Mention_Email": "Mention Email Subject",
"Offline_message": "Offline message",
Expand Down
2 changes: 2 additions & 0 deletions packages/rocketchat-i18n/i18n/pt-BR.i18n.json
Original file line number Diff line number Diff line change
Expand Up @@ -2269,6 +2269,8 @@
"Offline_form": "Formulário offline",
"Offline_form_unavailable_message": "Mensage quando formulário offline indisponível",
"Offline_Link_Message": "VÁ PARA A MENSAGEM",
"Offline_Message": "Mensagem quando Offline",
"Offline_Message_Use_DeepLink": "Usar URL no formato Deep Link",
"Offline_Mention_All_Email": "Mencionar todo o assunto do e-mail",
"Offline_Mention_Email": "Você foi mencionado por __user__ em #__room__",
"Offline_message": "Mensagem quando offline",
Expand Down