From 93846bfa5749af56c02341b514130aa0a41b7b84 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Blin?= <sebastien.blin@savoirfairelinux.com> Date: Mon, 23 Apr 2018 17:34:39 -0400 Subject: [PATCH] sendTextMessage: take into account payload type Currently, the daemon lie a bit about sendTextMessage. Indeed, it takes a map (string, string) like {{datatype: msg}} but the datatype is ignored. It can be problematic if a client wants to manipulate a custom datatype because the daemon will replace the datatype by "plain/text". Now, an ImMessage can have a datatype which permits to not lie in the api and manipulate the datatype the user wants. Change-Id: I1ec5a34082337570bf43231078fc894304b00182 Reviewed-by: Philippe Gorley <philippe.gorley@savoirfairelinux.com> --- src/ringdht/ringaccount.cpp | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/ringdht/ringaccount.cpp b/src/ringdht/ringaccount.cpp index 0898495a67..61f9f450af 100644 --- a/src/ringdht/ringaccount.cpp +++ b/src/ringdht/ringaccount.cpp @@ -2256,8 +2256,12 @@ RingAccount::doRegister_() const dht::InfoHash& peer_account) { auto now = clock::to_time_t(clock::now()); - std::map<std::string, std::string> payloads = {{"text/plain", - utf8_make_valid(v.msg)}}; + std::string datatype = utf8_make_valid(v.datatype); + if (datatype.empty()) { + datatype = "text/plain"; + } + std::map<std::string, std::string> payloads = {{datatype, + utf8_make_valid(v.msg)}}; shared->onTextMessage(peer_account.toString(), payloads); RING_DBG("Sending message confirmation %" PRIx64, v.id); shared->dht_.putEncrypted(inboxDeviceKey, @@ -3351,7 +3355,7 @@ RingAccount::sendTextMessage(const std::string& to, const std::map<std::string, }); confirm->listenTokens.emplace(h, std::move(list_token)); shared->dht_.putEncrypted(h, dev, - dht::ImMessage(token, std::string(payloads.begin()->second), now), + dht::ImMessage(token, std::string(payloads.begin()->first), std::string(payloads.begin()->second), now), [wshared,token,confirm,h](bool ok) { if (auto this_ = wshared.lock()) { RING_DBG("[Account %s] [message %" PRIx64 "] put encrypted %s", this_->getAccountID().c_str(), token, ok ? "ok" : "failed"); -- GitLab