From 16133a060219e684aa78c387a69aa41ce8dc4875 Mon Sep 17 00:00:00 2001
From: Adrien Beraud <adrien.beraud@savoirfairelinux.com>
Date: Tue, 6 Jun 2017 14:14:05 +0200
Subject: [PATCH] ringaccount: save registered name in configuration

Use the account configuration to store the registered name,
allowing to know the account registered name for disabled accounts,
before account registration happens,
or if the name server is not reachable and the name cache
was cleared.

This allows to show the account registered name instead of
the RingID more consistently in clients. The field is not
authoritative as information from the name server always
take precedence.

Change-Id: Ief8725da57d609ce9bbaeda6b2d564638ea3b191
---
 src/ringdht/ringaccount.cpp | 9 +++++++++
 1 file changed, 9 insertions(+)

diff --git a/src/ringdht/ringaccount.cpp b/src/ringdht/ringaccount.cpp
index 03a3f6c731..21c6b0fb1c 100644
--- a/src/ringdht/ringaccount.cpp
+++ b/src/ringdht/ringaccount.cpp
@@ -716,6 +716,8 @@ void RingAccount::serialize(YAML::Emitter &out)
     out << YAML::Key << Conf::RING_ACCOUNT_RECEIPT << YAML::Value << receipt_;
     out << YAML::Key << Conf::RING_ACCOUNT_RECEIPT_SIG << YAML::Value << YAML::Binary(receiptSignature_.data(), receiptSignature_.size());
     out << YAML::Key << DRing::Account::ConfProperties::RING_DEVICE_NAME << YAML::Value << ringDeviceName_;
+    if (not registeredName_.empty())
+        out << YAML::Key << DRing::Account::VolatileProperties::REGISTERED_NAME << YAML::Value << registeredName_;
 
     // tls submap
     out << YAML::Key << Conf::TLS_KEY << YAML::Value << YAML::BeginMap;
@@ -747,6 +749,13 @@ void RingAccount::unserialize(const YAML::Node &node)
     } catch (const std::exception& e) {
         RING_WARN("can't read device name: %s", e.what());
     }
+    if (registeredName_.empty()) {
+        try {
+            parseValue(node, DRing::Account::VolatileProperties::REGISTERED_NAME, registeredName_);
+        } catch (const std::exception& e) {
+            RING_WARN("can't read device name: %s", e.what());
+        }
+    }
 
     try {
         parsePath(node, DRing::Account::ConfProperties::ARCHIVE_PATH, archivePath_, idPath_);
-- 
GitLab