예제 #1
0
        internal async Task <Activity> GetActivity(AuditRecord audit, ApplicationUser user)
        {
            var avatar = user.Avatar;

            if (!GenericAvatarConstructor.IsGenericAvatar(avatar) && _s3Service.CheckIfPresignedUrlIsExpired(avatar))
            {
                avatar = await _s3Service.GetPresignedUrlAsync(avatar);
            }

            var userInfo = new BasicUserInfo
            {
                UserId     = audit.UserId,
                UserAvatar = avatar,
                UserName   = user.FullName,
            };

            var activityInfo = new BasicActivityInfo()
            {
                Id         = audit.Id,
                Date       = audit.Date,
                Type       = (ActivityType)Enum.Parse(typeof(ActivityType), audit.EntityType, true),
                JsonEntity = await _activityService.GetEntityAsJson(audit),
                Seen       = audit.Seen
            };

            return(new Activity(userInfo, activityInfo));
        }
        private async Task <IEnumerable <ApplicationUser> > RefreshAvatars(IQueryable <ApplicationUser> response, CancellationToken cancellationToken = default)
        {
            var list = await response.ToListAsync(cancellationToken);

            var s3Avatars = list.Where(x => GenericAvatarConstructor.IsGenericAvatar(x.Avatar) == false); // must be s3 then if not generic

            foreach (var s3Avatar in s3Avatars)
            {
                s3Avatar.Avatar = await _s3Service.GetPresignedUrlAsync(s3Avatar.Avatar);
            }

            return(list);
        }
        private async Task <IEnumerable <Notification> > RefreshAvatars(IEnumerable <Notification> notifications)
        {
            try
            {
                var list      = notifications.ToList();
                var s3Avatars = list.Where(x => !string.IsNullOrWhiteSpace(x.SenderAvatar) && !GenericAvatarConstructor.IsGenericAvatar(x.SenderAvatar)); // must be s3 then if not generic
                foreach (var s3Avatar in s3Avatars)
                {
                    s3Avatar.SenderAvatar = await _s3Service.GetPresignedUrlAsync(s3Avatar.SenderAvatar);
                }

                return(list);
            }
            catch (Exception e)
            {
                throw new Exception("Could not refresh notification sender avatar", e);
            }
        }
예제 #4
0
        public Mappings(IS3Service s3Service)
        {
            CreateMap <MessageViewModel, CreateChatMessageRequest>()
            .ForMember(x => x.SentAt, o => o.MapFrom(x => x.DateSent))
            .ForMember(x => x.SeenAt, o => o.MapFrom(x => x.DateSeen))
            .ForMember(x => x.ReceiverId, o => o.MapFrom(x => x.ToId))
            .ForMember(x => x.SenderId, o => o.MapFrom(x => x.FromId));
            //.ForMember(x => x.SenderId, o => o.ConvertUsing<Guid>(c => Guid.Parse(c.FromId)));

            CreateMap <CreateChatMessageRequest, ChatMessage>();

            // subscribe
            CreateMap <SendChatMessageRequest, ChatMessage>();
            CreateMap <ChatMessage, MessageViewModel>()
            .ForMember(x => x.FromId, y => y.MapFrom(z => z.SenderId))
            .ForMember(x => x.ToId, y => y.MapFrom(z => z.ReceiverId))
            .ForMember(x => x.Message, y => y.MapFrom(z => z.Message))
            .ForMember(x => x.DateSent, y => y.MapFrom(z => z.SentAt))
            .ForMember(x => x.DateSeen, y => y.MapFrom(z => z.SeenAt))
            .ForMember(x => x.Type, y => y.MapFrom(z => z.Type))
            .ForMember(x => x.DownloadUrl, y => y.MapFrom(z => z.DownloadUrl))
            .ForMember(x => x.FileSizeInBytes, y => y.MapFrom(z => z.FileSizeInBytes));

            CreateMap <ApplicationUser, ParticipantResponseViewModel>()
            .ForMember(x => x.Participant, y => y.MapFrom(z => new ChatParticipantViewModel()
            {
                Avatar      = GenericAvatarConstructor.IsGenericAvatar(z.Avatar) ? z.Avatar : s3Service.GetPresignedUrlAsync(z.Avatar).Result,
                Id          = z.Id.ToString(),
                DisplayName = $"{z.FirstName} {z.LastName}",
                Status      = ChatParticipantStatus.Offline
            }))
            .ForMember(x => x.Metadata, y => y.MapFrom(z => new ParticipantMetadataViewModel()
            {
                TotalUnreadMessages = 0,
            }));

            CreateMap <Athlete, ParticipantResponseViewModel>()
            .ForMember(x => x.Participant, y => y.MapFrom(z => new ChatParticipantViewModel()
            {
                Avatar      = GenericAvatarConstructor.IsGenericAvatar(z.Avatar) ? z.Avatar : s3Service.GetPresignedUrlAsync(z.Avatar).Result,
                Id          = z.Id.ToString(),
                DisplayName = $"{z.FirstName} {z.LastName}",
                Status      = ChatParticipantStatus.Offline
            }))
            .ForMember(x => x.Metadata, y => y.MapFrom(z => new ParticipantMetadataViewModel()
            {
                TotalUnreadMessages = 0,
            }));

            CreateMap <Coach, ParticipantResponseViewModel>()
            .ForMember(x => x.Participant, y => y.MapFrom(z => new ChatParticipantViewModel()
            {
                Avatar      = GenericAvatarConstructor.IsGenericAvatar(z.Avatar) ? z.Avatar : s3Service.GetPresignedUrlAsync(z.Avatar).Result,
                Id          = z.Id.ToString(),
                DisplayName = $"{z.FirstName} {z.LastName}",
                Status      = ChatParticipantStatus.Offline
            }))
            .ForMember(x => x.Metadata, y => y.MapFrom(z => new ParticipantMetadataViewModel()
            {
                TotalUnreadMessages = 0,
            }));
        }