diff --git a/src/jamidht/conversation.cpp b/src/jamidht/conversation.cpp index 05f2c46fb754acdbddc12d86137a5c19017e526c..0c44edcebe255841509caaab400f5ae63e9e6da6 100644 --- a/src/jamidht/conversation.cpp +++ b/src/jamidht/conversation.cpp @@ -702,16 +702,17 @@ void Conversation::sendMessage(std::string&& message, const std::string& type, const std::string& replyTo, + OnCommitCb&& onCommit, OnDoneCb&& cb) { Json::Value json; json["body"] = std::move(message); json["type"] = type; - sendMessage(std::move(json), replyTo, std::move(cb)); + sendMessage(std::move(json), replyTo, std::move(onCommit), std::move(cb)); } void -Conversation::sendMessage(Json::Value&& value, const std::string& replyTo, OnDoneCb&& cb) +Conversation::sendMessage(Json::Value&& value, const std::string& replyTo, OnCommitCb&& onCommit, OnDoneCb&& cb) { if (!replyTo.empty()) { auto commit = pimpl_->repository_->getCommit(replyTo); @@ -721,7 +722,7 @@ Conversation::sendMessage(Json::Value&& value, const std::string& replyTo, OnDon } value["reply-to"] = replyTo; } - dht::ThreadPool::io().run([w = weak(), value = std::move(value), cb = std::move(cb)] { + dht::ThreadPool::io().run([w = weak(), value = std::move(value), onCommit=std::move(onCommit), cb = std::move(cb)] { if (auto sthis = w.lock()) { auto acc = sthis->pimpl_->account_.lock(); if (!acc) @@ -736,6 +737,8 @@ Conversation::sendMessage(Json::Value&& value, const std::string& replyTo, OnDon sthis->pimpl_->saveSending(); sthis->clearFetched(); lk.unlock(); + if (onCommit) + onCommit(commit); sthis->pimpl_->announce(commit); emitSignal<DRing::ConfigurationSignal::AccountMessageStatusChanged>( acc->getAccountID(), diff --git a/src/jamidht/conversation.h b/src/jamidht/conversation.h index 0c6003f07f7630759ecb4480e1f65222923643a9..71798d284f3752afcc946e3bff3b2cc1fad2b1fe 100644 --- a/src/jamidht/conversation.h +++ b/src/jamidht/conversation.h @@ -106,6 +106,7 @@ enum class ConversationMode; using OnPullCb = std::function<void(bool fetchOk)>; using OnLoadMessages = std::function<void(std::vector<std::map<std::string, std::string>>&& messages)>; +using OnCommitCb = std::function<void(const std::string&)>; using OnDoneCb = std::function<void(bool, const std::string&)>; using OnMultiDoneCb = std::function<void(const std::vector<std::string>&)>; @@ -182,8 +183,9 @@ public: void sendMessage(std::string&& message, const std::string& type = "text/plain", const std::string& replyTo = "", + OnCommitCb&& onCommit = {}, OnDoneCb&& cb = {}); - void sendMessage(Json::Value&& message, const std::string& replyTo = "", OnDoneCb&& cb = {}); + void sendMessage(Json::Value&& message, const std::string& replyTo = "", OnCommitCb&& onCommit = {}, OnDoneCb&& cb = {}); // Note: used for replay. Should not be used by clients void sendMessages(std::vector<Json::Value>&& messages, OnMultiDoneCb&& cb = {}); /** diff --git a/src/jamidht/conversation_module.cpp b/src/jamidht/conversation_module.cpp index 382d5b75a349871d63479be27bdfd55553d0286d..970cc709753d3b94ffe28dbebd92b4b73f954829 100644 --- a/src/jamidht/conversation_module.cpp +++ b/src/jamidht/conversation_module.cpp @@ -216,6 +216,7 @@ public: Json::Value&& value, const std::string& replyTo = "", bool announce = true, + OnCommitCb&& onCommit = {}, OnDoneCb&& cb = {}); void sendMessage(const std::string& conversationId, @@ -223,6 +224,7 @@ public: const std::string& replyTo = "", const std::string& type = "text/plain", bool announce = true, + OnCommitCb&& onCommit = {}, OnDoneCb&& cb = {}); // The following informations are stored on the disk @@ -518,7 +520,7 @@ ConversationModule::Impl::handlePendingConversation(const std::string& conversat try { auto conversation = std::make_shared<Conversation>(account_, deviceId, conversationId); conversation->onLastDisplayedUpdated( - std::move([&](auto convId, auto lastId) { onLastDisplayedUpdated(convId, lastId); })); + [&](auto convId, auto lastId) { onLastDisplayedUpdated(convId, lastId); }); if (!conversation->isMember(username_, true)) { JAMI_ERR("Conversation cloned but doesn't seems to be a valid member"); conversation->erase(); @@ -797,12 +799,13 @@ ConversationModule::Impl::sendMessage(const std::string& conversationId, const std::string& replyTo, const std::string& type, bool announce, + OnCommitCb&& onCommit, OnDoneCb&& cb) { Json::Value json; json["body"] = std::move(message); json["type"] = type; - sendMessage(conversationId, std::move(json), replyTo, announce, std::move(cb)); + sendMessage(conversationId, std::move(json), replyTo, announce, std::move(onCommit), std::move(cb)); } void @@ -810,6 +813,7 @@ ConversationModule::Impl::sendMessage(const std::string& conversationId, Json::Value&& value, const std::string& replyTo, bool announce, + OnCommitCb&& onCommit, OnDoneCb&& cb) { std::lock_guard<std::mutex> lk(conversationsMtx_); @@ -818,6 +822,7 @@ ConversationModule::Impl::sendMessage(const std::string& conversationId, conversation->second->sendMessage( std::move(value), replyTo, + std::move(onCommit), [this, conversationId, announce, cb = std::move(cb)](bool ok, const std::string& commitId) { if (cb) @@ -900,8 +905,8 @@ ConversationModule::loadConversations() for (const auto& repository : conversationsRepositories) { try { auto conv = std::make_shared<Conversation>(pimpl_->account_, repository); - conv->onLastDisplayedUpdated(std::move( - [&](auto convId, auto lastId) { pimpl_->onLastDisplayedUpdated(convId, lastId); })); + conv->onLastDisplayedUpdated( + [&](auto convId, auto lastId) { pimpl_->onLastDisplayedUpdated(convId, lastId); }); auto convInfo = pimpl_->convInfos_.find(repository); if (convInfo == pimpl_->convInfos_.end()) { JAMI_ERR() << "Missing conv info for " << repository << ". This is a bug!"; @@ -1134,8 +1139,8 @@ ConversationModule::startConversation(ConversationMode mode, const std::string& std::shared_ptr<Conversation> conversation; try { conversation = std::make_shared<Conversation>(pimpl_->account_, mode, otherMember); - conversation->onLastDisplayedUpdated(std::move( - [&](auto convId, auto lastId) { pimpl_->onLastDisplayedUpdated(convId, lastId); })); + conversation->onLastDisplayedUpdated( + [&](auto convId, auto lastId) { pimpl_->onLastDisplayedUpdated(convId, lastId); }); } catch (const std::exception& e) { JAMI_ERR("[Account %s] Error while generating a conversation %s", pimpl_->accountId_.c_str(), @@ -1225,9 +1230,10 @@ ConversationModule::sendMessage(const std::string& conversationId, const std::string& replyTo, const std::string& type, bool announce, + OnCommitCb&& onCommit, OnDoneCb&& cb) { - pimpl_->sendMessage(conversationId, std::move(message), replyTo, type, announce, std::move(cb)); + pimpl_->sendMessage(conversationId, std::move(message), replyTo, type, announce, std::move(onCommit), std::move(cb)); } void @@ -1235,9 +1241,10 @@ ConversationModule::sendMessage(const std::string& conversationId, Json::Value&& value, const std::string& replyTo, bool announce, + OnCommitCb&& onCommit, OnDoneCb&& cb) { - pimpl_->sendMessage(conversationId, std::move(value), replyTo, announce, std::move(cb)); + pimpl_->sendMessage(conversationId, std::move(value), replyTo, announce, std::move(onCommit), std::move(cb)); } void diff --git a/src/jamidht/conversation_module.h b/src/jamidht/conversation_module.h index 20c4c803e5d314a17bd187960219d0a4ddbe8bed..068a03f1aa08f019210f7e2a334933f57f23fefa 100644 --- a/src/jamidht/conversation_module.h +++ b/src/jamidht/conversation_module.h @@ -149,6 +149,7 @@ public: Json::Value&& value, const std::string& replyTo = "", bool announce = true, + OnCommitCb&& onCommit = {}, OnDoneCb&& cb = {}); void sendMessage(const std::string& conversationId, @@ -156,6 +157,7 @@ public: const std::string& replyTo = "", const std::string& type = "text/plain", bool announce = true, + OnCommitCb&& onCommit = {}, OnDoneCb&& cb = {}); /** diff --git a/src/jamidht/jamiaccount.cpp b/src/jamidht/jamiaccount.cpp index 7cec47c9d25a3d45848d2f74791571a90bf1af94..c6dbeb089d5f8d493f4a0853b5b73617edc70d43 100644 --- a/src/jamidht/jamiaccount.cpp +++ b/src/jamidht/jamiaccount.cpp @@ -4259,7 +4259,7 @@ JamiAccount::sendFile(const std::string& conversationId, [accId = shared->getAccountID(), conversationId, tid, - path](bool, const std::string& commitId) { + path](const std::string& commitId) { // Create a symlink to answer to re-ask auto filelinkPath = fileutils::get_data_dir() + DIR_SEPARATOR_STR + accId + DIR_SEPARATOR_STR