private void FillContactsList()
        {
            if (this.InvokeRequired)
            {
                this.Invoke(new Action(() => FillContactsList()));
                return;
            }

            this.Text = "Voiperinho - " + accountInfo.Username;

            int contactControlOffset = 45;

            foreach (AccountInformation user in this.contacts.ContactsList)
            {
                UserInfoContainer contactBox = new UserInfoContainer(false, user.Username, user.Id, null);
                contactBox.Name        = "contact_" + user.Username;
                contactBox.Parent      = this.pnlContactsContainer;
                contactBox.Location    = new Point(0, contactControlOffset);
                contactBox.MouseClick += contactBox_MouseClick;

                this.listContactContainer.Add(contactBox);
                this.pnlContactsContainer.Controls.Add(contactBox);

                contactControlOffset += contactBox.Size.Height;
            }

            this.pnlContactsContainer.Invalidate();
        }
Esempio n. 2
0
            public void Set(string key, string value, UserInfoContainer userInfoContainer)
            {
                bool identityChange = false;

                if (!IdentitiesContainer.Keys.Contains(key))
                {
                    IdentitiesContainer.Add(key, value);
                    identityChange = true;
                }
                else
                {
                    if (IdentitiesContainer[key] != value)
                    {
                        IdentitiesContainer[key] = value;
                        identityChange           = true;
                    }
                }
                if (identityChange)
                {
                    userInfoContainer.languageShouldBeRefreshed    = true;
                    userInfoContainer.propertiesShouldBeRefreshed  = true;
                    userInfoContainer.rolesShouldBeRefreshed       = true;
                    userInfoContainer.userProfileShouldBeRefreshed = true;
                }
            }
        private void container_AddUserPressed(string username, object sender)
        {
            UserInfoContainer activeContainer = sender as UserInfoContainer;

            RequestContainer requestContainer = new RequestContainer(username, this.accountInfo.Id, activeContainer.UserId, this.socketHelper, this.accountInfo);

            requestContainer.Name     = "controlRequestContainer_" + username;
            requestContainer.Location = new Point(pnlDashboard.Right, ((activeContainer.Top + activeContainer.Height / 2) - 10));

            // Add the control and set it atop on all of the existing controls
            this.Controls.Add(requestContainer);
            requestContainer.BringToFront();
        }
        private void UserInfoContainer_RequestAccepted(object sender)
        {
            UserInfoContainer requestContainer = sender as UserInfoContainer;

            AddRequestToContacts(requestContainer);
            requestContainer.UpdateContacts();

            // After we're done with the request, remove it from the list
            this.requests.RemoveAll(request => request.Requester.Id == requestContainer.UserId);

            if (requests.Count == 0)
            {
                this.pnlContactsContainer.Controls.Remove(this.pnlAvailableRequests);
            }
        }
        private void removeFromContactsToolStripMenuItem_Click(object sender, EventArgs e)
        {
            UserInfoContainer activeContainer = GetActiveUserContainer();

            if (activeContainer != null)
            {
                int userId = activeContainer.UserId;

                // Add connector line
                WebConnector.RemoveContact(userId.ToString(), this.accountInfo.Id.ToString());

                this.RespositionContacts(activeContainer);
                this.pnlContactsContainer.Controls.Remove(activeContainer);
            }
        }
        private void RepositionUserContainers(Panel activePanel, UserInfoContainer container)
        {
            // If there are any requests that are positioned lower on the panel than the current request, reposition them
            for (int i = activePanel.Controls.Count - 1; i > 0; i--)
            {
                if (activePanel.Controls[i] is UserInfoContainer)
                {
                    UserInfoContainer control = activePanel.Controls[i] as UserInfoContainer;

                    if (control.Location.Y > container.Location.Y)
                    {
                        control.Location = new Point(control.Location.X, (control.Location.Y - control.Height));
                    }
                }
            }
        }
        private void contactBox_MouseClick(object sender, MouseEventArgs e)
        {
            UserInfoContainer contactContainer = sender as UserInfoContainer;

            if ((contactContainer.Parent == this.pnlContactsContainer) || (contactContainer.Parent == this.pnlAvailableRequests))
            {
                this.LoadMessengerLayout(contactContainer.Username, contactContainer.RequestNote); // fix
            }

            if (e.Button == MouseButtons.Right && !contactContainer.IsRequest)
            {
                this.menuContactOptions.Show(Cursor.Position);
            }

            if (this.isSearchViewLoaded)
            {
                foreach (Control control in this.pnlAvailableUsers.Controls)
                {
                    if (control is UserInfoContainer)
                    {
                        UserInfoContainer container = control as UserInfoContainer;

                        if (!(container.Name.Equals(contactContainer.Name)))
                        {
                            container.IsSelected = false;
                            container.HighlightContainer();
                        }
                    }
                }
            }
            else
            {
                foreach (UserInfoContainer container in this.listContactContainer)
                {
                    if (!(container.Name.Equals(contactContainer.Name)))
                    {
                        container.IsSelected = false;
                        container.HighlightContainer();
                    }
                }
            }

            contactContainer.IsNotificationReceived = false;
            contactContainer.IsSelected             = true;
            contactContainer.HighlightContainer();
        }
        private void UserInfoContainer_RequestRejected(object sender)
        {
            int requestId = 0;
            UserInfoContainer requestContainer  = sender as UserInfoContainer;
            Point             containerLocation = requestContainer.Location;

            this.pnlAvailableRequests.Controls.Remove(requestContainer);
            this.pnlAvailableRequests.Invalidate();

            foreach (Control control in this.pnlAvailableRequests.Controls)
            {
                if (control is UserInfoContainer)
                {
                    if (control.Location.Y > containerLocation.Y)
                    {
                        control.Location = new Point(control.Location.X, (control.Location.Y - control.Height));
                    }
                }
            }

            // Get the ID of the request itself
            foreach (RequestInformation request in this.requests)
            {
                if (request.Requester.Id == requestContainer.UserId)
                {
                    requestId = request.Id;
                    break;
                }
            }

            // Delete request from the database
            WebConnector.DeleteRequest(requestId);

            // Remove the current request both from the panel and the list containing the requests
            this.requests.RemoveAll(request => request.Requester.Id == requestContainer.UserId);

            // If there's no requests - no need to keep the header up anymore.
            if (requests.Count == 0)
            {
                this.pnlContactsContainer.Controls.Remove(this.pnlAvailableRequests);
            }
        }
        private void FillRequestsList()
        {
            if (this.InvokeRequired)
            {
                this.Invoke(new Action(() => FillRequestsList()));
                return;
            }

            if (this.requests != null && this.requests.Count > 0)
            {
                // Add small offset between contacts and new requests
                int contactControlOffset = this.GetContactsListLength();
                contactControlOffset += 10;

                // Panel to store all of the requests
                this.pnlAvailableRequests = new Panel();

                this.pnlAvailableRequests.Location = new Point(0, contactControlOffset);
                this.pnlAvailableRequests.Size     = new Size(this.pnlContactsContainer.Width, this.pnlContactsContainer.Height - contactControlOffset);
                this.pnlContactsContainer.Controls.Add(this.pnlAvailableRequests);

                this.CreateGroupHeader("RECEIVED REQUESTS", this.pnlAvailableRequests, new Point(3, 0), new Point(0, this.lblContactsList.Height + 5));
                contactControlOffset = this.lblContactsList.Height + 15;

                foreach (RequestInformation request in this.requests)
                {
                    UserInfoContainer requestBox = new UserInfoContainer(request.Requester.Username, request.RequesterId, request.RequestText);
                    requestBox.Name     = "request_" + request.Requester.Username;
                    requestBox.Parent   = this.pnlAvailableRequests;
                    requestBox.Location = new Point(0, contactControlOffset);

                    this.pnlAvailableRequests.Controls.Add(requestBox);

                    contactControlOffset += requestBox.Size.Height;

                    requestBox.MouseClick      += contactBox_MouseClick;
                    requestBox.RequestAccepted += UserInfoContainer_RequestAccepted;
                    requestBox.RequestRejected += UserInfoContainer_RequestRejected;
                }
            }
        }
        private void AddRequestToContacts(UserInfoContainer container)
        {
            int contactListBottom = GetContactsListLength();
            int requestId         = 0;

            // Get the ID of the request itself
            foreach (RequestInformation request in this.requests)
            {
                if (request.Requester.Id == container.UserId)
                {
                    requestId = request.Id;
                    break;
                }
            }

            RepositionRemainingRequests(container);

            container.Location = new Point(0, contactListBottom);
            contactListBottom += container.Height;

            container.Parent = this.pnlContactsContainer;
            this.pnlContactsContainer.Controls.Add(container);
            this.listContactContainer.Add(container);

            int offset = GetContactsListLength();

            this.pnlAvailableRequests.Location = new Point(this.pnlAvailableRequests.Location.X, offset);

            // Send query to the API so that we actually add the user to the database
            WebConnector.AddContact(this.accountInfo.Id, container.UserId);
            // Remove the request
            WebConnector.DeleteRequest(requestId);

            // Tell server to propagate the request to the accepted client if he's currently available
            string jsonClientInfo = JsonConvert.SerializeObject(this.accountInfo);

            // Send as message
            socketHelper.SendMessage(container.Username, jsonClientInfo, this.accountInfo.Username, @"/accept");
        }
        private void ListAvailableUsers(List <AccountInformation> users)
        {
            int contactControlOffset = 45;

            foreach (AccountInformation user in users)
            {
                UserInfoContainer contactBox = new UserInfoContainer(false, user.Username, user.Id, null, false);
                contactBox.Name     = "contact_" + user.Username;
                contactBox.Parent   = this.pnlAvailableRequests;
                contactBox.Location = new Point(0, contactControlOffset);

                this.pnlAvailableUsers.Controls.Add(contactBox);

                contactControlOffset += contactBox.Size.Height;

                // Add click handler for each consecutive container so that they fire independently of one another (per object)
                contactBox.MouseClick     += contactBox_MouseClick;
                contactBox.AddUserPressed += container_AddUserPressed;
            }

            this.pnlAvailableUsers.Invalidate();
        }
        private void AppendContact(AccountInformation user)
        {
            if (this.InvokeRequired)
            {
                this.Invoke(new Action(() => AppendContact(user)));
                return;
            }

            int offset = GetContactsListLength();

            UserInfoContainer contactBox = new UserInfoContainer(false, user.Username, user.Id, null);

            contactBox.Parent      = this.pnlContactsContainer;
            contactBox.Name        = "contact_" + user.Username;
            contactBox.Location    = new Point(0, offset);
            contactBox.MouseClick += contactBox_MouseClick;

            this.listContactContainer.Add(contactBox);
            this.pnlContactsContainer.Controls.Add(contactBox);

            this.pnlContactsContainer.Invalidate();
        }
        private void ChangeOnlineStatus(string username)
        {
            foreach (Control control in this.pnlContactsContainer.Controls)
            {
                if (control is UserInfoContainer)
                {
                    UserInfoContainer contact = control as UserInfoContainer;

                    if (contact.Username == username)
                    {
                        if (contact.OnlineStatus)
                        {
                            contact.OnlineStatus = false;
                        }
                        else
                        {
                            contact.OnlineStatus = true;
                        }

                        break;
                    }
                }
            }
        }
 private void RepositionRemainingRequests(UserInfoContainer container)
 {
     this.RepositionUserContainers(this.pnlAvailableRequests, container);
 }
 private void RespositionContacts(UserInfoContainer container)
 {
     this.RepositionUserContainers(this.pnlContactsContainer, container);
 }
Esempio n. 16
0
 /// <summary>
 /// Initializes a new instance of the <see cref="UserInfo"/> class.
 /// </summary>
 public AUserInfo()
 {
     userInfoContainer = new UserInfoContainer();
 }