public Task <UserNotificationMessage> FormatUserMessageAsync(UserNotificationMessage message) { var result = CreateBasicFormattedUserNotificationMessage(message); ReviewContentNotificationModel reviewContent; try { reviewContent = _objectSerializer.Deserialize <ReviewContentNotificationModel>(message.Content); } catch (Exception) { reviewContent = new ReviewContentNotificationModel(); } if (reviewContent == null) { return(Task.FromResult(result)); } result.Subject = reviewContent.Title; if (!ContentReference.IsNullOrEmpty(reviewContent.ContentLink)) { result.Link = new Uri("epi.cms.contentdata:///" + reviewContent.ContentLink); } var userNameContainer = "<span class='epi-username external-review'>{0}</span>"; var userName = reviewContent.SenderDisplayName ?? "external editor"; userName = string.Format(userNameContainer, userName); result.Content = $"{userName} added new comment: \"'{reviewContent.Text?.Ellipsis(50)}'\""; return(Task.FromResult(result)); }
public async Task <bool> NotifyCmsEditor(ContentReference contentLink, string token, string data, bool isSenderEditModeUser) { if (!_options.Notifications.NotificationsEnabled) { return(false); } var contentVersion = _contentLoader.Get <IContent>(contentLink); if (contentVersion == null) { return(false); } var comment = _reviewLocationParser.GetLastComment(data); var notificationReceiver = (contentVersion as IChangeTrackable).ChangedBy; var users = new List <string> { notificationReceiver }; if (isSenderEditModeUser) { users.Add(comment.Author); } var subscribers = users.Select(x => new NotificationUser(x)).ToList(); // subscribe users to comment var subscriptionKey = new Uri($"advancedreviews://notification/{token}"); await _subscriptionService.SubscribeAsync(subscriptionKey, subscribers).ConfigureAwait(false); var recipients = (await _subscriptionService.ListSubscribersAsync(subscriptionKey).ConfigureAwait(false)) .Where(u => !u.UserName.Equals(comment.Author, StringComparison.OrdinalIgnoreCase)) .ToList(); if (!recipients.Any()) { return(false); } // send message var model = new ReviewContentNotificationModel { Title = contentVersion.Name, ContentLink = contentLink, SenderDisplayName = comment.Author, Text = comment.Text }; var notificationMessage = new NotificationMessage { ChannelName = ChannelName, Sender = new NotificationUser(_principalAccessor.CurrentName()), Recipients = recipients, Content = _objectSerializer.Serialize(model) }; try { await _notifier.PostNotificationAsync(notificationMessage).ConfigureAwait(false); } catch { return(false); } return(true); }