prepares a private chat

This commit is contained in:
2016-10-25 23:20:26 +02:00
parent d8c02db505
commit afb2747134
15 changed files with 189 additions and 19 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.9 KiB

View File

@ -12,12 +12,15 @@ using XLabs.Enums;
namespace BookAStar namespace BookAStar
{ {
using System.Threading.Tasks;
using Data; using Data;
using Interfaces; using Interfaces;
using Model; using Model;
using Model.UI; using Model.UI;
using Pages; using Pages;
using Plugin.Connectivity;
using ViewModels; using ViewModels;
using Microsoft.AspNet.SignalR.Client;
public partial class App : Application // superclass new in 1.3 public partial class App : Application // superclass new in 1.3
{ {
@ -70,7 +73,10 @@ namespace BookAStar
// Called Once, at app init // Called Once, at app init
private void OnInitialize(object sender, EventArgs e) private void OnInitialize(object sender, EventArgs e)
{ {
CrossConnectivity.Current.ConnectivityChanged += (conSender, args) =>
{
App.IsConnected = args.IsConnected;
};
} }
// called on app startup, not on rotation // called on app startup, not on rotation
@ -225,6 +231,44 @@ namespace BookAStar
} }
public static INavigationService NavigationService { protected set; get; } public static INavigationService NavigationService { protected set; get; }
public static bool isConnected;
public static bool IsConnected { get { return isConnected; }
private set
{
if (isConnected != value)
{
isConnected = value;
if (isConnected)
{
// TODO Start all cloud related stuff
}
}
}
}
// Start the Hub connection
private async void StartHubConnection ()
{
chatHubConnection = new HubConnection(Constants.SignalRHubsUrl);
if (MainSettings.CurrentUser != null)
chatHubConnection.Headers.Add("Bearer", MainSettings.CurrentUser.YavscTokens.AccessToken);
chatHubProxy = chatHubConnection.CreateHubProxy("ChatHub");
chatHubProxy.On<string, string>("AddMessage", (n, m) => {
Messages.Add(string.Format("{0} says: {1}", n, m));
});
await chatHubConnection.Start();
}
private HubConnection chatHubConnection=null;
private IHubProxy chatHubProxy = null;
public static Task<bool> HasSomeCloud {
get
{
return CrossConnectivity.Current.IsReachable(Constants.YavscHomeUrl, Constants.CloudTimeout);
}
}
public void PostDeviceInfo() public void PostDeviceInfo()
{ {
var res = PlatformSpecificInstance.InvokeApi( var res = PlatformSpecificInstance.InvokeApi(

View File

@ -49,7 +49,10 @@
<Compile Include="Behaviors\StarBehavior.cs" /> <Compile Include="Behaviors\StarBehavior.cs" />
<Compile Include="Constants.cs" /> <Compile Include="Constants.cs" />
<Compile Include="Data\LocalState.cs" /> <Compile Include="Data\LocalState.cs" />
<Compile Include="Model\Social\Messaging\ChatStatus.cs" />
<Compile Include="Model\Social\PrivateMessage.cs" />
<Compile Include="Model\UI\PageState.cs" /> <Compile Include="Model\UI\PageState.cs" />
<Compile Include="Settings\ChatSettings.cs" />
<Compile Include="ViewModels\EditingViewModel.cs" /> <Compile Include="ViewModels\EditingViewModel.cs" />
<Compile Include="Views\EnumPicker.cs" /> <Compile Include="Views\EnumPicker.cs" />
<Compile Include="Converters\BooleanToObjectConverter.cs" /> <Compile Include="Converters\BooleanToObjectConverter.cs" />
@ -97,7 +100,7 @@
<Compile Include="Pages\EventDetail.xaml.cs"> <Compile Include="Pages\EventDetail.xaml.cs">
<DependentUpon>EventDetail.xaml</DependentUpon> <DependentUpon>EventDetail.xaml</DependentUpon>
</Compile> </Compile>
<Compile Include="Helpers\MainSettings.cs" /> <Compile Include="Settings\MainSettings.cs" />
<Compile Include="Data\RemoteEntity.cs" /> <Compile Include="Data\RemoteEntity.cs" />
<Compile Include="Interfaces\IPlatform.cs" /> <Compile Include="Interfaces\IPlatform.cs" />
<Compile Include="Model\Blog\Blog.cs" /> <Compile Include="Model\Blog\Blog.cs" />
@ -218,6 +221,12 @@
<Reference Include="Newtonsoft.Json"> <Reference Include="Newtonsoft.Json">
<HintPath>..\..\packages\Newtonsoft.Json.9.0.1\lib\portable-net45+wp80+win8+wpa81\Newtonsoft.Json.dll</HintPath> <HintPath>..\..\packages\Newtonsoft.Json.9.0.1\lib\portable-net45+wp80+win8+wpa81\Newtonsoft.Json.dll</HintPath>
</Reference> </Reference>
<Reference Include="Plugin.Connectivity">
<HintPath>..\..\packages\Xam.Plugin.Connectivity.2.2.12\lib\MonoAndroid10\Plugin.Connectivity.dll</HintPath>
</Reference>
<Reference Include="Plugin.Connectivity.Abstractions">
<HintPath>..\..\packages\Xam.Plugin.Connectivity.2.2.12\lib\MonoAndroid10\Plugin.Connectivity.Abstractions.dll</HintPath>
</Reference>
<Reference Include="Plugin.Settings, Version=2.5.1.0, Culture=neutral, processorArchitecture=MSIL"> <Reference Include="Plugin.Settings, Version=2.5.1.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\..\packages\Xam.Plugins.Settings.2.5.1.0\lib\portable-net45+wp80+win8+wpa81\Plugin.Settings.dll</HintPath> <HintPath>..\..\packages\Xam.Plugins.Settings.2.5.1.0\lib\portable-net45+wp80+win8+wpa81\Plugin.Settings.dll</HintPath>
<Private>True</Private> <Private>True</Private>

View File

@ -19,11 +19,13 @@ namespace BookAStar
public static readonly string UserInfoUrl = YavscApiUrl + "/me"; public static readonly string UserInfoUrl = YavscApiUrl + "/me";
public static readonly string BlogUrl = YavscApiUrl + "/blogs"; public static readonly string BlogUrl = YavscApiUrl + "/blogs";
public static readonly string FsUrl = YavscApiUrl + "/fs"; public static readonly string FsUrl = YavscApiUrl + "/fs";
public static readonly string SignalRHubsUrl = YavscHomeUrl + "/signalr/hubs"; public static readonly string SignalRHubsUrl = YavscHomeUrl + "/api/signalr/hubs";
#endregion #endregion
#region Permissions ids #region Permissions ids
public static int AllowBeATarget = 1; public static int AllowBeATarget = 1;
#endregion #endregion
public static int CloudTimeout = 400;
} }
} }

View File

@ -5,6 +5,7 @@
using Model.Workflow; using Model.Workflow;
using Model.UI; using Model.UI;
using ViewModels; using ViewModels;
using Model.Social;
public class DataManager public class DataManager
{ {
@ -19,7 +20,7 @@
/// </summary> /// </summary>
internal LocalEntity<EditEstimateViewModel, long> EstimationCache { get; set; } internal LocalEntity<EditEstimateViewModel, long> EstimationCache { get; set; }
internal LocalEntity<BillingLine, string> EstimateLinesTemplates { get; set; } internal LocalEntity<BillingLine, string> EstimateLinesTemplates { get; set; }
internal LocalEntity<PrivateMessage, int> PrivateMessages { get; set; }
protected static DataManager current ; protected static DataManager current ;
public static DataManager Current public static DataManager Current
@ -34,18 +35,16 @@
public DataManager() public DataManager()
{ {
BookQueries = new RemoteEntityRO<BookQueryData, long>("bookquery", BookQueries = new RemoteEntityRO<BookQueryData, long>("bookquery", q => q.Id);
q => q.Id); Estimates = new RemoteEntity<Estimate, long>("estimate", x => x.Id);
Estimates = new RemoteEntity<Estimate, long>("estimate", Blogspot = new RemoteEntity<Blog, long>("blog", x=>x.Id);
x => x.Id);
Blogspot = new RemoteEntity<Blog, long>("blog",
x=>x.Id);
Contacts = new LocalEntity<ClientProviderInfo, string>(c => c.UserId); Contacts = new LocalEntity<ClientProviderInfo, string>(c => c.UserId);
AppState = new LocalEntity<PageState, int>(s => s.Position); AppState = new LocalEntity<PageState, int>(s => s.Position);
EstimationCache = new LocalEntity<EditEstimateViewModel, long>( EstimationCache = new LocalEntity<EditEstimateViewModel, long>(e => e.Query.Id);
e => e.Query.Id); EstimateLinesTemplates = new LocalEntity<BillingLine, string>(l => l.Description);
EstimateLinesTemplates = new LocalEntity<BillingLine, string>( PrivateMessages = new LocalEntity<PrivateMessage, int>(m=> m.GetHashCode());
l => l.Description);
PrivateMessages.Load();
BookQueries.Load(); BookQueries.Load();
Estimates.Load(); Estimates.Load();
Blogspot.Load(); Blogspot.Load();

View File

@ -14,7 +14,9 @@ namespace BookAStar.Data
public LocalEntity(Func<V, K> getKey) : base() public LocalEntity(Func<V, K> getKey) : base()
{ {
if (getKey == null) throw new InvalidOperationException(); if (getKey == null)
// choose please, because of the genesis
throw new InvalidOperationException ("A key must be defined");
GetKey = getKey; GetKey = getKey;
IList<V> l = this; IList<V> l = this;
} }

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.7 KiB

View File

@ -0,0 +1,10 @@
namespace BookAStar.Model.Workflow.Messaging
{
public enum ChatStatus
{
OnLine,
Away,
OffLine
}
}

View File

@ -0,0 +1,15 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace BookAStar.Model.Social
{
class PrivateMessage
{
public DateTime Date { get; set; }
public string SenderId { get; set; }
public string Message { get; set; }
}
}

View File

@ -1,9 +1,10 @@
<?xml version="1.0" encoding="utf-8" ?> <?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms" <TabbedPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="BookAStar.Pages.ChatPage" x:Class="BookAStar.Pages.ChatPage"
> >
<TabbedPage.Children>
<ContentPage Title="Public" Icon="chat.png" >
<StackLayout Padding="5, 5, 5, 5"> <StackLayout Padding="5, 5, 5, 5">
<StackLayout Spacing = "12" <StackLayout Spacing = "12"
Orientation = "Horizontal" Orientation = "Horizontal"
@ -19,4 +20,10 @@
</StackLayout> </StackLayout>
<ListView x:Name="messageList"></ListView> <ListView x:Name="messageList"></ListView>
</StackLayout> </StackLayout>
</ContentPage> </ContentPage>
<ContentPage Title="Notifications" Icon="exclam.png" >
</ContentPage>
<ContentPage Title="Privé" Icon="nicubunu-Peer-to-peer.png" >
</ContentPage>
</TabbedPage.Children>
</TabbedPage>

View File

@ -6,7 +6,7 @@ using Xamarin.Forms;
namespace BookAStar.Pages namespace BookAStar.Pages
{ {
public partial class ChatPage : ContentPage public partial class ChatPage : TabbedPage
{ {
public ObservableCollection<string> Messages { get; set; } public ObservableCollection<string> Messages { get; set; }
public string ChatUser { get; set; } public string ChatUser { get; set; }
@ -42,7 +42,9 @@ namespace BookAStar.Pages
{ {
IsBusy = true; IsBusy = true;
chatHubConnection = new HubConnection(Constants.SignalRHubsUrl); chatHubConnection = new HubConnection(Constants.SignalRHubsUrl);
chatHubProxy = chatHubConnection.CreateHubProxy("ChatHub"); chatHubProxy = chatHubConnection.CreateHubProxy("ChatHub");
chatHubProxy.On<string, string>("AddMessage", (n, m) => { chatHubProxy.On<string, string>("AddMessage", (n, m) => {
Messages.Add(string.Format("{0} says: {1}", n, m)); Messages.Add(string.Format("{0} says: {1}", n, m));
}); });

View File

@ -0,0 +1,80 @@
using BookAStar.Model.Workflow.Messaging;
using Plugin.Settings;
using Plugin.Settings.Abstractions;
using System.Collections.Generic;
namespace BookAStar.Settings
{
public static class ChatSettings
{
public static ISettings AppSettings
{
get
{
return CrossSettings.Current;
}
}
private const string statusKey = "chat.status";
private const string ignoreListKey = "chat.ignoreList";
private const string denyAnonymousAccessKey = "chat.denyAnonymousAccess";
private const string denyTouristAccessKey = "chat.denyTouristAccess";
public static ChatStatus Status
{
get
{
return AppSettings.GetValueOrDefault<ChatStatus>(statusKey, ChatStatus.OffLine);
}
set
{
AppSettings.AddOrUpdateValue<ChatStatus>(statusKey, value);
}
}
public static List<string> IgnoreList
{
get
{
return AppSettings.GetValueOrDefault<List<string>>(ignoreListKey);
}
}
public static void Ignore(string userId)
{
var ignoreList = IgnoreList;
ignoreList.Add(userId);
AppSettings.AddOrUpdateValue(ignoreListKey, ignoreList);
}
public static void UnIgnore(string userId)
{
var ignoreList = IgnoreList;
ignoreList.Remove(userId);
AppSettings.AddOrUpdateValue(ignoreListKey, ignoreList);
}
public static void UnIgnoreAll()
{
var ignoreList = new List<string>();
AppSettings.AddOrUpdateValue(ignoreListKey, ignoreList);
}
public static bool DenyAnonymousAccess
{
get
{
return AppSettings.GetValueOrDefault<bool>(denyAnonymousAccessKey);
}
set
{
AppSettings.AddOrUpdateValue<bool>(denyAnonymousAccessKey, value);
}
}
public static bool DenyTouristAccess
{
get
{
return AppSettings.GetValueOrDefault<bool>(denyTouristAccessKey);
}
set
{
AppSettings.AddOrUpdateValue<bool>(denyTouristAccessKey, value);
}
}
}
}