mirror of
https://github.com/Nheko-Reborn/nheko.git
synced 2024-11-25 20:48:52 +03:00
add loading indicator
This commit is contained in:
parent
d535cc5e75
commit
cd3f719e43
4 changed files with 46 additions and 11 deletions
|
@ -34,6 +34,12 @@ ApplicationWindow {
|
||||||
onClicked: profile.isSelf ? profile.changeAvatar() : TimelineManager.openImageOverlay(TimelineManager.timeline.avatarUrl(userid), TimelineManager.timeline.data.id)
|
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 {
|
Text {
|
||||||
id: errorText
|
id: errorText
|
||||||
text: "Error Text"
|
text: "Error Text"
|
||||||
|
@ -60,6 +66,7 @@ ApplicationWindow {
|
||||||
Connections{
|
Connections{
|
||||||
target: profile
|
target: profile
|
||||||
onDisplayError: {
|
onDisplayError: {
|
||||||
|
errorText.text = errorMessage
|
||||||
errorText.opacity = 1
|
errorText.opacity = 1
|
||||||
hideErrorAnimation.restart()
|
hideErrorAnimation.restart()
|
||||||
}
|
}
|
||||||
|
|
|
@ -803,7 +803,7 @@ TimelineModel::openUserProfile(QString userid, bool global)
|
||||||
{
|
{
|
||||||
UserProfile *userProfile = new UserProfile(global ? "" : room_id_, userid, manager_, this);
|
UserProfile *userProfile = new UserProfile(global ? "" : room_id_, userid, manager_, this);
|
||||||
connect(
|
connect(
|
||||||
this, &TimelineModel::roomAvatarUrlChanged, userProfile, &UserProfile::avatarUrlChanged);
|
this, &TimelineModel::roomAvatarUrlChanged, userProfile, &UserProfile::updateAvatarUrl);
|
||||||
emit openProfile(userProfile);
|
emit openProfile(userProfile);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -321,6 +321,9 @@ UserProfile::changeAvatar()
|
||||||
const auto payload = std::string(bin.data(), bin.size());
|
const auto payload = std::string(bin.data(), bin.size());
|
||||||
const auto dimensions = QImageReader(&file).size();
|
const auto dimensions = QImageReader(&file).size();
|
||||||
|
|
||||||
|
isLoading_ = true;
|
||||||
|
emit loadingChanged();
|
||||||
|
|
||||||
// First we need to create a new mxc URI
|
// First we need to create a new mxc URI
|
||||||
// (i.e upload media to the Matrix content repository) for the new avatar.
|
// (i.e upload media to the Matrix content repository) for the new avatar.
|
||||||
http::client()->upload(
|
http::client()->upload(
|
||||||
|
@ -342,11 +345,14 @@ UserProfile::changeAvatar()
|
||||||
|
|
||||||
if (isGlobalUserProfile()) {
|
if (isGlobalUserProfile()) {
|
||||||
http::client()->set_avatar_url(
|
http::client()->set_avatar_url(
|
||||||
res.content_uri, [](mtx::http::RequestErr err) {
|
res.content_uri, [this](mtx::http::RequestErr err) {
|
||||||
if (err) {
|
if (err) {
|
||||||
nhlog::ui()->error("Failed to set user avatar url",
|
nhlog::ui()->error("Failed to set user avatar url",
|
||||||
err->matrix_error.error);
|
err->matrix_error.error);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
isLoading_ = false;
|
||||||
|
emit loadingChanged();
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
// change room username
|
// change room username
|
||||||
|
@ -363,13 +369,28 @@ UserProfile::changeAvatar()
|
||||||
void
|
void
|
||||||
UserProfile::updateRoomMemberState(mtx::events::state::Member member)
|
UserProfile::updateRoomMemberState(mtx::events::state::Member member)
|
||||||
{
|
{
|
||||||
http::client()->send_state_event(roomid_.toStdString(),
|
http::client()->send_state_event(
|
||||||
|
roomid_.toStdString(),
|
||||||
http::client()->user_id().to_string(),
|
http::client()->user_id().to_string(),
|
||||||
member,
|
member,
|
||||||
[](mtx::responses::EventId, mtx::http::RequestErr err) {
|
[this](mtx::responses::EventId, mtx::http::RequestErr err) {
|
||||||
if (err)
|
if (err)
|
||||||
nhlog::net()->error(
|
nhlog::net()->error("Failed to update room member state : ",
|
||||||
"Failed to update room member state : ",
|
|
||||||
err->matrix_error.error);
|
err->matrix_error.error);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
UserProfile::updateAvatarUrl()
|
||||||
|
{
|
||||||
|
isLoading_ = false;
|
||||||
|
emit loadingChanged();
|
||||||
|
|
||||||
|
emit avatarUrlChanged();
|
||||||
|
}
|
||||||
|
|
||||||
|
bool
|
||||||
|
UserProfile::isLoading() const
|
||||||
|
{
|
||||||
|
return isLoading_;
|
||||||
|
}
|
|
@ -87,6 +87,7 @@ class UserProfile : public QObject
|
||||||
Q_PROPERTY(DeviceInfoModel *deviceList READ deviceList CONSTANT)
|
Q_PROPERTY(DeviceInfoModel *deviceList READ deviceList CONSTANT)
|
||||||
Q_PROPERTY(bool isGlobalUserProfile READ isGlobalUserProfile CONSTANT)
|
Q_PROPERTY(bool isGlobalUserProfile READ isGlobalUserProfile CONSTANT)
|
||||||
Q_PROPERTY(bool isUserVerified READ getUserStatus NOTIFY userStatusChanged)
|
Q_PROPERTY(bool isUserVerified READ getUserStatus NOTIFY userStatusChanged)
|
||||||
|
Q_PROPERTY(bool isLoading READ isLoading NOTIFY loadingChanged)
|
||||||
Q_PROPERTY(
|
Q_PROPERTY(
|
||||||
bool userVerificationEnabled READ userVerificationEnabled NOTIFY userStatusChanged)
|
bool userVerificationEnabled READ userVerificationEnabled NOTIFY userStatusChanged)
|
||||||
Q_PROPERTY(bool isSelf READ isSelf CONSTANT)
|
Q_PROPERTY(bool isSelf READ isSelf CONSTANT)
|
||||||
|
@ -105,6 +106,7 @@ public:
|
||||||
bool getUserStatus();
|
bool getUserStatus();
|
||||||
bool userVerificationEnabled() const;
|
bool userVerificationEnabled() const;
|
||||||
bool isSelf() const;
|
bool isSelf() const;
|
||||||
|
bool isLoading() const;
|
||||||
|
|
||||||
Q_INVOKABLE void verify(QString device = "");
|
Q_INVOKABLE void verify(QString device = "");
|
||||||
Q_INVOKABLE void unverify(QString device = "");
|
Q_INVOKABLE void unverify(QString device = "");
|
||||||
|
@ -118,11 +120,15 @@ public:
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void userStatusChanged();
|
void userStatusChanged();
|
||||||
|
void loadingChanged();
|
||||||
void displayNameChanged();
|
void displayNameChanged();
|
||||||
void avatarUrlChanged();
|
void avatarUrlChanged();
|
||||||
void displayError(const QString &errorMessage);
|
void displayError(const QString &errorMessage);
|
||||||
void globalUsernameRetrieved(const QString &globalUser);
|
void globalUsernameRetrieved(const QString &globalUser);
|
||||||
|
|
||||||
|
public slots:
|
||||||
|
void updateAvatarUrl();
|
||||||
|
|
||||||
protected slots:
|
protected slots:
|
||||||
void setGlobalUsername(const QString &globalUser);
|
void setGlobalUsername(const QString &globalUser);
|
||||||
|
|
||||||
|
@ -135,6 +141,7 @@ private:
|
||||||
DeviceInfoModel deviceList_;
|
DeviceInfoModel deviceList_;
|
||||||
bool isUserVerified = false;
|
bool isUserVerified = false;
|
||||||
bool hasMasterKey = false;
|
bool hasMasterKey = false;
|
||||||
|
bool isLoading_ = false;
|
||||||
TimelineViewManager *manager;
|
TimelineViewManager *manager;
|
||||||
TimelineModel *model;
|
TimelineModel *model;
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in a new issue