Exemplo n.º 1
0
        public async Task UpdateUsersBox()
        {
            if (ChatSelected != null)
            {
                List <string> usersNames = new List <string>();

                string usersJson = await ApiManager.Read($"api/chat/getUsers/{ChatSelected}");

                usersNames = GetListValuesFromJson(usersJson, "name");

                ChatControl.UsersBox[ChatSelected].Items.Clear();
                foreach (string user in usersNames)
                {
                    ChatControl.CreateListBoxItem(ChatSelected, user);
                }
            }
        }
Exemplo n.º 2
0
        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();
        }