Skip to content

Commit 03f29ef

Browse files
authored
Merge pull request #10 from Dippys/fix/messenger-timestamp
Fix messenger timestamp to display properly.
2 parents 0ffa888 + 06eab7a commit 03f29ef

2 files changed

Lines changed: 27 additions & 1 deletion

File tree

Turbo.Players/Grains/MessengerGrain.cs

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -800,6 +800,7 @@ CancellationToken ct
800800
Message = message,
801801
SecondsSinceSent = 0,
802802
MessageId = sessionMsgId,
803+
SentAtUtc = now,
803804
}
804805
);
805806

@@ -857,6 +858,7 @@ public async Task ReceiveMessageAsync(
857858
Message = messageText,
858859
SecondsSinceSent = secondsSinceSent,
859860
MessageId = sessionMsgId,
861+
SentAtUtc = DateTime.UtcNow.AddSeconds(-secondsSinceSent),
860862
}
861863
);
862864

@@ -911,7 +913,22 @@ CancellationToken ct
911913
}
912914

913915
// Return up to pageSize entries, newest first (reverse order from the end)
914-
return Task.FromResult(result.Reverse().Take(pageSize).Reverse().ToList());
916+
// Recompute SecondsSinceSent based on actual SentAtUtc so timestamps are accurate
917+
// when the client fetches history later (not frozen at the value from creation time).
918+
var now = DateTime.UtcNow;
919+
return Task.FromResult(
920+
result
921+
.Reverse()
922+
.Take(pageSize)
923+
.Reverse()
924+
.Select(e =>
925+
e with
926+
{
927+
SecondsSinceSent = Math.Max(0, (int)(now - e.SentAtUtc).TotalSeconds),
928+
}
929+
)
930+
.ToList()
931+
);
915932
}
916933

917934
/// <summary>
@@ -952,6 +969,7 @@ public async Task DeliverOfflineMessagesAsync(CancellationToken ct)
952969
Message = msg.Message,
953970
SecondsSinceSent = secondsSince,
954971
MessageId = sessionMsgId,
972+
SentAtUtc = msg.Timestamp,
955973
}
956974
);
957975

Turbo.Primitives/Snapshots/FriendList/MessageHistoryEntrySnapshot.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
using System;
12
using Orleans;
23
using Turbo.Primitives.Players;
34

@@ -23,4 +24,11 @@ public record MessageHistoryEntrySnapshot
2324

2425
[Id(5)]
2526
public required string MessageId { get; init; }
27+
28+
/// <summary>
29+
/// The actual UTC time at which the message was originally sent.
30+
/// Used to recompute <see cref="SecondsSinceSent"/> when history is fetched later.
31+
/// </summary>
32+
[Id(6)]
33+
public required DateTime SentAtUtc { get; init; }
2634
}

0 commit comments

Comments
 (0)