diff --git a/scripts/build/make/dnx.mk b/scripts/build/make/dnx.mk
index 2e049626..79beeb87 100644
--- a/scripts/build/make/dnx.mk
+++ b/scripts/build/make/dnx.mk
@@ -44,7 +44,7 @@ project.lock.json: project.json
$(dnu) restore
watch: project.lock.json
- MONO_MANAGED_WATCHER=enabled ASPNET_ENV=$(ASPNET_ENV) ASPNET_LOG_LEVEL=$(ASPNET_LOG_LEVEL) dnx-watch web --configuration=$(CONFIGURATION)
+ MONO_OPTIONS=--debug MONO_MANAGED_WATCHER=enabled ASPNET_ENV=$(ASPNET_ENV) ASPNET_LOG_LEVEL=$(ASPNET_LOG_LEVEL) dnx-watch web --configuration=$(CONFIGURATION)
clean:
rm -rf bin obj
diff --git a/src/Yavsc.Abstract/Chat/ChatRoomAccessLevel.cs b/src/Yavsc.Abstract/Chat/ChatRoomAccessLevel.cs
index 20ade855..6752bc4f 100644
--- a/src/Yavsc.Abstract/Chat/ChatRoomAccessLevel.cs
+++ b/src/Yavsc.Abstract/Chat/ChatRoomAccessLevel.cs
@@ -1,7 +1,9 @@
namespace Yavsc.Abstract.Chat
{
public enum ChatRoomAccessLevel: int {
- Op=1,
- HalfOp=2
+ None=0,
+ Voice,
+ Op,
+ HalfOp
}
}
\ No newline at end of file
diff --git a/src/Yavsc.Server/ChatUserFlags.cs b/src/Yavsc.Server/ChatUserFlags.cs
new file mode 100644
index 00000000..21b221b2
--- /dev/null
+++ b/src/Yavsc.Server/ChatUserFlags.cs
@@ -0,0 +1,12 @@
+namespace Yavsc
+{
+ ///
+ /// Chat User Flags
+ ///
+ public enum ChatUserFlags : byte
+ {
+ away = 1,
+ invisible = 2,
+ cop = 4
+ }
+}
diff --git a/src/Yavsc.Server/Constants.cs b/src/Yavsc.Server/Constants.cs
index fb499b84..b3f39e47 100644
--- a/src/Yavsc.Server/Constants.cs
+++ b/src/Yavsc.Server/Constants.cs
@@ -61,9 +61,8 @@ namespace Yavsc
public const string HubGroupAnonymous = "anonymous";
public const string HubGroupCops= "cops";
public const int MaxChanelName = 255;
- }
- public static class NotificationTypes {
- public const string Connected = "connected";
- public const string DisConnected = "disconnected";
+
+ public const string AnonymousUserNamePrefix = "?";
+ public const string KeyParamChatUserName = "username";
}
}
diff --git a/src/Yavsc.Server/ErrorMessages.cs b/src/Yavsc.Server/ErrorMessages.cs
new file mode 100644
index 00000000..f49c3069
--- /dev/null
+++ b/src/Yavsc.Server/ErrorMessages.cs
@@ -0,0 +1,6 @@
+namespace Yavsc
+{
+ public static class ErrorMessages {
+ public const string ContactRefused = "contact refused";
+ }
+}
diff --git a/src/Yavsc.Server/Models/Access/BlackList.cs b/src/Yavsc.Server/Models/Access/BlackList.cs
index 64e9cbe4..62c3ed94 100644
--- a/src/Yavsc.Server/Models/Access/BlackList.cs
+++ b/src/Yavsc.Server/Models/Access/BlackList.cs
@@ -15,8 +15,11 @@ namespace Yavsc.Models.Access
[Required]
public string OwnerId { get; set; }
- [ForeignKey("OwnerId"),JsonIgnore]
+ [ForeignKey("OwnerId"), JsonIgnore]
public virtual ApplicationUser Owner { get; set; }
+
+ [ForeignKey("UserId"), JsonIgnore]
+ public virtual ApplicationUser User { get; set; }
}
}
diff --git a/src/Yavsc.Server/Models/Chat/ChatRoom.cs b/src/Yavsc.Server/Models/Chat/ChatRoom.cs
index eb397ecb..909d58fb 100644
--- a/src/Yavsc.Server/Models/Chat/ChatRoom.cs
+++ b/src/Yavsc.Server/Models/Chat/ChatRoom.cs
@@ -1,12 +1,14 @@
+using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
+using Newtonsoft.Json;
using Yavsc.Abstract.Chat;
namespace Yavsc.Models.Chat
{
- public class ChatRoom: IChatRoom
+ public class ChatRoom: IChatRoom, IBaseTrackedEntity
{
public string Topic { get; set; }
@@ -16,11 +18,17 @@ namespace Yavsc.Models.Chat
public string OwnerId { get; set; }
- [ForeignKey("OwnerId")]
+ [ForeignKey("OwnerId")][JsonIgnore]
public virtual ApplicationUser Owner { get; set; }
- [InverseProperty("Room")]
+ [InverseProperty("Room")][JsonIgnore]
public virtual List Moderation { get; set; }
+ public DateTime LatestJoinPart { get; set;}
+ public DateTime DateCreated { get; set; }
+
+ public string UserCreated { get; set; }
+ public DateTime DateModified { get; set;}
+ public string UserModified { get; set; }
}
}
\ No newline at end of file
diff --git a/src/Yavsc.Server/Models/Chat/ChatRoomAccess.cs b/src/Yavsc.Server/Models/Chat/ChatRoomAccess.cs
index 797ccdc7..18d3f301 100644
--- a/src/Yavsc.Server/Models/Chat/ChatRoomAccess.cs
+++ b/src/Yavsc.Server/Models/Chat/ChatRoomAccess.cs
@@ -25,8 +25,6 @@ namespace Yavsc.Models.Chat
get; set;
}
-
-
[ForeignKey("UserId")]
public virtual ApplicationUser User { get; set; }
}
diff --git a/src/Yavsc.Server/NotificationTypes.cs b/src/Yavsc.Server/NotificationTypes.cs
new file mode 100644
index 00000000..d3e8d02c
--- /dev/null
+++ b/src/Yavsc.Server/NotificationTypes.cs
@@ -0,0 +1,13 @@
+namespace Yavsc
+{
+ public static class NotificationTypes {
+ public const string Connected = "connected";
+ public const string DisConnected = "disconnected";
+ public const string Reconnected = "reconnected";
+ public const string UserPart = "userpart";
+ public const string UserJoin = "userjoin";
+ public const string PrivateMessageDenied = "deniedpv";
+
+ public const string Error = "error";
+ }
+}
diff --git a/src/Yavsc.Server/ServerCommands.cs b/src/Yavsc.Server/ServerCommands.cs
new file mode 100644
index 00000000..e6feff91
--- /dev/null
+++ b/src/Yavsc.Server/ServerCommands.cs
@@ -0,0 +1,33 @@
+namespace Yavsc
+{
+ public static class ServerCommands {
+
+ public const string whois = nameof(whois);
+ public const string whowas = nameof(whowas);
+
+ ///
+ /// modify a chan or an user
+ ///
+ ///
+ public const string mode = nameof(mode);
+
+ ///
+ /// register a channel
+ ///
+ ///
+ public const string register = nameof(register);
+
+ ///
+ /// kick some user
+ ///
+ ///
+ public const string kick = nameof(kick);
+
+ ///
+ /// ban an user
+ ///
+ ///
+ public const string ban = nameof(ban);
+
+ }
+}
diff --git a/src/Yavsc/Controllers/Contracting/CommandController.cs b/src/Yavsc/Controllers/Contracting/CommandController.cs
index b738dba4..6248c2bc 100644
--- a/src/Yavsc/Controllers/Contracting/CommandController.cs
+++ b/src/Yavsc/Controllers/Contracting/CommandController.cs
@@ -24,7 +24,7 @@ namespace Yavsc.Controllers
protected UserManager _userManager;
protected ApplicationDbContext _context;
protected GoogleAuthSettings _googleSettings;
- protected IYavscMessageSender _GCMSender;
+ protected IYavscMessageSender _MessageSender;
protected IEmailSender _emailSender;
protected IStringLocalizer _localizer;
protected SiteSettings _siteSettings;
@@ -44,7 +44,7 @@ namespace Yavsc.Controllers
ILoggerFactory loggerFactory)
{
_context = context;
- _GCMSender = GCMSender;
+ _MessageSender = GCMSender;
_emailSender = emailSender;
_googleSettings = googleSettings.Value;
_userManager = userManager;
@@ -165,47 +165,39 @@ namespace Yavsc.Controllers
var yaev = command.CreateEvent(_localizer, "NewCommand");
- MessageWithPayloadResponse grep = null;
+ MessageWithPayloadResponse nrep = null;
if (pro.AcceptNotifications
&& pro.AcceptPublicContact)
{
-
try
{
- _logger.LogInformation("sending GCM");
- if (pro.Performer.DeviceDeclarations.Count > 0)
- {
- var regids = command.PerformerProfile.Performer
- .DeviceDeclarations.Select(d => d.DeviceId);
- grep = await _GCMSender.NotifyBookQueryAsync(regids, yaev);
- }
-
-
+ _logger.LogInformation("sending message");
+ var regids = new [] { command.PerformerProfile.Performer.Id };
+ nrep = await _MessageSender.NotifyBookQueryAsync(regids, yaev);
// TODO setup a profile choice to allow notifications
// both on mailbox and mobile
// if (grep==null || grep.success<=0 || grep.failure>0)
- ViewBag.GooglePayload = grep;
+ ViewBag.MessagingResponsePayload = nrep;
}
catch (Exception ex)
{
- _logger.LogError(ex.Message);
+ _logger.LogError("Message sending failed with: "+ex.Message);
+ throw;
}
- try
- {
- ViewBag.EmailSent = await _emailSender.SendEmailAsync(
- command.PerformerProfile.Performer.UserName,
- command.PerformerProfile.Performer.Email,
- $"{command.Client.UserName} (un client) vous demande un rendez-vous",
- $"{yaev.CreateBody()}\r\n-- \r\n{yaev.Previsional}\r\n{yaev.EventDate}\r\n"
- );
- }
- catch (Exception ex)
- {
- _logger.LogError(ex.Message);
- }
}
+ else {
+ nrep = new MessageWithPayloadResponse { failure=1, results = new MessageWithPayloadResponse.Result[] {
+ new MessageWithPayloadResponse.Result
+ {
+ error=ErrorMessages.ContactRefused,
+ registration_id= pro.PerformerId
+ }
+ } };
+ _logger.LogInformation("Command.Create && ( !pro.AcceptNotifications || |pro.AcceptPublicContact ) ");
+ }
+ ViewBag.MessagingResponsePayload = nrep;
ViewBag.Activity = _context.Activities.FirstOrDefault(a => a.Code == command.ActivityCode);
ViewBag.GoogleSettings = _googleSettings;
return View("CommandConfirmation", command);
diff --git a/src/Yavsc/Controllers/Haircut/HairCutCommandController.cs b/src/Yavsc/Controllers/Haircut/HairCutCommandController.cs
index 7fcf0ccd..7608f3da 100644
--- a/src/Yavsc/Controllers/Haircut/HairCutCommandController.cs
+++ b/src/Yavsc/Controllers/Haircut/HairCutCommandController.cs
@@ -104,7 +104,7 @@ namespace Yavsc.Controllers
{
var regids = command.PerformerProfile.Performer
.DeviceDeclarations.Select(d => d.DeviceId);
- grep = await _GCMSender.NotifyAsync(regids, yaev);
+ grep = await _MessageSender.NotifyAsync(regids, yaev);
}
// TODO setup a profile choice to allow notifications
// both on mailbox and mobile
@@ -271,7 +271,7 @@ namespace Yavsc.Controllers
if (pro.Performer.DeviceDeclarations.Count > 0)
{
var regids = pro.Performer.DeviceDeclarations.Select(d => d.DeviceId);
- grep = await _GCMSender.NotifyHairCutQueryAsync(regids, yaev);
+ grep = await _MessageSender.NotifyHairCutQueryAsync(regids, yaev);
}
// TODO setup a profile choice to allow notifications
// both on mailbox and mobile
@@ -431,7 +431,7 @@ namespace Yavsc.Controllers
{
var regids = command.PerformerProfile.Performer
.DeviceDeclarations.Select(d => d.DeviceId);
- grep = await _GCMSender.NotifyHairCutQueryAsync(regids, yaev);
+ grep = await _MessageSender.NotifyHairCutQueryAsync(regids, yaev);
}
// TODO setup a profile choice to allow notifications
// both on mailbox and mobile, and to allow calendar event insertion.
diff --git a/src/Yavsc/Hubs/ChatHub.cs b/src/Yavsc/Hubs/ChatHub.cs
index d4d65c5f..81834394 100644
--- a/src/Yavsc/Hubs/ChatHub.cs
+++ b/src/Yavsc/Hubs/ChatHub.cs
@@ -19,6 +19,7 @@
// You should have received a copy of the GNU Lesser General Public License
// along with this program. If not, see .
using Microsoft.AspNet.SignalR;
+using Microsoft.AspNet.SignalR.Hosting;
using System.Threading.Tasks;
using System.Collections.Generic;
using System.Linq;
@@ -26,7 +27,8 @@ using System.Linq;
namespace Yavsc
{
using System;
- using Microsoft.AspNet.Authorization;
+ using System.Collections.Concurrent;
+ using Microsoft.AspNet.WebUtilities;
using Microsoft.Data.Entity;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
@@ -37,12 +39,12 @@ namespace Yavsc
{
ApplicationDbContext _dbContext;
ILogger _logger;
- IUserIdProvider _userIdProvider;
- public ChatHub(IUserIdProvider userIdProvider)
+ public ChatHub()
{
- _userIdProvider = userIdProvider;
+
var scope = Startup.Services.GetRequiredService().CreateScope();
+
_dbContext = scope.ServiceProvider.GetService();
var loggerFactory = scope.ServiceProvider.GetService();
_logger = loggerFactory.CreateLogger();
@@ -51,18 +53,21 @@ namespace Yavsc
public override async Task OnConnected()
{
bool isAuth = false;
- string userName = null;
+ string userName = setUserName();
if (Context.User != null)
{
isAuth = Context.User.Identity.IsAuthenticated;
- userName = Context.User.Identity.Name;
-
+
var group = isAuth ?
Constants.HubGroupAuthenticated : Constants.HubGroupAnonymous;
// Log ("Cx: " + group);
await Groups.Add(Context.ConnectionId, group);
if (isAuth)
{
+ _logger.LogInformation("Authenticated chat user");
+
+ var userId = _dbContext.Users.First(u=>u.UserName == userName).Id;
+
var userHadConnections = _dbContext.ChatConnection.Any(accx => accx.ConnectionId == Context.ConnectionId);
if (userHadConnections) {
@@ -72,134 +77,276 @@ namespace Yavsc
else
_dbContext.ChatConnection.Add(new ChatConnection
{
+ ApplicationUserId = userId,
ConnectionId = Context.ConnectionId,
UserAgent = Context.Request.Headers["User-Agent"],
Connected = true
});
_dbContext.SaveChanges();
- var userId = _userIdProvider.GetUserId(this.Context.Request);
- Clients.CallerState.BlackListedBy = await _dbContext.BlackListed.Where(r=>r.UserId == userId).Select(r=>r.OwnerId).ToArrayAsync();
- // TODO ChatHubConnectioinFlags
+ // TODO ChatHubConnectioinFlags
}
else
+ {
// FIXME is this line reached ?
- await Groups.Add(Context.ConnectionId, Constants.HubGroupAnonymous);
+ _logger.LogInformation("Anonymous chat user (first use case)");
+ throw new NotSupportedException();
+ }
+ }
+ else {
+ // TODO var uname = Context.Request.QueryString[Constants.KeyParamChatUserName] ?? "anon";
+
+ await Groups.Add(Context.ConnectionId, Constants.HubGroupAnonymous);
}
- else await Groups.Add(Context.ConnectionId, Constants.HubGroupAnonymous);
-
// TODO only notify followers
Clients.Group(Constants.HubGroupAuthenticated).notify(NotificationTypes.Connected, Context.ConnectionId, userName);
-
await base.OnConnected();
}
+ static ConcurrentDictionary ChatUserNames
+ = new ConcurrentDictionary();
+ string setUserName()
+ {
+ if (Context.User!=null)
+ if (Context.User.Identity.IsAuthenticated)
+ {
+ ChatUserNames[Context.ConnectionId]=Context.User.Identity.Name;
+ _logger.LogInformation($"chat user name set to : {Context.User.Identity.Name}");
+ return Context.User.Identity.Name;
+ }
+ anonymousSequence++;
+ var aname = $"{Constants.AnonymousUserNamePrefix}{anonymousSequence}";
+ ChatUserNames[Context.ConnectionId]=aname;
+ _logger.LogInformation($"Anonymous chat user name set to : {aname}");
+ return aname;
+ }
+
+ static long anonymousSequence=0;
public override Task OnDisconnected(bool stopCalled)
{
-
string userName = Context.User?.Identity.Name;
- Clients.Group("authenticated").notify("disconnected", Context.ConnectionId, userName);
+ Clients.Group("authenticated").notify(NotificationTypes.DisConnected, Context.ConnectionId, userName);
if (userName != null)
{
- using (var db = new ApplicationDbContext()) {
- var cx = db.ChatConnection.SingleOrDefault(c => c.ConnectionId == Context.ConnectionId);
- if (cx != null)
+ var cx = _dbContext.ChatConnection.SingleOrDefault(c => c.ConnectionId == Context.ConnectionId);
+ if (cx != null)
+ {
+ if (stopCalled)
{
- if (stopCalled)
- {
- var user = db.Users.Single(u => u.UserName == userName);
- user.Connections.Remove(cx);
- }
- else
- {
- cx.Connected = false;
- }
- db.SaveChanges();
+ var user = _dbContext.Users.Single(u => u.UserName == userName);
+ user.Connections.Remove(cx);
}
+ else
+ {
+ cx.Connected = false;
+ }
+ _dbContext.SaveChanges();
}
}
-
return base.OnDisconnected(stopCalled);
}
public override Task OnReconnected()
{
- string userName = Context.User?.Identity.Name;
- if (userName != null)
+ if (Context.User != null) if (Context.User.Identity.IsAuthenticated)
{
+ var userName = Context.User.Identity.Name;
+ var user = _dbContext.Users.FirstOrDefault(u=>u.UserName == userName);
+ if (user == null)
+ _logger.LogWarning($"null user with <{userName}> & Context.User.Identity.IsAuthenticated");
+ var userId = user.Id;
+ var userHadConnections = _dbContext.ChatConnection.Any(accx => accx.ConnectionId == Context.ConnectionId);
- var user = _dbContext.Users.Single(u => u.UserName == userName);
-
- if (user.Connections==null) user.Connections = new List();
-
-
- var cx = user.Connections.SingleOrDefault(c => c.ConnectionId == Context.ConnectionId);
- if (cx != null)
+ if (userHadConnections) {
+ var ccx = _dbContext.ChatConnection.First(c=> c.ConnectionId == Context.ConnectionId);
+ ccx.Connected=true;
+ }
+ else
+ _dbContext.ChatConnection.Add(new ChatConnection
{
- cx.Connected = true;
- _dbContext.SaveChanges();
- }
- else cx = new ChatConnection { ConnectionId = Context.ConnectionId,
+ ApplicationUserId = userId,
+ ConnectionId = Context.ConnectionId,
UserAgent = Context.Request.Headers["User-Agent"],
- Connected = true };
+ Connected = true
+ });
+ _dbContext.SaveChanges();
+ Clients.Group("authenticated").notify(NotificationTypes.Reconnected, Context.ConnectionId, userName);
}
-
return base.OnReconnected();
}
- public void Send(string name, string message)
+ static ConcurrentDictionary Channels = new ConcurrentDictionary();
+
+ public class ChatRoomInfo {
+ public string Name ;
+ public Dictionary Users = new Dictionary();
+ public string Topic;
+ }
+
+ public void Join(string roomName)
{
- string uname = (Context.User != null) ?
- $"[{Context.User.Identity.Name}]" :
- $"?{name}";
- Clients.All.addMessage(uname, message);
+ _logger.LogInformation("a client for "+roomName);
+ var userName = ChatUserNames[Context.ConnectionId];
+ _logger.LogInformation($" chat user : {userName}");
+ var roomGroupName = "room_"+roomName;
+
+ ChatRoomInfo chanInfo;
+ if (Channels.ContainsKey(roomName))
+ {
+ if (Channels.TryGetValue(roomName, out chanInfo)) {
+ _logger.LogInformation("room is avaible.");
+ if (chanInfo.Users.ContainsKey(Context.ConnectionId))
+ _logger.LogWarning("user already joined.");
+ else {
+ chanInfo.Users.Add(Context.ConnectionId, userName);
+
+ Groups.Add(Context.ConnectionId,roomGroupName);
+ }
+ Clients.Caller.onJoined(chanInfo);
+ Clients.Group("room_"+roomName).notify( NotificationTypes.UserJoin, Context.ConnectionId, Clients.Caller.UserName);
+
+ _logger.LogInformation("exiting ok.");
+ return;
+ }
+ else {
+ _logger.LogInformation("room seemd to be avaible ... but we could get no info on it.");
+ Clients.Caller.notify(NotificationTypes.Error, "join get chan failed ...");
+ return;
+ }
+ }
+ // chan was almost empty
+ _logger.LogInformation("joining empty chan.");
+
+ var room = _dbContext.ChatRoom.FirstOrDefault(r => r.Name == roomName);
+
+ chanInfo = new ChatRoomInfo();
+ chanInfo.Users.Add(Context.ConnectionId, userName);
+
+ if (room!=null)
+ {
+ _logger.LogInformation("existent room.");
+ chanInfo.Topic = room.Topic;
+ chanInfo.Name = room.Name;
+ }
+ else { // a first join, we create it.
+ _logger.LogInformation("room creation.");
+ chanInfo.Name = roomName;
+ chanInfo.Topic = "";
+ }
+
+ if (Channels.TryAdd(roomName, chanInfo))
+ {
+ Groups.Add(Context.ConnectionId, roomGroupName);
+ Clients.Caller.onJoined(chanInfo);
+ }
+ else _logger.LogError("Chan create failed unexpectly...");
+ }
+
+ [Authorize]
+ public void Register (string room )
+ {
+ var existent = _dbContext.ChatRoom.Any(r => r.Name == room);
+ if (existent) {
+ Clients.Caller.notify(NotificationTypes.Error, "already registered.");
+ return;
+ }
+ string userName = Context.User.Identity.Name;
+ var user = _dbContext.Users.FirstOrDefault(u=>u.UserName == userName);
+ var newroom = new ChatRoom { Name = room, OwnerId = user.Id };
+ ChatRoomInfo chanInfo;
+ if (Channels.TryGetValue(room, out chanInfo))
+ {
+ // TODO get and require some admin status for current user on this chan
+ newroom.Topic = chanInfo.Topic;
+ }
+ newroom.LatestJoinPart = DateTime.Now;
+
+ _dbContext.ChatRoom.Add(newroom);
+ _dbContext.SaveChanges(user.Id);
+ }
+
+ /** TODO chan register on server command
+ room = new ChatRoom { Name = roomName, OwnerId = uid };
+ _dbContext.ChatRoom.Add(room);
+ _dbContext.SaveChanges(uid);
+ room.LatestJoinPart = DateTime.Now;
+ chanInfo.Topic = room.Topic;
+ */
+
+
+ public void Part (string roomName, string reason)
+ {
+ ChatRoomInfo chanInfo;
+ if (Channels.TryGetValue(roomName, out chanInfo))
+ {
+ var roomGroupName = "room_"+roomName;
+ Groups.Remove(Context.ConnectionId, roomGroupName);
+ var group = Clients.Group(roomGroupName);
+ var username = ChatUserNames[Context.ConnectionId];
+ group.notify( NotificationTypes.UserPart, Context.ConnectionId, new { username, reason } );
+
+ chanInfo.Users.Remove(Context.ConnectionId);
+ ChatRoomInfo deadchanInfo;
+ if (chanInfo.Users.Count==0)
+ if (Channels.TryRemove(roomName, out deadchanInfo))
+ {
+ var room = _dbContext.ChatRoom.FirstOrDefault(r => r.Name == roomName);
+ room.LatestJoinPart = DateTime.Now;
+ _dbContext.SaveChanges();
+ }
+ }
+ else {
+ Clients.Caller.notify(NotificationTypes.Error, "not joint");
+ }
}
+ public void Send(string roomName, string message)
+ {
+ var groupname = "room_"+roomName;
+ ChatRoomInfo chanInfo;
+ if (Channels.TryGetValue(roomName, out chanInfo))
+ {
+ if (!chanInfo.Users.ContainsKey(Context.ConnectionId)){
+ Clients.Caller.notify(NotificationTypes.Error, $"could not join channel ({roomName})");
+ return;
+ }
+ string uname = ChatUserNames[Context.ConnectionId];
+ Clients.Group(groupname).addMessage(uname, roomName, message);
+ }
+ else
+ {
+ Clients.Caller.notify(NotificationTypes.Error, $"could not join channel ({roomName})");
+ return;
+ }
+
+ }
[Authorize]
public void SendPV(string connectionId, string message)
{
- if (Clients.CallerState.BlackListedBy!=null)
- foreach (string destId in Clients.CallerState.BlackListedBy)
+ if (!Context.User.IsInRole(Constants.AdminGroupName))
+ {
+ var bl = _dbContext.BlackListed
+ .Include(r => r.User)
+ .Where(r=>r.User.UserName == Context.User.Identity.Name)
+ .Select(r=>r.OwnerId);
+
+ if (bl!=null) foreach (string uid in bl)
{
- if (_dbContext.ChatConnection.Any(c => c.ConnectionId == connectionId && c.ApplicationUserId == destId ))
- {
- _logger.LogInformation($"PV aborted by black list");
- Clients.Caller.send("denied");
+ if (_dbContext.ChatConnection.Any(cx => cx.ApplicationUserId==uid && cx.Connected))
+ Clients.Caller.notify(NotificationTypes.PrivateMessageDenied, connectionId);
return ;
- }
}
+ }
var cli = Clients.Client(connectionId);
cli.addPV(Context.User.Identity.Name, message);
}
- private async Task AllowPv(string destConnectionId)
- {
- if (Context.User.IsInRole(Constants.BlogModeratorGroupName))
-
- if (Context.User.IsInRole(Constants.BlogModeratorGroupName)
- || Context.User.IsInRole(Constants.AdminGroupName))
- return true;
- if (!Context.User.Identity.IsAuthenticated)
- return false;
- string senderId = (await _dbContext.ChatConnection.SingleAsync (c=>c.ConnectionId == Context.ConnectionId)).ApplicationUserId;
-
-
- if (_dbContext.Ban.Any(b=>b.TargetId == senderId)) return false;
- var destChatUser = await _dbContext.ChatConnection.SingleAsync (c=>c.ConnectionId == destConnectionId);
-
- if (_dbContext.BlackListed.Any(b=>b.OwnerId == destChatUser.ApplicationUserId && b.UserId == senderId)) return false;
- var destUser = await _dbContext.Performers.FirstOrDefaultAsync( u=> u.PerformerId == destChatUser.ApplicationUserId);
- return destUser?.AcceptPublicContact ?? true;
- }
+ [Authorize]
public void SendStream(string connectionId, long streamId, string message)
{
var sender = Context.User.Identity.Name;
- // TODO personal black|white list +
- // Contact list allowed only +
- // only pro
- var hubCxContext = Clients.User(connectionId);
var cli = Clients.Client(connectionId);
cli.addStreamInfo(sender, streamId, message);
}
diff --git a/src/Yavsc/Migrations/20190510021107_chanDates.Designer.cs b/src/Yavsc/Migrations/20190510021107_chanDates.Designer.cs
new file mode 100644
index 00000000..d5e3fbe2
--- /dev/null
+++ b/src/Yavsc/Migrations/20190510021107_chanDates.Designer.cs
@@ -0,0 +1,2045 @@
+using System;
+using Microsoft.Data.Entity;
+using Microsoft.Data.Entity.Infrastructure;
+using Microsoft.Data.Entity.Metadata;
+using Microsoft.Data.Entity.Migrations;
+using Yavsc.Models;
+
+namespace Yavsc.Migrations
+{
+ [DbContext(typeof(ApplicationDbContext))]
+ [Migration("20190510021107_chanDates")]
+ partial class chanDates
+ {
+ protected override void BuildTargetModel(ModelBuilder modelBuilder)
+ {
+ modelBuilder
+ .HasAnnotation("ProductVersion", "7.0.0-rc1-16348");
+
+ modelBuilder.Entity("Microsoft.AspNet.Identity.EntityFramework.IdentityRole", b =>
+ {
+ b.Property("Id");
+
+ b.Property("ConcurrencyStamp")
+ .IsConcurrencyToken();
+
+ b.Property("Name")
+ .HasAnnotation("MaxLength", 256);
+
+ b.Property("NormalizedName")
+ .HasAnnotation("MaxLength", 256);
+
+ b.HasKey("Id");
+
+ b.HasIndex("NormalizedName")
+ .HasAnnotation("Relational:Name", "RoleNameIndex");
+
+ b.HasAnnotation("Relational:TableName", "AspNetRoles");
+ });
+
+ modelBuilder.Entity("Microsoft.AspNet.Identity.EntityFramework.IdentityRoleClaim", b =>
+ {
+ b.Property("Id")
+ .ValueGeneratedOnAdd();
+
+ b.Property("ClaimType");
+
+ b.Property("ClaimValue");
+
+ b.Property("RoleId")
+ .IsRequired();
+
+ b.HasKey("Id");
+
+ b.HasAnnotation("Relational:TableName", "AspNetRoleClaims");
+ });
+
+ modelBuilder.Entity("Microsoft.AspNet.Identity.EntityFramework.IdentityUserClaim", b =>
+ {
+ b.Property("Id")
+ .ValueGeneratedOnAdd();
+
+ b.Property("ClaimType");
+
+ b.Property("ClaimValue");
+
+ b.Property("UserId")
+ .IsRequired();
+
+ b.HasKey("Id");
+
+ b.HasAnnotation("Relational:TableName", "AspNetUserClaims");
+ });
+
+ modelBuilder.Entity("Microsoft.AspNet.Identity.EntityFramework.IdentityUserLogin", b =>
+ {
+ b.Property("LoginProvider");
+
+ b.Property("ProviderKey");
+
+ b.Property("ProviderDisplayName");
+
+ b.Property("UserId")
+ .IsRequired();
+
+ b.HasKey("LoginProvider", "ProviderKey");
+
+ b.HasAnnotation("Relational:TableName", "AspNetUserLogins");
+ });
+
+ modelBuilder.Entity("Microsoft.AspNet.Identity.EntityFramework.IdentityUserRole", b =>
+ {
+ b.Property("UserId");
+
+ b.Property("RoleId");
+
+ b.HasKey("UserId", "RoleId");
+
+ b.HasAnnotation("Relational:TableName", "AspNetUserRoles");
+ });
+
+ modelBuilder.Entity("Yavsc.Abstract.Identity.ClientProviderInfo", b =>
+ {
+ b.Property("UserId");
+
+ b.Property("Avatar");
+
+ b.Property("BillingAddressId");
+
+ b.Property("EMail");
+
+ b.Property("Phone");
+
+ b.Property("UserName");
+
+ b.HasKey("UserId");
+ });
+
+ modelBuilder.Entity("Yavsc.Models.Access.Ban", b =>
+ {
+ b.Property("Id")
+ .ValueGeneratedOnAdd();
+
+ b.Property("DateCreated");
+
+ b.Property("DateModified");
+
+ b.Property("Reason")
+ .IsRequired();
+
+ b.Property("TargetId")
+ .IsRequired();
+
+ b.Property("UserCreated");
+
+ b.Property("UserModified");
+
+ b.HasKey("Id");
+ });
+
+ modelBuilder.Entity("Yavsc.Models.Access.BlackListed", b =>
+ {
+ b.Property("Id")
+ .ValueGeneratedOnAdd();
+
+ b.Property("OwnerId")
+ .IsRequired();
+
+ b.Property("UserId")
+ .IsRequired();
+
+ b.HasKey("Id");
+ });
+
+ modelBuilder.Entity("Yavsc.Models.Access.CircleAuthorizationToBlogPost", b =>
+ {
+ b.Property("CircleId");
+
+ b.Property("BlogPostId");
+
+ b.HasKey("CircleId", "BlogPostId");
+ });
+
+ modelBuilder.Entity("Yavsc.Models.AccountBalance", b =>
+ {
+ b.Property("UserId");
+
+ b.Property("ContactCredits");
+
+ b.Property("Credits");
+
+ b.HasKey("UserId");
+ });
+
+ modelBuilder.Entity("Yavsc.Models.ApplicationUser", b =>
+ {
+ b.Property("Id");
+
+ b.Property("AccessFailedCount");
+
+ b.Property("AllowMonthlyEmail");
+
+ b.Property("Avatar")
+ .HasAnnotation("MaxLength", 512)
+ .HasAnnotation("Relational:DefaultValue", "/images/Users/icon_user.png")
+ .HasAnnotation("Relational:DefaultValueType", "System.String");
+
+ b.Property("BankInfoId");
+
+ b.Property("ConcurrencyStamp")
+ .IsConcurrencyToken();
+
+ b.Property("DedicatedGoogleCalendar")
+ .HasAnnotation("MaxLength", 512);
+
+ b.Property("DiskQuota")
+ .HasAnnotation("Relational:DefaultValue", "524288000")
+ .HasAnnotation("Relational:DefaultValueType", "System.Int64");
+
+ b.Property("DiskUsage");
+
+ b.Property("Email")
+ .HasAnnotation("MaxLength", 256);
+
+ b.Property("EmailConfirmed");
+
+ b.Property("FullName")
+ .HasAnnotation("MaxLength", 512);
+
+ b.Property("LockoutEnabled");
+
+ b.Property("LockoutEnd");
+
+ b.Property("MaxFileSize");
+
+ b.Property("NormalizedEmail")
+ .HasAnnotation("MaxLength", 256);
+
+ b.Property("NormalizedUserName")
+ .HasAnnotation("MaxLength", 256);
+
+ b.Property("PasswordHash");
+
+ b.Property("PhoneNumber");
+
+ b.Property("PhoneNumberConfirmed");
+
+ b.Property("PostalAddressId");
+
+ b.Property("SecurityStamp");
+
+ b.Property("TwoFactorEnabled");
+
+ b.Property("UserName")
+ .HasAnnotation("MaxLength", 256);
+
+ b.HasKey("Id");
+
+ b.HasIndex("NormalizedEmail")
+ .HasAnnotation("Relational:Name", "EmailIndex");
+
+ b.HasIndex("NormalizedUserName")
+ .HasAnnotation("Relational:Name", "UserNameIndex");
+
+ b.HasAnnotation("Relational:TableName", "AspNetUsers");
+ });
+
+ modelBuilder.Entity("Yavsc.Models.Auth.Client", b =>
+ {
+ b.Property("Id");
+
+ b.Property("Active");
+
+ b.Property("DisplayName");
+
+ b.Property("LogoutRedirectUri")
+ .HasAnnotation("MaxLength", 100);
+
+ b.Property("RedirectUri");
+
+ b.Property("RefreshTokenLifeTime");
+
+ b.Property("Secret");
+
+ b.Property("Type");
+
+ b.HasKey("Id");
+ });
+
+ modelBuilder.Entity("Yavsc.Models.Auth.OAuth2Tokens", b =>
+ {
+ b.Property("UserId");
+
+ b.Property("AccessToken");
+
+ b.Property("Expiration");
+
+ b.Property("ExpiresIn");
+
+ b.Property("RefreshToken");
+
+ b.Property("TokenType");
+
+ b.HasKey("UserId");
+ });
+
+ modelBuilder.Entity("Yavsc.Models.Auth.RefreshToken", b =>
+ {
+ b.Property("Id");
+
+ b.Property("ClientId")
+ .IsRequired()
+ .HasAnnotation("MaxLength", 50);
+
+ b.Property("ExpiresUtc");
+
+ b.Property("IssuedUtc");
+
+ b.Property("ProtectedTicket")
+ .IsRequired();
+
+ b.Property("Subject")
+ .IsRequired()
+ .HasAnnotation("MaxLength", 50);
+
+ b.HasKey("Id");
+ });
+
+ modelBuilder.Entity("Yavsc.Models.BalanceImpact", b =>
+ {
+ b.Property("Id")
+ .ValueGeneratedOnAdd();
+
+ b.Property("BalanceId")
+ .IsRequired();
+
+ b.Property("ExecDate");
+
+ b.Property("Impact");
+
+ b.Property("Reason")
+ .IsRequired();
+
+ b.HasKey("Id");
+ });
+
+ modelBuilder.Entity("Yavsc.Models.Bank.BankIdentity", b =>
+ {
+ b.Property("Id")
+ .ValueGeneratedOnAdd();
+
+ b.Property("AccountNumber")
+ .HasAnnotation("MaxLength", 15);
+
+ b.Property("BIC")
+ .HasAnnotation("MaxLength", 15);
+
+ b.Property("BankCode")
+ .HasAnnotation("MaxLength", 5);
+
+ b.Property("BankedKey");
+
+ b.Property("IBAN")
+ .HasAnnotation("MaxLength", 33);
+
+ b.Property("WicketCode")
+ .HasAnnotation("MaxLength", 5);
+
+ b.HasKey("Id");
+ });
+
+ modelBuilder.Entity("Yavsc.Models.Billing.CommandLine", b =>
+ {
+ b.Property("Id")
+ .ValueGeneratedOnAdd();
+
+ b.Property("Count");
+
+ b.Property("Currency");
+
+ b.Property("Description")
+ .IsRequired()
+ .HasAnnotation("MaxLength", 512);
+
+ b.Property("EstimateId");
+
+ b.Property("EstimateTemplateId");
+
+ b.Property("Name")
+ .IsRequired()
+ .HasAnnotation("MaxLength", 256);
+
+ b.Property("UnitaryCost");
+
+ b.HasKey("Id");
+ });
+
+ modelBuilder.Entity("Yavsc.Models.Billing.Estimate", b =>
+ {
+ b.Property("Id")
+ .ValueGeneratedOnAdd();
+
+ b.Property("AttachedFilesString");
+
+ b.Property("AttachedGraphicsString");
+
+ b.Property("ClientId")
+ .IsRequired();
+
+ b.Property("ClientValidationDate");
+
+ b.Property("CommandId");
+
+ b.Property("CommandType")
+ .IsRequired();
+
+ b.Property("Description");
+
+ b.Property("OwnerId");
+
+ b.Property("ProviderValidationDate");
+
+ b.Property("Title");
+
+ b.HasKey("Id");
+ });
+
+ modelBuilder.Entity("Yavsc.Models.Billing.EstimateTemplate", b =>
+ {
+ b.Property("Id")
+ .ValueGeneratedOnAdd();
+
+ b.Property("Description");
+
+ b.Property("OwnerId")
+ .IsRequired();
+
+ b.Property("Title");
+
+ b.HasKey("Id");
+ });
+
+ modelBuilder.Entity("Yavsc.Models.Billing.ExceptionSIREN", b =>
+ {
+ b.Property("SIREN");
+
+ b.HasKey("SIREN");
+ });
+
+ modelBuilder.Entity("Yavsc.Models.Blog.BlogPost", b =>
+ {
+ b.Property("Id")
+ .ValueGeneratedOnAdd();
+
+ b.Property("AuthorId");
+
+ b.Property("Content")
+ .HasAnnotation("MaxLength", 56224);
+
+ b.Property("DateCreated");
+
+ b.Property("DateModified");
+
+ b.Property("Lang")
+ .HasAnnotation("MaxLength", 8);
+
+ b.Property("Photo")
+ .HasAnnotation("MaxLength", 1024);
+
+ b.Property("Rate");
+
+ b.Property("Title")
+ .HasAnnotation("MaxLength", 1024);
+
+ b.Property("UserCreated");
+
+ b.Property("UserModified");
+
+ b.Property("Visible");
+
+ b.HasKey("Id");
+ });
+
+ modelBuilder.Entity("Yavsc.Models.Blog.BlogTag", b =>
+ {
+ b.Property("PostId");
+
+ b.Property("TagId");
+
+ b.HasKey("PostId", "TagId");
+ });
+
+ modelBuilder.Entity("Yavsc.Models.Blog.Comment", b =>
+ {
+ b.Property("Id")
+ .ValueGeneratedOnAdd();
+
+ b.Property("AuthorId")
+ .IsRequired();
+
+ b.Property("Content");
+
+ b.Property("DateCreated");
+
+ b.Property("DateModified");
+
+ b.Property("ParentId");
+
+ b.Property("PostId");
+
+ b.Property("UserCreated");
+
+ b.Property("UserModified");
+
+ b.Property("Visible");
+
+ b.HasKey("Id");
+ });
+
+ modelBuilder.Entity("Yavsc.Models.Calendar.Period", b =>
+ {
+ b.Property("Start");
+
+ b.Property("End");
+
+ b.HasKey("Start", "End");
+ });
+
+ modelBuilder.Entity("Yavsc.Models.Calendar.Schedule", b =>
+ {
+ b.Property("OwnerId");
+
+ b.HasKey("OwnerId");
+ });
+
+ modelBuilder.Entity("Yavsc.Models.Calendar.ScheduledEvent", b =>
+ {
+ b.Property("Id")
+ .ValueGeneratedOnAdd();
+
+ b.Property("PeriodEnd");
+
+ b.Property("PeriodStart");
+
+ b.Property("Reccurence");
+
+ b.Property("ScheduleOwnerId");
+
+ b.HasKey("Id");
+ });
+
+ modelBuilder.Entity("Yavsc.Models.Chat.ChatConnection", b =>
+ {
+ b.Property("ConnectionId");
+
+ b.Property("ApplicationUserId")
+ .IsRequired();
+
+ b.Property("Connected");
+
+ b.Property("UserAgent");
+
+ b.HasKey("ConnectionId");
+ });
+
+ modelBuilder.Entity("Yavsc.Models.Chat.ChatRoom", b =>
+ {
+ b.Property("Name")
+ .HasAnnotation("MaxLength", 255);
+
+ b.Property("DateCreated");
+
+ b.Property("DateModified");
+
+ b.Property("LatestJoinPart");
+
+ b.Property("OwnerId");
+
+ b.Property("Topic");
+
+ b.Property("UserCreated");
+
+ b.Property("UserModified");
+
+ b.HasKey("Name");
+ });
+
+ modelBuilder.Entity("Yavsc.Models.Chat.ChatRoomAccess", b =>
+ {
+ b.Property("ChannelName");
+
+ b.Property("UserId");
+
+ b.Property("Id")
+ .ValueGeneratedOnAdd();
+
+ b.Property("Level");
+
+ b.HasKey("ChannelName", "UserId");
+ });
+
+ modelBuilder.Entity("Yavsc.Models.Cratie.Option", b =>
+ {
+ b.Property("Code");
+
+ b.Property("CodeScrutin");
+
+ b.Property("DateCreated");
+
+ b.Property("DateModified");
+
+ b.Property("Description");
+
+ b.Property("UserCreated");
+
+ b.Property("UserModified");
+
+ b.HasKey("Code", "CodeScrutin");
+ });
+
+ modelBuilder.Entity("Yavsc.Models.Drawing.Color", b =>
+ {
+ b.Property("Id")
+ .ValueGeneratedOnAdd();
+
+ b.Property("Blue");
+
+ b.Property("Green");
+
+ b.Property("Name");
+
+ b.Property("Red");
+
+ b.HasKey("Id");
+ });
+
+ modelBuilder.Entity("Yavsc.Models.Forms.Form", b =>
+ {
+ b.Property("Id");
+
+ b.Property("Summary");
+
+ b.HasKey("Id");
+ });
+
+ modelBuilder.Entity("Yavsc.Models.Haircut.BrusherProfile", b =>
+ {
+ b.Property("UserId");
+
+ b.Property("ActionDistance");
+
+ b.Property("CarePrice");
+
+ b.Property("FlatFeeDiscount");
+
+ b.Property("HalfBalayagePrice");
+
+ b.Property("HalfBrushingPrice");
+
+ b.Property("HalfColorPrice");
+
+ b.Property("HalfDefrisPrice");
+
+ b.Property("HalfFoldingPrice");
+
+ b.Property("HalfMechPrice");
+
+ b.Property("HalfMultiColorPrice");
+
+ b.Property("HalfPermanentPrice");
+
+ b.Property("KidCutPrice");
+
+ b.Property("LongBalayagePrice");
+
+ b.Property("LongBrushingPrice");
+
+ b.Property("LongColorPrice");
+
+ b.Property("LongDefrisPrice");
+
+ b.Property("LongFoldingPrice");
+
+ b.Property("LongMechPrice");
+
+ b.Property("LongMultiColorPrice");
+
+ b.Property("LongPermanentPrice");
+
+ b.Property("ManBrushPrice");
+
+ b.Property("ManCutPrice");
+
+ b.Property("ScheduleOwnerId");
+
+ b.Property("ShampooPrice");
+
+ b.Property("ShortBalayagePrice");
+
+ b.Property("ShortBrushingPrice");
+
+ b.Property("ShortColorPrice");
+
+ b.Property("ShortDefrisPrice");
+
+ b.Property("ShortFoldingPrice");
+
+ b.Property("ShortMechPrice");
+
+ b.Property("ShortMultiColorPrice");
+
+ b.Property("ShortPermanentPrice");
+
+ b.Property("WomenHalfCutPrice");
+
+ b.Property("WomenLongCutPrice");
+
+ b.Property("WomenShortCutPrice");
+
+ b.HasKey("UserId");
+ });
+
+ modelBuilder.Entity("Yavsc.Models.Haircut.HairCutQuery", b =>
+ {
+ b.Property("Id")
+ .ValueGeneratedOnAdd();
+
+ b.Property("ActivityCode")
+ .IsRequired();
+
+ b.Property("AdditionalInfo")
+ .HasAnnotation("MaxLength", 512);
+
+ b.Property("ClientId")
+ .IsRequired();
+
+ b.Property("Consent");
+
+ b.Property("DateCreated");
+
+ b.Property("DateModified");
+
+ b.Property("Description");
+
+ b.Property("EventDate");
+
+ b.Property("LocationId");
+
+ b.Property("PaymentId");
+
+ b.Property("PerformerId")
+ .IsRequired();
+
+ b.Property("PrestationId");
+
+ b.Property("Previsional");
+
+ b.Property("Rejected");
+
+ b.Property("RejectedAt");
+
+ b.Property