User Profiles

The app now uses a server profile to load avatars and names.
This commit is contained in:
JacobTech 2024-04-13 00:36:33 -04:00
parent 0999d997cb
commit 5cec5c4230
7 changed files with 34 additions and 58 deletions

View File

@ -28,12 +28,14 @@ public class RoleView : FlowLayout
public async Task AddUser(SocketUser user, Role TopRole) public async Task AddUser(SocketUser user, Role TopRole)
{ {
UserView f = await UserView.Make(user, TopRole, r is null); ServerProfile DefaultProfile = await user.Server.GetProfile(user.ServerProfile, CancellationToken.None);
UserView f = await UserView.Make(user, DefaultProfile, TopRole, r is null);
uuu.Add(user.Id, f); uuu.Add(user.Id, f);
bool ff = false; bool ff = false;
for (int j = 0; j < Users.Count; j++) for (int j = 0; j < Users.Count; j++)
{ {
if (string.Compare(Users[j].DisplayName, user.DisplayName) > 0) if (string.Compare(DefaultProfile.DisplayName, DefaultProfile.DisplayName) > 0)
{ {
Users.Insert(j, user); Users.Insert(j, user);
Controls.Insert(j+1, f); Controls.Insert(j+1, f);

View File

@ -9,7 +9,7 @@ public class UserView : UserControl
{ {
public SocketUser User { get; set; } public SocketUser User { get; set; }
private UserView(IRenderObject user, SocketUser u, Role r, bool offline) private UserView(IRenderObject user, SocketUser u, ServerProfile p, Role r, bool offline)
{ {
this.User = u; this.User = u;
base.Size = new(244.ScaleInt(), 44.ScaleInt()); base.Size = new(244.ScaleInt(), 44.ScaleInt());
@ -18,7 +18,7 @@ public class UserView : UserControl
user.ForceDistanceUpdate(this); user.ForceDistanceUpdate(this);
Label uname = new(Globals.DefaultFont) Label uname = new(Globals.DefaultFont)
{ {
Text = u.DisplayName, Text = p.DisplayName,
Color = r.Color.ToColor4() Color = r.Color.ToColor4()
}; };
if (offline) uname.Color = new(uname.Color.R, uname.Color.G, uname.Color.B, uname.Color.A * 0.6f); if (offline) uname.Color = new(uname.Color.R, uname.Color.G, uname.Color.B, uname.Color.A * 0.6f);
@ -28,9 +28,9 @@ public class UserView : UserControl
Controls.Add(user); Controls.Add(user);
} }
public static async Task<UserView> Make(SocketUser u, Role r, bool offline) public static async Task<UserView> Make(SocketUser u, ServerProfile p, Role r, bool offline)
{ {
UserView m = new(await u.MakeRct(new(32.ScaleInt()), true), u, r, offline); UserView m = new(await p.MakeRct(u, new(32.ScaleInt())), u, p, r, offline);
return m; return m;
} }
} }

View File

@ -31,14 +31,16 @@ public class ChatMessage : UserControl
public static async Task<ChatMessage> MakeChatMessage(PublicChat p, SocketMessage message) public static async Task<ChatMessage> MakeChatMessage(PublicChat p, SocketMessage message)
{ {
IUser auth = await message.GetAuthor(CancellationToken.None); SocketUser auth = (SocketUser)(await message.GetAuthor(CancellationToken.None));
Color c = await auth.GetColor(); ServerProfile prof = await message.GetProfile(CancellationToken.None);
Color? c = await prof.GetColor();
if (c is null) c = await auth.GetColor();
Color4 c4 = new(c.R, c.G, c.B, c.A); Color4 c4 = new(c.R, c.G, c.B, c.A);
return new ChatMessage(p, message, await message.GetParent(CancellationToken.None), auth, await auth.MakeRct(new(40.ScaleInt()), message.IsProfile), c4); return new ChatMessage(p, message, await message.GetParent(CancellationToken.None), prof, await prof.MakeRct(auth, new(40.ScaleInt())), c4);
} }
private ChatMessage(PublicChat p, SocketMessage message, SocketChannel chan, IUser Author, IRenderObject UserIcon, Color4 UserNameColor) private ChatMessage(PublicChat p, SocketMessage message, SocketChannel chan, ServerProfile Author, IRenderObject UserIcon, Color4 UserNameColor)
{ {
pc = p; pc = p;
Label label1; Label label1;
@ -87,7 +89,6 @@ public class ChatMessage : UserControl
Controls.Add(label1 = new Label(Globals.DefaultFont) { Color = UserNameColor, Text = Author.DisplayName }); Controls.Add(label1 = new Label(Globals.DefaultFont) { Color = UserNameColor, Text = Author.DisplayName });
label1.Location = new( label1.Location = new(
54.ScaleInt(), 54.ScaleInt(),
//(int)(UserIcon.Location.Y + (UserIcon.Size.Y / 2) - (label1.Font.CurrentFonts[0].Face.Size.Metrics.NominalHeight / 2) - label1.Size.Y + label1.Font.PixelHeight),
UserIcon.Location.Y, UserIcon.Location.Y,
0); 0);
Label label2; Label label2;

View File

@ -355,7 +355,6 @@ public class PublicChat : UserControl
private SocketMessage? lastm; private SocketMessage? lastm;
private long? lastUser; private long? lastUser;
private bool fake = false;
public ChatMessage? LastChatMessage; public ChatMessage? LastChatMessage;
private SocketMessage? lastmIndex; private SocketMessage? lastmIndex;
@ -454,9 +453,8 @@ public class PublicChat : UserControl
} }
lastm = Message; lastm = Message;
if (lastUser is null || lastUser != Message.AuthorID || hasbeentenmin || fake != Message.IsProfile) if (lastUser is null || lastUser != Message.ProfileID || hasbeentenmin)
{ {
if (Window is null || !Globals.ms.InvokeRequired) if (Window is null || !Globals.ms.InvokeRequired)
{ {
MessageFlow.Controls.Add(LastChatMessage = await ChatMessage.MakeChatMessage(this, Message)); MessageFlow.Controls.Add(LastChatMessage = await ChatMessage.MakeChatMessage(this, Message));
@ -490,8 +488,7 @@ public class PublicChat : UserControl
}); });
} }
} }
fake = Message.IsProfile; lastUser = Message.ProfileID;
lastUser = Message.AuthorID;
} }
private int index = 0; private int index = 0;
@ -504,7 +501,7 @@ public class PublicChat : UserControl
Channel!.Epoch.AddMilliseconds(lastmIndex.ID >> 22).ToLocalTime().AddMinutes(10) < Channel!.Epoch.AddMilliseconds(lastmIndex.ID >> 22).ToLocalTime().AddMinutes(10) <
Channel!.Epoch.AddMilliseconds(Message.ID >> 22).ToLocalTime(); Channel!.Epoch.AddMilliseconds(Message.ID >> 22).ToLocalTime();
lastmIndex = Message; lastmIndex = Message;
if (lastUserIndex is null || lastUserIndex != Message.AuthorID || hasbeentenmin || fake != Message.IsProfile) if (lastUserIndex is null || lastUserIndex != Message.ProfileID || hasbeentenmin)
{ {
if (Window is null || !Globals.ms.InvokeRequired) if (Window is null || !Globals.ms.InvokeRequired)
{ {
@ -539,7 +536,6 @@ public class PublicChat : UserControl
}); });
} }
} }
fakeIndex = Message.IsProfile; lastUserIndex = Message.ProfileID;
lastUserIndex = Message.AuthorID;
} }
} }

View File

@ -259,7 +259,8 @@ public class MainScreenWindow : Window
Role[] ra = await Server.User.GetRoles(); Role[] ra = await Server.User.GetRoles();
Color c = ra[0].Color; Color c = ra[0].Color;
Color4 c4 = new(c.R, c.G, c.B, c.A); Color4 c4 = new(c.R, c.G, c.B, c.A);
IRenderObject u = await Server.User.MakeRct(new(46.ScaleInt()), false); ServerProfile DefaultProfile = await Server.GetProfile(Server.User.ServerProfile, CancellationToken.None);
IRenderObject u = await DefaultProfile.MakeRct(Server.User, new(46.ScaleInt()));
int ii = 4.ScaleInt(); int ii = 4.ScaleInt();
u.Location = new(ii, cs.Size.Y + ii, 0); u.Location = new(ii, cs.Size.Y + ii, 0);
u.Anchor = ObjectAnchor.Bottom | ObjectAnchor.Left; u.Anchor = ObjectAnchor.Bottom | ObjectAnchor.Left;
@ -269,7 +270,7 @@ public class MainScreenWindow : Window
Label ul = new Label(Globals.DefaultFont) Label ul = new Label(Globals.DefaultFont)
{ {
Anchor = u.Anchor, Anchor = u.Anchor,
Text = Server.User.DisplayName, Text = DefaultProfile.DisplayName,
Color = c4 Color = c4
}; };

View File

@ -266,21 +266,10 @@ public static class Globals
public static Dictionary<long, Texture> UserTextureMap = new(); public static Dictionary<long, Texture> UserTextureMap = new();
public static Dictionary<long, Texture> ProfileTextureMap = new(); public static Dictionary<long, Texture> ProfileTextureMap = new();
private static async Task<Texture> GetIcon(this SocketUser User) public static async Task<IRenderObject> MakeRct<TUser>(this ServerProfile Profile, TUser User, Vector2i Size) where TUser : SocketUser
{
if (UserTextureMap.TryGetValue(User.Id, out Texture? t)) return t;
Stream UserStream = await User.GetAvatar(CancellationToken.None);
t = Globals.ms.TextureManager.AddTexture(UserStream);
UserTextureMap.Add(User.Id, t);
UserStream.Dispose();
t.Unit = TextureUnit.Texture1;
return t;
}
public static async Task<IRenderObject> MakeRct<TUser>(this TUser User, Vector2i Size, bool IsProfile) where TUser : IUser
{ {
Texture t = ms.TextureManager.GetTextureResource("Status.png"); Texture t = ms.TextureManager.GetTextureResource("Status.png");
if (User.PictureType == PictureType.none) if (Profile.PictureType == PictureType.none)
{ {
UserControl r = new(t); UserControl r = new(t);
r.Size = Size; r.Size = Size;
@ -291,7 +280,7 @@ public static class Globals
{ {
Color = c.ToColor4() Color = c.ToColor4()
}; };
l.Text = User.DisplayName[0].ToString(); l.Text = Profile.DisplayName[0].ToString();
var y = l.GetSizeOfChar(0); var y = l.GetSizeOfChar(0);
l.Location = new((r.Size.X - l.Size.X)/2, l.Location = new((r.Size.X - l.Size.X)/2,
(int)(r.Size.Y - (l.Font.PixelHeight - y.Y) - (r.Size.Y / 2) - (y.Y/2)), (int)(r.Size.Y - (l.Font.PixelHeight - y.Y) - (r.Size.Y / 2) - (y.Y/2)),
@ -304,33 +293,20 @@ public static class Globals
Rectangle r = new(t); Rectangle r = new(t);
r.Size = Size; r.Size = Size;
r.Shader = Rectangle.DefaultAlphaTextureShader[ms.Context]; r.Shader = Rectangle.DefaultAlphaTextureShader[ms.Context];
r.Textures.Add(await User.GetIcon(IsProfile)); r.Textures.Add(await Profile.GetIcon());
return r; return r;
} }
} }
private static async Task<Texture> GetIcon(this IUser User, bool IsProfile) private static async Task<Texture> GetIcon(this ServerProfile User)
{ {
if (IsProfile) if (ProfileTextureMap.TryGetValue(User.ID, out Texture? t)) return t;
{ Stream UserStream = await User.GetAvatar(CancellationToken.None);
if (ProfileTextureMap.TryGetValue(User.Id, out Texture? t)) return t; t = Globals.ms.TextureManager.AddTexture(UserStream);
Stream UserStream = await User.GetAvatar(CancellationToken.None); ProfileTextureMap.Add(User.ID, t);
t = Globals.ms.TextureManager.AddTexture(UserStream); UserStream.Dispose();
ProfileTextureMap.Add(User.Id, t); t.Unit = TextureUnit.Texture1;
UserStream.Dispose(); return t;
t.Unit = TextureUnit.Texture1;
return t;
}
else
{
if (UserTextureMap.TryGetValue(User.Id, out Texture? t)) return t;
Stream UserStream = await User.GetAvatar(CancellationToken.None);
t = Globals.ms.TextureManager.AddTexture(UserStream);
UserTextureMap.Add(User.Id, t);
UserStream.Dispose();
t.Unit = TextureUnit.Texture1;
return t;
}
} }
public static Settings Settings { get; set; } public static Settings Settings { get; set; }

View File

@ -22,7 +22,7 @@
<ItemGroup> <ItemGroup>
<PackageReference Include="GraphicsManager" Version="1.0.9-alpha72" /> <PackageReference Include="GraphicsManager" Version="1.0.9-alpha72" />
<PackageReference Include="Luski.net" Version="2.0.0-alpha89" /> <PackageReference Include="Luski.net" Version="2.0.0-alpha93" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>