Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 19 additions & 1 deletion Turbo.Players/Grains/MessengerGrain.cs
Original file line number Diff line number Diff line change
Expand Up @@ -800,6 +800,7 @@ CancellationToken ct
Message = message,
SecondsSinceSent = 0,
MessageId = sessionMsgId,
SentAtUtc = now,
}
);

Expand Down Expand Up @@ -857,6 +858,7 @@ public async Task ReceiveMessageAsync(
Message = messageText,
SecondsSinceSent = secondsSinceSent,
MessageId = sessionMsgId,
SentAtUtc = DateTime.UtcNow.AddSeconds(-secondsSinceSent),
}
);

Expand Down Expand Up @@ -911,7 +913,22 @@ CancellationToken ct
}

// Return up to pageSize entries, newest first (reverse order from the end)
return Task.FromResult(result.Reverse().Take(pageSize).Reverse().ToList());
// Recompute SecondsSinceSent based on actual SentAtUtc so timestamps are accurate
// when the client fetches history later (not frozen at the value from creation time).
var now = DateTime.UtcNow;
return Task.FromResult(
result
.Reverse()
.Take(pageSize)
.Reverse()
.Select(e =>
e with
{
SecondsSinceSent = Math.Max(0, (int)(now - e.SentAtUtc).TotalSeconds),
}
)
.ToList()
);
}

/// <summary>
Expand Down Expand Up @@ -952,6 +969,7 @@ public async Task DeliverOfflineMessagesAsync(CancellationToken ct)
Message = msg.Message,
SecondsSinceSent = secondsSince,
MessageId = sessionMsgId,
SentAtUtc = msg.Timestamp,
}
);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using System;
using Orleans;
using Turbo.Primitives.Players;

Expand All @@ -23,4 +24,11 @@ public record MessageHistoryEntrySnapshot

[Id(5)]
public required string MessageId { get; init; }

/// <summary>
/// The actual UTC time at which the message was originally sent.
/// Used to recompute <see cref="SecondsSinceSent"/> when history is fetched later.
/// </summary>
[Id(6)]
public required DateTime SentAtUtc { get; init; }
}
Loading