コード例 #1
0
        private void chatsList_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            oneChat one = (oneChat)chatsList.SelectedItem;

            //MessageBox.Show(one.id);
            //msges.Clear();
            if (one != null)
            {
                enginee.setCurrentChat(one.id);
                one.isNotRead = false;
                if (one.id.StartsWith("gr"))
                {
                    btnAddUser.Visibility = Visibility.Visible;
                }
                else
                {
                    btnAddUser.Visibility = Visibility.Hidden;
                }
                btnLeaveChat.Visibility = Visibility.Visible;
                btnShowUsers.Visibility = Visibility.Visible;
                msgsList.Visibility     = Visibility.Visible;
                btnSendMsg.Visibility   = Visibility.Visible;
                boxtomsg.Visibility     = Visibility.Visible;
            }
            else
            {
                enginee.setCurrentChat("/none");
                btnAddUser.Visibility   = Visibility.Hidden;
                btnLeaveChat.Visibility = Visibility.Hidden;
                btnShowUsers.Visibility = Visibility.Hidden;
                msgsList.Visibility     = Visibility.Hidden;
                btnSendMsg.Visibility   = Visibility.Hidden;
                boxtomsg.Visibility     = Visibility.Hidden;
            }
        }
コード例 #2
0
ファイル: BridgeClient.cs プロジェクト: Justkek/connecttoweb
        private void doMessage(typedata income)
        {
            //Util.logTime();
            if (income.command == "usrdata")
            {
                for (int i = 0; i < income.data.Length; i++)
                {
                    OnePeople onee = new OnePeople(this);
                    onee         = (OnePeople)primeJSON.DeserializeObject(income.data[i], typeof(OnePeople));
                    map[onee.id] = onee;
                    if (onee.id == this.login)
                    {
                        this.win.Dispatcher.Invoke(new Action(() => {
                            ImageSourceConverter conv   = new ImageSourceConverter();
                            this.win.imgInfoPict.Source = (ImageSource)conv.ConvertFrom(onee.Pict);
                            this.win.lbInfoId.Content   = onee.id;
                        }));
                    }
                }
                this.win.Dispatcher.Invoke(new Action(() =>
                {
                    foreach (oneChat item in this.win.chates)
                    {
                        item.updateIcon(this);
                    }
                    foreach (OneUser item in this.win.users)
                    {
                        item.updateIcons(this);
                    }
                    foreach (oneMsg item in this.win.msges)
                    {
                        item.updateIcons(this);
                    }
                    foreach (OnePeople item in this.win.friends)
                    {
                        item.updateIcons(this);
                    }
                }));
            }
            else
            if (income.command == "answ")
            {
                if (income.data[0] == "no")
                {
                    Console.Write("\tWhoops! ");
                    if (income.data.Length > 1)
                    {
                        Console.WriteLine(income.data[1]);
                    }
                }
                else if (income.data[0] == "yes")
                {
                    Console.WriteLine("\tAccept!");
                    if (income.msg == "authuser")
                    {
                        this.authorized   = true;
                        this.currentGroup = "none";
                        authComplete();
                    }
                    else if (income.msg == "enduser")
                    {
                        this.authorized   = false;
                        this.currentGroup = "none";
                    }
                    else if (income.msg == "leavegr")
                    {
                        //this.currentGroup = "none";
                        this.win.Dispatcher.Invoke(new Action(() => {
                            oneChat pos = null;
                            foreach (oneChat item in this.win.chatsList.Items)
                            {
                                if (item.id == this.currentGroup)
                                {
                                    pos = item;
                                    break;
                                }
                            }
                            //this.win.chatsList.Items.Remove(pos);
                            this.win.chates.Remove(pos);
                            authComplete();
                            this.win.msges.Clear();
                        }));
                    }
                    else if (income.msg == "makegr")
                    {
                    }
                }
            }
            else
            if (income.command == "switch")
            {
                this.win.Dispatcher.Invoke(new Action(() =>
                {
                    this.win.tabcontroll.SelectedIndex = 1;
                    foreach (oneChat item in this.win.chates)
                    {
                        if (item.id == income.target)
                        {
                            this.win.chatsList.SelectedItem = item;
                            break;
                        }
                    }
                }));
            }

            else
            if (income.command == "upddata")
            {
                if (income.msg == "sendgru")
                {
                    this.win.Dispatcher.Invoke(new Action(() =>
                    {
                        oneChat selectedd = (oneChat)this.win.chatsList.SelectedItem;

                        this.listOfChates.Clear();
                        for (int i = 0; i < income.data.Length; i++)
                        {
                            typegetdata getdata = new typegetdata();
                            getdata             = (typegetdata)primeJSON.DeserializeObject(income.data[i], getdata.GetType());
                            oneChat newchat     = new oneChat(getdata.name, this.login, this);
                            getdata.display();

                            this.listOfChates.Add(newchat);
                        }
                        if (selectedd != null)
                        {
                            if (this.listOfChates.IndexOf(selectedd) == -1)
                            {
                                this.win.chatsList.SelectedIndex = -1;
                            }
                        }
                    }

                                                          ));
                }
                else if (income.msg == "sendugr")
                {
                    if (income.target == currentGroup)
                    {
                        this.win.Dispatcher.Invoke(new Action(() =>
                        {
                            this.win.users.Clear();
                            for (int i = 0; i < income.data.Length; i++)
                            {
                                typegetdata getdata = new typegetdata();
                                getdata             = (typegetdata)primeJSON.DeserializeObject(income.data[i], getdata.GetType());
                                OneUser us          = new OneUser(getdata.name, this);
                                if ((i == 0 && us.id == this.login) || (i > 0 && this.win.users[0].id == this.login))
                                {
                                    this.win.btnLeaveChat.Content = "Delete chat";
                                    us.isMaker = true;
                                }
                                else
                                {
                                    us.isMaker = false;
                                    this.win.btnLeaveChat.Content = "Leave chat";
                                }
                                this.win.users.Add(us);
                            }
                        }));
                    }
                }
                else if (income.msg == "sendgruws")
                {
                    this.win.Dispatcher.Invoke(new Action(() =>
                    {
                        this.listOfChates.Clear();
                        for (int i = 0; i < income.data.Length; i++)
                        {
                            typegetdata getdata = new typegetdata();
                            getdata             = (typegetdata)primeJSON.DeserializeObject(income.data[i], getdata.GetType());
                            oneChat newchat     = new oneChat(getdata.name, this.login, this);
                            getdata.display();

                            this.listOfChates.Add(newchat);
                        }

                        this.win.tabcontroll.SelectedIndex = 1;
                        foreach (oneChat item in this.win.chates)
                        {
                            if (item.id == income.target)
                            {
                                this.win.chatsList.SelectedItem = item;
                                break;
                            }
                        }
                    }
                                                          ));
                }
            }
            else
            if (income.command == "updmsg")
            {
                this.win.Dispatcher.Invoke(new Action(() =>
                {
                    this.listOfMsg.Clear();
                    for (int i = 0; i < income.data.Length; i++)
                    {
                        typemsg tmsg  = new typemsg();
                        tmsg          = (typemsg)primeJSON.DeserializeObject(income.data[i], tmsg.GetType());
                        oneMsg newmsg = new oneMsg(tmsg.from, tmsg.msg, tmsg.time, this.login, this);

                        this.listOfMsg.Add(newmsg);

                        //win.msges.
                        //tmsg.display();
                    }
                    if (this.win.msgsList.Items.Count > 0)
                    {
                        this.win.msgsList.ScrollIntoView(this.win.msgsList.Items[this.win.msgsList.Items.Count - 1]);
                    }
                }));
            }
            else
            if (income.command == "notification")
            {
                if (income.data[0] == "newmsg")
                // Console.WriteLine($"\t\t{income.msg}");
                {
                    //MessageBox.Show(income.msg, "notification", MessageBoxButtons.OK);
                    if (income.msg == currentGroup)
                    {
                        _sendRefreshMsg(null);
                    }
                    else
                    {
                        this.win.Dispatcher.Invoke(new Action(() =>
                        {
                            int index = -1;
                            for (int i = 0; i < this.win.chates.Count; i++)
                            {
                                if (this.win.chates[i].id == income.msg)
                                {
                                    index = i;
                                }
                            }
                            if (index != -1)
                            {
                                this.win.chates[index].isNotRead = true;
                            }
                        }));
                    }

                    this.win.Dispatcher.Invoke(new Action(() =>
                    {
                        int ind    = -1;
                        object sel = this.win.chatsList.SelectedItem;
                        for (int i = 0; i < this.win.chates.Count; i++)
                        {
                            if (this.win.chates[i].id == income.msg)
                            {
                                ind = i;
                            }
                        }
                        if (ind != -1)
                        {
                            oneChat forSwap = this.win.chates[ind];
                            this.win.chates.Remove(forSwap);
                            this.win.chates.Insert(0, forSwap);
                            this.win.chatsList.SelectedItem = sel;
                        }
                    }));
                }
                else if (income.data[0] == "updateusers")
                {
                    if (income.msg == currentGroup)
                    {
                        _updateUsersInCurrent();
                    }
                }
                //income.display();
            }
            else
            if (income.command == "friends")
            {
                this.win.Dispatcher.Invoke(new Action(() =>
                {
                    this.win.friends.Clear();

                    for (int i = 0; i < income.data.Length; i++)
                    {
                        OnePeople onee = new OnePeople(this);
                        onee           = (OnePeople)primeJSON.DeserializeObject(income.data[i], typeof(OnePeople));
                        this.win.friends.Add(onee);
                    }
                }));
            }
            //income.display();
            //Console.ReadKey();
        }