forked from WOA-Project/Chat
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Shell.xaml.cs
89 lines (73 loc) · 2.71 KB
/
Shell.xaml.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
using Chat.BackgroundTasks;
using Chat.Common;
using Chat.Controls;
using Chat.Pages;
using System;
using Windows.ApplicationModel.Activation;
using Windows.ApplicationModel.Chat;
using Windows.ApplicationModel.Contacts;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
namespace Chat
{
public sealed partial class Shell : UserControl
{
public Shell()
{
this.InitializeComponent();
Load();
}
private async void Load()
{
BackgroundTaskUtils.RegisterToastNotificationBackgroundTasks();
ContactUtils.AssignAppToPhoneContacts();
ChatMessageStore store = await ChatMessageManager.RequestStoreAsync();
var reader = store.GetConversationReader();
var convos = await reader.ReadBatchAsync();
bool initializedonce = false;
foreach (var convo in convos)
{
NavigationView.MenuItems.Add(new ChatMenuItemControl(convo));
if (!initializedonce)
NavigationView.SelectedItem = NavigationView.MenuItems[0];
initializedonce = true;
}
}
public void HandleArguments(object e)
{
var args = e as ProtocolActivatedEventArgs;
if (args != null)
{
HandleArguments(args);
}
}
private async void HandleArguments(ProtocolActivatedEventArgs args)
{
Uri uri = args.Uri;
string unescpateduri = Uri.UnescapeDataString(uri.Query);
var contactid = unescpateduri.Replace("?ContactRemoteIds=", "");
if (uri.Scheme == "ms-ipmessaging")
{
ContactStore store = await ContactManager.RequestStoreAsync(ContactStoreAccessType.AppContactsReadWrite);
Contact contact = await store.GetContactAsync(contactid);
MainFrame.Navigate(typeof(ComposePage), contact);
}
}
private void NewConvoButton_Click(object sender, RoutedEventArgs e)
{
MainFrame.Navigate(typeof(ComposePage));
NavigationView.SelectedItem = null;
}
private void NavigationView_SelectionChanged(NavigationView sender, NavigationViewSelectionChangedEventArgs args)
{
if (args.SelectedItem != null)
MainFrame.Navigate(typeof(ConversationPage), (args.SelectedItem as ChatMenuItemControl).ChatConversation);
}
private void NavigationView_PaneClosing(NavigationView sender, NavigationViewPaneClosingEventArgs args)
{
}
private void NavigationView_PaneOpening(NavigationView sender, object args)
{
}
}
}