add loading indicator

This commit is contained in:
Jedi18 2021-02-02 17:24:08 +05:30
parent d535cc5e75
commit cd3f719e43
4 changed files with 46 additions and 11 deletions

View file

@ -34,6 +34,12 @@ ApplicationWindow {
onClicked: profile.isSelf ? profile.changeAvatar() : TimelineManager.openImageOverlay(TimelineManager.timeline.avatarUrl(userid), TimelineManager.timeline.data.id)
}
BusyIndicator {
Layout.alignment: Qt.AlignHCenter
running: profile.isLoading
visible: profile.isLoading
}
Text {
id: errorText
text: "Error Text"
@ -60,6 +66,7 @@ ApplicationWindow {
Connections{
target: profile
onDisplayError: {
errorText.text = errorMessage
errorText.opacity = 1
hideErrorAnimation.restart()
}

View file

@ -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);
}

View file

@ -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_;
}

View file

@ -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;
};