// Initialize Stuff public async void Initialize() { BackgroundTaskUtils.RegisterToastNotificationBackgroundTasks(); ContactUtils.AssignAppToPhoneContacts(); _store = await ChatMessageManager.RequestStoreAsync(); ChatConversations = await GetChats(); if (ChatConversations.Count != 0) { SelectedItem = ChatConversations[0]; } if (!(await PerformMandatoryChecks())) { await CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, async() => { await new CellularUnavailableContentDialog().ShowAsync(); }); } _store.ChangeTracker.Enable(); _store.StoreChanged += Store_StoreChanged; }
private async void HandleArguments(ToastNotificationActivatedEventArgs args) { string arguments = args.Argument; string action = args.Argument.Split('&').First(x => x.ToLower(new CultureInfo("en-US")).StartsWith("action=", StringComparison.InvariantCulture)).Split('=')[1]; string from = args.Argument.Split('&').First(x => x.ToLower(new CultureInfo("en-US")).StartsWith("from=", StringComparison.InvariantCulture)).Split('=')[1]; string deviceid = args.Argument.Split('&').First(x => x.ToLower(new CultureInfo("en-US")).StartsWith("deviceid=", StringComparison.InvariantCulture)).Split('=')[1]; switch (action.ToLower(new CultureInfo("en-US"))) { case "reply": { try { string messagetosend = (string)args.UserInput["textBox"]; SmsDevice2 smsDevice = SmsDevice2.FromId(deviceid); await SmsUtils.SendTextMessageAsync(smsDevice, from, messagetosend); } catch { } break; } case "openthread": { ChatMenuItemControl selectedConvo = null; foreach (var convo in ViewModel.ChatConversations) { var contact = convo.ViewModel.Contact; foreach (var num in contact.Phones) { if (ContactUtils.ArePhoneNumbersMostLikelyTheSame(from, num.Number)) { selectedConvo = convo; break; } } if (selectedConvo != null) { break; } } if (selectedConvo != null) { ViewModel.SelectedItem = selectedConvo; } break; } } }
private async void Store_StoreChanged(ChatMessageStore sender, ChatMessageStoreChangedEventArgs args) { switch (args.Kind) { case ChatStoreChangedEventKind.ConversationModified: { var conversation = await _store.GetConversationAsync(args.Id); if (conversation == null) { if (ChatConversations.Any(x => x.ConversationId == args.Id)) { var existingConversation = ChatConversations.First(x => x.ConversationId == args.Id); bool wasSelected = SelectedItem == existingConversation; await CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () => { ChatConversations.Remove(existingConversation); if (wasSelected && ChatConversations.Count != 0) { SelectedItem = ChatConversations[0]; } }); } break; } if (!ChatConversations.Any(x => x.ConversationId == args.Id)) { await CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () => { ChatConversations.Insert(0, new ChatMenuItemControl(conversation.Id)); if (!ChatConversations.Contains(SelectedItem)) { SelectedItem = ChatConversations[0]; } }); } /*else * { * var existingConversation = ChatConversations.First(x => x.ConversationId == args.Id); * await CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, * () => * { * bool wasSelected = SelectedItem == existingConversation; * var newConvo = new ChatMenuItemControl(conversation.Id); * * ChatConversations.Remove(existingConversation); * ChatConversations.Insert(0, newConvo); * * if (wasSelected) * SelectedItem = newConvo; * }); * }*/ break; } case ChatStoreChangedEventKind.ConversationDeleted: { if (ChatConversations.Any(x => x.ConversationId == args.Id)) { var existingConversation = ChatConversations.First(x => x.ConversationId == args.Id); bool wasSelected = SelectedItem == existingConversation; await CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () => { ChatConversations.Remove(existingConversation); if (wasSelected && ChatConversations.Count != 0) { SelectedItem = ChatConversations[0]; } }); } break; } } }