Phase 1 Steps 4-6 (the receive pipeline, minus the App/sync wiring which lands next). - chat_message: the in-memory ChatMessage model (direction, kind, txid, cid, peer zaddr/pubkey, body, timestamp, payload_position). No libsodium. - chat_store: threads messages by conversation_id and dedups by (txid, payload_position) so re-scanning the chain never double-inserts. - chat_service: owns the long-lived chat identity keypair (move-disabled, wiped on destruction/clear) and the store. ingest() decrypts each Message (drops undecryptable ones silently — no plaintext/memo logging), passes a ContactRequest's plaintext through, and threads the result. No-op without an identity. Tests: a metadata batch decrypts into a threaded conversation; re-ingest dedups; a contact request carries through; a wrong identity decrypts nothing; no-identity ingest is a no-op. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
40 lines
1.1 KiB
C++
40 lines
1.1 KiB
C++
// DragonX Wallet - HushChat in-memory message store (implementation).
|
|
|
|
#include "chat_store.h"
|
|
|
|
namespace dragonx::chat {
|
|
|
|
std::string ChatStore::dedupKey(const ChatMessage& message) {
|
|
return message.txid + ":" + std::to_string(message.payload_position);
|
|
}
|
|
|
|
bool ChatStore::append(const ChatMessage& message) {
|
|
if (!seen_.insert(dedupKey(message)).second) return false;
|
|
messages_.push_back(message);
|
|
return true;
|
|
}
|
|
|
|
std::vector<ChatMessage> ChatStore::conversation(const std::string& conversationId) const {
|
|
std::vector<ChatMessage> out;
|
|
for (const auto& message : messages_) {
|
|
if (message.conversation_id == conversationId) out.push_back(message);
|
|
}
|
|
return out;
|
|
}
|
|
|
|
std::vector<std::string> ChatStore::conversationIds() const {
|
|
std::vector<std::string> ids;
|
|
std::unordered_set<std::string> seenIds;
|
|
for (const auto& message : messages_) {
|
|
if (seenIds.insert(message.conversation_id).second) ids.push_back(message.conversation_id);
|
|
}
|
|
return ids;
|
|
}
|
|
|
|
void ChatStore::clear() {
|
|
messages_.clear();
|
|
seen_.clear();
|
|
}
|
|
|
|
} // namespace dragonx::chat
|