diff --git a/include/UserInfoWidget.h b/include/UserInfoWidget.h index 15837cd5..e58cab60 100644 --- a/include/UserInfoWidget.h +++ b/include/UserInfoWidget.h @@ -57,7 +57,7 @@ private: QLabel *userIdLabel_; QString display_name_; - QString userid_; + QString user_id_; QImage avatar_image_; }; diff --git a/src/ChatPage.cc b/src/ChatPage.cc index 25073eac..b1c4e890 100644 --- a/src/ChatPage.cc +++ b/src/ChatPage.cc @@ -234,7 +234,8 @@ void ChatPage::updateOwnProfileInfo(const QUrl &avatar_url, const QString &displ user_info_widget_->setUserId(userid); user_info_widget_->setDisplayName(display_name); - client_->fetchOwnAvatar(avatar_url); + if (avatar_url.isValid()) + client_->fetchOwnAvatar(avatar_url); } void ChatPage::changeTopRoomInfo(const QString &room_id) diff --git a/src/Profile.cc b/src/Profile.cc index 86089bee..37def4c7 100644 --- a/src/Profile.cc +++ b/src/Profile.cc @@ -29,12 +29,9 @@ void ProfileResponse::deserialize(const QJsonDocument &data) QJsonObject object = data.object(); - if (object.value("avatar_url") == QJsonValue::Undefined) - throw DeserializationException("Missing avatar_url param"); + if (object.contains("avatar_url")) + avatar_url_ = QUrl(object.value("avatar_url").toString()); - if (object.value("displayname") == QJsonValue::Undefined) - throw DeserializationException("Missing displayname param"); - - avatar_url_ = QUrl(object.value("avatar_url").toString()); - display_name_ = object.value("displayname").toString(); + if (object.contains("displayname")) + display_name_ = object.value("displayname").toString(); } diff --git a/src/UserInfoWidget.cc b/src/UserInfoWidget.cc index 9a50145d..82ff822f 100644 --- a/src/UserInfoWidget.cc +++ b/src/UserInfoWidget.cc @@ -21,7 +21,7 @@ UserInfoWidget::UserInfoWidget(QWidget *parent) : QWidget(parent) , display_name_("User") - , userid_("@user:homeserver.org") + , user_id_("@user:homeserver.org") { QSizePolicy sizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Fixed); setSizePolicy(sizePolicy); @@ -36,8 +36,9 @@ UserInfoWidget::UserInfoWidget(QWidget *parent) userAvatar_ = new Avatar(this); userAvatar_->setLetter(QChar('?')); - userAvatar_->setSize(50); - userAvatar_->setMaximumSize(QSize(55, 55)); + userAvatar_->setSize(55); + userAvatar_->setBackgroundColor("#f9f9f9"); + userAvatar_->setTextColor("#333333"); displayNameLabel_ = new QLabel(this); displayNameLabel_->setStyleSheet( @@ -102,12 +103,17 @@ void UserInfoWidget::setAvatar(const QImage &img) void UserInfoWidget::setDisplayName(const QString &name) { - display_name_ = name; - displayNameLabel_->setText(name); + if (name.isEmpty()) + display_name_ = user_id_.split(':')[0].split('@')[1]; + else + display_name_ = name; + + displayNameLabel_->setText(display_name_); + userAvatar_->setLetter(QChar(display_name_[0])); } void UserInfoWidget::setUserId(const QString &userid) { - userid_ = userid; + user_id_ = userid; userIdLabel_->setText(userid); }