summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorJedi18 <targetakhil@gmail.com>2021-02-02 17:24:08 +0530
committerJedi18 <targetakhil@gmail.com>2021-02-02 17:24:08 +0530
commitcd3f719e43e06749a09a8e9eff20c4f2a0615742 (patch)
treefd1dfa75ad43cc51f691f4f3f6a84565898b028d /src
parentadd error message and update avatars on avatar change in timeline and user pr... (diff)
downloadnheko-cd3f719e43e06749a09a8e9eff20c4f2a0615742.tar.xz
add loading indicator
Diffstat (limited to 'src')
-rw-r--r--src/timeline/TimelineModel.cpp2
-rw-r--r--src/ui/UserProfile.cpp41
-rw-r--r--src/ui/UserProfile.h7
3 files changed, 39 insertions, 11 deletions
diff --git a/src/timeline/TimelineModel.cpp b/src/timeline/TimelineModel.cpp
index a4d551f5..968ec3c7 100644
--- a/src/timeline/TimelineModel.cpp
+++ b/src/timeline/TimelineModel.cpp
@@ -803,7 +803,7 @@ TimelineModel::openUserProfile(QString userid, bool global)
 {
         UserProfile *userProfile = new UserProfile(global ? "" : room_id_, userid, manager_, this);
         connect(
-          this, &TimelineModel::roomAvatarUrlChanged, userProfile, &UserProfile::avatarUrlChanged);
+          this, &TimelineModel::roomAvatarUrlChanged, userProfile, &UserProfile::updateAvatarUrl);
         emit openProfile(userProfile);
 }
 
diff --git a/src/ui/UserProfile.cpp b/src/ui/UserProfile.cpp
index e260c924..a3715fee 100644
--- a/src/ui/UserProfile.cpp
+++ b/src/ui/UserProfile.cpp
@@ -321,6 +321,9 @@ UserProfile::changeAvatar()
         const auto payload    = std::string(bin.data(), bin.size());
         const auto dimensions = QImageReader(&file).size();
 
+        isLoading_ = true;
+        emit loadingChanged();
+
         // First we need to create a new mxc URI
         // (i.e upload media to the Matrix content repository) for the new avatar.
         http::client()->upload(
@@ -342,11 +345,14 @@ UserProfile::changeAvatar()
 
                   if (isGlobalUserProfile()) {
                           http::client()->set_avatar_url(
-                            res.content_uri, [](mtx::http::RequestErr err) {
+                            res.content_uri, [this](mtx::http::RequestErr err) {
                                     if (err) {
                                             nhlog::ui()->error("Failed to set user avatar url",
                                                                err->matrix_error.error);
                                     }
+
+                                    isLoading_ = false;
+                                    emit loadingChanged();
                             });
                   } else {
                           // change room username
@@ -363,13 +369,28 @@ UserProfile::changeAvatar()
 void
 UserProfile::updateRoomMemberState(mtx::events::state::Member member)
 {
-        http::client()->send_state_event(roomid_.toStdString(),
-                                         http::client()->user_id().to_string(),
-                                         member,
-                                         [](mtx::responses::EventId, mtx::http::RequestErr err) {
-                                                 if (err)
-                                                         nhlog::net()->error(
-                                                           "Failed to update room member state : ",
-                                                           err->matrix_error.error);
-                                         });
+        http::client()->send_state_event(
+          roomid_.toStdString(),
+          http::client()->user_id().to_string(),
+          member,
+          [this](mtx::responses::EventId, mtx::http::RequestErr err) {
+                  if (err)
+                          nhlog::net()->error("Failed to update room member state : ",
+                                              err->matrix_error.error);
+          });
+}
+
+void
+UserProfile::updateAvatarUrl()
+{
+        isLoading_ = false;
+        emit loadingChanged();
+
+        emit avatarUrlChanged();
+}
+
+bool
+UserProfile::isLoading() const
+{
+        return isLoading_;
 }
\ No newline at end of file
diff --git a/src/ui/UserProfile.h b/src/ui/UserProfile.h
index 9f48f935..58fb0f0b 100644
--- a/src/ui/UserProfile.h
+++ b/src/ui/UserProfile.h
@@ -87,6 +87,7 @@ class UserProfile : public QObject
         Q_PROPERTY(DeviceInfoModel *deviceList READ deviceList CONSTANT)
         Q_PROPERTY(bool isGlobalUserProfile READ isGlobalUserProfile CONSTANT)
         Q_PROPERTY(bool isUserVerified READ getUserStatus NOTIFY userStatusChanged)
+        Q_PROPERTY(bool isLoading READ isLoading NOTIFY loadingChanged)
         Q_PROPERTY(
           bool userVerificationEnabled READ userVerificationEnabled NOTIFY userStatusChanged)
         Q_PROPERTY(bool isSelf READ isSelf CONSTANT)
@@ -105,6 +106,7 @@ public:
         bool getUserStatus();
         bool userVerificationEnabled() const;
         bool isSelf() const;
+        bool isLoading() const;
 
         Q_INVOKABLE void verify(QString device = "");
         Q_INVOKABLE void unverify(QString device = "");
@@ -118,11 +120,15 @@ public:
 
 signals:
         void userStatusChanged();
+        void loadingChanged();
         void displayNameChanged();
         void avatarUrlChanged();
         void displayError(const QString &errorMessage);
         void globalUsernameRetrieved(const QString &globalUser);
 
+public slots:
+        void updateAvatarUrl();
+
 protected slots:
         void setGlobalUsername(const QString &globalUser);
 
@@ -135,6 +141,7 @@ private:
         DeviceInfoModel deviceList_;
         bool isUserVerified = false;
         bool hasMasterKey   = false;
+        bool isLoading_     = false;
         TimelineViewManager *manager;
         TimelineModel *model;
 };