feat(db): chat log guild, team and filter result; chat flags

chat_log gets guild_id, team_id and filtered (migrations mysql 100, sqlite 83),
and the chat log queries take a time range, a guild, a team, a conversation
between two characters and paging back by id. Whispers are their own visibility
switch (includeWhispers), apart from team and guild chat (includePrivate).
Whisper partners and teams that talked are listed with counts.

chat_flags, chat_flag_messages and chat_flag_events (mysql 101, sqlite 84) hold
flagged chat with a copy of the messages around it, its status, note, linked
player report and history. Open flags are in the dashboard snapshot.

Tests on SQLite alone (dDatabaseSqliteTests) and in the MySQL parity tests.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Aaron Kimbrell
2026-09-29 18:22:26 -05:00
parent 1bdb4258a0
commit af54ca282f
22 changed files with 1015 additions and 41 deletions

View File

@@ -0,0 +1,75 @@
#ifndef __ICHATFLAGS__H__
#define __ICHATFLAGS__H__
#include <cstdint>
#include <optional>
#include <string>
#include <vector>
#include "dCommonVars.h"
/**
* Chat messages staff flagged for review (the Chat Flags page). A flag covers one message or several from one
* conversation, keeps a copy of them and the chat around them (chat_log is pruned after log_chat_days; the flag keeps
* its evidence), and has a history of who did what with it.
*/
class IChatFlags {
public:
struct ChatFlag {
uint64_t id{};
int64_t createdAt{};
uint32_t createdById{}; // the staff account
std::string createdBy;
std::string status{ "open" }; // open, actioned, dismissed
std::string channel; // of the flagged messages
LWOOBJID characterId{}; // who the flag is about
std::string characterName;
uint32_t accountId{};
uint64_t firstMessageId{};
uint64_t lastMessageId{};
int64_t firstTime{};
int64_t lastTime{};
std::string excerpt; // the flagged text, shortened, for the queue
std::string note; // why it was flagged, and what was done
std::string messages; // JSON array: the flagged messages and the chat around them, as they were
uint64_t playerReportId{}; // a player report this goes with (0: none)
int64_t updatedAt{};
std::string updatedBy;
};
struct ChatFlagEvent {
uint64_t id{};
uint64_t flagId{};
int64_t time{};
uint32_t accountId{};
std::string actor;
std::string action; // created, actioned, dismissed, reopened, note, report
std::string detail;
};
struct ChatFlagQuery {
std::string status; // empty: any
LWOOBJID characterId{}; // 0: anyone
uint32_t accountId{}; // 0: any
bool includePrivate{}; // flags on team and guild chat
bool includeWhispers{}; // flags on whispers
uint32_t offset{};
uint32_t limit{ 50 };
};
// Adds the flag and remembers which messages it covers. Returns its id.
virtual uint64_t InsertChatFlag(const ChatFlag& flag, const std::vector<uint64_t>& messageIds) = 0;
virtual std::optional<ChatFlag> GetChatFlag(uint64_t id) = 0;
// Newest first
virtual std::vector<ChatFlag> GetChatFlags(const ChatFlagQuery& query) = 0;
virtual uint64_t CountChatFlags(const ChatFlagQuery& query) = 0;
// Status, note and linked report; returns false when there is no such flag
virtual bool UpdateChatFlag(uint64_t id, const std::string& status, const std::string& note, uint64_t playerReportId, int64_t time, const std::string& updatedBy) = 0;
virtual void InsertChatFlagEvent(const ChatFlagEvent& event) = 0;
// Oldest first
virtual std::vector<ChatFlagEvent> GetChatFlagEvents(uint64_t flagId) = 0;
// Of these messages, the ones in a flag, with the newest flag covering each
virtual std::vector<std::pair<uint64_t, uint64_t>> GetFlaggedMessages(const std::vector<uint64_t>& messageIds) = 0;
};
#endif //!__ICHATFLAGS__H__

View File

@@ -28,18 +28,27 @@ public:
uint32_t cloneId{};
std::string message;
bool blocked{}; // stopped by the chat filter: nobody saw it
int64_t guildId{}; // guild chat: the guild
LWOOBJID teamId{}; // team chat: the chat server's team
bool filtered{}; // the chat filter found words it doesn't allow (delivered anyway unless blocked)
};
struct ChatQuery {
uint64_t afterId{}; // only messages newer than this (for bots catching up)
uint32_t limit{ 100 };
std::string channel; // empty: any
bool includePrivate{}; // whispers and team chat
bool includePrivate{}; // team and guild chat
bool includeWhispers{}; // whispers
LWOOBJID characterId{}; // sent or received by this character (0: anyone)
LWOOBJID otherCharacterId{}; // with characterId: only whispers between the two
uint32_t accountId{}; // sent by this account (0: anyone)
uint32_t zoneId{}; // 0: any
int64_t instanceId{ -1 }; // -1: any (instance 0 is character select)
int64_t since{}; // only messages at or after this time (0: any)
int64_t until{}; // only messages before this time (0: any)
uint64_t beforeId{}; // only messages older than this (0: any; for paging back through a conversation)
int64_t guildId{}; // 0: any
LWOOBJID teamId{}; // 0: any
std::string search; // text in the message or a name
bool blockedOnly{};
bool newestFirst{};
@@ -49,6 +58,28 @@ public:
virtual uint64_t InsertChatMessage(const ChatMessage& message) = 0;
virtual std::vector<ChatMessage> GetChatMessages(const ChatQuery& query) = 0;
virtual uint64_t CountChatMessages(const ChatQuery& query) = 0;
// The characters a character whispered with, most recent conversation first
struct WhisperPartner {
LWOOBJID characterId{};
std::string name; // the name in their newest message
uint64_t messages{};
int64_t firstTime{};
int64_t lastTime{};
};
virtual std::vector<WhisperPartner> GetWhisperPartners(LWOOBJID characterId, uint32_t offset, uint32_t limit) = 0;
virtual uint64_t CountWhisperPartners(LWOOBJID characterId) = 0;
// Teams that talked in team chat, most recent first; characterId (0: any) only teams that character talked in
struct ChatTeam {
LWOOBJID teamId{};
uint64_t messages{};
int64_t firstTime{};
int64_t lastTime{};
std::string senders; // the names that talked, comma separated
};
virtual std::vector<ChatTeam> GetChatTeams(LWOOBJID characterId, uint32_t offset, uint32_t limit) = 0;
virtual uint64_t CountChatTeams(LWOOBJID characterId) = 0;
};
#endif //!__ICHATLOG__H__

View File

@@ -27,6 +27,9 @@ public:
uint64_t mailMaxId{};
uint64_t openEconomyFlags{};
uint64_t economyFlagsMaxId{};
uint64_t openChatFlags{};
uint64_t chatFlagsMaxId{};
uint64_t chatFlagsUpdatedAt{};
bool operator==(const Snapshot&) const = default;
};