summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--src/timeline/TimelineModel.cpp15
-rw-r--r--src/timeline/TimelineModel.h1
-rw-r--r--src/ui/UserProfile.cpp29
-rw-r--r--src/ui/UserProfile.h10
4 files changed, 34 insertions, 21 deletions
diff --git a/src/timeline/TimelineModel.cpp b/src/timeline/TimelineModel.cpp
index a25e77fd..73077508 100644
--- a/src/timeline/TimelineModel.cpp
+++ b/src/timeline/TimelineModel.cpp
@@ -22,7 +22,6 @@
 #include "TimelineViewManager.h"
 #include "Utils.h"
 #include "dialogs/RawMessage.h"
-#include <mtx/responses.hpp>
 
 Q_DECLARE_METATYPE(QModelIndex)
 
@@ -261,17 +260,6 @@ TimelineModel::TimelineModel(TimelineViewManager *manager, QString room_id, QObj
         connect(&events, &EventStore::updateFlowEventId, this, [this](std::string event_id) {
                 this->updateFlowEventId(event_id);
         });
-
-        const auto userid = utils::localUser().toStdString();
-        http::client()->get_profile(
-          userid, [this](const mtx::responses::Profile &res, mtx::http::RequestErr err) {
-                  if (err) {
-                          nhlog::net()->warn("failed to retrieve own profile info");
-                          return;
-                  }
-
-                  globalUsername = QString::fromStdString(res.display_name);
-          });
 }
 
 QHash<int, QByteArray>
@@ -814,8 +802,7 @@ void
 TimelineModel::openUserProfile(QString userid, bool global)
 {
         if (global) {
-                emit openProfile(
-                  new UserProfile("", utils::localUser(), manager_, this, globalUsername));
+                emit openProfile(new UserProfile("", utils::localUser(), manager_, this));
         } else {
                 emit openProfile(new UserProfile(room_id_, userid, manager_, this));
         }
diff --git a/src/timeline/TimelineModel.h b/src/timeline/TimelineModel.h
index e6cb7d3a..51b8049e 100644
--- a/src/timeline/TimelineModel.h
+++ b/src/timeline/TimelineModel.h
@@ -317,7 +317,6 @@ private:
         mutable EventStore events;
 
         QString room_id_;
-        QString globalUsername;
 
         bool decryptDescription     = true;
         bool m_paginationInProgress = false;
diff --git a/src/ui/UserProfile.cpp b/src/ui/UserProfile.cpp
index 28757b72..df404494 100644
--- a/src/ui/UserProfile.cpp
+++ b/src/ui/UserProfile.cpp
@@ -8,18 +8,17 @@
 #include "timeline/TimelineModel.h"
 #include "timeline/TimelineViewManager.h"
 #include <mtx/responses/common.hpp>
+#include <mtx/responses.hpp>
 
 UserProfile::UserProfile(QString roomid,
                          QString userid,
                          TimelineViewManager *manager_,
-                         TimelineModel *parent,
-                         QString globalUsername)
+                         TimelineModel *parent)
   : QObject(parent)
   , roomid_(roomid)
   , userid_(userid)
   , manager(manager_)
   , model(parent)
-  , globalUsername(globalUsername)
 {
         fetchDeviceList(this->userid_);
 
@@ -47,6 +46,23 @@ UserProfile::UserProfile(QString roomid,
                         }
                         deviceList_.reset(deviceList_.deviceList_);
                 });
+
+        connect(this,
+                &UserProfile::globalUsernameRetrieved,
+                this,
+                &UserProfile::setGlobalUsername,
+                Qt::QueuedConnection);
+
+        http::client()->get_profile(
+          userid_.toStdString(),
+          [this](const mtx::responses::Profile &res, mtx::http::RequestErr err) {
+                  if (err) {
+                          nhlog::net()->warn("failed to retrieve own profile info");
+                          return;
+                  }
+
+                  emit globalUsernameRetrieved(QString::fromStdString(res.display_name));
+          });
 }
 
 QHash<int, QByteArray>
@@ -286,3 +302,10 @@ UserProfile::isUsernameEditingAllowed() const
 {
         return usernameEditing;
 }
+
+void
+UserProfile::setGlobalUsername(const QString& globalUser)
+{
+        globalUsername = globalUser;
+        emit displayNameChanged();
+}
\ No newline at end of file
diff --git a/src/ui/UserProfile.h b/src/ui/UserProfile.h
index b1172077..2a674732 100644
--- a/src/ui/UserProfile.h
+++ b/src/ui/UserProfile.h
@@ -79,7 +79,7 @@ private:
 class UserProfile : public QObject
 {
         Q_OBJECT
-        Q_PROPERTY(QString displayName READ displayName CONSTANT)
+        Q_PROPERTY(QString displayName READ displayName NOTIFY displayNameChanged)
         Q_PROPERTY(QString userid READ userid CONSTANT)
         Q_PROPERTY(QString avatarUrl READ avatarUrl CONSTANT)
         Q_PROPERTY(DeviceInfoModel *deviceList READ deviceList CONSTANT)
@@ -94,8 +94,7 @@ public:
         UserProfile(QString roomid,
                     QString userid,
                     TimelineViewManager *manager_,
-                    TimelineModel *parent  = nullptr,
-                    QString globalUsername = "");
+                    TimelineModel *parent = nullptr);
 
         DeviceInfoModel *deviceList();
 
@@ -121,6 +120,11 @@ public:
 signals:
         void userStatusChanged();
         void usernameEditingChanged();
+        void displayNameChanged();
+        void globalUsernameRetrieved(const QString& globalUser);
+
+protected slots:
+        void setGlobalUsername(const QString &globalUser);
 
 private:
         QString roomid_, userid_;