From 0cd9e3b1e56e991dd357ff4e98c4aba108c25e3f Mon Sep 17 00:00:00 2001 From: Konstantinos Sideris Date: Fri, 26 May 2017 21:34:16 +0300 Subject: Resolve name and avatar on 1-on-1 rooms --- include/ChatPage.h | 1 + include/RoomInfoListItem.h | 8 ++++---- include/RoomState.h | 40 +++++++++++++++++++++++++++++++++---- include/events/MemberEventContent.h | 10 +++++----- 4 files changed, 46 insertions(+), 13 deletions(-) (limited to 'include') diff --git a/include/ChatPage.h b/include/ChatPage.h index 12eaf6b7..68495276 100644 --- a/include/ChatPage.h +++ b/include/ChatPage.h @@ -59,6 +59,7 @@ private slots: void logout(); private: + void updateDisplayNames(const RoomState &state); void updateRoomState(RoomState &room_state, const QJsonArray &events); QHBoxLayout *topLayout_; diff --git a/include/RoomInfoListItem.h b/include/RoomInfoListItem.h index 75a90ff3..17c75fc3 100644 --- a/include/RoomInfoListItem.h +++ b/include/RoomInfoListItem.h @@ -50,8 +50,8 @@ protected: void paintEvent(QPaintEvent *event) override; private: - const int Padding = 10; - const int IconSize = 45; + const int Padding = 7; + const int IconSize = 46; RippleOverlay *ripple_overlay_; @@ -66,7 +66,7 @@ private: bool isPressed_ = false; - int maxHeight_ = 60; + int maxHeight_; int unreadMsgCount_ = 0; }; @@ -87,5 +87,5 @@ inline RoomState RoomInfoListItem::state() const inline void RoomInfoListItem::setAvatar(const QImage &img) { - roomAvatar_ = QPixmap::fromImage(img.scaled(IconSize, IconSize, Qt::KeepAspectRatio, Qt::SmoothTransformation)); + roomAvatar_ = QPixmap::fromImage(img.scaled(IconSize, IconSize, Qt::IgnoreAspectRatio, Qt::SmoothTransformation)); } diff --git a/include/RoomState.h b/include/RoomState.h index 788940e2..0389a6df 100644 --- a/include/RoomState.h +++ b/include/RoomState.h @@ -18,6 +18,7 @@ #pragma once #include +#include #include "AliasesEventContent.h" #include "AvatarEventContent.h" @@ -25,6 +26,7 @@ #include "CreateEventContent.h" #include "HistoryVisibilityEventContent.h" #include "JoinRulesEventContent.h" +#include "MemberEventContent.h" #include "NameEventContent.h" #include "PowerLevelsEventContent.h" #include "TopicEventContent.h" @@ -38,11 +40,20 @@ namespace events = matrix::events; class RoomState { public: - QString resolveName() const; - inline QString resolveTopic() const; + // Calculate room data that are not immediatly accessible. Like room name and avatar. + // + // e.g If the room is 1-on-1 name and avatar should be extracted from a user. + void resolveName(); + void resolveAvatar(); - QPixmap avatar_img_; + inline QUrl getAvatar() const; + inline QString getName() const; + inline QString getTopic() const; + void removeLeaveMemberships(); + void update(const RoomState &state); + + // The latest state events. events::StateEvent aliases; events::StateEvent avatar; events::StateEvent canonical_alias; @@ -52,9 +63,30 @@ public: events::StateEvent name; events::StateEvent power_levels; events::StateEvent topic; + + // Contains the m.room.member events for all the joined users. + QMap> memberships; + +private: + QUrl avatar_; + QString name_; + + // It defines the user whose avatar is used for the room. If the room has an avatar + // event this should be empty. + QString userAvatar_; }; -inline QString RoomState::resolveTopic() const +inline QString RoomState::getTopic() const { return topic.content().topic().simplified(); } + +inline QString RoomState::getName() const +{ + return name_; +} + +inline QUrl RoomState::getAvatar() const +{ + return avatar_; +} diff --git a/include/events/MemberEventContent.h b/include/events/MemberEventContent.h index f3714462..e61d0cda 100644 --- a/include/events/MemberEventContent.h +++ b/include/events/MemberEventContent.h @@ -28,19 +28,19 @@ namespace events { enum class Membership { // The user is banned. - BanState, + Ban, // The user has been invited. - InviteState, + Invite, // The user has joined. - JoinState, + Join, // The user has requested to join. - KnockState, + Knock, // The user has left. - LeaveState, + Leave, }; /* -- cgit 1.5.1