mirror of
https://github.com/RedWizardsLab/EchoHub.git
synced 2026-09-04 00:26:07 +02:00
feat: show date on messages older than a day and improve time formatting
This commit is contained in:
@@ -101,7 +101,7 @@ public sealed class ChatMessageManager
|
||||
_channelMessages[channelName] = messages;
|
||||
}
|
||||
|
||||
var time = DateTimeOffset.Now.ToString("HH:mm");
|
||||
var time = FormatDateTime(DateTimeOffset.Now);
|
||||
var textLines = text.Split('\n');
|
||||
|
||||
messages.Add(new ChatLine(
|
||||
@@ -130,7 +130,7 @@ public sealed class ChatMessageManager
|
||||
/// </summary>
|
||||
public void AddStatusMessage(string channelName, string username, string status)
|
||||
{
|
||||
var time = DateTimeOffset.Now.ToString("HH:mm");
|
||||
var time = FormatDateTime(DateTimeOffset.Now);
|
||||
var segments = new List<ChatSegment>
|
||||
{
|
||||
new($"[{time}] ", ChatColors.TimestampAttr),
|
||||
@@ -234,7 +234,7 @@ public sealed class ChatMessageManager
|
||||
|
||||
private List<ChatLine> FormatMessage(MessageDto message)
|
||||
{
|
||||
var time = message.SentAt.ToLocalTime().ToString("HH:mm");
|
||||
var time = FormatDateTime(message.SentAt);
|
||||
var senderName = message.SenderUsername + ":";
|
||||
var senderColor = HexColorHelper.ParseHexColor(message.SenderNicknameColor);
|
||||
|
||||
@@ -425,6 +425,14 @@ public sealed class ChatMessageManager
|
||||
return result;
|
||||
}
|
||||
|
||||
private static string FormatDateTime(DateTimeOffset timestamp)
|
||||
{
|
||||
if (timestamp.Date == DateTimeOffset.Now.Date)
|
||||
return timestamp.ToLocalTime().ToString("t");
|
||||
else
|
||||
return timestamp.ToLocalTime().ToString("g");
|
||||
}
|
||||
|
||||
internal static string FormatFileSize(long? bytes)
|
||||
{
|
||||
if (bytes is null or 0)
|
||||
|
||||
Reference in New Issue
Block a user