[FIX] Fix permalink of message when running system with subdir (#11781)

* Fix permalink of message when running system with subdir

* Fix linter error

* fix some code style
pull/11796/head^2
Hiroki Ishiura 7 years ago committed by Guilherme Gazzo
parent f71b740246
commit d289d4087b
  1. 4
      packages/rocketchat-lib/client/MessageAction.js
  2. 17
      packages/rocketchat-lib/client/lib/roomTypes.js
  3. 25
      packages/rocketchat-lib/lib/RoomTypesCommon.js
  4. 5
      packages/rocketchat-lib/server/functions/notifications/email.js

@ -119,8 +119,8 @@ RocketChat.MessageAction = new class {
}
const subData = RocketChat.models.Subscriptions.findOne({ rid: roomData._id, 'u._id': Meteor.userId() });
const routePath = RocketChat.roomTypes.getRouteLink(roomData.t, subData || roomData);
return `${ Meteor.absoluteUrl(routePath.replace(/^\//, '')) }?msg=${ msgId }`;
const roomURL = RocketChat.roomTypes.getURL(roomData.t, subData || roomData);
return `${ roomURL }?msg=${ msgId }`;
}
};

@ -113,4 +113,21 @@ RocketChat.roomTypes = new class RocketChatRoomTypes extends RoomTypesCommon {
}
return this.roomTypes[roomType].notSubscribedTpl;
}
openRouteLink(roomType, subData, queryParams) {
if (!this.roomTypes[roomType]) {
return false;
}
let routeData = {};
if (this.roomTypes[roomType] && this.roomTypes[roomType].route && this.roomTypes[roomType].route.link) {
routeData = this.roomTypes[roomType].route.link(subData);
} else if (subData && subData.name) {
routeData = {
name: subData.name,
};
}
return FlowRouter.go(this.roomTypes[roomType].route.name, routeData, queryParams);
}
};

@ -74,23 +74,6 @@ export class RoomTypesCommon {
return FlowRouter.path(this.roomTypes[roomType].route.name, routeData);
}
openRouteLink(roomType, subData, queryParams) {
if (!this.roomTypes[roomType]) {
return false;
}
let routeData = {};
if (this.roomTypes[roomType] && this.roomTypes[roomType].route && this.roomTypes[roomType].route.link) {
routeData = this.roomTypes[roomType].route.link(subData);
} else if (subData && subData.name) {
routeData = {
name: subData.name,
};
}
return FlowRouter.go(this.roomTypes[roomType].route.name, routeData, queryParams);
}
/**
* @param {string} roomType room type (e.g.: c (for channels), d (for direct channels))
* @param {RoomTypeConfig} roomConfig room's type configuration
@ -98,4 +81,12 @@ export class RoomTypesCommon {
getConfig(roomType) {
return this.roomTypes[roomType];
}
getURL(...args) {
const path = this.getRouteLink(...args);
if (!path) {
return false;
}
return Meteor.absoluteUrl(path.replace(/^\//, ''));
}
}

@ -71,8 +71,7 @@ function getEmailContent({ message, user, room }) {
}
function getMessageLink(room, sub) {
const roomPath = RocketChat.roomTypes.getRouteLink(room.t, sub);
const path = Meteor.absoluteUrl(roomPath ? roomPath.replace(/^\//, '') : '');
const roomPath = RocketChat.roomTypes.getURL(room.t, sub);
const style = [
'color: #fff;',
'padding: 9px 12px;',
@ -81,7 +80,7 @@ function getMessageLink(room, sub) {
'text-decoration: none;',
].join(' ');
const message = TAPi18n.__('Offline_Link_Message');
return `<p style="text-align:center;margin-bottom:8px;"><a style="${ style }" href="${ path }">${ message }</a>`;
return `<p style="text-align:center;margin-bottom:8px;"><a style="${ style }" href="${ roomPath }">${ message }</a>`;
}
export function sendEmail({ message, user, subscription, room, emailAddress, hasMentionToUser }) {

Loading…
Cancel
Save