Example #1
0
        public GoogleTalkHelper()
        {
            settings = App.Current.Settings;
            gtalk = App.Current.GtalkClient;
            pushHelper = App.Current.PushHelper;

            pushHelper.UriUpdated += UriUpdated;
            pushHelper.RawNotificationReceived += RawNotificationReceived;
            Connected = false;
        }
Example #2
0
        public void GetOfflineMessages(GoogleTalk.FinishedCallback cb)
        {
            Dictionary<string, string> firstMessage = new Dictionary<string, string>();
            Dictionary<string, int> messageCount = new Dictionary<string, int>();

            gtalk.MessageQueue(
                message => {
                    message.Offline = true;
                    NotifyMessageReceived(message);

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

                    if (!messageCount.ContainsKey(email)) {
                        messageCount[email] = 1;
                        firstMessage[email] = message.Body;
                    } else {
                        messageCount[email]++;
                    }
                },
                error => {
                    if (error.Equals("")) {
                        ShowToast(AppResources.Error_OfflineMessagesMessage);
                    } else if (error.StartsWith("403")) {
                        GracefulReLogin();
                    } else {
                        ShowToast(error, AppResources.Error_OfflineMessagesTitle);
                    }
                    cb();
                },
                () => {
                    foreach(var mc in messageCount) {
                        if (mc.Value == 1) {
                            if (mc.Key != App.Current.CurrentChat) {
                                ShowToast(new Message {
                                    From = mc.Key,
                                    Body = firstMessage[mc.Key]
                                });
                            }
                        } else {
                            if (mc.Key != App.Current.CurrentChat) {
                                ShowToast(new Message {
                                    From = mc.Key,
                                    Body = string.Format(AppResources.Notification_OfflineMessages, mc.Value)
                                });
                            }
                        }
                    }
                    cb();
                }
            );

            App.Current.RootFrame.Dispatcher.BeginInvoke(() => {
                var tileToFind = ShellTile.ActiveTiles.First();
                var newTileData = new StandardTileData {
                    Count = 0
                };
                tileToFind.Update(newTileData);
            });
        }
Example #3
0
        protected override void OnNavigatedTo(NavigationEventArgs e)
        {
            base.OnNavigatedTo(e);

            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 (App.Current.Roster.Contains(email)) {
                Initialize();
            } else if (gtalkHelper.RosterLoaded && gtalk.LoggedIn) {
                if(e.IsNavigationInitiator) {
                    gtalkHelper.GetOfflineMessages();
                }
            } else {
                gtalkHelper.RosterUpdated += Initialize;
            }

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

            gtalkHelper.LoginIfNeeded();

            ScrollToBottom();
        }
Example #4
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();
        }
Example #5
0
        // Code to execute when the application is launching (eg, from Start)
        // This code will not execute when the application is reactivated
        private void Application_Launching(object sender, LaunchingEventArgs e)
        {
            Settings = IsolatedStorageSettings.ApplicationSettings;
            PushHelper = new PushHelper();
            GtalkClient = new GoogleTalk();

            if (!Settings.Contains("chatlog")) {
                Settings["chatlog"] = new Dictionary<string, List<Message>>();
            }
            if (!Settings.Contains("unread")) {
                Settings["unread"] = new Dictionary<string, int>();
            }
            if (!Settings.Contains("recent")) {
                Settings["recent"] = new ObservableCollection<Contact>();
            }

            Roster = new Roster();
            GtalkHelper = new GoogleTalkHelper();
            Roster.Load();

            RecentContacts = Settings["recent"] as ObservableCollection<Contact>;

            PushHelper.RegisterPushNotifications();

            InitAnalytics();

            if (Settings.Contains("lastError")) {
                var result = MessageBox.Show(
                    AppResources.CrashReport_Message,
                    AppResources.CrashReport_Title,
                    MessageBoxButton.OKCancel
                );

                if(result == MessageBoxResult.OK) {
                    GtalkClient.CrashReport(Settings["lastError"] as string, success => Settings.Remove("lastError"), error => {});
                } else {
                    Settings.Remove("lastError");
                }
            }
        }
Example #6
0
        // Code to execute when the application is activated (brought to foreground)
        // This code will not execute when the application is first launched
        private void Application_Activated(object sender, ActivatedEventArgs e)
        {
            if (Settings == null) Settings = IsolatedStorageSettings.ApplicationSettings;
            if (PushHelper == null) PushHelper = new PushHelper();
            if (GtalkClient == null) GtalkClient = new GoogleTalk();

            if (RecentContacts == null) {
                if (!Settings.Contains("recent")) {
                    Settings["recent"] = RecentContacts = new ObservableCollection<Contact>();
                }
                RecentContacts = Settings["recent"] as ObservableCollection<Contact>;
            }

            if (!Settings.Contains("chatlog")) {
                Settings["chatlog"] = new Dictionary<string, List<Message>>();
            }

            if (!Settings.Contains("unread")) {
                Settings["unread"] = new Dictionary<string, int>();
            }

            Roster = new Roster();
            if (GtalkHelper == null) GtalkHelper = new GoogleTalkHelper();
            Roster.Load();

            InitAnalytics();

            PushHelper.RegisterPushNotifications();
        }