Skip to content

Commit

Permalink
Add Challenge Comment Notifications for Owners (#975)
Browse files Browse the repository at this point in the history
* notify the challenge owners of challenge comments

* run scalafmt

* remove unused var

* fix variable reference to email setting

* run formatter again
  • Loading branch information
jschwarz2030 authored Oct 11, 2022
1 parent e2476cd commit 9fb96d0
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 2 deletions.
5 changes: 4 additions & 1 deletion app/org/maproulette/framework/model/UserNotification.scala
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,8 @@ object UserNotification extends CommonField {
val NOTIFICATION_TYPE_REVIEW_COUNT_NAME = "Review Count"
val NOTIFICATION_TYPE_REVISION_COUNT = 13
val NOTIFICATION_TYPE_REVISION_COUNT_NAME = "Revision Count"
val NOTIFICATION_TYPE_CHALLENGE_COMMENT = 14
val NOTIFICATION_TYPE_CHALLENGE_COMMENT_NAME = "Challenge Comment"

val notificationTypeMap = Map(
NOTIFICATION_TYPE_SYSTEM -> NOTIFICATION_TYPE_SYSTEM_NAME,
Expand All @@ -91,7 +93,8 @@ object UserNotification extends CommonField {
NOTIFICATION_TYPE_CHALLENGE_COMPLETED -> NOTIFICATION_TYPE_CHALLENGE_COMPLETED_NAME,
NOTIFICATION_TYPE_TEAM -> NOTIFICATION_TYPE_TEAM_NAME,
NOTIFICATION_TYPE_FOLLOW -> NOTIFICATION_TYPE_FOLLOW_NAME,
NOTIFICATION_TYPE_MAPPER_CHALLENGE_COMPLETED -> NOTIFICATION_TYPE_MAPPER_CHALLENGE_COMPLETED_NAME
NOTIFICATION_TYPE_MAPPER_CHALLENGE_COMPLETED -> NOTIFICATION_TYPE_MAPPER_CHALLENGE_COMPLETED_NAME,
NOTIFICATION_TYPE_CHALLENGE_COMMENT -> NOTIFICATION_TYPE_CHALLENGE_COMMENT_NAME
)

val NOTIFICATION_IGNORE = 0 // ignore notification
Expand Down
25 changes: 24 additions & 1 deletion app/org/maproulette/framework/service/NotificationService.scala
Original file line number Diff line number Diff line change
Expand Up @@ -192,13 +192,34 @@ class NotificationService @Inject() (
// match [@username] (username may contain spaces) or @username (no spaces allowed)
val mentionRegex = """\[@([^\]]+)\]|@([\w\d_-]+)""".r.unanchored

// Challenge owners should be notified everytime a challenge comment is posted unless its their comment
if (fromUser.id != challenge.general.owner) {
this.addNotification(
UserNotification(
-1,
userId = challenge.general.owner,
notificationType = UserNotification.NOTIFICATION_TYPE_CHALLENGE_COMMENT,
fromUsername = Some(fromUser.osmProfile.displayName),
taskId = None,
challengeId = Some(challenge.id),
targetId = Some(comment.id),
extra = Some(comment.comment)
),
User.superUser
)
}

for (m <- mentionRegex.findAllMatchIn(comment.comment)) {
// use first non-null group
val username = m.subgroups.filter(_ != null).head

// Retrieve and notify mentioned user
this.serviceManager.user.retrieveByOSMUsername(username, User.superUser) match {
case Some(mentionedUser) =>
// Since challenge owners always get notified, don't duplicate the notification if they're mentioned
if (mentionedUser.id == challenge.general.owner) {
return None
}
this.addNotification(
UserNotification(
-1,
Expand Down Expand Up @@ -426,7 +447,9 @@ class NotificationService @Inject() (
subscriptions.challengeCompleted
case UserNotification.NOTIFICATION_TYPE_TEAM => subscriptions.team
case UserNotification.NOTIFICATION_TYPE_FOLLOW => subscriptions.follow
case _ => throw new InvalidException("Invalid notification type")
case UserNotification.NOTIFICATION_TYPE_CHALLENGE_COMMENT =>
UserNotification.NOTIFICATION_EMAIL_IMMEDIATE
case _ => throw new InvalidException("Invalid notification type")
}

// Guard against ignored notification type
Expand Down

0 comments on commit 9fb96d0

Please sign in to comment.