Skip to content

The Unified and Autonomous Development Platform

Send issue/pull request notification to watchers whenever there is an event

Robin Shenb1cb96d321a5
diff --git a/server-core/src/main/java/io/onedev/server/infomanager/DefaultUserInfoManager.java b/server-core/src/main/java/io/onedev/server/infomanager/DefaultUserInfoManager.java
index 4af1bc0f74..c12579b9a1 100644
--- a/server-core/src/main/java/io/onedev/server/infomanager/DefaultUserInfoManager.java
+++ b/server-core/src/main/java/io/onedev/server/infomanager/DefaultUserInfoManager.java
@@ -38,20 +38,16 @@ import jetbrains.exodus.env.TransactionalExecutable;
@Singleton
public class DefaultUserInfoManager extends AbstractEnvironmentManager implements UserInfoManager {
- private static final int INFO_VERSION = 5;
+ private static final int INFO_VERSION = 6;
private static final String PULL_REQUEST_VISIT_STORE = "pullRequestVisit";
- private static final String PULL_REQUEST_NOTIFICATION_STORE = "pullRequestNotification";
-
private static final String PULL_REQUEST_CODE_COMMENTS_VISIT_STORE = "pullRequestCodeCommentsVisit";
private static final String CODE_COMMENT_VISIT_STORE = "codeCommentVisit";
private static final String ISSUE_VISIT_STORE = "issueVisit";
- private static final String ISSUE_NOTIFICATION_STORE = "issueNotification";
-
private final StorageManager storageManager;
@Inject
@@ -89,8 +85,6 @@ public class DefaultUserInfoManager extends AbstractEnvironmentManager implement
}
});
-
- setIssueNotified(user, issue, false);
}
@Override
@@ -106,8 +100,6 @@ public class DefaultUserInfoManager extends AbstractEnvironmentManager implement
}
});
-
- setPullRequestNotified(user, request, false);
}
@Override
@@ -236,62 +228,4 @@ public class DefaultUserInfoManager extends AbstractEnvironmentManager implement
}
}
- @Override
- public boolean isNotified(User user, PullRequest request) {
- Environment env = getEnv(request.getTargetProject().getId().toString());
- Store store = getStore(env, PULL_REQUEST_NOTIFICATION_STORE);
- return env.computeInTransaction(new TransactionalComputable<Boolean>() {
-
- @Override
- public Boolean compute(Transaction txn) {
- return readBoolean(store, txn, new LongsByteIterable(Lists.newArrayList(user.getId(), request.getId())), false);
- }
-
- });
- }
-
- @Override
- public boolean isNotified(User user, Issue issue) {
- Environment env = getEnv(issue.getProject().getId().toString());
- Store store = getStore(env, ISSUE_NOTIFICATION_STORE);
- return env.computeInTransaction(new TransactionalComputable<Boolean>() {
-
- @Override
- public Boolean compute(Transaction txn) {
- return readBoolean(store, txn, new LongsByteIterable(Lists.newArrayList(user.getId(), issue.getId())), false);
- }
-
- });
- }
-
- @Override
- public void setPullRequestNotified(User user, PullRequest request, boolean notified) {
- Environment env = getEnv(request.getTargetProject().getId().toString());
-
- Store store = getStore(env, PULL_REQUEST_NOTIFICATION_STORE);
- env.executeInTransaction(new TransactionalExecutable() {
-
- @Override
- public void execute(Transaction txn) {
- writeBoolean(store, txn, new LongsByteIterable(Lists.newArrayList(user.getId(), request.getId())), notified);
- }
-
- });
- }
-
- @Override
- public void setIssueNotified(User user, Issue issue, boolean notified) {
- Environment env = getEnv(issue.getProject().getId().toString());
-
- Store store = getStore(env, ISSUE_NOTIFICATION_STORE);
- env.executeInTransaction(new TransactionalExecutable() {
-
- @Override
- public void execute(Transaction txn) {
- writeBoolean(store, txn, new LongsByteIterable(Lists.newArrayList(user.getId(), issue.getId())), notified);
- }
-
- });
- }
-
}
diff --git a/server-core/src/main/java/io/onedev/server/infomanager/UserInfoManager.java b/server-core/src/main/java/io/onedev/server/infomanager/UserInfoManager.java
index ada93953fa..435b6cf19a 100644
--- a/server-core/src/main/java/io/onedev/server/infomanager/UserInfoManager.java
+++ b/server-core/src/main/java/io/onedev/server/infomanager/UserInfoManager.java
@@ -19,14 +19,6 @@ public interface UserInfoManager {
void visitCodeComment(User user, CodeComment comment);
- boolean isNotified(User user, PullRequest request);
-
- boolean isNotified(User user, Issue issue);
-
- void setPullRequestNotified(User user, PullRequest request, boolean notified);
-
- void setIssueNotified(User user, Issue issue, boolean notified);
-
@Nullable
Date getIssueVisitDate(User user, Issue issue);
diff --git a/server-core/src/main/java/io/onedev/server/notification/IssueNotificationManager.java b/server-core/src/main/java/io/onedev/server/notification/IssueNotificationManager.java
index 3c3805ce82..59dc8eea8b 100644
--- a/server-core/src/main/java/io/onedev/server/notification/IssueNotificationManager.java
+++ b/server-core/src/main/java/io/onedev/server/notification/IssueNotificationManager.java
@@ -149,10 +149,9 @@ public class IssueNotificationManager {
.collect(Collectors.toSet());
mailManager.sendMailAsync(emails, subject, body.toString());
- for (User member: entry.getValue().getMembers()) {
- userInfoManager.setIssueNotified(member, issue, true);
+ for (User member: entry.getValue().getMembers())
issueWatchManager.watch(issue, member, true);
- }
+
notifiedUsers.addAll(entry.getValue().getMembers());
}
for (Map.Entry<String, Collection<User>> entry: newUsers.entrySet()) {
@@ -165,10 +164,8 @@ public class IssueNotificationManager {
.collect(Collectors.toSet());
mailManager.sendMailAsync(emails, subject, body.toString());
- for (User each: entry.getValue()) {
+ for (User each: entry.getValue())
issueWatchManager.watch(issue, each, true);
- userInfoManager.setIssueNotified(each, issue, true);
- }
notifiedUsers.addAll(entry.getValue());
}
@@ -196,7 +193,6 @@ public class IssueNotificationManager {
mailManager.sendMailAsync(Sets.newHashSet(mentionedUser.getEmail()), subject, body);
issueWatchManager.watch(issue, mentionedUser, true);
- userInfoManager.setIssueNotified(mentionedUser, issue, true);
notifiedUsers.add(mentionedUser);
}
}
@@ -221,11 +217,9 @@ public class IssueNotificationManager {
for (IssueWatch watch: issue.getWatches()) {
Date visitDate = userInfoManager.getIssueVisitDate(watch.getUser(), issue);
if (watch.isWatching()
- && !userInfoManager.isNotified(watch.getUser(), watch.getIssue())
&& (visitDate == null || visitDate.before(event.getDate()))
&& !notifiedUsers.contains(watch.getUser())) {
usersToNotify.add(watch.getUser());
- userInfoManager.setIssueNotified(watch.getUser(), watch.getIssue(), true);
}
}
diff --git a/server-core/src/main/java/io/onedev/server/notification/PullRequestNotificationManager.java b/server-core/src/main/java/io/onedev/server/notification/PullRequestNotificationManager.java
index 6579fd98b9..81bf6ec28f 100644
--- a/server-core/src/main/java/io/onedev/server/notification/PullRequestNotificationManager.java
+++ b/server-core/src/main/java/io/onedev/server/notification/PullRequestNotificationManager.java
@@ -184,7 +184,6 @@ public class PullRequestNotificationManager {
String url = urlManager.urlFor(request);
String body = String.format("Visit <a href='%s'>%s</a> for details", url, url);
mailManager.sendMailAsync(Lists.newArrayList(request.getSubmitter().getEmail()), subject, body);
- userInfoManager.setPullRequestNotified(request.getSubmitter(), request, true);
notifiedUsers.add(request.getSubmitter());
}
}
@@ -215,7 +214,6 @@ public class PullRequestNotificationManager {
String body = String.format("Visit <a href='%s'>%s</a> for details", url, url);
mailManager.sendMailAsync(Sets.newHashSet(mentionedUser.getEmail()), subject, body);
- userInfoManager.setPullRequestNotified(mentionedUser, request, true);
notifiedUsers.add(mentionedUser);
}
@@ -243,12 +241,10 @@ public class PullRequestNotificationManager {
for (PullRequestWatch watch: request.getWatches()) {
Date visitDate = userInfoManager.getPullRequestVisitDate(watch.getUser(), request);
if (watch.isWatching()
- && !userInfoManager.isNotified(watch.getUser(), watch.getRequest())
&& (visitDate == null || visitDate.before(event.getDate()))
&& (!(event instanceof PullRequestUpdated) || !watch.getUser().equals(request.getSubmitter()))
&& !notifiedUsers.contains(watch.getUser())) {
usersToNotify.add(watch.getUser());
- userInfoManager.setPullRequestNotified(watch.getUser(), watch.getRequest(), true);
}
}
@@ -273,7 +269,6 @@ public class PullRequestNotificationManager {
String subject = String.format("You are invited to review pull request %s", request.describe());
String body = String.format("Visit <a href='%s'>%s</a> for details", url, url);
mailManager.sendMailAsync(Lists.newArrayList(review.getUser().getEmail()), subject, body);
- userInfoManager.setPullRequestNotified(review.getUser(), review.getRequest(), true);
}
@Transactional