public async Task Run([QueueTrigger(Shared.Constants.QueueNames.ReactionAdded, Connection = "AzureWebJobsStorage")] ReactionAddedMessage reactionAddedMessage, ILogger log) { var activity = await activityRepository.GetActivityAsync(reactionAddedMessage.ActivityId); var reactingUser = await userRepository.GetUserAsync(reactionAddedMessage.UserId); var originUser = await userRepository.GetUserAsync(activity.UserId); await this.activityDistributionService.DistributeActivitiesAsync(originUser, activity.ToEntity()); List <NotificationBase> notifications = new List <NotificationBase>(); var url = GetActivityUrlWithHighlightedActivityId(activity.Id); // notify involved users if (activity.UserId != reactingUser.Id) { var notification = new ReactionNotification( originUser.Id, reactionAddedMessage.ReactionType, reactingUser.Name, originUser.Name, true, url); notifications.Add(notification); } // now other ones (with likes and cheers) var involvedUserNotifications = activity.Cheers?.Select(c => new UserInfo(c.UserId, c.UserName)) .Union(activity.Likes?.Select(l => new UserInfo(l.UserId, l.UserName))) .Union(activity.Comments?.Select(c => new UserInfo(c.UserId, c.UserName))) .Distinct() .Where(u => u.UserId != activity.UserId && u.UserId != reactingUser.Id) .ToList(); var involvedNotifications = involvedUserNotifications .Select(u => new ReactionNotification(u.UserId, reactionAddedMessage.ReactionType, reactingUser.Name, activity.UserName, false, url)) .ToList(); notifications.AddRange(involvedNotifications); await pushNotificationService.NotifyAsync(notifications); }
private async Task <NotificationMessage> BuildNotificationMessageAsync(string language, ReactionNotification notification) { string message = null; string postFix; if (notification.IsPersonal) { postFix = "Your"; } else if (notification.OriginUserName == notification.ReactingUserName) { postFix = "Self"; } else { postFix = "Other"; } switch (notification.ReactionType) { case ReactionType.Cheers: message = await translationService.GetTranslationAsync(language, "CheersReactionMessage" + postFix, notification.OriginUserName); break; case ReactionType.Like: message = await translationService.GetTranslationAsync(language, "LikeReactionMessage" + postFix, notification.OriginUserName); break; case ReactionType.Comment: message = await translationService.GetTranslationAsync(language, "CommentReactionMessage" + postFix, notification.OriginUserName); break; } return(new NotificationMessage(Constants.ApplicationName, $"{notification.ReactingUserName} {message}")); }