mirror of
https://github.com/wekan/wekan.git
synced 2025-12-16 15:30:13 +01:00
commit
ddd00a27a9
3 changed files with 94 additions and 54 deletions
|
|
@ -381,6 +381,10 @@ a
|
||||||
display: block
|
display: block
|
||||||
word-wrap: break-word
|
word-wrap: break-word
|
||||||
|
|
||||||
|
table
|
||||||
|
word-wrap: normal
|
||||||
|
word-break: normal
|
||||||
|
|
||||||
ol
|
ol
|
||||||
list-style-type: decimal
|
list-style-type: decimal
|
||||||
padding-left: 20px
|
padding-left: 20px
|
||||||
|
|
|
||||||
|
|
@ -180,7 +180,7 @@ if (Meteor.isServer) {
|
||||||
const comment = activity.comment();
|
const comment = activity.comment();
|
||||||
params.comment = comment.text;
|
params.comment = comment.text;
|
||||||
if (board) {
|
if (board) {
|
||||||
const atUser = /(?:^|>|\b|\s)@(\S+)(?:\s|$|<|\b)/g;
|
const atUser = /(?:^|>|\b|\s)@(\S+?)(?:\s|$|<|\b)/g;
|
||||||
const comment = params.comment;
|
const comment = params.comment;
|
||||||
if (comment.match(atUser)) {
|
if (comment.match(atUser)) {
|
||||||
const commenter = params.user;
|
const commenter = params.user;
|
||||||
|
|
@ -192,12 +192,14 @@ if (Meteor.isServer) {
|
||||||
}
|
}
|
||||||
const atUser =
|
const atUser =
|
||||||
Users.findOne(username) || Users.findOne({ username });
|
Users.findOne(username) || Users.findOne({ username });
|
||||||
const uid = atUser && atUser._id;
|
if (atUser && atUser._id) {
|
||||||
params.atUsername = username;
|
const uid = atUser._id;
|
||||||
params.atEmails = atUser.emails;
|
params.atUsername = username;
|
||||||
if (board.hasMember(uid)) {
|
params.atEmails = atUser.emails;
|
||||||
title = 'act-atUserComment';
|
if (board.hasMember(uid)) {
|
||||||
watchers = _.union(watchers, [uid]);
|
title = 'act-atUserComment';
|
||||||
|
watchers = _.union(watchers, [uid]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -10,11 +10,39 @@ const postCatchError = Meteor.wrapAsync((url, options, resolve) => {
|
||||||
|
|
||||||
const Lock = {
|
const Lock = {
|
||||||
_lock: {},
|
_lock: {},
|
||||||
has(id) {
|
_timer: {},
|
||||||
return !!this._lock[id];
|
echoDelay: 500, // echo should be happening much faster
|
||||||
|
normalDelay: 1e3, // normally user typed comment will be much slower
|
||||||
|
ECHO: 2,
|
||||||
|
NORMAL: 1,
|
||||||
|
NULL: 0,
|
||||||
|
has(id, value) {
|
||||||
|
const existing = this._lock[id];
|
||||||
|
let ret = this.NULL;
|
||||||
|
if (existing) {
|
||||||
|
ret = existing === value ? this.ECHO : this.NORMAL;
|
||||||
|
}
|
||||||
|
return ret;
|
||||||
},
|
},
|
||||||
set(id) {
|
clear(id, delay) {
|
||||||
this._lock[id] = 1;
|
const previous = this._timer[id];
|
||||||
|
if (previous) {
|
||||||
|
Meteor.clearTimeout(previous);
|
||||||
|
}
|
||||||
|
this._timer[id] = Meteor.setTimeout(() => this.unset(id), delay);
|
||||||
|
},
|
||||||
|
set(id, value) {
|
||||||
|
const state = this.has(id, value);
|
||||||
|
let delay = this.normalDelay;
|
||||||
|
if (state === this.ECHO) {
|
||||||
|
delay = this.echoDelay;
|
||||||
|
}
|
||||||
|
if (!value) {
|
||||||
|
// user commented, we set a lock
|
||||||
|
value = 1;
|
||||||
|
}
|
||||||
|
this._lock[id] = value;
|
||||||
|
this.clear(id, delay); // always auto reset the locker after delay
|
||||||
},
|
},
|
||||||
unset(id) {
|
unset(id) {
|
||||||
delete this._lock[id];
|
delete this._lock[id];
|
||||||
|
|
@ -33,40 +61,44 @@ const webhooksAtbts = (process.env.WEBHOOKS_ATTRIBUTES &&
|
||||||
'commentId',
|
'commentId',
|
||||||
'swimlaneId',
|
'swimlaneId',
|
||||||
];
|
];
|
||||||
const responseFunc = 'reactOnHookResponse';
|
const responseFunc = data => {
|
||||||
Meteor.methods({
|
const paramCommentId = data.commentId;
|
||||||
[responseFunc](data) {
|
const paramCardId = data.cardId;
|
||||||
check(data, Object);
|
const paramBoardId = data.boardId;
|
||||||
const paramCommentId = data.commentId;
|
const newComment = data.comment;
|
||||||
const paramCardId = data.cardId;
|
if (paramCardId && paramBoardId && newComment) {
|
||||||
const paramBoardId = data.boardId;
|
// only process data with the cardid, boardid and comment text, TODO can expand other functions here to react on returned data
|
||||||
const newComment = data.comment;
|
const comment = CardComments.findOne({
|
||||||
if (paramCardId && paramBoardId && newComment) {
|
_id: paramCommentId,
|
||||||
// only process data with the cardid, boardid and comment text, TODO can expand other functions here to react on returned data
|
cardId: paramCardId,
|
||||||
const comment = CardComments.findOne({
|
boardId: paramBoardId,
|
||||||
_id: paramCommentId,
|
});
|
||||||
cardId: paramCardId,
|
const board = Boards.findOne(paramBoardId);
|
||||||
boardId: paramBoardId,
|
const card = Cards.findOne(paramCardId);
|
||||||
});
|
if (board && card) {
|
||||||
if (comment) {
|
if (comment) {
|
||||||
CardComments.update(comment._id, {
|
Lock.set(comment._id, newComment);
|
||||||
|
CardComments.direct.update(comment._id, {
|
||||||
$set: {
|
$set: {
|
||||||
text: newComment,
|
text: newComment,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
} else {
|
}
|
||||||
const userId = data.userId;
|
} else {
|
||||||
if (userId) {
|
const userId = data.userId;
|
||||||
CardComments.insert({
|
if (userId) {
|
||||||
text: newComment,
|
const inserted = CardComments.direct.insert({
|
||||||
userId,
|
text: newComment,
|
||||||
cardId,
|
userId,
|
||||||
boardId,
|
cardId,
|
||||||
});
|
boardId,
|
||||||
}
|
});
|
||||||
|
Lock.set(inserted._id, newComment);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
}
|
||||||
|
};
|
||||||
|
Meteor.methods({
|
||||||
outgoingWebhooks(integration, description, params) {
|
outgoingWebhooks(integration, description, params) {
|
||||||
check(integration, Object);
|
check(integration, Object);
|
||||||
check(description, String);
|
check(description, String);
|
||||||
|
|
@ -119,9 +151,20 @@ Meteor.methods({
|
||||||
if (token) headers['X-Wekan-Token'] = token;
|
if (token) headers['X-Wekan-Token'] = token;
|
||||||
const options = {
|
const options = {
|
||||||
headers,
|
headers,
|
||||||
data: is2way ? clonedParams : value,
|
data: is2way ? { description, ...clonedParams } : value,
|
||||||
};
|
};
|
||||||
const url = integration.url;
|
const url = integration.url;
|
||||||
|
if (is2way) {
|
||||||
|
const cid = params.commentId;
|
||||||
|
const comment = params.comment;
|
||||||
|
const lockState = cid && Lock.has(cid, comment);
|
||||||
|
if (cid && lockState !== Lock.NULL) {
|
||||||
|
// it's a comment and there is a previous lock
|
||||||
|
return;
|
||||||
|
} else if (cid) {
|
||||||
|
Lock.set(cid, comment); // set a lock here
|
||||||
|
}
|
||||||
|
}
|
||||||
const response = postCatchError(url, options);
|
const response = postCatchError(url, options);
|
||||||
|
|
||||||
if (
|
if (
|
||||||
|
|
@ -131,21 +174,12 @@ Meteor.methods({
|
||||||
response.statusCode < 300
|
response.statusCode < 300
|
||||||
) {
|
) {
|
||||||
if (is2way) {
|
if (is2way) {
|
||||||
const cid = params.commentId;
|
const data = response.data; // only an JSON encoded response will be actioned
|
||||||
const tooSoon = Lock.has(cid); // if an activity happens to fast, notification shouldn't fire with the same id
|
if (data) {
|
||||||
if (!tooSoon) {
|
try {
|
||||||
let clearNotification = () => {};
|
responseFunc(data);
|
||||||
if (cid) {
|
} catch (e) {
|
||||||
Lock.set(cid);
|
throw new Meteor.Error('error-process-data');
|
||||||
const clearNotificationFlagTimeout = 1000;
|
|
||||||
clearNotification = () => Lock.unset(cid);
|
|
||||||
Meteor.setTimeout(clearNotification, clearNotificationFlagTimeout);
|
|
||||||
}
|
|
||||||
const data = response.data; // only an JSON encoded response will be actioned
|
|
||||||
if (data) {
|
|
||||||
Meteor.call(responseFunc, data, () => {
|
|
||||||
clearNotification();
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue