summary refs log tree commit diff
diff options
context:
space:
mode:
authorKonstantinos Sideris <sideris.konstantin@gmail.com>2017-05-16 15:43:29 +0300
committerKonstantinos Sideris <sideris.konstantin@gmail.com>2017-05-16 15:43:29 +0300
commit992af5611bc4d1f543739f2bbd17bb710606135a (patch)
treeda76d7400a47d8902dbbe560a55f86130cbd128f
parentClear room state on logout (diff)
downloadnheko-992af5611bc4d1f543739f2bbd17bb710606135a.tar.xz
Show user info even if the display name or avatar are missing
-rw-r--r--include/UserInfoWidget.h2
-rw-r--r--src/ChatPage.cc3
-rw-r--r--src/Profile.cc11
-rw-r--r--src/UserInfoWidget.cc18
4 files changed, 19 insertions, 15 deletions
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);
 }