Re-enable groups

This commit is contained in:
Konstantinos Sideris 2018-07-14 12:08:16 +03:00
parent 4f41c0df4d
commit 73dbd3c8dd
14 changed files with 142 additions and 159 deletions

View file

@ -197,7 +197,6 @@ set(SRC_FILES
src/ChatPage.cc src/ChatPage.cc
src/CommunitiesListItem.cc src/CommunitiesListItem.cc
src/CommunitiesList.cc src/CommunitiesList.cc
src/Community.cc
src/InviteeItem.cc src/InviteeItem.cc
src/LoginPage.cc src/LoginPage.cc
src/Logging.cpp src/Logging.cpp

View file

@ -6,6 +6,10 @@
# OLM_LIBRARY = full path to the library # OLM_LIBRARY = full path to the library
# OLM_INCLUDE_DIR = where to find the library headers # OLM_INCLUDE_DIR = where to find the library headers
# #
if(WIN32)
message(STATUS "FindOlm is not supported in Windows")
return()
endif()
find_path(OLM_INCLUDE_DIR find_path(OLM_INCLUDE_DIR
NAMES olm/olm.h NAMES olm/olm.h

4
deps/CMakeLists.txt vendored
View file

@ -39,10 +39,10 @@ set(BOOST_SHA256
5721818253e6a0989583192f96782c4a98eb6204965316df9f5ad75819225ca9) 5721818253e6a0989583192f96782c4a98eb6204965316df9f5ad75819225ca9)
set(MATRIX_STRUCTS_URL https://github.com/mujx/matrix-structs) set(MATRIX_STRUCTS_URL https://github.com/mujx/matrix-structs)
set(MATRIX_STRUCTS_TAG 92a5e99db51301b5abf626aa872a1a87b7727634) set(MATRIX_STRUCTS_TAG 8de04afea34e95c14d1dde82af390592dfde90dd)
set(MTXCLIENT_URL https://github.com/mujx/mtxclient) set(MTXCLIENT_URL https://github.com/mujx/mtxclient)
set(MTXCLIENT_TAG 708c8c6772b9bd99d77c5be6bb3ba58643258628) set(MTXCLIENT_TAG 2f519d28b4521f7f234b2ed0f32360cbb1edd2f7)
set(TWEENY_URL https://github.com/mobius3/tweeny) set(TWEENY_URL https://github.com/mobius3/tweeny)
set(TWEENY_TAG b94ce07cfb02a0eb8ac8aaf66137dabdaea857cf) set(TWEENY_TAG b94ce07cfb02a0eb8ac8aaf66137dabdaea857cf)

View file

@ -28,7 +28,6 @@
#include "Cache.h" #include "Cache.h"
#include "CommunitiesList.h" #include "CommunitiesList.h"
#include "Community.h"
#include "MatrixClient.h" #include "MatrixClient.h"
#include "notifications/Manager.h" #include "notifications/Manager.h"
@ -149,10 +148,11 @@ signals:
const QString &message, const QString &message,
const QImage &icon); const QImage &icon);
void updateGroupsInfo(const mtx::responses::JoinedGroups &groups);
private slots: private slots:
void showUnreadMessageNotification(int count); void showUnreadMessageNotification(int count);
void updateTopBarAvatar(const QString &roomid, const QPixmap &img); void updateTopBarAvatar(const QString &roomid, const QPixmap &img);
void updateOwnCommunitiesInfo(const QList<QString> &own_communities);
void changeTopRoomInfo(const QString &room_id); void changeTopRoomInfo(const QString &room_id);
void logout(); void logout();
void removeRoom(const QString &room_id); void removeRoom(const QString &room_id);
@ -233,8 +233,6 @@ private:
UserInfoWidget *user_info_widget_; UserInfoWidget *user_info_widget_;
std::map<QString, QSharedPointer<Community>> communities_;
// Keeps track of the users currently typing on each room. // Keeps track of the users currently typing on each room.
std::map<QString, QList<QString>> typingUsers_; std::map<QString, QList<QString>> typingUsers_;
QTimer *typingRefresher_; QTimer *typingRefresher_;

View file

@ -5,7 +5,6 @@
#include <QVBoxLayout> #include <QVBoxLayout>
#include "CommunitiesListItem.h" #include "CommunitiesListItem.h"
#include "Community.h"
#include "ui/Theme.h" #include "ui/Theme.h"
class CommunitiesList : public QWidget class CommunitiesList : public QWidget
@ -15,26 +14,29 @@ class CommunitiesList : public QWidget
public: public:
CommunitiesList(QWidget *parent = nullptr); CommunitiesList(QWidget *parent = nullptr);
void setCommunities(const std::map<QString, QSharedPointer<Community>> &communities);
void clear() { communities_.clear(); } void clear() { communities_.clear(); }
void addCommunity(QSharedPointer<Community> community, const QString &id); void addCommunity(const std::string &id);
void removeCommunity(const QString &id) { communities_.erase(id); }; void removeCommunity(const QString &id) { communities_.erase(id); };
std::vector<QString> roomList(const QString &id) const;
signals: signals:
void communityChanged(const QString &id); void communityChanged(const QString &id);
void avatarRetrieved(const QString &id, const QPixmap &img); void avatarRetrieved(const QString &id, const QPixmap &img);
void groupProfileRetrieved(const QString &group_id, const mtx::responses::GroupProfile &);
void groupRoomsRetrieved(const QString &group_id, const std::vector<QString> &res);
public slots: public slots:
void updateCommunityAvatar(const QString &id, const QPixmap &img); void updateCommunityAvatar(const QString &id, const QPixmap &img);
void highlightSelectedCommunity(const QString &id); void highlightSelectedCommunity(const QString &id);
void setCommunities(const mtx::responses::JoinedGroups &groups);
private: private:
void fetchCommunityAvatar(const QString &id, const QString &avatarUrl); void fetchCommunityAvatar(const QString &id, const QString &avatarUrl);
void addGlobalItem() { addCommunity(QSharedPointer<Community>(new Community), "world"); } void addGlobalItem() { addCommunity("world"); }
//! Check whether or not a community id is currently managed. //! Check whether or not a community id is currently managed.
bool communityExists(const QString &id) bool communityExists(const QString &id) const
{ {
return communities_.find(id) != communities_.end(); return communities_.find(id) != communities_.end();
} }

View file

@ -6,7 +6,8 @@
#include <QSharedPointer> #include <QSharedPointer>
#include <QWidget> #include <QWidget>
#include "Community.h" #include <mtx/responses/groups.hpp>
#include "Config.h" #include "Config.h"
#include "ui/Theme.h" #include "ui/Theme.h"
@ -25,15 +26,15 @@ class CommunitiesListItem : public QWidget
Q_PROPERTY(QColor avatarBgColor READ avatarBgColor WRITE setAvatarBgColor) Q_PROPERTY(QColor avatarBgColor READ avatarBgColor WRITE setAvatarBgColor)
public: public:
CommunitiesListItem(QSharedPointer<Community> community, CommunitiesListItem(QString group_id, QWidget *parent = nullptr);
QString community_id,
QWidget *parent = nullptr);
void setCommunity(QSharedPointer<Community> community) { community_ = community; };
void setName(QString name) { name_ = name; }
bool isPressed() const { return isPressed_; } bool isPressed() const { return isPressed_; }
void setAvatar(const QImage &img); void setAvatar(const QImage &img);
void setRooms(std::vector<QString> room_ids) { room_ids_ = std::move(room_ids); }
std::vector<QString> rooms() const { return room_ids_; }
QColor highlightedBackgroundColor() const { return highlightedBackgroundColor_; } QColor highlightedBackgroundColor() const { return highlightedBackgroundColor_; }
QColor hoverBackgroundColor() const { return hoverBackgroundColor_; } QColor hoverBackgroundColor() const { return hoverBackgroundColor_; }
QColor backgroundColor() const { return backgroundColor_; } QColor backgroundColor() const { return backgroundColor_; }
@ -54,7 +55,7 @@ public:
} }
signals: signals:
void clicked(const QString &community_id); void clicked(const QString &group_id);
public slots: public slots:
void setPressedState(bool state); void setPressedState(bool state);
@ -66,12 +67,13 @@ protected:
private: private:
const int IconSize = 36; const int IconSize = 36;
QSharedPointer<Community> community_; QString resolveName() const;
QString communityId_;
QString communityName_;
QString communityShortDescription;
QPixmap communityAvatar_; std::vector<QString> room_ids_;
QString name_;
QString groupId_;
QPixmap avatar_;
QColor highlightedBackgroundColor_; QColor highlightedBackgroundColor_;
QColor hoverBackgroundColor_; QColor hoverBackgroundColor_;

View file

@ -1,25 +0,0 @@
#pragma once
#include <QJsonObject>
#include <QString>
#include <QUrl>
#include <vector>
struct Community
{
void parseProfile(const QJsonObject &profile);
void parseRooms(const QJsonObject &rooms);
QUrl getAvatar() const { return avatar_; }
QString getName() const { return name_; }
QString getShortDescription() const { return short_description_; }
QString getLongDescription() const { return long_description_; }
std::vector<QString> getRoomList() const { return rooms_; }
QUrl avatar_;
QString name_;
QString short_description_;
QString long_description_;
std::vector<QString> rooms_;
};

View file

@ -1,6 +1,7 @@
#pragma once #pragma once
#include <QMetaType> #include <QMetaType>
#include <QString>
#include <mtx/responses.hpp> #include <mtx/responses.hpp>
#include <mtxclient/http/client.hpp> #include <mtxclient/http/client.hpp>
@ -10,8 +11,11 @@ Q_DECLARE_METATYPE(mtx::responses::Messages)
Q_DECLARE_METATYPE(mtx::responses::Notifications) Q_DECLARE_METATYPE(mtx::responses::Notifications)
Q_DECLARE_METATYPE(mtx::responses::Rooms) Q_DECLARE_METATYPE(mtx::responses::Rooms)
Q_DECLARE_METATYPE(mtx::responses::Sync) Q_DECLARE_METATYPE(mtx::responses::Sync)
Q_DECLARE_METATYPE(mtx::responses::JoinedGroups)
Q_DECLARE_METATYPE(mtx::responses::GroupProfile)
Q_DECLARE_METATYPE(std::string) Q_DECLARE_METATYPE(std::string)
Q_DECLARE_METATYPE(std::vector<std::string>) Q_DECLARE_METATYPE(std::vector<std::string>)
Q_DECLARE_METATYPE(std::vector<QString>)
namespace http { namespace http {
namespace v2 { namespace v2 {

View file

@ -987,7 +987,8 @@ Cache::getTimelineMessages(lmdb::txn &txn, const std::string &room_id)
if (obj.count("event") == 0 || obj.count("token") == 0) if (obj.count("event") == 0 || obj.count("token") == 0)
continue; continue;
mtx::events::collections::TimelineEvent event = obj.at("event"); mtx::events::collections::TimelineEvent event;
mtx::events::collections::from_json(obj.at("event"), event);
index += 1; index += 1;
@ -1058,7 +1059,8 @@ Cache::getLastMessageInfo(lmdb::txn &txn, const std::string &room_id)
if (obj.count("event") == 0) if (obj.count("event") == 0)
continue; continue;
mtx::events::collections::TimelineEvent event = obj.at("event"); mtx::events::collections::TimelineEvent event;
mtx::events::collections::from_json(obj.at("event"), event);
cursor.close(); cursor.close();
return utils::getMessageDescription( return utils::getMessageDescription(

View file

@ -501,31 +501,8 @@ ChatPage::ChatPage(QSharedPointer<UserSettings> userSettings, QWidget *parent)
connect(room_list_, &RoomList::roomAvatarChanged, this, &ChatPage::updateTopBarAvatar); connect(room_list_, &RoomList::roomAvatarChanged, this, &ChatPage::updateTopBarAvatar);
// connect(http::client(), connect(
// SIGNAL(getOwnCommunitiesResponse(QList<QString>)), this, &ChatPage::updateGroupsInfo, communitiesList_, &CommunitiesList::setCommunities);
// this,
// SLOT(updateOwnCommunitiesInfo(QList<QString>)));
// connect(http::client(),
// &MatrixClient::communityProfileRetrieved,
// this,
// [this](QString communityId, QJsonObject profile) {
// communities_[communityId]->parseProfile(profile);
// });
// connect(http::client(),
// &MatrixClient::communityRoomsRetrieved,
// this,
// [this](QString communityId, QJsonObject rooms) {
// communities_[communityId]->parseRooms(rooms);
// if (communityId == current_community_) {
// if (communityId == "world") {
// room_list_->setFilterRooms(false);
// } else {
// room_list_->setRoomFilter(
// communities_[communityId]->getRoomList());
// }
// }
// });
connect(this, &ChatPage::leftRoom, this, &ChatPage::removeRoom); connect(this, &ChatPage::leftRoom, this, &ChatPage::removeRoom);
connect(this, &ChatPage::notificationsRetrieved, this, &ChatPage::sendDesktopNotifications); connect(this, &ChatPage::notificationsRetrieved, this, &ChatPage::sendDesktopNotifications);
@ -533,13 +510,13 @@ ChatPage::ChatPage(QSharedPointer<UserSettings> userSettings, QWidget *parent)
connect(communitiesList_, connect(communitiesList_,
&CommunitiesList::communityChanged, &CommunitiesList::communityChanged,
this, this,
[this](const QString &communityId) { [this](const QString &groupId) {
current_community_ = communityId; current_community_ = groupId;
if (communityId == "world") if (groupId == "world")
room_list_->setFilterRooms(false); room_list_->setFilterRooms(false);
else else
room_list_->setRoomFilter(communities_[communityId]->getRoomList()); room_list_->setRoomFilter(communitiesList_->roomList(groupId));
}); });
connect(&notificationsManager, connect(&notificationsManager,
@ -758,18 +735,6 @@ ChatPage::updateTopBarAvatar(const QString &roomid, const QPixmap &img)
top_bar_->updateRoomAvatar(img.toImage()); top_bar_->updateRoomAvatar(img.toImage());
} }
void
ChatPage::updateOwnCommunitiesInfo(const QList<QString> &own_communities)
{
for (int i = 0; i < own_communities.size(); i++) {
QSharedPointer<Community> community = QSharedPointer<Community>(new Community());
communities_[own_communities[i]] = community;
}
communitiesList_->setCommunities(communities_);
}
void void
ChatPage::changeTopRoomInfo(const QString &room_id) ChatPage::changeTopRoomInfo(const QString &room_id)
{ {
@ -1335,7 +1300,18 @@ ChatPage::getProfileInfo()
QImage::fromData(QByteArray(data.data(), data.size()))); QImage::fromData(QByteArray(data.data(), data.size())));
}); });
}); });
// TODO http::client()->getOwnCommunities();
http::v2::client()->joined_groups(
[this](const mtx::responses::JoinedGroups &res, mtx::http::RequestErr err) {
if (err) {
nhlog::net()->critical("failed to retrieve joined groups: {} {}",
static_cast<int>(err->status_code),
err->matrix_error.error);
return;
}
emit updateGroupsInfo(res);
});
} }
void void

View file

@ -40,50 +40,81 @@ CommunitiesList::CommunitiesList(QWidget *parent)
scrollArea_->setWidget(scrollAreaContents_); scrollArea_->setWidget(scrollAreaContents_);
topLayout_->addWidget(scrollArea_); topLayout_->addWidget(scrollArea_);
// connect(http::client(),
// &MatrixClient::communityProfileRetrieved,
// this,
// [this](QString communityId, QJsonObject profile) {
// fetchCommunityAvatar(communityId, profile["avatar_url"].toString());
// });
connect( connect(
this, &CommunitiesList::avatarRetrieved, this, &CommunitiesList::updateCommunityAvatar); this, &CommunitiesList::avatarRetrieved, this, &CommunitiesList::updateCommunityAvatar);
} }
void void
CommunitiesList::setCommunities(const std::map<QString, QSharedPointer<Community>> &communities) CommunitiesList::setCommunities(const mtx::responses::JoinedGroups &response)
{ {
communities_.clear(); communities_.clear();
addGlobalItem(); addGlobalItem();
for (const auto &community : communities) { for (const auto &group : response.groups)
addCommunity(community.second, community.first); addCommunity(group);
// http::client()->fetchCommunityProfile(community.first);
// http::client()->fetchCommunityRooms(community.first);
}
communities_["world"]->setPressedState(true); communities_["world"]->setPressedState(true);
emit communityChanged("world"); emit communityChanged("world");
} }
void void
CommunitiesList::addCommunity(QSharedPointer<Community> community, const QString &community_id) CommunitiesList::addCommunity(const std::string &group_id)
{ {
CommunitiesListItem *list_item = const auto id = QString::fromStdString(group_id);
new CommunitiesListItem(community, community_id, scrollArea_);
communities_.emplace(community_id, QSharedPointer<CommunitiesListItem>(list_item));
fetchCommunityAvatar(community_id, community->getAvatar().toString());
CommunitiesListItem *list_item = new CommunitiesListItem(id, scrollArea_);
communities_.emplace(id, QSharedPointer<CommunitiesListItem>(list_item));
contentsLayout_->insertWidget(contentsLayout_->count() - 1, list_item); contentsLayout_->insertWidget(contentsLayout_->count() - 1, list_item);
connect(this,
&CommunitiesList::groupProfileRetrieved,
this,
[this](const QString &id, const mtx::responses::GroupProfile &profile) {
if (communities_.find(id) == communities_.end())
return;
communities_.at(id)->setName(QString::fromStdString(profile.name));
if (!profile.avatar_url.empty())
fetchCommunityAvatar(id,
QString::fromStdString(profile.avatar_url));
});
connect(this,
&CommunitiesList::groupRoomsRetrieved,
this,
[this](const QString &id, const std::vector<QString> &rooms) {
if (communities_.find(id) == communities_.end())
return;
communities_.at(id)->setRooms(rooms);
});
connect(list_item, connect(list_item,
&CommunitiesListItem::clicked, &CommunitiesListItem::clicked,
this, this,
&CommunitiesList::highlightSelectedCommunity); &CommunitiesList::highlightSelectedCommunity);
http::v2::client()->group_profile(
group_id, [id, this](const mtx::responses::GroupProfile &res, mtx::http::RequestErr err) {
if (err) {
return;
}
emit groupProfileRetrieved(id, res);
});
http::v2::client()->group_rooms(
group_id, [id, this](const nlohmann::json &res, mtx::http::RequestErr err) {
if (err) {
return;
}
std::vector<QString> room_ids;
for (const auto &room : res.at("chunk"))
room_ids.push_back(QString::fromStdString(room.at("room_id")));
emit groupRoomsRetrieved(id, room_ids);
});
} }
void void
@ -94,7 +125,7 @@ CommunitiesList::updateCommunityAvatar(const QString &community_id, const QPixma
return; return;
} }
communities_.find(community_id)->second->setAvatar(img.toImage()); communities_.at(community_id)->setAvatar(img.toImage());
} }
void void
@ -153,3 +184,12 @@ CommunitiesList::fetchCommunityAvatar(const QString &id, const QString &avatarUr
emit avatarRetrieved(id, pix); emit avatarRetrieved(id, pix);
}); });
} }
std::vector<QString>
CommunitiesList::roomList(const QString &id) const
{
if (communityExists(id))
return communities_.at(id)->rooms();
return {};
}

View file

@ -4,12 +4,9 @@
#include "RippleOverlay.h" #include "RippleOverlay.h"
#include "Utils.h" #include "Utils.h"
CommunitiesListItem::CommunitiesListItem(QSharedPointer<Community> community, CommunitiesListItem::CommunitiesListItem(QString group_id, QWidget *parent)
QString community_id,
QWidget *parent)
: QWidget(parent) : QWidget(parent)
, community_(community) , groupId_(group_id)
, communityId_(community_id)
{ {
setMouseTracking(true); setMouseTracking(true);
setAttribute(Qt::WA_Hover); setAttribute(Qt::WA_Hover);
@ -20,8 +17,8 @@ CommunitiesListItem::CommunitiesListItem(QSharedPointer<Community> community,
rippleOverlay_->setClipPath(path); rippleOverlay_->setClipPath(path);
rippleOverlay_->setClipping(true); rippleOverlay_->setClipping(true);
if (communityId_ == "world") if (groupId_ == "world")
communityAvatar_ = QPixmap(":/icons/icons/ui/world.svg"); avatar_ = QPixmap(":/icons/icons/ui/world.svg");
} }
void void
@ -41,7 +38,7 @@ CommunitiesListItem::mousePressEvent(QMouseEvent *event)
return; return;
} }
emit clicked(communityId_); emit clicked(groupId_);
setPressedState(true); setPressedState(true);
@ -70,12 +67,12 @@ CommunitiesListItem::paintEvent(QPaintEvent *)
else else
p.fillRect(rect(), backgroundColor_); p.fillRect(rect(), backgroundColor_);
if (communityAvatar_.isNull()) { if (avatar_.isNull()) {
QFont font; QFont font;
font.setPixelSize(conf::roomlist::fonts::communityBubble); font.setPixelSize(conf::roomlist::fonts::communityBubble);
p.setFont(font); p.setFont(font);
p.drawLetterAvatar(utils::firstChar(community_->getName()), p.drawLetterAvatar(utils::firstChar(resolveName()),
avatarFgColor_, avatarFgColor_,
avatarBgColor_, avatarBgColor_,
width(), width(),
@ -84,7 +81,7 @@ CommunitiesListItem::paintEvent(QPaintEvent *)
} else { } else {
p.save(); p.save();
p.drawAvatar(communityAvatar_, width(), height(), IconSize); p.drawAvatar(avatar_, width(), height(), IconSize);
p.restore(); p.restore();
} }
} }
@ -92,6 +89,20 @@ CommunitiesListItem::paintEvent(QPaintEvent *)
void void
CommunitiesListItem::setAvatar(const QImage &img) CommunitiesListItem::setAvatar(const QImage &img)
{ {
communityAvatar_ = utils::scaleImageToPixmap(img, IconSize); avatar_ = utils::scaleImageToPixmap(img, IconSize);
update(); update();
} }
QString
CommunitiesListItem::resolveName() const
{
if (!name_.isEmpty())
return name_;
if (!groupId_.startsWith("+"))
return QString("Group"); // Group with no name or id.
// Extract the localpart of the group.
auto firstPart = groupId_.split(':').at(0);
return firstPart.right(firstPart.size() - 1);
}

View file

@ -1,33 +0,0 @@
#include "include/Community.h"
#include <QJsonArray>
#include <QJsonValue>
void
Community::parseProfile(const QJsonObject &profile)
{
if (profile["name"].type() == QJsonValue::Type::String)
name_ = profile["name"].toString();
else
name_ = "Unnamed Community"; // TODO: what is correct here?
if (profile["avatar_url"].type() == QJsonValue::Type::String)
avatar_ = QUrl(profile["avatar_url"].toString());
if (profile["short_description"].type() == QJsonValue::Type::String)
short_description_ = profile["short_description"].toString();
if (profile["long_description"].type() == QJsonValue::Type::String)
long_description_ = profile["long_description"].toString();
}
void
Community::parseRooms(const QJsonObject &rooms)
{
rooms_.clear();
for (auto const &room : rooms["chunk"].toArray()) {
if (room.toObject().contains("room_id"))
rooms_.emplace_back(room.toObject()["room_id"].toString());
}
}

View file

@ -31,8 +31,11 @@ init()
qRegisterMetaType<mtx::responses::Notifications>(); qRegisterMetaType<mtx::responses::Notifications>();
qRegisterMetaType<mtx::responses::Rooms>(); qRegisterMetaType<mtx::responses::Rooms>();
qRegisterMetaType<mtx::responses::Sync>(); qRegisterMetaType<mtx::responses::Sync>();
qRegisterMetaType<mtx::responses::JoinedGroups>();
qRegisterMetaType<mtx::responses::GroupProfile>();
qRegisterMetaType<std::string>(); qRegisterMetaType<std::string>();
qRegisterMetaType<std::vector<std::string>>(); qRegisterMetaType<std::vector<std::string>>();
qRegisterMetaType<std::vector<QString>>();
} }
} // namespace http } // namespace http