Show user info even if the display name or avatar are missing

This commit is contained in:
Konstantinos Sideris 2017-05-16 15:43:29 +03:00
parent 49831a2390
commit 992af5611b
4 changed files with 19 additions and 15 deletions

View file

@ -57,7 +57,7 @@ private:
QLabel *userIdLabel_; QLabel *userIdLabel_;
QString display_name_; QString display_name_;
QString userid_; QString user_id_;
QImage avatar_image_; QImage avatar_image_;
}; };

View file

@ -234,7 +234,8 @@ void ChatPage::updateOwnProfileInfo(const QUrl &avatar_url, const QString &displ
user_info_widget_->setUserId(userid); user_info_widget_->setUserId(userid);
user_info_widget_->setDisplayName(display_name); 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) void ChatPage::changeTopRoomInfo(const QString &room_id)

View file

@ -29,12 +29,9 @@ void ProfileResponse::deserialize(const QJsonDocument &data)
QJsonObject object = data.object(); QJsonObject object = data.object();
if (object.value("avatar_url") == QJsonValue::Undefined) if (object.contains("avatar_url"))
throw DeserializationException("Missing avatar_url param"); avatar_url_ = QUrl(object.value("avatar_url").toString());
if (object.value("displayname") == QJsonValue::Undefined) if (object.contains("displayname"))
throw DeserializationException("Missing displayname param"); display_name_ = object.value("displayname").toString();
avatar_url_ = QUrl(object.value("avatar_url").toString());
display_name_ = object.value("displayname").toString();
} }

View file

@ -21,7 +21,7 @@
UserInfoWidget::UserInfoWidget(QWidget *parent) UserInfoWidget::UserInfoWidget(QWidget *parent)
: QWidget(parent) : QWidget(parent)
, display_name_("User") , display_name_("User")
, userid_("@user:homeserver.org") , user_id_("@user:homeserver.org")
{ {
QSizePolicy sizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Fixed); QSizePolicy sizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Fixed);
setSizePolicy(sizePolicy); setSizePolicy(sizePolicy);
@ -36,8 +36,9 @@ UserInfoWidget::UserInfoWidget(QWidget *parent)
userAvatar_ = new Avatar(this); userAvatar_ = new Avatar(this);
userAvatar_->setLetter(QChar('?')); userAvatar_->setLetter(QChar('?'));
userAvatar_->setSize(50); userAvatar_->setSize(55);
userAvatar_->setMaximumSize(QSize(55, 55)); userAvatar_->setBackgroundColor("#f9f9f9");
userAvatar_->setTextColor("#333333");
displayNameLabel_ = new QLabel(this); displayNameLabel_ = new QLabel(this);
displayNameLabel_->setStyleSheet( displayNameLabel_->setStyleSheet(
@ -102,12 +103,17 @@ void UserInfoWidget::setAvatar(const QImage &img)
void UserInfoWidget::setDisplayName(const QString &name) void UserInfoWidget::setDisplayName(const QString &name)
{ {
display_name_ = name; if (name.isEmpty())
displayNameLabel_->setText(name); 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) void UserInfoWidget::setUserId(const QString &userid)
{ {
userid_ = userid; user_id_ = userid;
userIdLabel_->setText(userid); userIdLabel_->setText(userid);
} }