diff --git a/Yavsc/ApiControllers/ChatApiController.cs b/Yavsc/ApiControllers/ChatApiController.cs index cd5e8779..ce8e206b 100644 --- a/Yavsc/ApiControllers/ChatApiController.cs +++ b/Yavsc/ApiControllers/ChatApiController.cs @@ -6,6 +6,7 @@ using Microsoft.Data.Entity; namespace Yavsc.Controllers { + using System.Threading.Tasks; using Microsoft.AspNet.Identity; using Models; using ViewModels.Chat; @@ -22,7 +23,7 @@ namespace Yavsc.Controllers } [HttpGet("users")] - public IEnumerable GetUserList() + public async Task> GetUserList() { List result = new List(); var cxsQuery = dbContext.Connections?.Include(c=>c.Owner).GroupBy( c => c.ApplicationUserId ); @@ -36,10 +37,13 @@ namespace Yavsc.Controllers if (cxs !=null) if (cxs.Count>0) { var user = cxs.First().Owner; - + if (user!=null) { + var roles = await userManager.GetRolesAsync(user); + result.Add(new ChatUserInfo { UserName = user.UserName, UserId = user.Id, Avatar = user.Avatar, Connections = cxs, - Roles = ( userManager.GetRolesAsync(user) ).Result.ToArray() }); + Roles = roles?.ToArray() }); + } } } return result; diff --git a/Yavsc/Controllers/BlogspotController.cs b/Yavsc/Controllers/BlogspotController.cs index 4a60ae66..273c5de2 100644 --- a/Yavsc/Controllers/BlogspotController.cs +++ b/Yavsc/Controllers/BlogspotController.cs @@ -56,9 +56,10 @@ namespace Yavsc.Controllers [AllowAnonymous] public IActionResult Title(string id) { + var uid = User.GetUserId(); return View("Index", _context.Blogspot.Include( b => b.Author - ).Where(x => x.Title == id && x.Visible).ToList()); + ).Where(x => x.Title == id && (x.Visible || x.AuthorId == uid )).ToList()); } [Route("/Blog/{id?}")] @@ -93,7 +94,7 @@ namespace Yavsc.Controllers { return HttpNotFound(); } - + return View(blog); } diff --git a/Yavsc/Hubs/ChatHub.cs b/Yavsc/Hubs/ChatHub.cs index 21e2e4b2..4e665e32 100644 --- a/Yavsc/Hubs/ChatHub.cs +++ b/Yavsc/Hubs/ChatHub.cs @@ -127,7 +127,7 @@ namespace Yavsc { string uname = (Context.User != null) ? $"[{Context.User.Identity.Name}]" : - $"(anony{name})"; + $"({name})"; Clients.All.addMessage(uname, message); } @@ -155,26 +155,5 @@ namespace Yavsc } - public List GetUserList() - { - using (var db = new ApplicationDbContext()) { - - var cxsQuery = db.Connections.Include(c=>c.Owner).GroupBy( c => c.ApplicationUserId ); - - List result = new List(); - - foreach (var g in cxsQuery) { - - var uid = g.Key; - var cxs = g.ToList(); - var user = cxs.First().Owner; - - result.Add(new ChatUserInfo { UserName = user.UserName, - UserId = user.Id, Avatar = user.Avatar, Connections = cxs } ); - - } - return result; - } - } } } diff --git a/Yavsc/Views/Blogspot/Details.cshtml b/Yavsc/Views/Blogspot/Details.cshtml index 414ec434..9166f905 100644 --- a/Yavsc/Views/Blogspot/Details.cshtml +++ b/Yavsc/Views/Blogspot/Details.cshtml @@ -1,7 +1,7 @@ @model Yavsc.Models.Blog @{ - ViewData["Title"]="Details"; + ViewData["Title"]=Model.Title; }
diff --git a/Yavsc/Views/Home/Chat.cshtml b/Yavsc/Views/Home/Chat.cshtml index c1a5cdf3..e358f159 100644 --- a/Yavsc/Views/Home/Chat.cshtml +++ b/Yavsc/Views/Home/Chat.cshtml @@ -18,7 +18,10 @@ font-style: bold; background-color: yellow; } - + +#targets { + display:inline-block; +}
@@ -26,13 +29,13 @@

Salons

  • Public

Utilisateurs

-
    +
-
+
@@ -176,15 +179,27 @@ $('#discussion').append('
  • ' + htmlEncode(tag) } + + var sendMessage = function() { + chat.server.send($('#displayname').val(), $('#message').val()); + // Clear text box and reset focus for next comment. + $('#message').val('') + }; + // Set initial focus to message input box. $('#message').focus(); + + // Start the connection. $.connection.hub.start().done(function () { $('#sendmessage').click(function () { // Call the Send method on the hub. - chat.server.send($('#displayname').val(), $('#message').val()); - // Clear text box and reset focus for next comment. - $('#message').val('').focus(); + sendMessage().focus(); + }); + $( "#message" ).keydown(function( event ) { + if ( event.which == 13 ) { + sendMessage() + } }); $('#sendpv').click(function () {