mirror of
https://github.com/DarkflameUniverse/DarkflameServer.git
synced 2026-10-02 10:53:44 +00:00
feat(mail): mail history query for the dashboard
IMail::GetMailHistory and CountMailHistory return mail rows as stored, deleted mail included, newest first, with the sender's and receiver's accounts. Filters: character (sent or received), account, text in the subject, body or a name (LIKE wildcards matched literally), state (unread, read, attachment waiting, claimed, deleted) and whether to include deleted mail. MySQL and SQLite share the SQL (MailSql.h). Check: parity test ParitySeeded.Mail (GetMailHistory). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -347,6 +347,8 @@ public:
|
||||
void MarkMailRead(const uint64_t mailId) override;
|
||||
void DeleteMail(const uint64_t mailId) override;
|
||||
void ClaimMailItem(const uint64_t mailId) override;
|
||||
std::vector<MailRecord> GetMailHistory(const MailQuery& query) override;
|
||||
uint64_t CountMailHistory(const MailQuery& query) override;
|
||||
void InsertSlashCommandUsage(const LWOOBJID characterId, const std::string_view command) override;
|
||||
void UpdateAccountUnmuteTime(const uint32_t accountId, const uint64_t timeToUnmute) override;
|
||||
void UpdateAccountBan(const uint32_t accountId, const bool banned) override;
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
#include "SQLiteDatabase.h"
|
||||
#include "GeneralUtils.h"
|
||||
#include "MailSql.h"
|
||||
|
||||
void SQLiteDatabase::InsertNewMail(const MailInfo& mail) {
|
||||
ExecuteInsert(
|
||||
@@ -89,3 +91,25 @@ void SQLiteDatabase::DeleteMail(const uint64_t mailId) {
|
||||
// Kept for staff (the dashboard shows it as deleted); every read for the game skips it
|
||||
ExecuteUpdate("UPDATE mail SET deleted_at=? WHERE id=? AND deleted_at=0;", static_cast<int64_t>(time(NULL)), mailId);
|
||||
}
|
||||
|
||||
std::vector<IMail::MailRecord> SQLiteDatabase::GetMailHistory(const MailQuery& q) {
|
||||
const auto pattern = GeneralUtils::LikeEscape(q.search, '!');
|
||||
auto [_, res] = ExecuteSelect(MailSql::Select() + MailSql::Where(q, "'%' || ? || '%'") + " ORDER BY m.id DESC LIMIT ? OFFSET ?;",
|
||||
q.characterId, q.characterId, q.characterId, q.accountId, q.accountId, q.accountId, q.search, pattern, pattern, pattern, pattern, q.limit, q.offset);
|
||||
std::vector<MailRecord> rows;
|
||||
for (; !res.eof(); res.nextRow()) {
|
||||
rows.push_back({ static_cast<uint64_t>(res.getInt64Field("id")), res.getInt64Field("sender_id"), res.getStringField("sender_name"),
|
||||
static_cast<uint32_t>(res.getIntField("sender_account")), res.getInt64Field("receiver_id"), res.getStringField("receiver_name"),
|
||||
static_cast<uint32_t>(res.getIntField("receiver_account")), res.getInt64Field("time_sent"), res.getStringField("subject"), res.getStringField("body"),
|
||||
res.getInt64Field("attachment_id"), res.getIntField("attachment_lot"), res.getInt64Field("attachment_subkey"), res.getIntField("attachment_count"),
|
||||
res.fieldIsNull("attachment_config") ? "" : res.getStringField("attachment_config"), res.getIntField("was_read") != 0, res.getInt64Field("deleted_at") });
|
||||
}
|
||||
return rows;
|
||||
}
|
||||
|
||||
uint64_t SQLiteDatabase::CountMailHistory(const MailQuery& q) {
|
||||
const auto pattern = GeneralUtils::LikeEscape(q.search, '!');
|
||||
auto [_, res] = ExecuteSelect("SELECT COUNT(*) AS count FROM mail AS m" + MailSql::Where(q, "'%' || ? || '%'") + ";",
|
||||
q.characterId, q.characterId, q.characterId, q.accountId, q.accountId, q.accountId, q.search, pattern, pattern, pattern, pattern);
|
||||
return res.eof() ? 0 : static_cast<uint64_t>(res.getInt64Field("count"));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user