Пример #1
0
        public void UpdateContact(UserInfo userInfo)
        {
            lock (Personal.USER_CONTACTS)
            {
                UserInfo userFound = Personal.USER_CONTACTS.FirstOrDefault(p => p.id == userInfo.id.Trim());

                if (userFound == null)
                {
                    Personal.USER_CONTACTS.Add(userInfo);
                    AddContactToList(userInfo);
                }
                else
                {
                    bool userJustLoggedOn  = false;
                    bool userJustLoggedOff = false;

                    ManageChatWindows.UpdateChatWindowUser(userInfo);

                    if (userFound.status != userInfo.status & userFound.status == Convert.ToInt16(UserStatus.Offline)
                        & userInfo.status != Convert.ToInt16(UserStatus.Offline))
                    {
                        userJustLoggedOn = true;
                    }

                    if (userFound.status != userInfo.status & userFound.status != Convert.ToInt16(UserStatus.Offline)
                        & userInfo.status == Convert.ToInt16(UserStatus.Offline))
                    {
                        userJustLoggedOff = true;
                    }

                    userFound.name    = userInfo.name;
                    userFound.status  = userInfo.status;
                    userFound.avatar  = userInfo.avatar;
                    userFound.comment = userInfo.comment;

                    userFound = userInfo;

                    foreach (ContactListEntryData contact in listContacts)
                    {
                        if (contact.richTextBox.ToolTip.ToString() == userFound.id.ToString())
                        {
                            contact.image.Source = LoadResource.GetSmallIconFromStatus((UserStatus)userInfo.status);
                            if (userInfo.comment.Length == 0)
                            {
                                contact.name.Text = userInfo.name;
                            }
                            else
                            {
                                contact.name.Text = userInfo.name + " - ";
                            }


                            if (userJustLoggedOn)
                            {
                                contactListView.Items.Remove(contact.richTextBox);
                                contactListView.Items.Insert(0, contact.richTextBox);
                            }

                            if (userJustLoggedOff)
                            {
                                contactListView.Items.Remove(contact.richTextBox);
                                contactListView.Items.Insert(contactListView.Items.Count, contact.richTextBox);
                            }

                            contact.comment.Text = userInfo.comment;

                            TextParser.ParseText(contact.name, false);
                            TextParser.ParseText(contact.comment, true);

                            break;
                        }
                    }

                    if (userJustLoggedOn & Personal.USER_INFO.status == Convert.ToInt16(UserStatus.Available) & !userInfo.blocked)
                    {
                        Notification.NotificationManager.Showpopup(userInfo.name, "has just signed in.", null);

                        Resource.Sounds.Player.PlaySound(Resource.Sounds.Identifiers.ONLINE);
                    }
                }
            }

            UpdateContactCount();
        }