diff options
author | 蔡仲明 (Romulus Urakagi Tsai) <urakagi@gmail.com> | 2019-11-21 11:25:56 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-11-21 11:25:56 +0800 |
commit | 3e0bedd8c7a6dec97352212adb1cbde1ade44190 (patch) | |
tree | 651ff30d25ddb0416444370368d699e597c142d7 /models/activities.js | |
parent | 9bbeb73db1cd0ce1caaaca8dfb14ea92131bbf9d (diff) | |
parent | 4f5de87cc4c2281bd576548693de7c94e6a988c6 (diff) | |
download | wekan-3e0bedd8c7a6dec97352212adb1cbde1ade44190.tar.gz wekan-3e0bedd8c7a6dec97352212adb1cbde1ade44190.tar.bz2 wekan-3e0bedd8c7a6dec97352212adb1cbde1ade44190.zip |
Merge pull request #1 from wekan/master
Update master
Diffstat (limited to 'models/activities.js')
-rw-r--r-- | models/activities.js | 70 |
1 files changed, 48 insertions, 22 deletions
diff --git a/models/activities.js b/models/activities.js index 3ecd5c8c..19e3fb7d 100644 --- a/models/activities.js +++ b/models/activities.js @@ -62,8 +62,14 @@ Activities.helpers({ //}, }); +Activities.before.update((userId, doc, fieldNames, modifier) => { + modifier.$set = modifier.$set || {}; + modifier.$set.modifiedAt = new Date(); +}); + Activities.before.insert((userId, doc) => { doc.createdAt = new Date(); + doc.modifiedAt = doc.createdAt; }); Activities.after.insert((userId, doc) => { @@ -174,25 +180,34 @@ if (Meteor.isServer) { const comment = activity.comment(); params.comment = comment.text; if (board) { - const atUser = /(?:^|>|\b|\s)@(\S+)(?:\s|$|<|\b)/g; const comment = params.comment; - if (comment.match(atUser)) { - const commenter = params.user; - while (atUser.exec(comment)) { - const username = RegExp.$1; - if (commenter === username) { - // it's person at himself, ignore it? - continue; - } - const user = Users.findOne(username) || Users.findOne({ username }); - const uid = user && user._id; - params.atUsername = username; - params.atEmails = user.emails; - if (board.hasMember(uid)) { - title = 'act-atUserComment'; - watchers = _.union(watchers, [uid]); - } + const knownUsers = board.members.map(member => { + const u = Users.findOne(member.userId); + if (u) { + member.username = u.username; + member.emails = u.emails; + } + return member; + }); + const mentionRegex = /\B@(?:(?:"([\w.\s]*)")|([\w.]+))/gi; // including space in username + let currentMention; + while ((currentMention = mentionRegex.exec(comment)) !== null) { + /*eslint no-unused-vars: ["error", { "varsIgnorePattern": "[iI]gnored" }]*/ + const [ignored, quoteduser, simple] = currentMention; + const username = quoteduser || simple; + if (username === params.user) { + // ignore commenter mention himself? + continue; + } + const atUser = _.findWhere(knownUsers, { username }); + if (!atUser) { + continue; } + const uid = atUser.userId; + params.atUsername = username; + params.atEmails = atUser.emails; + title = 'act-atUserComment'; + watchers = _.union(watchers, [uid]); } } params.commentId = comment._id; @@ -227,8 +242,8 @@ if (Meteor.isServer) { (!activity.timeKey || activity.timeKey === 'dueAt') && activity.timeValue ) { - // due time reminder - title = 'act-withDue'; + // due time reminder, if it doesn't have old value, it's a brand new set, need some differentiation + title = activity.timeOldValue ? 'act-withDue' : 'act-newDue'; } ['timeValue', 'timeOldValue'].forEach(key => { // copy time related keys & values to params @@ -268,13 +283,24 @@ if (Meteor.isServer) { }); const integrations = Integrations.find({ - boardId: board._id, - type: 'outgoing-webhooks', + boardId: { $in: [board._id, Integrations.Const.GLOBAL_WEBHOOK_ID] }, + // type: 'outgoing-webhooks', // all types enabled: true, activities: { $in: [description, 'all'] }, }).fetch(); if (integrations.length > 0) { - Meteor.call('outgoingWebhooks', integrations, description, params); + params.watchers = watchers; + integrations.forEach(integration => { + Meteor.call( + 'outgoingWebhooks', + integration, + description, + params, + () => { + return; + }, + ); + }); } }); } |