public static ChannelSummaryResponse ToChannelSummaryResponse(this Domain.Channel.Channel channel, bool isMuted, Domain.Message.Message lastReadMessage, MemberSummary creator, CloudStorageConfiguration configuration) { var channelListResponse = new ChannelSummaryResponse(); if (channel != null) { channelListResponse.Id = channel.Id; channelListResponse.IsClosed = channel.IsClosed; channelListResponse.Created = channel.Created; channelListResponse.Updated = channel.Updated; channelListResponse.Name = channel.Name; channelListResponse.Description = channel.Description; channelListResponse.WelcomeMessage = channel.WelcomeMessage; channelListResponse.Type = channel.Type; channelListResponse.IsMuted = isMuted; channelListResponse.CreatorId = channel.CreatorId ?? creator?.Id; channelListResponse.Creator = channel.Creator?.ToMemberSummary(configuration) ?? creator; channelListResponse.CreatorSaasUserId = channel.Creator?.SaasUserId ?? creator?.SaasUserId; channelListResponse.LastMessage = channel.Messages?.FirstOrDefault()?.ToMessageResponse(lastReadMessage, configuration); channelListResponse.UnreadMessagesCount = lastReadMessage != null?channel.Messages?.Count(x => x.Created > lastReadMessage.Created) ?? 0 : channel.Messages?.Count ?? 0; } return(channelListResponse); }
public async Task <MessageResponse> CreateMessageAsync(CreateMessageRequest request) { var channel = await UnitOfWork.ChannelRepository.GetChannelByIdAsync(request.ChannelId); Ensure.That(channel).WithException(x => new NotFoundException(new ErrorDto(ErrorCode.NotFound, "Channel does not exist."))).IsNotNull(); var member = await UnitOfWork.MemberRepository.GetMemberBySaasUserIdAsync(request.SaasUserId); Ensure.That(member).WithException(x => new NotFoundException(new ErrorDto(ErrorCode.NotFound, "Member does not exist."))).IsNotNull(); var message = new Domain.Message.Message { Id = Guid.NewGuid(), ChannelId = request.ChannelId, OwnerId = member.Id, Owner = member, Body = request.Body, Created = DateTimeOffset.UtcNow, Type = request.Type, ImageUrl = request.ImageUrl }; using (var transactionScope = new TransactionScope(TransactionScopeAsyncFlowOption.Enabled)) { await UnitOfWork.MessageRepository.AddMessageAsync(message); await AddLastReadMessageAsync(new AddLastReadMessageRequest(request.ChannelId, message.Id, request.SaasUserId)); transactionScope.Complete(); } return(message.ToMessageResponse(null, _cloudStorageConfiguration)); }
public MessageModel(Domain.Message.Message message) { SendContent = message.SendContent; Type = message.Type; Intent = message.Intent; ResponseContent = message.ResponseContent; }
public static MessageResponse ToMessageResponse(this Domain.Message.Message message, Domain.Message.Message lastReadMessage, CloudStorageConfiguration configuration) { var messageResponse = new MessageResponse(); if (message != null) { messageResponse.Id = message.Id; messageResponse.Created = message.Created; messageResponse.Body = message.Body; messageResponse.ImageUrl = message.ImageUrl; messageResponse.ChannelId = message.ChannelId; messageResponse.Type = message.Type; messageResponse.Updated = message.Updated; messageResponse.Sender = message.Owner.ToMemberSummary(configuration); messageResponse.IsRead = lastReadMessage != null && message.Created <= lastReadMessage.Created; } return(messageResponse); }