From 53797a320eb89cf2725a7b30029aa52880a80afd Mon Sep 17 00:00:00 2001
From: philippegorley <philippe.gorley@savoirfairelinux.com>
Date: Wed, 6 Jun 2018 12:34:35 -0400
Subject: [PATCH] account: get user uri

Ring account: returns the registered name or falls back on ring id
SIP account: returns the account's sip uri

Change-Id: I9bc2fa579dde41b8ee9378e2b56681db1d6aaeda
---
 src/ringdht/ringaccount.cpp | 9 +++++++++
 src/ringdht/ringaccount.h   | 2 ++
 src/sip/sipaccount.cpp      | 6 ++++++
 src/sip/sipaccount.h        | 2 ++
 src/sip/sipaccountbase.h    | 2 ++
 5 files changed, 21 insertions(+)

diff --git a/src/ringdht/ringaccount.cpp b/src/ringdht/ringaccount.cpp
index 110b9c4b64..a5d84e69d2 100644
--- a/src/ringdht/ringaccount.cpp
+++ b/src/ringdht/ringaccount.cpp
@@ -3457,5 +3457,14 @@ void RingAccount::pushNotificationReceived(const std::string& from, const std::m
     dht_.pushNotificationReceived(data);
 }
 
+std::string
+RingAccount::getUserUri() const
+{
+#ifdef HAVE_RINGNS
+    if (not registeredName_.empty())
+        return RING_URI_PREFIX + registeredName_;
+#endif
+    return username_;
+}
 
 } // namespace ring
diff --git a/src/ringdht/ringaccount.h b/src/ringdht/ringaccount.h
index 5d9c8907ab..d6021a78c4 100644
--- a/src/ringdht/ringaccount.h
+++ b/src/ringdht/ringaccount.h
@@ -376,6 +376,8 @@ class RingAccount : public SIPAccountBase {
          */
         void pushNotificationReceived(const std::string& from, const std::map<std::string, std::string>& data);
 
+        std::string getUserUri() const override;
+
     private:
         NON_COPYABLE(RingAccount);
 
diff --git a/src/sip/sipaccount.cpp b/src/sip/sipaccount.cpp
index 73f64ae6f7..7f94a6c8d5 100644
--- a/src/sip/sipaccount.cpp
+++ b/src/sip/sipaccount.cpp
@@ -2101,4 +2101,10 @@ SIPAccount::sendTextMessage(const std::string& to, const std::map<std::string, s
     }
 }
 
+std::string
+SIPAccount::getUserUri() const
+{
+    return getFromUri();
+}
+
 } // namespace ring
diff --git a/src/sip/sipaccount.h b/src/sip/sipaccount.h
index e6f594d992..7f5d2d57ff 100644
--- a/src/sip/sipaccount.h
+++ b/src/sip/sipaccount.h
@@ -494,6 +494,8 @@ class SIPAccount : public SIPAccountBase {
 
         void connectivityChanged() override;
 
+        std::string getUserUri() const override;
+
     private:
         void doRegister1_();
         void doRegister2_();
diff --git a/src/sip/sipaccountbase.h b/src/sip/sipaccountbase.h
index 4b1e9e5686..a1ecedcb30 100644
--- a/src/sip/sipaccountbase.h
+++ b/src/sip/sipaccountbase.h
@@ -274,6 +274,8 @@ public:
 
     void connectivityChanged() override {};
 
+    virtual std::string getUserUri() const = 0;
+
 public: // overloaded methods
     virtual void flush() override;
 
-- 
GitLab