コード例 #1
0
        private async Task SendWallSubscriberEmailsAsync(NewlyCreatedPostDto post,
                                                         IEnumerable <string> destinationEmails,
                                                         ApplicationUser postCreator,
                                                         Organization organization,
                                                         MultiwallWall wall)
        {
            var postLink = await GetPostLinkAsync(post.WallType, post.WallId, organization.ShortName, post.Id);

            var authorPictureUrl            = _appSettings.PictureUrl(organization.ShortName, postCreator.PictureId);
            var userNotificationSettingsUrl = _appSettings.UserNotificationSettingsUrl(organization.ShortName);
            var subject = string.Format(Templates.NewWallPostEmailSubject, wall.Name, postCreator.FullName);
            var body    = _markdownConverter.ConvertToHtml(post.MessageBody);

            var emailTemplateViewModel = new NewWallPostEmailTemplateViewModel(GetWallTitle(wall),
                                                                               authorPictureUrl,
                                                                               postCreator.FullName,
                                                                               postLink,
                                                                               body,
                                                                               userNotificationSettingsUrl,
                                                                               GetActionButtonTitle(wall));

            var content = _mailTemplate.Generate(emailTemplateViewModel, EmailTemplateCacheKeys.NewWallPost);

            var emailData = new EmailDto(destinationEmails, subject, content);
            await _mailingService.SendEmailAsync(emailData);
        }
コード例 #2
0
        private async Task SendMentionEmailsAsync(NewlyCreatedPostDto post, IEnumerable <ApplicationUser> mentionedUsers, ApplicationUser postCreator, Organization organization)
        {
            var          messageBody = _markdownConverter.ConvertToHtml(await _postService.GetPostBodyAsync(post.Id));
            var          userNotificationSettingsUrl = _appSettings.UserNotificationSettingsUrl(organization.ShortName);
            var          postUrl = _appSettings.WallPostUrl(organization.ShortName, post.Id);
            const string subject = "You have been mentioned in the post";

            foreach (var mentionedUser in mentionedUsers)
            {
                try
                {
                    if (mentionedUser.NotificationsSettings?.MentionEmailNotifications == false)
                    {
                        continue;
                    }

                    var newMentionTemplateViewModel = new NewMentionTemplateViewModel(mentionedUser.FullName,
                                                                                      postCreator.FacebookEmail,
                                                                                      postUrl,
                                                                                      userNotificationSettingsUrl,
                                                                                      messageBody);

                    var content = _mailTemplate.Generate(newMentionTemplateViewModel, EmailTemplateCacheKeys.NewMention);

                    var emailData = new EmailDto(mentionedUser.Email, subject, content);
                    await _mailingService.SendEmailAsync(emailData);
                }
                catch (Exception e)
                {
                    _logger.Debug(e.Message, e);
                }
            }
        }
コード例 #3
0
        public async Task NotifyAsync(NewPostDto postModel, NewlyCreatedPostDto createdPost, UserAndOrganizationHubDto userHubDto)
        {
            await _postNotificationService.NotifyAboutNewPostAsync(createdPost);

            var membersToNotify = await _wallService.GetWallMembersIdsAsync(postModel.WallId, postModel);

            await NotificationHub.SendWallNotificationAsync(postModel.WallId, membersToNotify, createdPost.WallType, userHubDto);
        }
コード例 #4
0
        public async Task NotifyAsync(NewlyCreatedPostDto createdPost, UserAndOrganizationHubDto userAndOrganizationHubDto)
        {
            await _postNotificationService.NotifyAboutNewPostAsync(createdPost);

            var membersToNotify = (await _userService.GetWallUserAppNotificationEnabledIdsAsync(createdPost.User.UserId, createdPost.WallId)).ToList();

            var notificationDto = await _notificationService.CreateForPostAsync(userAndOrganizationHubDto, createdPost, createdPost.WallId, membersToNotify);

            var notificationViewModel = _mapper.Map <NotificationViewModel>(notificationDto);
            await NotificationHub.SendNotificationToParticularUsersAsync(notificationViewModel, userAndOrganizationHubDto, membersToNotify);

            await NotificationHub.SendWallNotificationAsync(createdPost.WallId, membersToNotify, createdPost.WallType, userAndOrganizationHubDto);
        }
コード例 #5
0
ファイル: PostService.cs プロジェクト: VismaLietuva/simoona
        private static NewlyCreatedPostDto MapNewlyCreatedPostToDto(Post post, UserDto user, WallType wallType, IEnumerable <string> mentionedUserIds)
        {
            var newlyCreatedPostDto = new NewlyCreatedPostDto
            {
                Id                = post.Id,
                MessageBody       = post.MessageBody,
                PictureId         = post.PictureId,
                Created           = post.Created,
                CreatedBy         = post.CreatedBy,
                User              = user,
                WallType          = wallType,
                WallId            = post.WallId,
                MentionedUsersIds = mentionedUserIds
            };

            return(newlyCreatedPostDto);
        }
コード例 #6
0
        public async Task NotifyAboutNewPostAsync(NewlyCreatedPostDto post)
        {
            var postCreator = await _userService.GetApplicationUserAsync(post.User.UserId);

            var organization = await _organizationService.GetOrganizationByIdAsync(postCreator.OrganizationId);

            var wall = await _wallsDbSet.SingleAsync(w => w.Id == post.WallId);

            var mentionedUsers    = (await GetMentionedUsersAsync(post.MentionedUsersIds)).ToList();
            var destinationEmails = (await _userService.GetWallUsersEmailsAsync(postCreator.Email, wall))
                                    .Except(mentionedUsers.Select(x => x.Email)).ToList();

            if (destinationEmails.Count > 0)
            {
                await SendWallSubscriberEmailsAsync(post, destinationEmails, postCreator, organization, wall);
            }

            if (mentionedUsers.Count > 0)
            {
                await SendMentionEmailsAsync(post, mentionedUsers, postCreator, organization);
            }
        }
コード例 #7
0
        public async Task <NotificationDto> CreateForPostAsync(UserAndOrganizationDto userOrg, NewlyCreatedPostDto post, int wallId, IEnumerable <string> membersToNotify)
        {
            var postType = NotificationType.WallPost;
            var sources  = new Sources {
                PostId = post.Id
            };

            switch (post.WallType)
            {
            case WallType.Events:
                postType        = NotificationType.EventPost;
                sources.EventId = _eventDbSet.FirstOrDefault(x => x.WallId == wallId)?.Id.ToString();
                break;

            case WallType.Project:
                postType          = NotificationType.ProjectPost;
                sources.ProjectId = _projectDbSet.FirstOrDefault(x => x.WallId == wallId)?.Id.ToString();
                break;
            }

            var wallName = await _wallDbSet
                           .Where(x => x.Id == wallId && x.OrganizationId == userOrg.OrganizationId)
                           .Select(s => s.Name)
                           .SingleAsync();

            var newNotification = Notification.Create(post.User.FullName, wallName, post.User.PictureId, sources, postType, userOrg.OrganizationId, membersToNotify);

            _notificationDbSet.Add(newNotification);

            await _uow.SaveChangesAsync();

            return(_mapper.Map <NotificationDto>(newNotification));
        }