Beispiel #1
0
        public async void OnUserRelevantEvent()
        {
            try
            {
                await Frontend.RunAsync(() =>
                {
                    bool notifications = false;
                    foreach (var account in Frontend.Accounts)
                    {
                        if (account.Roster.UnreadNotificationCount > 0)
                        {
                            notifications = true;
                        }
                    }

                    if (Frontend.Notifications.NotificationList.Count > 0)
                    {
                        notifications = true;
                    }

                    ConversationHeaderControl.Notify = notifications;
                });
            }
            catch (Exception uiEx) { Frontend.UIError(uiEx); }
        }
Beispiel #2
0
        private async void ClearMessageCount()
        {
            try
            {
                await Frontend.RunAsync(() =>
                {
                    var visible = false;
                    if (Frontend.CoreWindow != null)
                    {
                        visible = Frontend.CoreWindow.Visible;
                    }

                    if (CurrentConversation != null && visible)
                    {
                        if (CurrentConversation.Other != null)
                        {
                            var other = GetOther();
                            if (other != null && other.UnreadMessageCount >= 0)
                            {
                                other.LockUpdates();
                                other.UnreadMessageCount = 0;
                                other.UnlockUpdates();
                            }
                        }
                    }
                });
            }
            catch (Exception uiEx) { Frontend.UIError(uiEx); }
        }
 private async void OnBackClicked(object sender, RoutedEventArgs e)
 {
     try
     {
         await Frontend.RunAsync(() =>
         {
             Frontend.Events.DeselectContact();
         });
     }
     catch (Exception uiEx) { Frontend.UIError(uiEx); }
 }
Beispiel #4
0
 private async void Events_OnRosterItemSelected(object sender, Frontend.ContactSelectedEventArgs e)
 {
     try
     {
         await Frontend.RunAsync(() =>
         {
             SelectedContact = e.Contact;
             RecreateLayout();
         });
     }
     catch (Exception uiEx) { Frontend.UIError(uiEx); }
 }
Beispiel #5
0
 private async void OpenNotifications(object sender, RoutedEventArgs e)
 {
     try
     {
         await Frontend.RunAsync(() =>
         {
             if (CleanPaneState())
             {
                 CurrentFlyout = new Flyout.Flyout(FlyoutType.Notifications);
             }
         });
     }
     catch (Exception uiEx) { Frontend.UIError(uiEx); }
 }
Beispiel #6
0
 private async void OnAccounts(bool returnCharm)
 {
     try
     {
         await Frontend.RunAsync(() =>
         {
             if (CleanPaneState())
             {
                 CurrentFlyout = new Flyout.Flyout(FlyoutType.AccountListEdit, null, null, returnCharm);
             }
         });
     }
     catch (Exception uiEx) { Frontend.UIError(uiEx); }
 }
Beispiel #7
0
 private async void Frontend_OnRequestBackgroundAccess(object sender, EventArgs e)
 {
     try
     {
         await Frontend.RunAsync(() =>
         {
             if (Backend != null)
             {
                 Backend.RequestBackgroundAccess();
             }
         });
     }
     catch (Exception uiEx) { Frontend.UIError(uiEx); }
 }
Beispiel #8
0
 private async void Events_OnSubscriptionContactSelected(object sender, Frontend.ContactSelectedEventArgs e)
 {
     try
     {
         await Frontend.RunAsync(() =>
         {
             if (CleanPaneState())
             {
                 CurrentFlyout = new Flyout.Flyout(FlyoutType.Subscription, e.Contact);
             }
         });
     }
     catch (Exception uiEx) { Frontend.UIError(uiEx); }
 }
Beispiel #9
0
 private async void ScrollToBottom()
 {
     try
     {
         await Frontend.RunAsync(() =>
         {
             if (ItemList.Items.Count > 0)
             {
                 ItemList.ScrollIntoView(ItemList.Items.First());
             }
         });
     }
     catch (Exception uiEx) { Frontend.UIError(uiEx); }
 }
 private async void Events_OnRosterItemSelected(object sender, Frontend.ContactSelectedEventArgs e)
 {
     try
     {
         await Frontend.RunAsync(() =>
         {
             if (e.Contact != null)
             {
                 this.DataContext = e.Contact;
             }
         });
     }
     catch (Exception uiEx) { Frontend.UIError(uiEx); }
 }
Beispiel #11
0
 private async void OnContactInfo(object sender, RoutedEventArgs e)
 {
     try
     {
         await Frontend.RunAsync(() =>
         {
             if (SelectedContact != null)
             {
                 if (CleanPaneState())
                 {
                     CurrentFlyout = new Flyout.Flyout(FlyoutType.EditContact, SelectedContact);
                 }
             }
         });
     }
     catch (Exception uiEx) { Frontend.UIError(uiEx); }
 }
Beispiel #12
0
        private async void OnImageLoaded(object sender, RoutedEventArgs e)
        {
            try
            {
                await Frontend.RunAsync(() =>
                {
                    var image = sender as AvatarControl;
                    if (image != null)
                    {
                        image.Height = image.ActualWidth;
                    }

                    image.UpdateLayout();
                });
            }
            catch (Exception uiEx) { Frontend.UIError(uiEx); }
        }
Beispiel #13
0
        private async void SendMessage()
        {
            try
            {
                await Frontend.RunAsync(() =>
                {
                    if (CurrentConversation != null && !string.IsNullOrEmpty(SendText.Text))
                    {
                        var account = Frontend.Accounts[CurrentConversation.Self];
                        if (account == null)
                        {
                            return;
                        }

                        if (account.persistantState == AccountState.Enabled)
                        {
                            var self  = GetSelf();
                            var other = GetOther();
                            if (self != null && other != null)
                            {
                                if (!string.IsNullOrEmpty(self.jid) && !string.IsNullOrEmpty(other.CurrentJID))
                                {
                                    var message = XMPPHelper.SendMessage(self.jid, other.CurrentJID, SendText.Text);
                                    if (message != null)
                                    {
                                        message.from = message.Account;
                                        CurrentConversation.AddMessage(message);
                                    }

                                    SendText.Text = string.Empty;
                                }
                            }
                        }
                    }
                });
            }
            catch (Exception uiEx) { Frontend.UIError(uiEx); }
        }
Beispiel #14
0
        public async void RecreateLayout()
        {
            try
            {
                await Frontend.RunAsync(() =>
                {
                    if (Frontend.Accounts == null)
                    {
                        return;
                    }

                    OnUserRelevantEvent();

                    // No accounts overlay
                    if (Frontend.Accounts.Count <= 0)
                    {
                        NoAccountsOverlay.Visibility = Visibility.Visible;
                    }
                    else
                    {
                        NoAccountsOverlay.Visibility = Visibility.Collapsed;
                    }

                    // Snapping
                    if (ApplicationView.Value == ApplicationViewState.Snapped) // Snapped
                    {
                        if (SelectedContact != null)                           // Contact Selected
                        {
                            this.LeftGridControl.Visibility           = Visibility.Collapsed;
                            this.RightGridControl.Visibility          = Visibility.Visible;
                            this.RosterControl.Visibility             = Visibility.Visible;
                            this.ConversationControl.Visibility       = Visibility.Visible;
                            this.StatusControl.Visibility             = Visibility.Visible;
                            this.ConversationHeaderControl.Visibility = Visibility.Visible;
                        }
                        else
                        {
                            this.LeftGridControl.Visibility           = Visibility.Visible;
                            this.RightGridControl.Visibility          = Visibility.Collapsed;
                            this.RosterControl.Visibility             = Visibility.Visible;
                            this.ConversationControl.Visibility       = Visibility.Visible;
                            this.StatusControl.Visibility             = Visibility.Visible;
                            this.ConversationHeaderControl.Visibility = Visibility.Visible;
                        }
                    }
                    else // Not snapped
                    {
                        this.LeftGridControl.Visibility           = Visibility.Visible;
                        this.RightGridControl.Visibility          = Visibility.Visible;
                        this.RosterControl.Visibility             = Visibility.Visible;
                        this.ConversationControl.Visibility       = Visibility.Visible;
                        this.StatusControl.Visibility             = Visibility.Visible;
                        this.ConversationHeaderControl.Visibility = Visibility.Collapsed;
                    }

                    // Appbar
                    if (SelectedContact != null)
                    {
                        RemoveContact.IsEnabled = true;
                        ContactInfo.IsEnabled   = true;
                    }
                    else
                    {
                        RemoveContact.IsEnabled = false;
                        ContactInfo.IsEnabled   = false;
                    }

                    if (Frontend.Accounts.Enabled.Count() > 0)
                    {
                        AddContact.IsEnabled = true;
                    }
                    else
                    {
                        AddContact.IsEnabled = false;
                    }
                });
            }
            catch (Exception uiEx) { Frontend.UIError(uiEx); }
        }
Beispiel #15
0
        private async void OnRosterContactSelected(object sender, Frontend.ContactSelectedEventArgs e)
        {
            try
            {
                await Frontend.RunAsync(() =>
                {
                    if (e.Contact != null && !string.IsNullOrEmpty(e.Contact.jid))
                    {
                        var account = Frontend.Accounts[new XMPP.JID(e.Contact.account).Bare];
                        if (account == null || account.OwnContact == null)
                        {
                            return;
                        }

                        if (!account.CurrentConversations.Keys.Contains(e.Contact.jid))
                        {
                            account.CurrentConversations[e.Contact.jid] = new Backend.Data.Conversation(account.OwnContact.jid, e.Contact.jid);
                        }

                        // Remove old listerners
                        if (CurrentConversation != null)
                        {
                            CurrentConversation.Items.CollectionChanged -= OnCoversationItemCollectionChanged;
                        }

                        // Change to the new Conversation
                        CurrentConversation = account.CurrentConversations[e.Contact.jid];

                        UpdateOfflineWarnings();

                        // Remove old text
                        SendText.Text = string.Empty;

                        // Add new listener
                        CurrentConversation.Items.CollectionChanged += OnCoversationItemCollectionChanged;

                        ClearMessageCount();

                        ScrollToBottom();

                        // Can be vary annoying
                        if (Frontend.Settings.focusTextInput)
                        {
                            this.SendText.Focus(FocusState.Programmatic);
                        }
                    }
                    else // No contact selected
                    {
                        if (CurrentConversation != null)
                        {
                            if (CurrentConversation.Items.Count > 0)
                            {
                                foreach (var item in CurrentConversation.Items)
                                {
                                    item.Messages.CollectionChanged -= OnConversationItemMessageCollectionChanged;
                                }
                            }

                            CurrentConversation.Items.CollectionChanged -= OnCoversationItemCollectionChanged;

                            AccountOfflineWarning.Visibility = Visibility.Collapsed;
                            ContactOfflineWarning.Visibility = Visibility.Collapsed;
                        }

                        CurrentConversation = null;
                    }
                });
            }
            catch (Exception uiEx) { Frontend.UIError(uiEx); }
        }