WIP
This commit is contained in:
parent
98a6e6f355
commit
eb2ea3bc5f
5 changed files with 33 additions and 34 deletions
|
|
@ -6,6 +6,7 @@ using Microsoft.Data.Entity;
|
||||||
|
|
||||||
namespace Yavsc.Controllers
|
namespace Yavsc.Controllers
|
||||||
{
|
{
|
||||||
|
using System.Threading.Tasks;
|
||||||
using Microsoft.AspNet.Identity;
|
using Microsoft.AspNet.Identity;
|
||||||
using Models;
|
using Models;
|
||||||
using ViewModels.Chat;
|
using ViewModels.Chat;
|
||||||
|
|
@ -22,7 +23,7 @@ namespace Yavsc.Controllers
|
||||||
}
|
}
|
||||||
|
|
||||||
[HttpGet("users")]
|
[HttpGet("users")]
|
||||||
public IEnumerable<ChatUserInfo> GetUserList()
|
public async Task<IEnumerable<ChatUserInfo>> GetUserList()
|
||||||
{
|
{
|
||||||
List<ChatUserInfo> result = new List<ChatUserInfo>();
|
List<ChatUserInfo> result = new List<ChatUserInfo>();
|
||||||
var cxsQuery = dbContext.Connections?.Include(c=>c.Owner).GroupBy( c => c.ApplicationUserId );
|
var cxsQuery = dbContext.Connections?.Include(c=>c.Owner).GroupBy( c => c.ApplicationUserId );
|
||||||
|
|
@ -36,10 +37,13 @@ namespace Yavsc.Controllers
|
||||||
if (cxs !=null)
|
if (cxs !=null)
|
||||||
if (cxs.Count>0) {
|
if (cxs.Count>0) {
|
||||||
var user = cxs.First().Owner;
|
var user = cxs.First().Owner;
|
||||||
|
if (user!=null) {
|
||||||
|
var roles = await userManager.GetRolesAsync(user);
|
||||||
|
|
||||||
result.Add(new ChatUserInfo { UserName = user.UserName,
|
result.Add(new ChatUserInfo { UserName = user.UserName,
|
||||||
UserId = user.Id, Avatar = user.Avatar, Connections = cxs,
|
UserId = user.Id, Avatar = user.Avatar, Connections = cxs,
|
||||||
Roles = ( userManager.GetRolesAsync(user) ).Result.ToArray() });
|
Roles = roles?.ToArray() });
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
|
|
|
||||||
|
|
@ -56,9 +56,10 @@ namespace Yavsc.Controllers
|
||||||
[AllowAnonymous]
|
[AllowAnonymous]
|
||||||
public IActionResult Title(string id)
|
public IActionResult Title(string id)
|
||||||
{
|
{
|
||||||
|
var uid = User.GetUserId();
|
||||||
return View("Index", _context.Blogspot.Include(
|
return View("Index", _context.Blogspot.Include(
|
||||||
b => b.Author
|
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?}")]
|
[Route("/Blog/{id?}")]
|
||||||
|
|
|
||||||
|
|
@ -127,7 +127,7 @@ namespace Yavsc
|
||||||
{
|
{
|
||||||
string uname = (Context.User != null) ?
|
string uname = (Context.User != null) ?
|
||||||
$"[{Context.User.Identity.Name}]" :
|
$"[{Context.User.Identity.Name}]" :
|
||||||
$"(anony{name})";
|
$"({name})";
|
||||||
Clients.All.addMessage(uname, message);
|
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
|
@model Yavsc.Models.Blog
|
||||||
|
|
||||||
@{
|
@{
|
||||||
ViewData["Title"]="Details";
|
ViewData["Title"]=Model.Title;
|
||||||
}
|
}
|
||||||
|
|
||||||
<div>
|
<div>
|
||||||
|
|
|
||||||
|
|
@ -19,6 +19,9 @@
|
||||||
background-color: yellow;
|
background-color: yellow;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#targets {
|
||||||
|
display:inline-block;
|
||||||
|
}
|
||||||
</style>
|
</style>
|
||||||
<div class="container">
|
<div class="container">
|
||||||
<input type="hidden" id="displayname" />
|
<input type="hidden" id="displayname" />
|
||||||
|
|
@ -26,13 +29,13 @@
|
||||||
<h3>Salons</h3>
|
<h3>Salons</h3>
|
||||||
<ul><li id="pubChan">Public</li></ul>
|
<ul><li id="pubChan">Public</li></ul>
|
||||||
<h3>Utilisateurs</h3>
|
<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>
|
</ul>
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
<ul id="discussion">
|
<ul id="discussion">
|
||||||
</ul>
|
</ul>
|
||||||
<div style="display: inline-block;">
|
<div id="targets">
|
||||||
<div id="sendmessagebox">
|
<div id="sendmessagebox">
|
||||||
<input type="text" id="message" />
|
<input type="text" id="message" />
|
||||||
<input type="button" id="sendmessage" value="@SR["Send"]" />
|
<input type="button" id="sendmessage" value="@SR["Send"]" />
|
||||||
|
|
@ -176,15 +179,27 @@ $('#discussion').append('<li class="notif"><i>' + htmlEncode(tag)
|
||||||
</text>
|
</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.
|
// Set initial focus to message input box.
|
||||||
$('#message').focus();
|
$('#message').focus();
|
||||||
|
|
||||||
|
|
||||||
// Start the connection.
|
// Start the connection.
|
||||||
$.connection.hub.start().done(function () {
|
$.connection.hub.start().done(function () {
|
||||||
$('#sendmessage').click(function () {
|
$('#sendmessage').click(function () {
|
||||||
// Call the Send method on the hub.
|
// Call the Send method on the hub.
|
||||||
chat.server.send($('#displayname').val(), $('#message').val());
|
sendMessage().focus();
|
||||||
// Clear text box and reset focus for next comment.
|
});
|
||||||
$('#message').val('').focus();
|
$( "#message" ).keydown(function( event ) {
|
||||||
|
if ( event.which == 13 ) {
|
||||||
|
sendMessage()
|
||||||
|
}
|
||||||
});
|
});
|
||||||
$('#sendpv').click(function () {
|
$('#sendpv').click(function () {
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue