From 6a1cc12b2ca35637241ec1b9f9109eb602652f8c Mon Sep 17 00:00:00 2001 From: ChrisK91 Date: Fri, 6 Sep 2013 00:35:40 +0200 Subject: [PATCH] Multiple enhancements - Fixed various search issues, closes #78 - Added basic support for chat, updates every two seconds. Still some bugs to iron out (see #8) - Made "message" button on profile page functional (closes #69) - Added SmartDispatcher, that only dispatches when needed, Should give us a little performance increase - Changed Dispatching in MainViewModel - Added ability to suppress notifications - Made Helpers.Notify thread safe - Added auto updating to Chat - Added client function to post a chat message - Added client function to get chat beacon --- SparklrLib/Objects/Requests/Work/Chat.cs | 2 +- SparklrLib/Objects/Responses/Beacon/Chat.cs | 5 +- SparklrLib/PortableSparklrLib.csproj | 1 + SparklrLib/SparklrClient.cs | 17 +- SparklrWP/App.xaml.cs | 4 +- SparklrWP/Pages/ChatPage.xaml | 2 +- SparklrWP/Pages/ChatPage.xaml.cs | 12 ++ SparklrWP/Pages/Profile.xaml | 2 +- SparklrWP/Pages/Profile.xaml.cs | 5 + SparklrWP/Pages/SearchPage.xaml | 4 +- SparklrWP/Pages/SearchPage.xaml.cs | 12 +- SparklrWP/SparklrWP.csproj | 1 + SparklrWP/Utils/Helpers.cs | 11 +- SparklrWP/Utils/SmartDispatcher.cs | 34 ++++ SparklrWP/ViewModels/ChatViewModel.cs | 166 ++++++++++++++++++-- SparklrWP/ViewModels/MainViewModel.cs | 51 ++++-- SparklrWP/ViewModels/SearchViewModel.cs | 38 ++--- 17 files changed, 306 insertions(+), 61 deletions(-) create mode 100644 SparklrWP/Utils/SmartDispatcher.cs diff --git a/SparklrLib/Objects/Requests/Work/Chat.cs b/SparklrLib/Objects/Requests/Work/Chat.cs index a9d2379..f1d1044 100644 --- a/SparklrLib/Objects/Requests/Work/Chat.cs +++ b/SparklrLib/Objects/Requests/Work/Chat.cs @@ -3,7 +3,7 @@ namespace SparklrLib.Objects.Requests.Work { public class Chat { - public string to { get; set; } + public int to { get; set; } public string message { get; set; } } } diff --git a/SparklrLib/Objects/Responses/Beacon/Chat.cs b/SparklrLib/Objects/Responses/Beacon/Chat.cs index ef78f52..33e000d 100644 --- a/SparklrLib/Objects/Responses/Beacon/Chat.cs +++ b/SparklrLib/Objects/Responses/Beacon/Chat.cs @@ -1,5 +1,4 @@ -using System.Collections.Generic; - + namespace SparklrLib.Objects.Responses.Beacon { public class ChatMessage @@ -12,6 +11,6 @@ public class ChatMessage public class Chat : BeaconBase { - public List data { get; set; } + public ChatMessage[] data { get; set; } } } diff --git a/SparklrLib/PortableSparklrLib.csproj b/SparklrLib/PortableSparklrLib.csproj index aa266eb..37689ac 100644 --- a/SparklrLib/PortableSparklrLib.csproj +++ b/SparklrLib/PortableSparklrLib.csproj @@ -39,6 +39,7 @@ + diff --git a/SparklrLib/SparklrClient.cs b/SparklrLib/SparklrClient.cs index 5a1948c..e61a86c 100644 --- a/SparklrLib/SparklrClient.cs +++ b/SparklrLib/SparklrClient.cs @@ -1,6 +1,5 @@ using Newtonsoft.Json; using SparklrLib.Objects; -using SparklrLib.Objects.Responses; using System; using System.Collections.Generic; using System.IO; @@ -488,7 +487,7 @@ public async Task PostAsync(string message, Stream image) int count; while ((count = image.Read(array, 0, array.Length)) != 0) { - ms.Write(array, 0, count); + ms.Write(array, 0, count); } #else image.CopyTo(ms); @@ -666,6 +665,20 @@ public async Task PostAsync(string message, Stream image) return requestJsonObjectAsync("/work/chat/" + otherid.ToString()); } + public Task> GetBeaconChatAsync(int otherid, int since, int limit = 0) + { + return requestJsonObjectAsync("/beacon/chat/" + otherid.ToString() + "?since=" + since.ToString() + "&n=" + limit.ToString()); + } + + public Task> PostChatMessageAsync(int recipient, string message) + { + return requestJsonObjectAsync("/work/chat", new Objects.Requests.Work.Chat() + { + to = recipient, + message = message + }, "", "POST"); + } + private void raiseCredentialsExpired() { //Fire only once diff --git a/SparklrWP/App.xaml.cs b/SparklrWP/App.xaml.cs index 2c39a89..93bc0dd 100644 --- a/SparklrWP/App.xaml.cs +++ b/SparklrWP/App.xaml.cs @@ -68,6 +68,7 @@ public App() } + static internal bool SuppressNotifications = false; private int previousNotifications = 0; void SparklrClient_NotificationsReceived(object sender, SparklrLib.Objects.NotificationEventArgs e) { @@ -76,7 +77,8 @@ void SparklrClient_NotificationsReceived(object sender, SparklrLib.Objects.Notif { if (e.Notifications.Length != previousNotifications) { - Helpers.Notify(String.Format("You have {0} notifications.", e.Notifications.Length)); + if (!SuppressNotifications) + Helpers.Notify(String.Format("You have {0} notifications.", e.Notifications.Length)); previousNotifications = e.Notifications.Length; } diff --git a/SparklrWP/Pages/ChatPage.xaml b/SparklrWP/Pages/ChatPage.xaml index 7009dd9..07e195e 100644 --- a/SparklrWP/Pages/ChatPage.xaml +++ b/SparklrWP/Pages/ChatPage.xaml @@ -69,7 +69,7 @@ - + diff --git a/SparklrWP/Pages/ChatPage.xaml.cs b/SparklrWP/Pages/ChatPage.xaml.cs index 19b991b..88fa835 100644 --- a/SparklrWP/Pages/ChatPage.xaml.cs +++ b/SparklrWP/Pages/ChatPage.xaml.cs @@ -1,6 +1,8 @@ using Microsoft.Phone.Controls; +using SparklrWP.Utils; using System; using System.Windows; +using System.Windows.Input; namespace SparklrWP.Pages { @@ -58,5 +60,15 @@ void model_LoadingFinished(object sender, EventArgs e) if (loadingOverlay.Visibility == System.Windows.Visibility.Visible) loadingOverlay.FinishLoading(); } + + private void ChatBubbleTextBox_KeyDown(object sender, System.Windows.Input.KeyEventArgs e) + { + if (e.Key == Key.Enter) + { + chatBubbleTextBox.UpdateBinding(); + model.sendMessage(); + Focus(); + } + } } } \ No newline at end of file diff --git a/SparklrWP/Pages/Profile.xaml b/SparklrWP/Pages/Profile.xaml index 02d0dae..6f4bb68 100644 --- a/SparklrWP/Pages/Profile.xaml +++ b/SparklrWP/Pages/Profile.xaml @@ -140,7 +140,7 @@ - +