From 1a5ea1f01169b550b5ee835db64cf10212f4e875 Mon Sep 17 00:00:00 2001 From: Paul Schneider Date: Wed, 26 Oct 2016 05:49:28 +0200 Subject: [PATCH] Saves the private message --- BookAStar/BookAStar/App.xaml.cs | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/BookAStar/BookAStar/App.xaml.cs b/BookAStar/BookAStar/App.xaml.cs index 98337fed..7c40f614 100644 --- a/BookAStar/BookAStar/App.xaml.cs +++ b/BookAStar/BookAStar/App.xaml.cs @@ -241,24 +241,34 @@ namespace BookAStar if (isConnected) { // TODO Start all cloud related stuff - - + CurrentApp.StartHubConnection(); } } } } // Start the Hub connection - private async void StartHubConnection () + public async void StartHubConnection () { + if (chatHubConnection != null) + chatHubConnection.Dispose(); chatHubConnection = new HubConnection(Constants.SignalRHubsUrl); if (MainSettings.CurrentUser != null) chatHubConnection.Headers.Add("Bearer", MainSettings.CurrentUser.YavscTokens.AccessToken); + chatHubProxy = chatHubConnection.CreateHubProxy("ChatHub"); - chatHubProxy.On("AddMessage", (n, m) => { - Messages.Add(string.Format("{0} says: {1}", n, m)); + chatHubProxy.On("PV", (n, m) => { + DataManager.Current.PrivateMessages.Add( + new Model.Social.PrivateMessage + { + Message = m, + SenderId = n, + Date = DateTime.Now + } + ); }); await chatHubConnection.Start(); + } private HubConnection chatHubConnection=null; private IHubProxy chatHubProxy = null;