diff --git a/ProtocolInterfaces/DiscordInterface/DiscordInterface.cs b/ProtocolInterfaces/DiscordInterface/DiscordInterface.cs
index 3100833..38031ed 100644
--- a/ProtocolInterfaces/DiscordInterface/DiscordInterface.cs
+++ b/ProtocolInterfaces/DiscordInterface/DiscordInterface.cs
@@ -114,7 +114,7 @@ public class DiscordInterface
private async Task SelfConnected()
{
- var selfAccount = UpsertAccount(client.CurrentUser, protocolAsChannel.Id);
+ var selfAccount = UpsertAccount(client.CurrentUser, protocolAsChannel);
selfAccount.DisplayName = client.CurrentUser.Username;
await _db.SaveChangesAsync();
@@ -150,7 +150,7 @@ public class DiscordInterface
var guild = UpsertChannel(arg.Guild);
var defaultChannel = UpsertChannel(arg.Guild.DefaultChannel);
defaultChannel.ParentChannel = guild;
- var u = UpsertAccount(arg, guild.Id);
+ var u = UpsertAccount(arg, guild);
u.DisplayName = arg.DisplayName;
}
private async Task ButtonHandler(SocketMessageComponent component)
@@ -226,8 +226,7 @@ public class DiscordInterface
m.ExternalId = dMessage.Id.ToString();
m.Timestamp = dMessage.EditedTimestamp ?? dMessage.CreatedAt;
m.Channel = UpsertChannel(dMessage.Channel);
- m.Author = UpsertAccount(dMessage.Author, m.Channel.Id);
- m.Author.SeenInChannel = m.Channel;
+ m.Author = UpsertAccount(dMessage.Author, m.Channel);
if(dMessage.Channel is IGuildChannel)
{
m.Author.DisplayName = (dMessage.Author as IGuildUser).DisplayName;//discord forgot how display names work.
@@ -301,9 +300,9 @@ public class DiscordInterface
c.SendFile = (f, t) => { throw new InvalidOperationException($"channel {channel.Name} is guild; send file"); };
return c;
}
- internal Account UpsertAccount(IUser user, Guid inChannel)
+ internal Account UpsertAccount(IUser user, Channel inChannel)
{
- var acc = _db.Accounts.FirstOrDefault(ui => ui.ExternalId == user.Id.ToString() && ui.SeenInChannel.Id == inChannel);
+ var acc = _db.Accounts.FirstOrDefault(ui => ui.ExternalId == user.Id.ToString() && ui.SeenInChannel.Id == inChannel.Id);
if (acc == null)
{
acc = new Account();
@@ -313,6 +312,7 @@ public class DiscordInterface
acc.ExternalId = user.Id.ToString();
acc.IsBot = user.IsBot || user.IsWebhook;
acc.Protocol = PROTOCOL;
+ acc.SeenInChannel = inChannel;
acc.IsUser = _db.Users.FirstOrDefault(u => u.Accounts.Any(a => a.ExternalId == acc.ExternalId && a.Protocol == acc.Protocol));
if(acc.IsUser == null)
diff --git a/WebInterface/Controllers/ChannelsController.cs b/WebInterface/Controllers/ChannelsController.cs
index fb63581..1e0efeb 100644
--- a/WebInterface/Controllers/ChannelsController.cs
+++ b/WebInterface/Controllers/ChannelsController.cs
@@ -26,7 +26,7 @@ public class ChannelsController : Controller
{
if(_db.Channels == null)
return Problem("Entity set '_db.Channels' is null.");
- var channel = await _db.Channels.Include(u => u.ParentChannel).FirstAsync(u => u.Id == id);
+ var channel = await _db.Channels.Include(u => u.SubChannels).Include(u => u.Users).Include(u => u.ParentChannel).FirstAsync(u => u.Id == id);
var walker = channel;
while(walker != null)
{
diff --git a/WebInterface/Controllers/HomeController.cs b/WebInterface/Controllers/HomeController.cs
index b3d8646..6bda4cb 100644
--- a/WebInterface/Controllers/HomeController.cs
+++ b/WebInterface/Controllers/HomeController.cs
@@ -2,6 +2,7 @@
using System.Text;
using System.Web;
using Microsoft.AspNetCore.Mvc;
+using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.FileSystemGlobbing.Internal.PathSegments;
using vassago.Models;
@@ -21,7 +22,7 @@ public class HomeController : Controller
public IActionResult Index()
{
var allAccounts = _db.Accounts.ToList();
- var allChannels = _db.Channels.ToList();
+ var allChannels = _db.Channels.Include(c => c.Users).ToList();
var sb = new StringBuilder();
sb.Append("[");
sb.Append("{text: \"channels\", nodes: [");
@@ -41,11 +42,11 @@ public class HomeController : Controller
serializeChannel(ref sb, ref allChannels, ref allAccounts, topLevelChannel);
}
- sb.Append("]},");
+ sb.Append("]}");
if (allChannels.Any())
{
- sb.Append("{text: \"orphaned channels\", nodes: [");
+ sb.Append(",{text: \"orphaned channels\", nodes: [");
first = true;
while (true)
{
@@ -63,11 +64,11 @@ public class HomeController : Controller
break;
}
}
- sb.Append("]},");
+ sb.Append("]}");
}
if (allAccounts.Any())
{
- sb.Append("{text: \"channelless accounts\", nodes: [");
+ sb.Append(",{text: \"channelless accounts\", nodes: [");
first = true;
foreach (var acc in allAccounts)
{
@@ -84,13 +85,9 @@ public class HomeController : Controller
sb.Append("]}");
}
var users = _db.Users.ToList();
- if(topLevelChannels.Any() && users.Any())
- {
- sb.Append(',');
- }
if(users.Any())
{
- sb.Append("{text: \"users\", nodes: [");
+ sb.Append(",{text: \"users\", nodes: [");
first=true;
//refresh list; we'll be knocking them out again in serializeUser
allAccounts = _db.Accounts.ToList();
@@ -117,7 +114,7 @@ public class HomeController : Controller
allChannels.Remove(currentChannel);
//"but adam", you say, "there's an href attribute, why make a link?" because that makes the entire bar a link, and trying to expand the node will probably click the link
sb.Append($"{{\"text\": \"{currentChannel.DisplayName}\"");
- var theseAccounts = allAccounts.Where(a => a.SeenInChannel?.Id == currentChannel.Id);
+ var theseAccounts = allAccounts.Where(a => a.SeenInChannel?.Id == currentChannel.Id).ToList();
allAccounts.RemoveAll(a => a.SeenInChannel?.Id == currentChannel.Id);
var first = true;
if (currentChannel.SubChannels != null || theseAccounts != null)
@@ -140,7 +137,6 @@ public class HomeController : Controller
}
if (theseAccounts != null)
{
-
sb.Append(',');
}
}
@@ -170,7 +166,11 @@ public class HomeController : Controller
}
private void serializeUser(ref StringBuilder sb, ref List allAccounts, User currentUser)
{
- sb.Append($"{{\"text\": \"{currentUser.DisplayName}\", ");
+ sb.Append($"{{\"text\": " +
+ $"\""
+ + currentUser.DisplayName +
+ "\", ");
+// \"{currentUser.DisplayName}\", ");
var ownedAccounts = allAccounts.Where(a => a.IsUser == currentUser);
sb.Append("nodes: [");
sb.Append($"{{\"text\": \"owned accounts:\", \"expanded\":true, \"nodes\": [");
diff --git a/WebInterface/Views/Home/Index.cshtml b/WebInterface/Views/Home/Index.cshtml
index 5c9d513..446233a 100644
--- a/WebInterface/Views/Home/Index.cshtml
+++ b/WebInterface/Views/Home/Index.cshtml
@@ -8,6 +8,7 @@ tree above.