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

Merge branch 'issue-1023' into 'next'
from pull-request 1433 * refs/heads/issue-1023: adds tests for models.NotificationEvent.getNewMentionedUsers method. Adds a method to get new mentioned users when issues are edited. Reviewed-by: 채수원
@3a461f859e070b0c9cfdbf1f9a0b9c9e4e6d789b
--- app/models/NotificationEvent.java
+++ app/models/NotificationEvent.java
... | ... | @@ -658,7 +658,7 @@ |
658 | 658 |
public static NotificationEvent afterIssueBodyChanged(String oldBody, Issue issue) { |
659 | 659 |
NotificationEvent notiEvent = createFromCurrentUser(issue); |
660 | 660 |
notiEvent.title = formatReplyTitle(issue); |
661 |
- notiEvent.receivers = getReceivers(issue); |
|
661 |
+ notiEvent.receivers = getReceiversForIssueBodyChanged(oldBody, issue); |
|
662 | 662 |
notiEvent.eventType = EventType.ISSUE_BODY_CHANGED; |
663 | 663 |
notiEvent.oldValue = oldBody; |
664 | 664 |
notiEvent.newValue = issue.body; |
... | ... | @@ -666,6 +666,13 @@ |
666 | 666 |
NotificationEvent.add(notiEvent); |
667 | 667 |
|
668 | 668 |
return notiEvent; |
669 |
+ } |
|
670 |
+ |
|
671 |
+ private static Set<User> getReceiversForIssueBodyChanged(String oldBody, Issue issue) { |
|
672 |
+ Set<User> receivers = issue.getWatchers(); |
|
673 |
+ receivers.addAll(getNewMentionedUsers(oldBody, issue.body)); |
|
674 |
+ receivers.remove(UserApp.currentUser()); |
|
675 |
+ return receivers; |
|
669 | 676 |
} |
670 | 677 |
|
671 | 678 |
public static void afterNewPost(Posting post) { |
... | ... | @@ -999,6 +1006,12 @@ |
999 | 1006 |
return Messages.get("notification.member.request.accept.title", organization.name, user.loginId); |
1000 | 1007 |
} |
1001 | 1008 |
|
1009 |
+ /** |
|
1010 |
+ * Get mentioned users in {@code body}. |
|
1011 |
+ * |
|
1012 |
+ * @param body |
|
1013 |
+ * @return |
|
1014 |
+ */ |
|
1002 | 1015 |
public static Set<User> getMentionedUsers(String body) { |
1003 | 1016 |
Matcher matcher = Pattern.compile("@" + User.LOGIN_ID_PATTERN_ALLOW_FORWARD_SLASH).matcher(body); |
1004 | 1017 |
Set<User> users = new HashSet<>(); |
... | ... | @@ -1012,6 +1025,25 @@ |
1012 | 1025 |
return users; |
1013 | 1026 |
} |
1014 | 1027 |
|
1028 |
+ /** |
|
1029 |
+ * Get new mentioned users. |
|
1030 |
+ * |
|
1031 |
+ * It gets mentioned users from {@code oldBody} and {@code newBody}, |
|
1032 |
+ * subtracts old from new and returns it. |
|
1033 |
+ * |
|
1034 |
+ * @param oldBody |
|
1035 |
+ * @param newBody |
|
1036 |
+ * @return |
|
1037 |
+ */ |
|
1038 |
+ public static Set<User> getNewMentionedUsers(String oldBody, String newBody) { |
|
1039 |
+ Set<User> oldBodyMentionedUsers = getMentionedUsers(oldBody); |
|
1040 |
+ Set<User> newBodyMentionedUsers = getMentionedUsers(newBody); |
|
1041 |
+ |
|
1042 |
+ newBodyMentionedUsers.removeAll(oldBodyMentionedUsers); |
|
1043 |
+ |
|
1044 |
+ return newBodyMentionedUsers; |
|
1045 |
+ } |
|
1046 |
+ |
|
1015 | 1047 |
private static Set<User> findOrganizationMembers(String mentionWord) { |
1016 | 1048 |
Set<User> users = new HashSet<>(); |
1017 | 1049 |
Organization org = Organization.findByName(mentionWord); |
--- test/models/NotificationEventTest.java
+++ test/models/NotificationEventTest.java
... | ... | @@ -26,6 +26,7 @@ |
26 | 26 |
|
27 | 27 |
|
28 | 28 |
import java.util.HashSet; |
29 |
+import java.util.Set; |
|
29 | 30 |
|
30 | 31 |
import static org.fest.assertions.Assertions.assertThat; |
31 | 32 |
|
... | ... | @@ -104,4 +105,37 @@ |
104 | 105 |
// Then |
105 | 106 |
assertThat(event.receivers).containsOnly(off); |
106 | 107 |
} |
108 |
+ |
|
109 |
+ @Test |
|
110 |
+ public void getNewMentionedUsers1() { |
|
111 |
+ // Given |
|
112 |
+ String loginId = "doortts"; |
|
113 |
+ String oldBody = "I'm @yobi"; |
|
114 |
+ String newBody = "I'm @" + loginId; |
|
115 |
+ |
|
116 |
+ // When |
|
117 |
+ Set<User> newMentionedUsers = NotificationEvent.getNewMentionedUsers(oldBody, newBody); |
|
118 |
+ |
|
119 |
+ // Then |
|
120 |
+ User newMentionedUser = User.findByLoginId(loginId); |
|
121 |
+ assertThat(newMentionedUsers.size() == 1).isTrue(); |
|
122 |
+ assertThat(newMentionedUsers.contains(newMentionedUser)).isTrue(); |
|
123 |
+ } |
|
124 |
+ |
|
125 |
+ @Test |
|
126 |
+ public void getNewMentionedUsers2() { |
|
127 |
+ // Given |
|
128 |
+ String loginId = "laziel"; |
|
129 |
+ String oldBody = "They are @yobi and @doortts"; |
|
130 |
+ String newBody = "They are @" + loginId + " and @unknownUserLoginId"; |
|
131 |
+ |
|
132 |
+ // When |
|
133 |
+ Set<User> newMentionedUsers = NotificationEvent.getNewMentionedUsers(oldBody, newBody); |
|
134 |
+ |
|
135 |
+ // Then |
|
136 |
+ User newMentionedUser = User.findByLoginId(loginId); |
|
137 |
+ assertThat(newMentionedUsers.size() == 1).isTrue(); |
|
138 |
+ assertThat(newMentionedUsers.contains(newMentionedUser)).isTrue(); |
|
139 |
+ } |
|
140 |
+ |
|
107 | 141 |
} |
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?