Beispiel #1
0
        public async Task RemoveFromGroup(string userToRemoveId, int conversationId, bool IsSelf)
        {
            var whoSentId = userProvider.GetUserId(Context);
            await userService.MakeUserOnline(whoSentId, Context.ConnectionId);

            try
            {
                await chatsService.RemoveUserFromConversation(userToRemoveId, whoSentId, conversationId, IsSelf);

                MessageDataModel chatEvent;

                if (IsSelf || userToRemoveId == whoSentId)
                {
                    chatEvent = await messagesService.AddChatEvent(ChatEventType.Left, userToRemoveId,
                                                                   userToRemoveId, conversationId);
                }
                else
                {
                    chatEvent = await messagesService.AddChatEvent(ChatEventType.Kicked, whoSentId,
                                                                   userToRemoveId, conversationId);
                }

                var removedUser = await userService.GetUserById(userToRemoveId);

                await RemovedFromGroup(userToRemoveId, conversationId);

                if (removedUser.IsOnline)
                {
                    foreach (var connection in removedUser.Connections)
                    {
                        await RemoveConnectionFromGroup(connection.ConnectionId, conversationId);
                    }
                }

                await SendMessageToGroup(conversationId, whoSentId, chatEvent.ToMessage());
            }
            catch (Exception ex)
            {
                await SendError(Context.ConnectionId, ex.Message);

                logger.LogError(ex.Message);
            }
        }