conversation: move logic of message management in daemon

This heavily changes the API for the client. The goal here is
to move the logic to construct the history to show in the daemon
and not the client. This has several advantages:

1. Logic is common across every platforms, so bugs should not be
platform-specific
2. Client got less logic
3. Signal are simplified, if an edition comes, "MessageUpdated"
will be triggered instead MessageReceived.
4. Some tests are added for linearizing the history.
5. Search on edition is fixed.

Tests got heavily re-written, but the content didn't change (2 tests
are added, the rest is simplification).

GitLab: #831
Change-Id: Ie7c81077067e9e49db1dd396829c9225c0512c16
This commit is contained in:
Sébastien Blin
2023-06-27 11:45:43 -04:00
parent f83c60f275
commit 8468f15927
24 changed files with 2717 additions and 5420 deletions

View File

@ -29,6 +29,7 @@
class DBusConfigurationManager : public sdbus::AdaptorInterfaces<cx::ring::Ring::ConfigurationManager_adaptor>
{
public:
using DBusSwarmMessage = sdbus::Struct<std::string, std::string, std::string, std::map<std::string, std::string>, std::vector<std::map<std::string, std::string>>, std::vector<std::map<std::string, std::string>>>;
DBusConfigurationManager(sdbus::IConnection& connection)
: AdaptorInterfaces(connection, "/cx/ring/Ring/ConfigurationManager")
{
@ -931,6 +932,15 @@ public:
return libjami::loadConversationMessages(accountId, conversationId, fromMessage, n);
}
uint32_t
loadConversation(const std::string& accountId,
const std::string& conversationId,
const std::string& fromMessage,
const uint32_t& n)
{
return libjami::loadConversation(accountId, conversationId, fromMessage, n);
}
uint32_t
loadConversationUntil(const std::string& accountId,
const std::string& conversationId,
@ -950,6 +960,13 @@ public:
return libjami::countInteractions(accountId, conversationId, toId, fromId, authorUri);
}
void
clearCache(const std::string& accountId,
const std::string& conversationId)
{
return libjami::clearCache(accountId, conversationId);
}
uint32_t
searchConversation(const std::string& accountId,
const std::string& conversationId,
@ -1122,10 +1139,30 @@ private:
const std::map<std::string, SharedCallback> convEvHandlers = {
exportable_serialized_callback<ConversationSignal::ConversationLoaded>(
std::bind(&DBusConfigurationManager::emitConversationLoaded, this, _1, _2, _3, _4)),
exportable_serialized_callback<ConversationSignal::SwarmLoaded>([this](const uint32_t& id, const std::string& account_id, const std::string& conversation_id, const std::vector<libjami::SwarmMessage>& messages) {
std::vector<DBusSwarmMessage> msgList;
for (const auto& message: messages) {
DBusSwarmMessage msg {message.id, message.type, message.linearizedParent, message.body, message.reactions, message.editions};
msgList.push_back(msg);
}
DBusConfigurationManager::emitSwarmLoaded(id, account_id, conversation_id, msgList);
}),
exportable_serialized_callback<ConversationSignal::MessagesFound>(
std::bind(&DBusConfigurationManager::emitMessagesFound, this, _1, _2, _3, _4)),
exportable_serialized_callback<ConversationSignal::MessageReceived>(
std::bind(&DBusConfigurationManager::emitMessageReceived, this, _1, _2, _3)),
exportable_serialized_callback<ConversationSignal::SwarmMessageReceived>([this](const std::string& account_id, const std::string& conversation_id, const libjami::SwarmMessage& message) {
DBusSwarmMessage msg {message.id, message.type, message.linearizedParent, message.body, message.reactions, message.editions};
DBusConfigurationManager::emitSwarmMessageReceived(account_id, conversation_id, msg);
}),
exportable_serialized_callback<ConversationSignal::SwarmMessageUpdated>([this](const std::string& account_id, const std::string& conversation_id, const libjami::SwarmMessage& message) {
DBusSwarmMessage msg {message.id, message.type, message.linearizedParent, message.body, message.reactions, message.editions};
DBusConfigurationManager::emitSwarmMessageUpdated(account_id, conversation_id, msg);
}),
exportable_serialized_callback<ConversationSignal::ReactionAdded>(
std::bind(&DBusConfigurationManager::emitReactionAdded, this, _1, _2, _3, _4)),
exportable_serialized_callback<ConversationSignal::ReactionRemoved>(
std::bind(&DBusConfigurationManager::emitReactionRemoved, this, _1, _2, _3, _4)),
exportable_serialized_callback<ConversationSignal::ConversationProfileUpdated>(
std::bind(&DBusConfigurationManager::emitConversationProfileUpdated, this, _1, _2, _3)),
exportable_serialized_callback<ConversationSignal::ConversationRequestReceived>(