diff --git a/src/jamidht/account_manager.cpp b/src/jamidht/account_manager.cpp index a58b4097a50fe06c04534a898b78fd5d1fa9c2a0..55f9c3bdec6164d15d750f4163618aaa43653300 100644 --- a/src/jamidht/account_manager.cpp +++ b/src/jamidht/account_manager.cpp @@ -520,11 +520,11 @@ AccountManager::removeContactConversation(const std::string& uri) { dht::InfoHash h(uri); if (not h) { - JAMI_ERR("removeContact: invalid contact URI"); + JAMI_ERROR("[Account {}] removeContactConversation: invalid contact URI", accountId_); return; } if (not info_) { - JAMI_ERR("addContact(): account not loaded"); + JAMI_ERROR("[Account {}] removeContactConversation: account not loaded", accountId_); return; } if (info_->contacts->removeContactConversation(h)) @@ -536,11 +536,11 @@ AccountManager::updateContactConversation(const std::string& uri, const std::str { dht::InfoHash h(uri); if (not h) { - JAMI_ERR("removeContact: invalid contact URI"); + JAMI_ERROR("[Account {}] updateContactConversation: invalid contact URI", accountId_); return; } if (not info_) { - JAMI_ERR("addContact(): account not loaded"); + JAMI_ERROR("[Account {}] updateContactConversation: account not loaded", accountId_); return; } info_->contacts->updateConversation(h, convId); @@ -557,7 +557,7 @@ std::vector<std::map<std::string, std::string>> AccountManager::getContacts(bool includeRemoved) const { if (not info_) { - JAMI_ERR("getContacts(): account not loaded"); + JAMI_ERROR("[Account {}] getContacts(): account not loaded", accountId_); return {}; } const auto& contacts = info_->contacts->getContacts(); @@ -581,12 +581,12 @@ std::map<std::string, std::string> AccountManager::getContactDetails(const std::string& uri) const { if (!info_) { - JAMI_ERR("getContactDetails(): account not loaded"); + JAMI_ERROR("[Account {}] getContactDetails(): account not loaded", accountId_); return {}; } dht::InfoHash h(uri); if (not h) { - JAMI_ERR("getContactDetails: invalid contact URI"); + JAMI_ERROR("[Account {}] getContactDetails: invalid contact URI", accountId_); return {}; } return info_->contacts->getContactDetails(h); @@ -668,7 +668,7 @@ std::vector<std::map<std::string, std::string>> AccountManager::getTrustRequests() const { if (not info_) { - JAMI_ERR("getTrustRequests(): account not loaded"); + JAMI_ERROR("[Account {}] getTrustRequests(): account not loaded", accountId_); return {}; } return info_->contacts->getTrustRequests(); diff --git a/src/jamidht/conversation_module.cpp b/src/jamidht/conversation_module.cpp index 6e996f6f5d747198b409324bbf6f62dff6df7b33..952fa4b3e23057d892946d62abcee9bd7429a5fd 100644 --- a/src/jamidht/conversation_module.cpp +++ b/src/jamidht/conversation_module.cpp @@ -363,20 +363,20 @@ public: md["syncing"] = "true"; md["created"] = std::to_string(it->second.received); } - saveMetadatas(); + saveMetadata(); conversationsRequests_.erase(id); saveConvRequests(); } std::weak_ptr<JamiAccount> account_; std::shared_ptr<AccountManager> accountManager_; + const std::string accountId_ {}; NeedsSyncingCb needsSyncingCb_; SengMsgCb sendMsgCb_; NeedSocketCb onNeedSocket_; NeedSocketCb onNeedSwarmSocket_; OneToOneRecvCb oneToOneRecvCb_; - std::string accountId_ {}; std::string deviceId_ {}; std::string username_ {}; @@ -427,14 +427,14 @@ public: // While syncing, we do not want to lose metadata (avatar/title and mode) std::map<std::string, std::map<std::string, std::string>> syncingMetadatas_; - void saveMetadatas() + void saveMetadata() { auto path = fileutils::get_data_dir() / accountId_; std::ofstream file(path / "syncingMetadatas", std::ios::trunc | std::ios::binary); msgpack::pack(file, syncingMetadatas_); } - void loadMetadatas() + void loadMetadata() { try { // read file @@ -446,7 +446,7 @@ public: msgpack::unpack(result, (const char*) file.data(), file.size(), 0); result.get().convert(syncingMetadatas_); } catch (const std::exception& e) { - JAMI_WARNING("[ConversationModule] error loading syncingMetadatas_: {}", e.what()); + JAMI_WARNING("[Account {}] [ConversationModule] unable to load syncing metadata: {}", accountId_, e.what()); } } }; @@ -460,12 +460,12 @@ ConversationModule::Impl::Impl(std::shared_ptr<JamiAccount>&& account, OneToOneRecvCb&& oneToOneRecvCb) : account_(account) , accountManager_(accountManager) + , accountId_(account->getAccountID()) , needsSyncingCb_(needsSyncingCb) , sendMsgCb_(sendMsgCb) , onNeedSocket_(onNeedSocket) , onNeedSwarmSocket_(onNeedSwarmSocket) , oneToOneRecvCb_(oneToOneRecvCb) - , accountId_(account->getAccountID()) { if (auto accm = account->accountManager()) if (const auto* info = accm->getInfo()) { @@ -473,7 +473,7 @@ ConversationModule::Impl::Impl(std::shared_ptr<JamiAccount>&& account, username_ = info->accountId; } conversationsRequests_ = convRequests(accountId_); - loadMetadatas(); + loadMetadata(); } void @@ -826,7 +826,7 @@ ConversationModule::Impl::handlePendingConversation(const std::string& conversat if (!status.empty()) conversation->updateMessageStatus(status); syncingMetadatas_.erase(conversationId); - saveMetadatas(); + saveMetadata(); // Inform user that the conversation is ready emitSignal<libjami::ConversationSignal::ConversationReady>(accountId_, conversationId); @@ -945,7 +945,7 @@ ConversationModule::Impl::declineOtherConversationWith(const std::string& uri) n JAMI_WARNING("Decline conversation request ({}) from {}", id, uri); request.declined = std::time(nullptr); syncingMetadatas_.erase(id); - saveMetadatas(); + saveMetadata(); emitSignal<libjami::ConversationSignal::ConversationRequestDeclined>(accountId_, id); } } @@ -2055,7 +2055,7 @@ ConversationModule::declineConversationRequest(const std::string& conversationId pimpl_->saveConvRequests(); } pimpl_->syncingMetadatas_.erase(conversationId); - pimpl_->saveMetadatas(); + pimpl_->saveMetadata(); emitSignal<libjami::ConversationSignal::ConversationRequestDeclined>(pimpl_->accountId_, conversationId); pimpl_->needsSyncingCb_({}); @@ -2506,7 +2506,7 @@ ConversationModule::onSyncData(const SyncMsg& msg, convId, deviceId); pimpl_->syncingMetadatas_.erase(convId); - pimpl_->saveMetadatas(); + pimpl_->saveMetadata(); emitSignal<libjami::ConversationSignal::ConversationRequestDeclined>(pimpl_->accountId_, convId); continue; @@ -2736,7 +2736,7 @@ ConversationModule::conversationInfos(const std::string& conversationId) const if (syncingMetadatasIt != pimpl_->syncingMetadatas_.end()) { if (conv->conversation) { pimpl_->syncingMetadatas_.erase(syncingMetadatasIt); - pimpl_->saveMetadatas(); + pimpl_->saveMetadata(); } else { md = syncingMetadatasIt->second; } @@ -2834,7 +2834,7 @@ ConversationModule::removeContact(const std::string& uri, bool banned) if (it->second.from == uri && !it->second.declined) { JAMI_DEBUG("Declining conversation request {:s} from {:s}", it->first, uri); pimpl_->syncingMetadatas_.erase(it->first); - pimpl_->saveMetadatas(); + pimpl_->saveMetadata(); emitSignal<libjami::ConversationSignal::ConversationRequestDeclined>( pimpl_->accountId_, it->first); update = true; diff --git a/src/jamidht/conversation_module.h b/src/jamidht/conversation_module.h index 3c113a16016cd345a4a85e6f84161cb67803b760..479331005dfead94b1d2e036a0744f5b271aaa5e 100644 --- a/src/jamidht/conversation_module.h +++ b/src/jamidht/conversation_module.h @@ -53,6 +53,7 @@ struct SyncMsg * }} */ std::map<std::string, std::map<std::string, std::map<std::string, std::string>>> ms; + MSGPACK_DEFINE(ds, c, cr, p, ld, ms) }; diff --git a/src/jamidht/jamiaccount.cpp b/src/jamidht/jamiaccount.cpp index bc672d05c83d7b49dc1a05a3cc6af029fcabe9d3..7b6b26403a94d6d2c0d0aea3ae8543628ec76b17 100644 --- a/src/jamidht/jamiaccount.cpp +++ b/src/jamidht/jamiaccount.cpp @@ -2181,7 +2181,8 @@ JamiAccount::convModule(bool noCreation) if (auto shared = w.lock()) { auto& config = shared->config(); // For JAMS account, we must update the server - if (!config.managerUri.empty()) + // for now, only sync with the JAMS server for changes to the conversation list + if (!config.managerUri.empty() && !syncMsg) if (auto am = shared->accountManager()) am->syncDevices(); if (auto sm = shared->syncModule()) diff --git a/src/jamidht/server_account_manager.cpp b/src/jamidht/server_account_manager.cpp index db3a4d9c047dced1d9c65f44df5ee3022a955a01..3db6cb3162b24e7a5c227e8101977b5a64528e7f 100644 --- a/src/jamidht/server_account_manager.cpp +++ b/src/jamidht/server_account_manager.cpp @@ -83,9 +83,7 @@ ServerAccountManager::initAuthentication(PrivateKey key, onChange_ = std::move(onChange); const std::string url = managerHostname_ + PATH_DEVICE; - JAMI_WARN("[Auth] Authentication with: %s to %s", - ctx->credentials->username.c_str(), - url.c_str()); + JAMI_WARNING("[Account {}] [Auth] Authentication with: {} to {}", accountId_, ctx->credentials->username, url); dht::ThreadPool::computation().run([ctx, url, w=weak_from_this()] { auto this_ = std::static_pointer_cast<ServerAccountManager>(w.lock()); @@ -393,7 +391,7 @@ ServerAccountManager::syncDevices() const std::string urlConversations = managerHostname_ + PATH_CONVERSATIONS; const std::string urlConversationsRequests = managerHostname_ + PATH_CONVERSATIONS_REQUESTS; - JAMI_WARNING("[Auth] Sync conversations {}", urlConversations); + JAMI_WARNING("[Account {}] [Auth] Sync conversations {}", accountId_, urlConversations); Json::Value jsonConversations(Json::arrayValue); for (const auto& [key, convInfo] : ConversationModule::convInfos(accountId_)) { jsonConversations.append(convInfo.toJson()); @@ -403,15 +401,16 @@ ServerAccountManager::syncDevices() urlConversations, jsonConversations, [w=weak_from_this()](Json::Value json, const dht::http::Response& response) { - JAMI_DEBUG("[Auth] Got conversation sync request callback with status code={}", - response.status_code); auto this_ = std::static_pointer_cast<ServerAccountManager>(w.lock()); if (!this_) return; + JAMI_DEBUG("[Account {}] [Auth] Got conversation sync request callback with status code={}", + this_->accountId_, + response.status_code); if (response.status_code >= 200 && response.status_code < 300) { try { - JAMI_WARNING("[Auth] Got server response: {}", response.body); + JAMI_WARNING("[Account {}] [Auth] Got server response: {}", this_->accountId_, response.body); if (not json.isArray()) { - JAMI_ERROR("[Auth] Unable to parse server response: not an array"); + JAMI_ERROR("[Account {}] [Auth] Unable to parse server response: not an array", this_->accountId_); } else { SyncMsg convs; for (unsigned i = 0, n = json.size(); i < n; i++) { @@ -426,7 +425,7 @@ ServerAccountManager::syncDevices() }); } } catch (const std::exception& e) { - JAMI_ERROR("Error when iterating conversation list: {}", e.what()); + JAMI_ERROR("[Account {}] Error when iterating conversation list: {}", this_->accountId_, e.what()); } } else if (response.status_code == 401) this_->authError(TokenScope::Device); @@ -435,7 +434,7 @@ ServerAccountManager::syncDevices() }, logger_)); - JAMI_WARNING("[Auth] Sync conversations requests {}", urlConversationsRequests); + JAMI_WARNING("[Account {}] [Auth] Sync conversations requests {}", accountId_, urlConversationsRequests); Json::Value jsonConversationsRequests(Json::arrayValue); for (const auto& [key, convRequest] : ConversationModule::convRequests(accountId_)) { auto jsonConversation = convRequest.toJson(); @@ -446,15 +445,15 @@ ServerAccountManager::syncDevices() urlConversationsRequests, jsonConversationsRequests, [w=weak_from_this()](Json::Value json, const dht::http::Response& response) { - JAMI_DEBUG("[Auth] Got conversations requests sync request callback with status code={}", - response.status_code); auto this_ = std::static_pointer_cast<ServerAccountManager>(w.lock()); if (!this_) return; + JAMI_DEBUG("[Account {}] [Auth] Got conversations requests sync request callback with status code={}", + this_->accountId_, response.status_code); if (response.status_code >= 200 && response.status_code < 300) { try { - JAMI_WARNING("[Auth] Got server response: {}", response.body); + JAMI_WARNING("[Account {}] [Auth] Got server response: {}", this_->accountId_, response.body); if (not json.isArray()) { - JAMI_ERROR("[Auth] Unable to parse server response: not an array"); + JAMI_ERROR("[Account {}] [Auth] Unable to parse server response: not an array", this_->accountId_); } else { SyncMsg convReqs; for (unsigned i = 0, n = json.size(); i < n; i++) { @@ -469,7 +468,7 @@ ServerAccountManager::syncDevices() }); } } catch (const std::exception& e) { - JAMI_ERROR("Error when iterating conversations requests list: {}", e.what()); + JAMI_ERROR("[Account {}] Error when iterating conversations requests list: {}", this_->accountId_, e.what()); } } else if (response.status_code == 401) this_->authError(TokenScope::Device); @@ -478,7 +477,7 @@ ServerAccountManager::syncDevices() }, logger_)); - JAMI_WARNING("[Auth] syncContacts {}", urlContacts); + JAMI_WARNING("[Account {}] [Auth] syncContacts {}", accountId_, urlContacts); Json::Value jsonContacts(Json::arrayValue); for (const auto& contact : info_->contacts->getContacts()) { auto jsonContact = contact.second.toJson(); @@ -518,14 +517,14 @@ ServerAccountManager::syncDevices() }, logger_)); - JAMI_WARNING("[Auth] syncDevices {}", urlDevices); + JAMI_WARNING("[Account {}] [Auth] syncDevices {}", accountId_, urlDevices); sendDeviceRequest(std::make_shared<Request>( *Manager::instance().ioContext(), urlDevices, [w=weak_from_this()](Json::Value json, const dht::http::Response& response) { - JAMI_DEBUG("[Auth] Got request callback with status code={}", response.status_code); auto this_ = std::static_pointer_cast<ServerAccountManager>(w.lock()); if (!this_) return; + JAMI_DEBUG("[Account {}] [Auth] Got request callback with status code={}", this_->accountId_, response.status_code); if (response.status_code >= 200 && response.status_code < 300) { try { JAMI_WARNING("[Auth] Got server response: {}", response.body);