Paul Schneider 9 years ago
parent 281abd0027
commit 2a0ca73400
5 changed files with 33 additions and 34 deletions

@ -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<ChatUserInfo> GetUserList()
public async Task<IEnumerable<ChatUserInfo>> GetUserList()
{
List<ChatUserInfo> result = new List<ChatUserInfo>();
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;

@ -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?}")]

@ -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<ChatUserInfo> GetUserList()
{
using (var db = new ApplicationDbContext()) {
var cxsQuery = db.Connections.Include(c=>c.Owner).GroupBy( c => c.ApplicationUserId );
List<ChatUserInfo> result = new List<ChatUserInfo>();
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;
}
}
}
}

@ -1,7 +1,7 @@
@model Yavsc.Models.Blog
@{
ViewData["Title"]="Details";
ViewData["Title"]=Model.Title;
}
<div>

@ -19,6 +19,9 @@
background-color: yellow;
}
#targets {
display:inline-block;
}
</style>
<div class="container">
<input type="hidden" id="displayname" />
@ -26,13 +29,13 @@
<h3>Salons</h3>
<ul><li id="pubChan">Public</li></ul>
<h3>Utilisateurs</h3>
<ul id="userlist" style="list-style:none; padding: 1em;">
<ul id="userlist" style="list-style:none; padding: 1em; margin:1em;sqc">
</ul>
</div>
<ul id="discussion">
</ul>
<div style="display: inline-block;">
<div id="targets">
<div id="sendmessagebox">
<input type="text" id="message" />
<input type="button" id="sendmessage" value="@SR["Send"]" />
@ -176,15 +179,27 @@ $('#discussion').append('<li class="notif"><i>' + htmlEncode(tag)
</text>
}
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 () {

Loading…