Skip to content

Commit 4e0055b

Browse files
committed
Finished implementation of clickable links. Had to add dname field to channel objects and message parser to make matching by parser possible without changing display of channels by using fname.
1 parent 978f9ea commit 4e0055b

File tree

2 files changed

+31
-16
lines changed

2 files changed

+31
-16
lines changed

app/importer-slack/server/importer.js

Lines changed: 29 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -243,35 +243,46 @@ export class SlackImporter extends Base {
243243
});
244244
}
245245

246-
parseMentions(message) {
247-
let mentionsParser;
248-
mentionsParser = new MentionsParser({
246+
parseMentions (message) {
247+
const mentionsParser = new MentionsParser({
249248
pattern: () => settings.get('UTF8_Names_Validation'),
250249
useRealName: () => settings.get('UI_Use_Real_Name'),
251250
me: () => 'me',
252251
});
253252

254-
if(!message.mentions){
255-
message.mentions=[];
253+
if (!message.mentions) {
254+
message.mentions = [];
256255
}
257-
message.mentions.push(...mentionsParser.getUserMentions(message.msg));
256+
let users = mentionsParser.getUserMentions(message.msg);
257+
users.forEach((user_id, index, arr) => {
258+
const user = user_id.slice(1, user_id.length);
259+
try {
260+
if (user === 'all' || user === 'here'){
261+
arr[index] = user;
262+
} else {
263+
arr[index] = Users.findOneByUsernameIgnoringCase(user);
264+
}
265+
} catch (e) {
266+
this.logger.warn(`Failed to import user mention with name: ${ user }`);
267+
}
268+
});
269+
message.mentions.push(...users);
258270

259-
if(!message.channels){
260-
message.channels=[];
271+
if (!message.channels) {
272+
message.channels = [];
261273
}
262274
let channels = mentionsParser.getChannelMentions(message.msg);
263275
channels.forEach((channel_name, index, arr) => {
264-
let chan = channel_name.slice(1, channel_name.length);
265-
try{
276+
const chan = channel_name.slice(1, channel_name.length);
277+
try {
266278
const slackChannel = this.getSlackChannelFromName(chan);
267279
arr[index] = Rooms.findOneById(slackChannel.rocketId);
280+
arr[index].dname = chan; // Have to store name to display so parser can match it
268281
} catch (e) {
269-
this.logger.warn(`Failed to import room with name: ${ chan }`);
282+
this.logger.warn(`Failed to import channel mention with name: ${ chan }`);
270283
}
271284
});
272285
message.channels.push(...channels);
273-
274-
message.temp = message.msg;
275286
}
276287

277288
processMessageSubType(message, room, msgDataDefaults, missedTypes) {
@@ -552,8 +563,12 @@ export class SlackImporter extends Base {
552563
Meteor.call('saveRoomSettings', 'GENERAL', 'roomName', channel.name);
553564
}
554565

566+
if (!channel.fname) {
567+
channel.fname = channel.name;
568+
}
569+
555570
channel.rocketId = channel.is_general ? 'GENERAL' : existingRoom._id;
556-
Rooms.update({ _id: channel.rocketId }, { $addToSet: { importIds: channel.id } });
571+
Rooms.update({ _id: channel.rocketId }, { $set: { fname: channel.name}, $addToSet: { importIds: channel.id } });
557572
} else {
558573
const users = this._getChannelUserList(channel);
559574
const userId = this.getImportedRocketUserIdFromSlackUserId(channel.creator) || startedByUserId;

app/mentions/lib/MentionsParser.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,11 +79,11 @@ export class MentionsParser {
7979
replaceChannels = (msg, { temp, channels }) => msg
8080
.replace(/'/g, '\'')
8181
.replace(this.channelMentionRegex, (match, prefix, mention) => {
82-
if (!temp && !(channels && channels.find((c) => c.name === mention))) {
82+
if (!temp && !(channels && channels.find((c) => c.dname ? c.dname === mention : c.name === mention))) {
8383
return match;
8484
}
8585

86-
const channel = channels && channels.find(({ name }) => name === mention);
86+
const channel = channels && channels.find(({ name, dname }) => dname? dname === mention : name === mention);
8787
const reference = channel ? channel._id : mention;
8888
return `${ prefix }<a class="mention-link mention-link--room" data-channel="${ reference }">${ `#${ mention }` }</a>`;
8989
})

0 commit comments

Comments
 (0)