Пример #1
0
        public async Task LoadHistory(RequestContext <IScenePeerClient> ctx)
        {
            List <ChatMessageDto> result = new List <ChatMessageDto>();

            try
            {
                long startTimestamp = ctx.ReadObject <long>();
                long endTimestamp   = ctx.ReadObject <long>();

                DateTime start = TimestampHelper.UnixTimeStampSecondToDateTime(startTimestamp);
                DateTime end   = TimestampHelper.UnixTimeStampSecondToDateTime(endTimestamp);

                string channelName  = ctx.RemotePeer.SceneId;
                var    messagesData = await _chat.LoadHistory(channelName, start, end);

                foreach (ChatMessage msg in messagesData)
                {
                    var message = new ChatMessageDto {
                        Message   = msg.Message,
                        TimeStamp = TimestampHelper.DateTimeToUnixTimeStamp(msg.Date),
                        UserInfo  = new ChatUserInfoDto
                        {
                            UserId = msg.UserInfo.UserId,
                            Data   = msg.UserInfo.Data.ToString(),
                        }
                    };
                    result.Add(message);
                }
            }
            catch (Exception ex)
            {
                _logger.Log(LogLevel.Error, _logCategory, "Error occured when server try to load history", ex);
                throw new ClientException(ex.Message);
            }

            ctx.SendValue(result);
        }