private void userList_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (userList.SelectedItems.Count <= 0 && userList.SelectedItems[0] == null)
            {
                return;
            }
            var selectedItemText = ((ListViewItem)userList.SelectedItems[0]).Tag as User;
            var found            = false;

            foreach (var chat in privateChat)
            {
                if (!chat.Other.IpAddress.Equals(selectedItemText?.IpAddress))
                {
                    continue;
                }
                chat.Show();
                formLogin.Client.SendMessage(formLogin.Client.CurrentUser.Name + "@" + formLogin.Client.CurrentUser.IpAddress + " wants to connect", selectedItemText, Message.Type.PrivateChatConnect);
                found = true;
            }

            if (found)
            {
                return;
            }
            var chatNew = new PrivateChatUser(formLogin.Client, selectedItemText);

            formLogin.Client.SendMessage(formLogin.Client.CurrentUser.Name + "@" + formLogin.Client.CurrentUser.IpAddress + " wants to connect", selectedItemText, Message.Type.PrivateChatConnect);
            chatNew.Show();
            privateChat.Add(chatNew);
        }
示例#2
0
 public void ShowPrivateChat(object source, PrivateChatUser e)
 {
     this.Dispatcher.Invoke(() =>
     {
         //Console.WriteLine(usernameWindow3Owner);
         PrivateChat win3 = new PrivateChat(communication, chatService, e.user);
         win3.Show();
     });
 }
        public void Print(Message message)
        {
            bool found = false;

            this.Invoke(() =>
            {
                Console.WriteLine("Message: " + message.MessageText);
                switch (message.MessageType)
                {
                case Message.Type.OneToMany:
                    txtReceive.AppendText("\r\n" + message.FromUser.Name + " says: " + message.MessageText);
                    txtReceive.ScrollToCaret();
                    break;

                case Message.Type.OneToOne:
                    foreach (var chat in privateChat)
                    {
                        if (!chat.Other.IpAddress.Equals(message.FromUser.IpAddress))
                        {
                            continue;
                        }
                        chat.txtReceive.AppendText("\r\n" + message.FromUser.Name + " says: " + message.MessageText);
                        chat.txtReceive.ScrollToCaret();
                        found = true;
                    }

                    if (!found)
                    {
                        foreach (var user in chats)
                        {
                            if (!user.IpAddress.Equals(message.FromUser.IpAddress))
                            {
                                continue;
                            }
                            found = true;
                        }
                        if (!found)
                        {
                            chats.Add(message.FromUser);
                        }
                        var chat = new PrivateChatUser(formLogin.Client, message.FromUser);
                        chat.txtReceive.AppendText("\r\n" + message.FromUser.Name + " says: " + message.MessageText);
                        chat.txtReceive.ScrollToCaret();
                        privateChat.Add(chat);
                    }

                    break;

                case Message.Type.PrivateChatConnect:
                    found = false;
                    foreach (var chat in privateChat)
                    {
                        if (!chat.Other.IpAddress.Equals(message.FromUser.IpAddress))
                        {
                            continue;
                        }
                        chat.Show();
                        found = true;
                    }

                    if (found)
                    {
                        break;
                    }
                    var chatNew = new PrivateChatUser(formLogin.Client, message.FromUser);
                    chatNew.Show();
                    privateChat.Add(chatNew);

                    break;

                case Message.Type.PrivateChatDisconnect:
                    found = false;
                    foreach (var chat in privateChat)
                    {
                        if (!chat.Other.IpAddress.Equals(message.FromUser.IpAddress))
                        {
                            continue;
                        }
                        chat.Hide();
                    }
                    break;
                }
            });
        }