Skip to content

Commit

Permalink
prevent duplicate notifications in task bundles (#994)
Browse files Browse the repository at this point in the history
* prevent duplicate notifications in task bundles

* run formatter
  • Loading branch information
jschwarz2030 authored Dec 8, 2022
1 parent 0b8a894 commit ac83268
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@ class TaskBundleController @Inject() (
case None => throw new InvalidException("No tasks found in this bundle.")
}

var notify = true
for (task <- tasks) {
val action = this.actionManager.setAction(
Some(user),
Expand All @@ -168,7 +169,10 @@ class TaskBundleController @Inject() (
}

this.serviceManager.taskReview
.setTaskReviewStatus(task, reviewStatus, user, actionId, comment, errorTags)
.setTaskReviewStatus(task, reviewStatus, user, actionId, comment, errorTags, notify)

//disable notifications after the first task to prevent duplicates
notify = false

if (tags.nonEmpty) {
val tagList = tags.split(",").toList
Expand Down
17 changes: 14 additions & 3 deletions app/org/maproulette/framework/service/CommentService.scala
Original file line number Diff line number Diff line change
Expand Up @@ -115,8 +115,10 @@ class CommentService @Inject() (
case None => throw new InvalidException("No tasks found in this bundle.")
}

var notify = true
for (task <- tasks) {
this.create(user, task.id, URLDecoder.decode(comment, "UTF-8"), actionId)
this.create(user, task.id, URLDecoder.decode(comment, "UTF-8"), actionId, notify)
notify = false
}
bundle
}
Expand All @@ -128,9 +130,16 @@ class CommentService @Inject() (
* @param taskId The id of the task that the user is adding the comment too
* @param comment The actual comment being added
* @param actionId If there is any actions associated with this add
* @param notify enable/disable notification, used to prevent multiple notifications in task bundles
* @return The newly created comment object
*/
def create(user: User, taskId: Long, comment: String, actionId: Option[Long]): Comment = {
def create(
user: User,
taskId: Long,
comment: String,
actionId: Option[Long],
notify: Boolean = true
): Comment = {
val task = this.taskDAL.retrieveById(taskId) match {
case Some(t) => t
case None =>
Expand All @@ -140,7 +149,9 @@ class CommentService @Inject() (
throw new InvalidException("Invalid empty string supplied. Comment could not be created.")
}
val newComment = this.repository.create(user, task.id, comment, actionId)
this.serviceManager.notification.createMentionNotifications(user, newComment, task)
if (notify) {
this.serviceManager.notification.createMentionNotifications(user, newComment, task)
}
newComment
}

Expand Down
5 changes: 3 additions & 2 deletions app/org/maproulette/framework/service/TaskReviewService.scala
Original file line number Diff line number Diff line change
Expand Up @@ -434,7 +434,8 @@ class TaskReviewService @Inject() (
user: User,
actionId: Option[Long],
commentContent: String = "",
errorTags: String = ""
errorTags: String = "",
notify: Boolean = true
): Int = {
if (!permission.isSuperUser(user) && !user.settings.isReviewer.get && reviewStatus != Task.REVIEW_STATUS_REQUESTED &&
reviewStatus != Task.REVIEW_STATUS_DISPUTED && reviewStatus != Task.REVIEW_STATUS_UNNECESSARY) {
Expand Down Expand Up @@ -517,7 +518,7 @@ class TaskReviewService @Inject() (

val comment = commentContent.nonEmpty match {
case true =>
Some(this.serviceManager.comment.create(user, task.id, commentContent, actionId))
Some(this.serviceManager.comment.create(user, task.id, commentContent, actionId, notify))
case false => None
}

Expand Down

0 comments on commit ac83268

Please sign in to comment.