Exemplo n.º 1
0
        public Conversation()
        {
            try
            {
                this.InitializeComponent();

                CurrentConversation = null;

                Frontend.Events.OnRosterContactSelected += OnRosterContactSelected;
                Frontend.Events.OnMessageReceived       += OnMessageReceived;
                Frontend.Events.OnSettingsChanged       += OnSettingsChanged;
                Frontend.Events.OnContactsChanged       += OnContactsChanged;
                Frontend.CoreWindow.VisibilityChanged   += CoreWindow_VisibilityChanged;

                SizeChanged += Conversation_SizeChanged;
            }
            catch (Exception uiEx) { Frontend.UIError(uiEx); }
        }
Exemplo n.º 2
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); }
        }
Exemplo n.º 3
0
        public Conversation()
        {
            try
            {
                this.InitializeComponent();

                SendText.DataContext = Frontend.Settings;
                CurrentConversation = null;

                Frontend.Events.OnRosterContactSelected += OnRosterContactSelected;
                Frontend.Events.OnMessageReceived += OnMessageReceived;
                Frontend.Events.OnSettingsChanged += OnSettingsChanged;
                Frontend.Events.OnContactsChanged += OnContactsChanged;
                Frontend.CoreWindow.VisibilityChanged += CoreWindow_VisibilityChanged;
                Frontend.CoreWindow.Activated += CoreWindow_Activated;

                SizeChanged += Conversation_SizeChanged;
            }
            catch (Exception uiEx) { Frontend.UIError(uiEx); }
        }
Exemplo n.º 4
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); }
        }