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)
{
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);
bool ff = false;
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);
Controls.Insert(j+1, f);

View File

@ -9,7 +9,7 @@ public class UserView : UserControl
{
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;
base.Size = new(244.ScaleInt(), 44.ScaleInt());
@ -18,7 +18,7 @@ public class UserView : UserControl
user.ForceDistanceUpdate(this);
Label uname = new(Globals.DefaultFont)
{
Text = u.DisplayName,
Text = p.DisplayName,
Color = r.Color.ToColor4()
};
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);
}
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;
}
}

View File

@ -31,14 +31,16 @@ public class ChatMessage : UserControl
public static async Task<ChatMessage> MakeChatMessage(PublicChat p, SocketMessage message)
{
IUser auth = await message.GetAuthor(CancellationToken.None);
Color c = await auth.GetColor();
SocketUser auth = (SocketUser)(await message.GetAuthor(CancellationToken.None));
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);
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;
Label label1;
@ -87,7 +89,6 @@ public class ChatMessage : UserControl
Controls.Add(label1 = new Label(Globals.DefaultFont) { Color = UserNameColor, Text = Author.DisplayName });
label1.Location = new(
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,
0);
Label label2;

View File

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

View File

@ -259,7 +259,8 @@ public class MainScreenWindow : Window
Role[] ra = await Server.User.GetRoles();
Color c = ra[0].Color;
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();
u.Location = new(ii, cs.Size.Y + ii, 0);
u.Anchor = ObjectAnchor.Bottom | ObjectAnchor.Left;
@ -269,7 +270,7 @@ public class MainScreenWindow : Window
Label ul = new Label(Globals.DefaultFont)
{
Anchor = u.Anchor,
Text = Server.User.DisplayName,
Text = DefaultProfile.DisplayName,
Color = c4
};

View File

@ -266,21 +266,10 @@ public static class Globals
public static Dictionary<long, Texture> UserTextureMap = new();
public static Dictionary<long, Texture> ProfileTextureMap = new();
private static async Task<Texture> GetIcon(this SocketUser User)
{
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
public static async Task<IRenderObject> MakeRct<TUser>(this ServerProfile Profile, TUser User, Vector2i Size) where TUser : SocketUser
{
Texture t = ms.TextureManager.GetTextureResource("Status.png");
if (User.PictureType == PictureType.none)
if (Profile.PictureType == PictureType.none)
{
UserControl r = new(t);
r.Size = Size;
@ -291,7 +280,7 @@ public static class Globals
{
Color = c.ToColor4()
};
l.Text = User.DisplayName[0].ToString();
l.Text = Profile.DisplayName[0].ToString();
var y = l.GetSizeOfChar(0);
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)),
@ -304,34 +293,21 @@ public static class Globals
Rectangle r = new(t);
r.Size = Size;
r.Shader = Rectangle.DefaultAlphaTextureShader[ms.Context];
r.Textures.Add(await User.GetIcon(IsProfile));
r.Textures.Add(await Profile.GetIcon());
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;
if (ProfileTextureMap.TryGetValue(User.ID, out Texture? t)) return t;
Stream UserStream = await User.GetAvatar(CancellationToken.None);
t = Globals.ms.TextureManager.AddTexture(UserStream);
ProfileTextureMap.Add(User.Id, t);
ProfileTextureMap.Add(User.ID, t);
UserStream.Dispose();
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; }

View File

@ -22,7 +22,7 @@
<ItemGroup>
<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>