示例#1
0
        public async Task <UserProfileMold> Get(GetProfile request)
        {
            var user = await RavenSession.LoadAsync <User>(request.UserId);

            var mapped = Mapper.Map <UserProfileMold>(user);

            return(mapped);
        }
示例#2
0
        public async Task <MessagePage> Get(GetMessages request)
        {
            var messages = RavenSession.Query <Message>().Where(e => e.ChatId == request.ChatId).OrderByDescending(x => x.PostTime);
            var result   = new MessagePage();

            if (request.BeforePostTime != null)
            {
                messages = messages.Where(x => x.PostTime.UtcDateTime < request.BeforePostTime.Value.UtcDateTime);
            }
            var pageSize = request.PageSize ?? 10;

            var docs =
                await messages.Take(pageSize)
                .Include(x => x.UserId)
                .Include(s => s.Attachments)
                .ToListAsync();

            result.Messages = new List <MessageMold>();
            foreach (var doc in docs)
            {
                var user = await RavenSession.LoadAsync <User>(doc.UserId);

                var message = Mapper.Map <MessageMold>(doc);

                if (doc.Attachments != null)
                {
                    var attach = await RavenSession.LoadAsync <Attachment>(doc.Attachments);

                    message.Attachments = new List <AttachmentMold>();

                    foreach (var id in doc.Attachments)
                    {
                        if (attach.TryGetValue(id, out var attachment))
                        {
                            message.Attachments.Add(Mapper.Map <AttachmentMold>(attachment));
                        }
                        //TODO учесть в будущем показ потерянных файлов
                    }
                }

                if (user != null)
                {
                    message.UserNickName = string.IsNullOrWhiteSpace(user.DisplayName) ? user.Login : user.DisplayName;
                }
                result.Messages.Add(message);
            }
            return(result);
        }
示例#3
0
 private async Task <User> GetUserById(string uid)
 {
     return(await RavenSession.LoadAsync <User>(uid, b => b.IncludeDocuments(uid + SecretPostfix)));
 }
示例#4
0
        private async Task <UserSecret> GetUserSecret(string uid)
        {
            var secret = await RavenSession.LoadAsync <UserSecret>(uid + SecretPostfix);

            return(secret);
        }