예제 #1
0
        public async Task <GroupMessagesToClientDto> OnGroupJoin(string groupId, string clientConnectionId)
        {
            Ensure.NotNull(nameof(groupId), groupId);
            Ensure.NotNull(nameof(clientConnectionId), clientConnectionId);

            try
            {
                var client = await _clientRepo.Get(clientConnectionId);

                await _groupRepo.AddClientToGroup(groupId, client);

                var historyModel = await _messageRepo.GetGroupHistory(groupId);

                var history = new List <MessageDto>();
                foreach (var item in historyModel)
                {
                    var historyItem = new MessageDto
                    {
                        GroupId            = item.Group.PublicId,
                        Body               = item.Body,
                        SenderName         = item.Client.PublicName,
                        SenderConnectionId = item.Client.ConnectionId,
                        SentToGroup        = true,
                        Time               = item.Time
                    };
                    history.Add(historyItem);
                }
                return(new GroupMessagesToClientDto
                {
                    Messages = history,
                    Client = client
                });
            }
            catch (Exception ex)
            {
                Log.Error(ex, $"OnGroupJoin failed for client: {clientConnectionId}, group: {groupId}");
                throw ex;
            }
        }