[Notice] Announcing the End of Demo Server [Read me]

Adds a method to get new mentioned users when issues are edited.
* Issue When issues are edited, all mentioned users in issue contents receives notification emails. It is not what Yobi want. The notifications have to be sent to only new mentioned users. * Solution A method to get new mentioned users is added. It gets mentioned users from old body and new body, subtracts old from new and returns it. Private-issue: 1023
@1e3d867a7b5d577643f83108254bbf41b85ad60d
--- app/models/NotificationEvent.java
+++ app/models/NotificationEvent.java
... | ... | @@ -657,7 +657,7 @@ |
657 | 657 |
public static NotificationEvent afterIssueBodyChanged(String oldBody, Issue issue) { |
658 | 658 |
NotificationEvent notiEvent = createFromCurrentUser(issue); |
659 | 659 |
notiEvent.title = formatReplyTitle(issue); |
660 |
- notiEvent.receivers = getReceivers(issue); |
|
660 |
+ notiEvent.receivers = getReceiversForIssueBodyChanged(oldBody, issue); |
|
661 | 661 |
notiEvent.eventType = EventType.ISSUE_BODY_CHANGED; |
662 | 662 |
notiEvent.oldValue = oldBody; |
663 | 663 |
notiEvent.newValue = issue.body; |
... | ... | @@ -665,6 +665,13 @@ |
665 | 665 |
NotificationEvent.add(notiEvent); |
666 | 666 |
|
667 | 667 |
return notiEvent; |
668 |
+ } |
|
669 |
+ |
|
670 |
+ private static Set<User> getReceiversForIssueBodyChanged(String oldBody, Issue issue) { |
|
671 |
+ Set<User> receivers = issue.getWatchers(); |
|
672 |
+ receivers.addAll(getNewMentionedUsers(oldBody, issue.body)); |
|
673 |
+ receivers.remove(UserApp.currentUser()); |
|
674 |
+ return receivers; |
|
668 | 675 |
} |
669 | 676 |
|
670 | 677 |
public static void afterNewPost(Posting post) { |
... | ... | @@ -998,6 +1005,12 @@ |
998 | 1005 |
return Messages.get("notification.member.request.accept.title", organization.name, user.loginId); |
999 | 1006 |
} |
1000 | 1007 |
|
1008 |
+ /** |
|
1009 |
+ * Get mentioned users in {@code body}. |
|
1010 |
+ * |
|
1011 |
+ * @param body |
|
1012 |
+ * @return |
|
1013 |
+ */ |
|
1001 | 1014 |
public static Set<User> getMentionedUsers(String body) { |
1002 | 1015 |
Matcher matcher = Pattern.compile("@" + User.LOGIN_ID_PATTERN_ALLOW_FORWARD_SLASH).matcher(body); |
1003 | 1016 |
Set<User> users = new HashSet<>(); |
... | ... | @@ -1011,6 +1024,25 @@ |
1011 | 1024 |
return users; |
1012 | 1025 |
} |
1013 | 1026 |
|
1027 |
+ /** |
|
1028 |
+ * Get new mentioned users. |
|
1029 |
+ * |
|
1030 |
+ * It gets mentioned users from {@code oldBody} and {@code newBody}, |
|
1031 |
+ * subtracts old from new and returns it. |
|
1032 |
+ * |
|
1033 |
+ * @param oldBody |
|
1034 |
+ * @param newBody |
|
1035 |
+ * @return |
|
1036 |
+ */ |
|
1037 |
+ public static Set<User> getNewMentionedUsers(String oldBody, String newBody) { |
|
1038 |
+ Set<User> oldBodyMentionedUsers = getMentionedUsers(oldBody); |
|
1039 |
+ Set<User> newBodyMentionedUsers = getMentionedUsers(newBody); |
|
1040 |
+ |
|
1041 |
+ newBodyMentionedUsers.removeAll(oldBodyMentionedUsers); |
|
1042 |
+ |
|
1043 |
+ return newBodyMentionedUsers; |
|
1044 |
+ } |
|
1045 |
+ |
|
1014 | 1046 |
private static Set<User> findOrganizationMembers(String mentionWord) { |
1015 | 1047 |
Set<User> users = new HashSet<>(); |
1016 | 1048 |
Organization org = Organization.findByName(mentionWord); |
Add a comment
Delete comment
Once you delete this comment, you won't be able to recover it. Are you sure you want to delete this comment?