Esempio n. 1
0
        protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e)
        {
            base.OnNavigatedTo(e);

            FlurryWP7SDK.Api.LogEvent("ContactList - ContactList started", true);

            if (App.Current.LastPage != null && App.Current.LastPage.StartsWith("/Pages/Chat.xaml?from=") && App.Current.RootFrame.BackStack.Count() > 0)
            {
                App.Current.RootFrame.RemoveBackEntry();
            }
            App.Current.LastPage = e.Uri.OriginalString;

            if (gtalkHelper != App.Current.GtalkHelper)
            {
                gtalkHelper = App.Current.GtalkHelper;

                Dispatcher.BeginInvoke(() => AllContactsListBox.ItemsSource = App.Current.Roster);
            }

            gtalkHelper.RosterUpdated += RosterLoaded;
            gtalkHelper.ConnectFailed += ConnectFailed;

            gtalkHelper.SetCorrectOrientation(this);

            Dispatcher.BeginInvoke(
                () => {
                if (gtalkHelper.RosterLoaded)
                {
                    HideProgressBar();
                }
                else
                {
                    ShowProgressBar(AppResources.ContactList_ProgressLoading);
                }
            });

            if (gtalkHelper.RosterLoaded && App.Current.GtalkClient.LoggedIn)
            {
                if (e.IsNavigationInitiator)
                {
                    gtalkHelper.GetOfflineMessages(() => { });
                }
            }
            else
            {
                UpdateRoster();
            }

            gtalkHelper.LoginIfNeeded();
            gtalkHelper.MessageReceived += gtalkHelper.ShowToast;
        }
Esempio n. 2
0
        private void SendButton_Click(object sender, EventArgs e)
        {
            if (MessageText.Text.Length == 0)
            {
                return;
            }

            ShowProgressBar(AppResources.Chat_ProgressSendingMessage);

            sendButton.IsEnabled = false;

            try {
                gtalk.SendMessage(to, MessageText.Text, data => Dispatcher.BeginInvoke(() => {
                    HideProgressBar();

                    var bubble       = new SentChatBubble();
                    bubble.Text      = MessageText.Text;
                    bubble.TimeStamp = DateTime.Now;

                    App.Current.GtalkHelper.AddRecentContact(currentContact);

                    MessageList.Children.Add(bubble);

                    sendButton.IsEnabled = true;

                    MessageList.UpdateLayout();
                    Scroller.UpdateLayout();
                    Scroller.ScrollToVerticalOffset(Scroller.ExtentHeight);

                    lock (chatLog) {
                        while (chatLog.Count >= GoogleTalkHelper.MaximumChatLogSize)
                        {
                            chatLog.RemoveAt(0);
                        }
                        chatLog.Add(new Message {
                            Body     = MessageText.Text,
                            Outbound = true,
                            Time     = DateTime.Now,
                            OTR      = otr
                        });
                    }

                    MessageText.Text = "";
                    // Refocus text box to reset text suggestions.
                    // Only refocus is it's currently focused.
                    if (System.Windows.Input.FocusManager.GetFocusedElement() == MessageText)
                    {
                        this.Focus();
                        MessageText.Focus();
                    }

                    FlurryWP7SDK.Api.LogEvent("Chat - Chat sent");
                }), error => {
                    HideProgressBar();
                    if (error.StartsWith("403"))
                    {
                        settings.Remove("token");
                        settings.Remove("rootUrl");
                        gtalkHelper.LoginIfNeeded();
                    }
                    else
                    {
                        Dispatcher.BeginInvoke(
                            () => {
                            sendButton.IsEnabled = true;
                            gtalkHelper.ShowToast(AppResources.Chat_ErrorMessageNotSent);
                        }
                            );
                    }
                });
            } catch (InvalidOperationException) {
                Dispatcher.BeginInvoke(
                    () => {
                    HideProgressBar();
                    MessageBox.Show(
                        AppResources.Chat_ErrorAuthExpiredBody,
                        AppResources.Chat_ErrorAuthExpiredTitle,
                        MessageBoxButton.OK
                        );
                    App.Current.RootFrame.Navigate(new Uri("/Pages/Login.xaml", UriKind.Relative));
                }
                    );
            }
        }
Esempio n. 3
0
        protected override void OnNavigatedTo(NavigationEventArgs e)
        {
            base.OnNavigatedTo(e);

            FlurryWP7SDK.Api.LogEvent("Chat - Chat started", true);

            App.Current.LastPage = e.Uri.OriginalString;

            gtalk       = App.Current.GtalkClient;
            gtalkHelper = App.Current.GtalkHelper;
            settings    = App.Current.Settings;

            App.Current.GtalkHelper.SetCorrectOrientation(this);

            currentContact = null;

            if (NavigationContext.QueryString.ContainsKey("from"))
            {
                to    = NavigationContext.QueryString["from"];
                email = to;

                if (email.Contains("/"))
                {
                    email = email.Substring(0, email.IndexOf('/'));
                }

                App.Current.CurrentChat = email;

                to = email;

                if (App.Current.Roster.Contains(email))
                {
                    currentContact = App.Current.Roster[email];
                }
            }

            gtalkHelper.MessageReceived += DisplayMessage;

            if (gtalkHelper.RosterLoaded && gtalk.LoggedIn && App.Current.Roster.Contains(email))
            {
                Initialize();

                if (e.NavigationMode == NavigationMode.Back)
                {
                    ShowProgressBar(AppResources.Chat_ProgressGettingMessages);
                    gtalkHelper.GetOfflineMessages(() => Dispatcher.BeginInvoke(() => HideProgressBar()));
                }
            }
            else
            {
                Initialize();
                ShowProgressBar(AppResources.Chat_ProgressGettingMessages);
                gtalkHelper.RosterUpdated += () => HideProgressBar();
                gtalkHelper.RosterUpdated += Initialize;
            }

            object savedText;

            if (State.TryGetValue("message", out savedText))
            {
                MessageText.Text = (string)savedText;
            }

            gtalkHelper.LoginIfNeeded();

            ScrollToBottom();
        }