Example #1
0
        private async void Delete()
        {
            ChatControl chatWindow = new ChatControl(ChatsControl);
            string      chatName   = Command["objectName"];
            bool        hasRight   = Convert.ToBoolean(await ApiManager.Read($"api/chat/hasHighRightInChat/{chatName}/{User.Name}"));

            if (hasRight)
            {
                if (chatName != string.Empty)
                {
                    SignalRManager signalRManager = new SignalRManager();

                    ApiManager.Delete("api/chat", $"deleteChat/{chatName}/{User.Name}");

                    chatWindow.DeleteTabItem(chatName);

                    signalRManager.RemoveChat(chatName);
                }
                else
                {
                    MessageBox.Show("Некорректное имя.");
                }
            }
            else
            {
                MessageBox.Show("У вас нет прав на это действие.");
            }
        }
Example #2
0
        private async void Disconnect()
        {
            ChatControl    chatWindow     = new ChatControl(ChatsControl);
            MainWindow     mainWindow     = new MainWindow();
            SignalRManager signalRManager = new SignalRManager();
            string         chatName       = Command["objectName"];
            string         userName       = User.Name;

            if (chatName == string.Empty)
            {
                chatName = ChatSelected;
            }
            if (chatName != string.Empty)
            {
                await ApiManager.Delete("api/chat", $"removeUserFromChat/{chatName}/{userName}");

                chatWindow.DeleteTabItem(chatName);

                signalRManager.RemoveUserFromChat(chatName, userName);
            }
            else
            {
                MessageBox.Show("Подключитесь к комнате или введите корректное название.");
            }
        }
        public async void OnConnect()
        {
            connection.On <string, string, string>("ReceiveMessage", (chatName, userName, message) =>
            {
                Dispatcher.Invoke(() =>
                {
                    string newMessage = $"{userName}: {message}";
                    if (ChatControl.ChatBox.Count != 0)
                    {
                        if (ChatControl.HasTabItemToDictionary(chatName))
                        {
                            ChatControl.ChatBox[chatName].Items.Add(newMessage);
                        }
                    }
                });
            });
            connection.On <string, string>("ReceiveUser", (chatName, userName) =>
            {
                Dispatcher.Invoke(() =>
                {
                    if (ChatControl.UsersBox.Count != 0)
                    {
                        if (!ChatControl.HasUserToUsersBox(chatName, userName))
                        {
                            ChatControl.CreateListBoxItem(chatName, userName);
                        }
                        else
                        {
                            ChatControl.UpdateListBoxItem(chatName, userName);
                        }
                    }
                });
            });
            connection.On <string, string>("RenameUser", (oldName, newName) =>
            {
                Dispatcher.Invoke(() =>
                {
                    if (User.Name == oldName)
                    {
                        User.Name = newName;
                    }

                    UpdateUsersBox();
                });
            });
            connection.On("ChangeRoleUser", () =>
            {
                Dispatcher.Invoke(() =>
                {
                    UpdateUsersBox();
                });
            });
            connection.On <string, string>("RenameChat", (oldName, newName) =>
            {
                Dispatcher.Invoke(() =>
                {
                    ChatControl chatWindow = new ChatControl(ChatsControl);

                    if (ChatSelected == oldName)
                    {
                        ChatSelected = newName;
                    }

                    chatWindow.RenameTabItem(oldName, newName);
                });
            });
            connection.On("RemoveUser", () =>
            {
                Dispatcher.Invoke(() =>
                {
                    UpdateUsersBox();
                });
            });
            connection.On <string>("RemoveChat", (chatName) =>
            {
                Dispatcher.Invoke(() =>
                {
                    ChatControl chatWindow = new ChatControl(ChatsControl);

                    chatWindow.DeleteTabItem(chatName);
                });
            });
            connection.On <string, string>("BanUser", (chatName, userName) =>
            {
                Dispatcher.Invoke(() =>
                {
                    if (User.Name == userName && chatName == "allChats")
                    {
                        ChatControl chatWindow = new ChatControl(ChatsControl);
                        chatWindow.DeleteAllTabItem();
                    }
                    else if (User.Name == userName)
                    {
                        ChatControl chatWindow = new ChatControl(ChatsControl);
                        chatWindow.DeleteTabItem(chatName);
                    }
                    else
                    {
                        ChatControl.UpdateListBoxItem(chatName, userName);
                    }
                });
            });

            await connection.StartAsync();
        }