2021-03-05 02:35:15 +03:00
|
|
|
// SPDX-FileCopyrightText: 2021 Nheko Contributors
|
|
|
|
//
|
|
|
|
// SPDX-License-Identifier: GPL-3.0-or-later
|
|
|
|
|
2018-01-09 16:07:32 +03:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <QScrollArea>
|
|
|
|
#include <QSharedPointer>
|
|
|
|
#include <QVBoxLayout>
|
|
|
|
|
2019-12-15 01:39:02 +03:00
|
|
|
#include "CacheStructs.h"
|
2018-01-09 16:07:32 +03:00
|
|
|
#include "CommunitiesListItem.h"
|
|
|
|
#include "ui/Theme.h"
|
|
|
|
|
2020-01-31 08:12:02 +03:00
|
|
|
namespace mtx::responses {
|
|
|
|
struct GroupProfile;
|
|
|
|
struct JoinedGroups;
|
|
|
|
}
|
|
|
|
|
2018-01-09 16:07:32 +03:00
|
|
|
class CommunitiesList : public QWidget
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
public:
|
2018-05-08 18:43:56 +03:00
|
|
|
CommunitiesList(QWidget *parent = nullptr);
|
2018-01-09 16:07:32 +03:00
|
|
|
|
2018-01-24 21:46:37 +03:00
|
|
|
void clear() { communities_.clear(); }
|
|
|
|
|
2018-07-14 12:08:16 +03:00
|
|
|
void addCommunity(const std::string &id);
|
2018-01-25 15:34:15 +03:00
|
|
|
void removeCommunity(const QString &id) { communities_.erase(id); };
|
2021-01-23 02:30:45 +03:00
|
|
|
std::set<QString> roomList(const QString &id) const;
|
2018-01-09 16:07:32 +03:00
|
|
|
|
2018-09-28 15:40:51 +03:00
|
|
|
void syncTags(const std::map<QString, RoomInfo> &info);
|
|
|
|
void setTagsForRoom(const QString &id, const std::vector<std::string> &tags);
|
2020-05-18 04:30:04 +03:00
|
|
|
std::vector<std::string> currentTags() const;
|
2021-01-23 02:30:45 +03:00
|
|
|
std::set<QString> hiddenTagsAndCommunities() const;
|
2018-09-28 15:40:51 +03:00
|
|
|
|
2018-01-09 16:07:32 +03:00
|
|
|
signals:
|
2018-01-24 21:46:37 +03:00
|
|
|
void communityChanged(const QString &id);
|
2018-06-09 16:03:14 +03:00
|
|
|
void avatarRetrieved(const QString &id, const QPixmap &img);
|
2018-07-14 12:08:16 +03:00
|
|
|
void groupProfileRetrieved(const QString &group_id, const mtx::responses::GroupProfile &);
|
2021-01-23 02:30:45 +03:00
|
|
|
void groupRoomsRetrieved(const QString &group_id, const std::set<QString> &res);
|
2018-01-09 16:07:32 +03:00
|
|
|
|
|
|
|
public slots:
|
2018-01-24 21:46:37 +03:00
|
|
|
void updateCommunityAvatar(const QString &id, const QPixmap &img);
|
|
|
|
void highlightSelectedCommunity(const QString &id);
|
2018-07-14 12:08:16 +03:00
|
|
|
void setCommunities(const mtx::responses::JoinedGroups &groups);
|
2018-01-09 16:07:32 +03:00
|
|
|
|
|
|
|
private:
|
2018-06-09 16:03:14 +03:00
|
|
|
void fetchCommunityAvatar(const QString &id, const QString &avatarUrl);
|
2018-07-14 12:08:16 +03:00
|
|
|
void addGlobalItem() { addCommunity("world"); }
|
2018-09-28 15:40:51 +03:00
|
|
|
void sortEntries();
|
2018-04-28 15:27:12 +03:00
|
|
|
|
2018-01-24 21:46:37 +03:00
|
|
|
//! Check whether or not a community id is currently managed.
|
2018-07-14 12:08:16 +03:00
|
|
|
bool communityExists(const QString &id) const
|
2018-01-24 21:46:37 +03:00
|
|
|
{
|
|
|
|
return communities_.find(id) != communities_.end();
|
|
|
|
}
|
|
|
|
|
2021-02-14 17:27:29 +03:00
|
|
|
QString selectedCommunity_;
|
2018-01-09 16:07:32 +03:00
|
|
|
QVBoxLayout *topLayout_;
|
|
|
|
QVBoxLayout *contentsLayout_;
|
|
|
|
QScrollArea *scrollArea_;
|
|
|
|
|
2018-01-24 21:46:37 +03:00
|
|
|
std::map<QString, QSharedPointer<CommunitiesListItem>> communities_;
|
2018-01-09 16:07:32 +03:00
|
|
|
};
|