Communities (#195)
This commit is contained in:
parent
81a706bf20
commit
312df6f3bb
23 changed files with 1054 additions and 13 deletions
|
|
@ -24,6 +24,8 @@
|
|||
#include <QTimer>
|
||||
#include <QWidget>
|
||||
|
||||
#include "CommunitiesList.h"
|
||||
#include "Community.h"
|
||||
#include <mtx.hpp>
|
||||
|
||||
class Cache;
|
||||
|
|
@ -80,6 +82,7 @@ private slots:
|
|||
void showUnreadMessageNotification(int count);
|
||||
void updateTopBarAvatar(const QString &roomid, const QPixmap &img);
|
||||
void updateOwnProfileInfo(const QUrl &avatar_url, const QString &display_name);
|
||||
void updateOwnCommunitiesInfo(const QList<QString> &own_communities);
|
||||
void setOwnAvatar(const QPixmap &img);
|
||||
void initialSyncCompleted(const mtx::responses::Sync &response);
|
||||
void syncCompleted(const mtx::responses::Sync &response);
|
||||
|
|
@ -126,13 +129,21 @@ private:
|
|||
QHBoxLayout *topLayout_;
|
||||
Splitter *splitter;
|
||||
|
||||
QFrame *sideBar_;
|
||||
QWidget *sideBar_;
|
||||
QWidget *communitiesSideBar_;
|
||||
QVBoxLayout *communitiesSideBarLayout_;
|
||||
QVBoxLayout *sideBarLayout_;
|
||||
QVBoxLayout *sideBarTopLayout_;
|
||||
QVBoxLayout *sideBarMainLayout_;
|
||||
QWidget *sideBarTopWidget_;
|
||||
QVBoxLayout *sideBarTopWidgetLayout_;
|
||||
|
||||
QFrame *content_;
|
||||
QVBoxLayout *contentLayout_;
|
||||
|
||||
CommunitiesList *communitiesList_;
|
||||
RoomList *room_list_;
|
||||
|
||||
TimelineViewManager *view_manager_;
|
||||
SideBarActions *sidebarActions_;
|
||||
|
||||
|
|
@ -145,13 +156,18 @@ private:
|
|||
QTimer *consensusTimer_;
|
||||
|
||||
QString current_room_;
|
||||
QString current_community_;
|
||||
|
||||
QMap<QString, QPixmap> room_avatars_;
|
||||
QMap<QString, QPixmap> community_avatars_;
|
||||
|
||||
UserInfoWidget *user_info_widget_;
|
||||
|
||||
QMap<QString, RoomState> state_manager_;
|
||||
QMap<QString, QSharedPointer<RoomSettings>> settingsManager_;
|
||||
|
||||
QMap<QString, QSharedPointer<Community>> communityManager_;
|
||||
|
||||
// Keeps track of the users currently typing on each room.
|
||||
QMap<QString, QList<QString>> typingUsers_;
|
||||
QTimer *typingRefresher_;
|
||||
|
|
|
|||
42
include/CommunitiesList.h
Normal file
42
include/CommunitiesList.h
Normal file
|
|
@ -0,0 +1,42 @@
|
|||
#pragma once
|
||||
|
||||
#include <QScrollArea>
|
||||
#include <QSharedPointer>
|
||||
#include <QVBoxLayout>
|
||||
#include <QWidget>
|
||||
|
||||
#include "CommunitiesListItem.h"
|
||||
#include "Community.h"
|
||||
#include "MatrixClient.h"
|
||||
#include "ui/Theme.h"
|
||||
|
||||
class CommunitiesList : public QWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
CommunitiesList(QSharedPointer<MatrixClient> client, QWidget *parent = nullptr);
|
||||
~CommunitiesList();
|
||||
|
||||
void setCommunities(const QMap<QString, QSharedPointer<Community>> &communities);
|
||||
void clear();
|
||||
|
||||
void addCommunity(QSharedPointer<Community> community, const QString &community_id);
|
||||
void removeCommunity(const QString &community_id);
|
||||
signals:
|
||||
void communityChanged(const QString &community_id);
|
||||
|
||||
public slots:
|
||||
void updateCommunityAvatar(const QString &community_id, const QPixmap &img);
|
||||
void highlightSelectedCommunity(const QString &community_id);
|
||||
|
||||
private:
|
||||
QVBoxLayout *topLayout_;
|
||||
QVBoxLayout *contentsLayout_;
|
||||
QWidget *scrollAreaContents_;
|
||||
QScrollArea *scrollArea_;
|
||||
|
||||
QMap<QString, QSharedPointer<CommunitiesListItem>> communities_;
|
||||
|
||||
QSharedPointer<MatrixClient> client_;
|
||||
};
|
||||
98
include/CommunitiesListItem.h
Normal file
98
include/CommunitiesListItem.h
Normal file
|
|
@ -0,0 +1,98 @@
|
|||
#pragma once
|
||||
|
||||
#include <QDebug>
|
||||
#include <QMouseEvent>
|
||||
#include <QPainter>
|
||||
#include <QSharedPointer>
|
||||
#include <QWidget>
|
||||
|
||||
#include "Community.h"
|
||||
#include "Menu.h"
|
||||
#include "ui/Theme.h"
|
||||
|
||||
class CommunitiesListItem : public QWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_PROPERTY(QColor highlightedBackgroundColor READ highlightedBackgroundColor WRITE
|
||||
setHighlightedBackgroundColor)
|
||||
Q_PROPERTY(
|
||||
QColor hoverBackgroundColor READ hoverBackgroundColor WRITE setHoverBackgroundColor)
|
||||
Q_PROPERTY(QColor backgroundColor READ backgroundColor WRITE setBackgroundColor)
|
||||
|
||||
public:
|
||||
CommunitiesListItem(QSharedPointer<Community> community,
|
||||
QString community_id,
|
||||
QWidget *parent = nullptr);
|
||||
|
||||
~CommunitiesListItem();
|
||||
|
||||
void setCommunity(QSharedPointer<Community> community);
|
||||
|
||||
inline bool isPressed() const;
|
||||
inline void setAvatar(const QImage &avatar_image);
|
||||
|
||||
QColor highlightedBackgroundColor() const { return highlightedBackgroundColor_; }
|
||||
QColor hoverBackgroundColor() const { return hoverBackgroundColor_; }
|
||||
QColor backgroundColor() const { return backgroundColor_; }
|
||||
|
||||
void setHighlightedBackgroundColor(QColor &color) { highlightedBackgroundColor_ = color; }
|
||||
void setHoverBackgroundColor(QColor &color) { hoverBackgroundColor_ = color; }
|
||||
void setBackgroundColor(QColor &color) { backgroundColor_ = color; }
|
||||
|
||||
QColor highlightedBackgroundColor_;
|
||||
QColor hoverBackgroundColor_;
|
||||
QColor backgroundColor_;
|
||||
|
||||
signals:
|
||||
void clicked(const QString &community_id);
|
||||
|
||||
public slots:
|
||||
void setPressedState(bool state);
|
||||
|
||||
protected:
|
||||
void mousePressEvent(QMouseEvent *event) override;
|
||||
void paintEvent(QPaintEvent *event) override;
|
||||
void contextMenuEvent(QContextMenuEvent *event) override;
|
||||
|
||||
private:
|
||||
const int IconSize = 55;
|
||||
|
||||
QSharedPointer<Community> community_;
|
||||
QString communityId_;
|
||||
QString communityName_;
|
||||
QString communityShortDescription;
|
||||
|
||||
QPixmap communityAvatar_;
|
||||
|
||||
Menu *menu_;
|
||||
bool isPressed_ = false;
|
||||
};
|
||||
|
||||
inline bool
|
||||
CommunitiesListItem::isPressed() const
|
||||
{
|
||||
return isPressed_;
|
||||
}
|
||||
|
||||
inline void
|
||||
CommunitiesListItem::setAvatar(const QImage &avatar_image)
|
||||
{
|
||||
communityAvatar_ = QPixmap::fromImage(
|
||||
avatar_image.scaled(IconSize, IconSize, Qt::IgnoreAspectRatio, Qt::SmoothTransformation));
|
||||
update();
|
||||
}
|
||||
|
||||
class WorldCommunityListItem : public CommunitiesListItem
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
WorldCommunityListItem(QWidget *parent = nullptr);
|
||||
~WorldCommunityListItem();
|
||||
|
||||
protected:
|
||||
void mousePressEvent(QMouseEvent *event) override;
|
||||
void paintEvent(QPaintEvent *event) override;
|
||||
|
||||
private:
|
||||
const int IconSize = 55;
|
||||
};
|
||||
62
include/Community.h
Normal file
62
include/Community.h
Normal file
|
|
@ -0,0 +1,62 @@
|
|||
#pragma once
|
||||
|
||||
#include <QJsonObject>
|
||||
#include <QObject>
|
||||
#include <QString>
|
||||
#include <QUrl>
|
||||
|
||||
class Community : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
void parseProfile(const QJsonObject &profile);
|
||||
void parseRooms(const QJsonObject &rooms);
|
||||
|
||||
inline QUrl getAvatar() const;
|
||||
inline QString getName() const;
|
||||
inline QString getShortDescription() const;
|
||||
inline QString getLongDescription() const;
|
||||
inline const QList<QString> getRoomList() const;
|
||||
|
||||
signals:
|
||||
void roomsChanged(QList<QString> &rooms);
|
||||
|
||||
private:
|
||||
QUrl avatar_;
|
||||
QString name_;
|
||||
QString short_description_;
|
||||
QString long_description_;
|
||||
|
||||
QList<QString> rooms_;
|
||||
};
|
||||
|
||||
inline QUrl
|
||||
Community::getAvatar() const
|
||||
{
|
||||
return avatar_;
|
||||
}
|
||||
|
||||
inline QString
|
||||
Community::getName() const
|
||||
{
|
||||
return name_;
|
||||
}
|
||||
|
||||
inline QString
|
||||
Community::getShortDescription() const
|
||||
{
|
||||
return short_description_;
|
||||
}
|
||||
|
||||
inline QString
|
||||
Community::getLongDescription() const
|
||||
{
|
||||
return long_description_;
|
||||
}
|
||||
|
||||
inline const QList<QString>
|
||||
Community::getRoomList() const
|
||||
{
|
||||
return rooms_;
|
||||
}
|
||||
|
|
@ -48,6 +48,9 @@ public:
|
|||
void versions() noexcept;
|
||||
void fetchRoomAvatar(const QString &roomid, const QUrl &avatar_url);
|
||||
void fetchUserAvatar(const QString &userId, const QUrl &avatarUrl);
|
||||
void fetchCommunityAvatar(const QString &communityId, const QUrl &avatarUrl);
|
||||
void fetchCommunityProfile(const QString &communityId);
|
||||
void fetchCommunityRooms(const QString &communityId);
|
||||
void fetchOwnAvatar(const QUrl &avatar_url);
|
||||
void downloadImage(const QString &event_id, const QUrl &url);
|
||||
void downloadFile(const QString &event_id, const QUrl &url);
|
||||
|
|
@ -71,6 +74,7 @@ public:
|
|||
|
||||
public slots:
|
||||
void getOwnProfile() noexcept;
|
||||
void getOwnCommunities() noexcept;
|
||||
void logout() noexcept;
|
||||
|
||||
void setServer(const QString &server)
|
||||
|
|
@ -103,12 +107,16 @@ signals:
|
|||
const QString &url,
|
||||
const QByteArray &data);
|
||||
void userAvatarRetrieved(const QString &userId, const QImage &img);
|
||||
void communityAvatarRetrieved(const QString &communityId, const QPixmap &img);
|
||||
void communityProfileRetrieved(const QString &communityId, const QJsonObject &profile);
|
||||
void communityRoomsRetrieved(const QString &communityId, const QJsonObject &rooms);
|
||||
void ownAvatarRetrieved(const QPixmap &img);
|
||||
void imageDownloaded(const QString &event_id, const QPixmap &img);
|
||||
void fileDownloaded(const QString &event_id, const QByteArray &data);
|
||||
|
||||
// Returned profile data for the user's account.
|
||||
void getOwnProfileResponse(const QUrl &avatar_url, const QString &display_name);
|
||||
void getOwnCommunitiesResponse(const QList<QString> &own_communities);
|
||||
void initialSyncCompleted(const mtx::responses::Sync &response);
|
||||
void initialSyncFailed(const QString &msg);
|
||||
void syncCompleted(const mtx::responses::Sync &response);
|
||||
|
|
|
|||
|
|
@ -73,9 +73,10 @@ public:
|
|||
void clearUnreadMessageCount();
|
||||
void setState(const RoomState &state);
|
||||
|
||||
bool isPressed() const { return isPressed_; }
|
||||
RoomState state() const { return state_; }
|
||||
int unreadMessageCount() const { return unreadMsgCount_; }
|
||||
QString roomId();
|
||||
bool isPressed() const { return isPressed_; };
|
||||
RoomState state() const { return state_; };
|
||||
int unreadMessageCount() const { return unreadMsgCount_; };
|
||||
|
||||
void setAvatar(const QImage &avatar_image);
|
||||
void setDescriptionMessage(const DescInfo &info);
|
||||
|
|
@ -182,3 +183,9 @@ private:
|
|||
QRectF acceptBtnRegion_;
|
||||
QRectF declineBtnRegion_;
|
||||
};
|
||||
|
||||
inline QString
|
||||
RoomInfoListItem::roomId()
|
||||
{
|
||||
return roomId_;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -64,6 +64,8 @@ public:
|
|||
const QString &room_id);
|
||||
void addInvitedRoom(const QString &room_id, const mtx::responses::InvitedRoom &room);
|
||||
void removeRoom(const QString &room_id, bool reset);
|
||||
void setFilterRooms(bool filterRooms);
|
||||
void setRoomFilter(QList<QString> room_ids);
|
||||
|
||||
signals:
|
||||
void roomChanged(const QString &room_id);
|
||||
|
|
@ -105,6 +107,10 @@ private:
|
|||
QSharedPointer<dialogs::LeaveRoom> leaveRoomDialog_;
|
||||
|
||||
QMap<QString, QSharedPointer<RoomInfoListItem>> rooms_;
|
||||
QString selectedRoom_;
|
||||
|
||||
bool filterRooms_ = false;
|
||||
QList<QString> roomFilter_ = QList<QString>(); // which rooms to include in the room list
|
||||
|
||||
QSharedPointer<MatrixClient> client_;
|
||||
QSharedPointer<Cache> cache_;
|
||||
|
|
|
|||
|
|
@ -13,8 +13,9 @@ enum class AvatarType
|
|||
};
|
||||
|
||||
namespace sidebar {
|
||||
static const int SmallSize = 60;
|
||||
static const int NormalSize = 300;
|
||||
static const int SmallSize = 60;
|
||||
static const int NormalSize = 300;
|
||||
static const int CommunitiesSidebarSize = 64;
|
||||
}
|
||||
// Default font size.
|
||||
const int FontSize = 16;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue