From 08eef0f221604164df737432894907b391bc93a8 Mon Sep 17 00:00:00 2001 From: Paul-Sebastian Ungureanu Date: Mon, 11 Mar 2019 22:43:22 +0200 Subject: [PATCH] Add support for composing "silent mentions". Add markdown syntax for "silent mentions", which happens when a user starts their mention with "@_". --- markdown.js | 7 ++++--- marked.js | 8 ++++---- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/markdown.js b/markdown.js index 0fc3acf..5360416 100644 --- a/markdown.js +++ b/markdown.js @@ -155,18 +155,19 @@ function handleStream(streamName) { } -function handleUser(name) { +function handleUser(name, silently) { var person = this.people.get_by_name(name); + const silent = silently ? ' silent' : ''; if (person !== undefined) { if (this.people.is_my_user_id(person.user_id)) { push_uniquely(message.flags, 'mentioned'); } - return '' + + return '' + '@' + person.full_name + ''; } else if (name === 'all' || name === 'everyone') { push_uniquely(message.flags, 'mentioned'); - return '' + + return '' + '@' + name + ''; } diff --git a/marked.js b/marked.js index f884f90..d39d666 100644 --- a/marked.js +++ b/marked.js @@ -519,7 +519,7 @@ inline.zulip = merge({}, inline.breaks, { '\ud83d[\ude80-\udeff]|\ud83e[\udd00-\uddff]|' + '[\u2000-\u206F]|[\u2300-\u27BF]|[\u2B00-\u2BFF]|' + '[\u3000-\u303F]|[\u3200-\u32FF])'), - usermention: /^(@(?:\*\*([^\*]+)\*\*|(\w+)))/, // Match multi-word string between @** ** or match any one-word + usermention: /^(@(_?)(?:\*\*([^\*]+)\*\*|(\w+)))/, // Match multi-word string between @** ** or match any one-word stream: /^#\*\*([^\*]+)\*\*/, avatar: /^!avatar\(([^)]+)\)/, gravatar: /^!gravatar\(([^)]+)\)/, @@ -709,7 +709,7 @@ InlineLexer.prototype.output = function(src) { // usermention (zulip) if (cap = this.rules.usermention.exec(src)) { src = src.substring(cap[0].length); - out += this.usermention(cap[2] || cap[3], cap[1]); + out += this.usermention(cap[3] || cap[4], cap[1], cap[2]); continue; } @@ -856,13 +856,13 @@ InlineLexer.prototype.realm_filter = function (filter, matches, orig) { return this.options.realmFilterHandler(filter, matches); }; -InlineLexer.prototype.usermention = function (username, orig) { +InlineLexer.prototype.usermention = function (username, orig, silent) { if (typeof this.options.userMentionHandler !== 'function') { return orig; } - var handled = this.options.userMentionHandler(username); + var handled = this.options.userMentionHandler(username, silent === '_'); if (handled !== undefined) { return handled; }