Example #1
0
        private void Update(object sender, EventArgs e)
        {
            int newContacts = MyConnection.RetrieveInt("People", "Contacts", "ID", ActiveUser.Id);

            if (newContacts != ActiveUser.Contacts)
            {
                List <int> addedContacts = Methods.GetPrimeFactors(newContacts / ActiveUser.Contacts);
                foreach (int id in addedContacts)
                {
                    ActiveUser.ContactList.Add(new Contact(id));
                }
            }
            BrushConverter BrushColorConverter = new BrushConverter();

            NewsFeed.Update();
            ActiveUser.LoadConversations();
            ContactsOfUser.Children.Clear();
            MessagesOfUser.Children.Clear();
            GlobalNewsFeed.Children.Clear();
            foreach (Contact contact in ActiveUser.ContactList) // Draw contact Button
            {
                ContactButton cbutton = new ContactButton(contact.Id);
                cbutton.Content = contact.Name + " (" + contact.Username + ")";
                cbutton.Click  += Cbutton_Click;
                ContactsOfUser.Children.Add(cbutton);
                if (ActiveConversation != null && "C" + contact.Id * ActiveUser.Id == ActiveConversation.ColumnName)
                {
                    cbutton.Background = BrushColorConverter.ConvertFromString("#5DBCD2") as SolidColorBrush;
                }
            }
            foreach (string message in NewsFeed.Posts) //Draw newsfeed
            {
                Border border = new Border();

                TextBlock tb = new TextBlock();
                tb.Text             = message.Replace("%%", "'").Replace("%%%", "\"");
                border.CornerRadius = new CornerRadius(10);
                border.MaxWidth     = 250;
                border.Padding      = new Thickness(5, 0, 8, 0);
                border.Margin       = new Thickness(0, 5, 0, 5);
                tb.FontSize         = 13;
                tb.TextWrapping     = TextWrapping.Wrap;
                tb.Foreground       = Brushes.White;
                border.Child        = tb;
                border.Background   = BrushColorConverter.ConvertFromString("#0084FF") as SolidColorBrush;
                GlobalNewsFeed.Children.Add(border);
            }

            if (ActiveConversation == null)
            {
                return;
            }
            ActiveConversation.Update();
            foreach (string message in ActiveConversation.MessageList)
            {
                if (message == null)
                {
                    continue;
                }
                Border    border = new Border();
                TextBlock tb     = new TextBlock();
                if (message.Length >= ActiveUser.Name.Length + 2 && message.Substring(0, ActiveUser.Name.Length + 2) == ActiveUser.Name + ": ")
                {
                    border.HorizontalAlignment = HorizontalAlignment.Right;
                    tb.TextAlignment           = TextAlignment.Right;
                    //tb.HorizontalAlignment = HorizontalAlignment.Right;

                    tb.Text           = (message.Substring(ActiveUser.Name.Length + 1, message.Length - (ActiveUser.Name.Length + 1))).Replace("%%", "'").Replace("%%%", "\"");
                    border.Background = BrushColorConverter.ConvertFromString("#0084FF") as SolidColorBrush;
                    // Message By User
                }
                else
                {
                    border.Background          = BrushColorConverter.ConvertFromString("red") as SolidColorBrush;
                    tb.Text                    = message.Replace("%%", "'").Replace("%%%", "\"");
                    border.HorizontalAlignment = HorizontalAlignment.Left;
                }
                border.Margin       = new Thickness(0, 5, 0, 0);
                border.CornerRadius = new CornerRadius(10);
                border.MaxWidth     = 200;
                border.Padding      = new Thickness(5, 0, 8, 0);
                tb.FontSize         = 13;
                tb.TextWrapping     = TextWrapping.Wrap;
                tb.Foreground       = Brushes.White;
                border.Child        = tb;
                MessagesOfUser.Children.Add(border);
            }
        }