feat(auto-tell-tabs): add GetTellHistoryWithSender query and ChunkUtil sender helper
This commit is contained in:
@@ -361,41 +361,12 @@ public class Tab
|
||||
// here, otherwise all temp tabs would mirror "Tell Exclusive".
|
||||
if (IsTempTab && TellTarget?.IsSet() == true)
|
||||
{
|
||||
return MatchesTempTabSender(message);
|
||||
return ChunkUtil.MatchesSender(message, TellTarget.Name, TellTarget.World);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private bool MatchesTempTabSender(Message message)
|
||||
{
|
||||
var senderPayload = ExtractPlayerPayload(message.Sender);
|
||||
if (senderPayload == null)
|
||||
{
|
||||
senderPayload = ExtractPlayerPayload(message.Content);
|
||||
}
|
||||
if (senderPayload == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
var nameMatches = string.Equals(senderPayload.PlayerName, TellTarget.Name, StringComparison.OrdinalIgnoreCase);
|
||||
var worldMatches = senderPayload.World.RowId == TellTarget.World;
|
||||
return nameMatches && worldMatches;
|
||||
}
|
||||
|
||||
private static PlayerPayload? ExtractPlayerPayload(IReadOnlyList<Chunk> chunks)
|
||||
{
|
||||
foreach (var chunk in chunks)
|
||||
{
|
||||
if (chunk.Link is PlayerPayload pp)
|
||||
{
|
||||
return pp;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public void AddMessage(Message message, bool unread = true)
|
||||
{
|
||||
Messages.AddPrune(message, MessageManager.MessageDisplayLimit);
|
||||
|
||||
@@ -602,6 +602,84 @@ internal class MessageStore : IDisposable
|
||||
return new MessageEnumerator(cmd.ExecuteReader());
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Hellion Chat — Auto-Tell-Tabs history preload.
|
||||
///
|
||||
/// Returns up to <paramref name="limit"/> tells exchanged with the named
|
||||
/// player, oldest-first, ready to be added to a freshly spawned auto
|
||||
/// tell tab. The Sender column is a serialized chunk blob, so SQL on its
|
||||
/// own cannot filter by player identity; we narrow with SQL on Receiver
|
||||
/// + ChatType (cheap, indexed) and let the client do the final
|
||||
/// PlayerPayload comparison on the result set.
|
||||
///
|
||||
/// <paramref name="sqlScanLimit"/> caps how many recent tells we scan
|
||||
/// before giving up. 500 covers around 10 days for an active greeter
|
||||
/// and stays well under the 20 ms budget required to keep the spawn on
|
||||
/// the message-processing worker thread.
|
||||
/// </summary>
|
||||
internal IReadOnlyList<Message> GetTellHistoryWithSender(
|
||||
ulong receiver,
|
||||
string senderName,
|
||||
uint senderWorld,
|
||||
int limit,
|
||||
int sqlScanLimit = 500)
|
||||
{
|
||||
if (limit <= 0)
|
||||
{
|
||||
return [];
|
||||
}
|
||||
|
||||
using var cmd = Connection.CreateCommand();
|
||||
cmd.CommandText = @"
|
||||
SELECT
|
||||
Id,
|
||||
Receiver,
|
||||
ContentId,
|
||||
Date,
|
||||
ChatType,
|
||||
SourceKind,
|
||||
TargetKind,
|
||||
Sender,
|
||||
Content,
|
||||
SenderSource,
|
||||
ContentSource,
|
||||
ExtraChatChannel
|
||||
FROM messages
|
||||
WHERE deleted = false
|
||||
AND Receiver = $Receiver
|
||||
AND ChatType IN ($TellIncoming, $TellOutgoing)
|
||||
ORDER BY Date DESC
|
||||
LIMIT $ScanLimit;
|
||||
";
|
||||
cmd.CommandTimeout = 60;
|
||||
cmd.Parameters.AddWithValue("$Receiver", receiver);
|
||||
cmd.Parameters.AddWithValue("$TellIncoming", (int)ChatType.TellIncoming);
|
||||
cmd.Parameters.AddWithValue("$TellOutgoing", (int)ChatType.TellOutgoing);
|
||||
cmd.Parameters.AddWithValue("$ScanLimit", sqlScanLimit);
|
||||
|
||||
var collected = new List<Message>();
|
||||
using var enumerator = new MessageEnumerator(cmd.ExecuteReader());
|
||||
foreach (var message in enumerator)
|
||||
{
|
||||
if (!ChunkUtil.MatchesSender(message, senderName, senderWorld))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
collected.Add(message);
|
||||
if (collected.Count >= limit)
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// SQL was DESC (newest-first) so we hit the limit on the most
|
||||
// recent matching tells. Reverse to oldest-first for chronological
|
||||
// display in the tab.
|
||||
collected.Reverse();
|
||||
return collected;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Marks a message as deleted so it won't get returned in queries.
|
||||
/// </summary>
|
||||
|
||||
@@ -398,6 +398,40 @@ internal static class ChunkUtil
|
||||
return builder.ToString();
|
||||
}
|
||||
|
||||
// Hellion Chat — shared helper for Auto-Tell-Tabs and the MessageStore
|
||||
// history-preload query. Walks the chunk list once and returns the
|
||||
// first PlayerPayload it finds, or null when the message has no
|
||||
// resolved player link (e.g. system messages, GM tells we already
|
||||
// skipped earlier in the pipeline).
|
||||
internal static PlayerPayload? TryGetPlayerPayload(IReadOnlyList<Chunk> chunks)
|
||||
{
|
||||
foreach (var chunk in chunks)
|
||||
{
|
||||
if (chunk.Link is PlayerPayload pp)
|
||||
{
|
||||
return pp;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
// True when the message's sender (or, as a fallback, content) carries a
|
||||
// PlayerPayload that matches the given identity. Used by both the
|
||||
// Tab.Matches sender filter and the MessageStore tell-history scan.
|
||||
internal static bool MatchesSender(Message message, string senderName, uint senderWorld)
|
||||
{
|
||||
var payload = TryGetPlayerPayload(message.Sender) ?? TryGetPlayerPayload(message.Content);
|
||||
if (payload == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (!string.Equals(payload.PlayerName, senderName, StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return payload.World.RowId == senderWorld;
|
||||
}
|
||||
|
||||
internal static readonly RawPayload PeriodicRecruitmentLink = new([0x02, 0x27, 0x07, 0x08, 0x01, 0x01, 0x01, 0xFF, 0x01, 0x03]);
|
||||
|
||||
private static uint GetInteger(BinaryReader input)
|
||||
|
||||
Reference in New Issue
Block a user