Public room directory.
This commit is contained in:
@@ -1,19 +1,6 @@
|
||||
#include "controller.h"
|
||||
|
||||
#include "settings.h"
|
||||
#include "spectralroom.h"
|
||||
#include "spectraluser.h"
|
||||
|
||||
#include "events/eventcontent.h"
|
||||
#include "events/roommessageevent.h"
|
||||
|
||||
#include "csapi/account-data.h"
|
||||
#include "csapi/content-repo.h"
|
||||
#include "csapi/joining.h"
|
||||
#include "csapi/logout.h"
|
||||
#include "csapi/profile.h"
|
||||
|
||||
#include "utils.h"
|
||||
#include <qt5keychain/keychain.h>
|
||||
|
||||
#include <QClipboard>
|
||||
#include <QFile>
|
||||
@@ -33,7 +20,17 @@
|
||||
#include <QtNetwork/QAuthenticator>
|
||||
#include <QtNetwork/QNetworkReply>
|
||||
|
||||
#include <qt5keychain/keychain.h>
|
||||
#include "csapi/account-data.h"
|
||||
#include "csapi/content-repo.h"
|
||||
#include "csapi/joining.h"
|
||||
#include "csapi/logout.h"
|
||||
#include "csapi/profile.h"
|
||||
#include "events/eventcontent.h"
|
||||
#include "events/roommessageevent.h"
|
||||
#include "settings.h"
|
||||
#include "spectralroom.h"
|
||||
#include "spectraluser.h"
|
||||
#include "utils.h"
|
||||
|
||||
Controller::Controller(QObject* parent) : QObject(parent) {
|
||||
QApplication::setQuitOnLastWindowClosed(false);
|
||||
@@ -386,7 +383,7 @@ void Controller::changeAvatar(Connection* conn, QUrl localFile) {
|
||||
}
|
||||
|
||||
void Controller::markAllMessagesAsRead(Connection* conn) {
|
||||
for (auto room : conn->roomMap().values()) {
|
||||
for (auto room : conn->allRooms()) {
|
||||
room->markAllMessagesAsRead();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,12 +1,6 @@
|
||||
#ifndef CONTROLLER_H
|
||||
#define CONTROLLER_H
|
||||
|
||||
#include "connection.h"
|
||||
#include "notifications/manager.h"
|
||||
#include "room.h"
|
||||
#include "settings.h"
|
||||
#include "user.h"
|
||||
|
||||
#include <QApplication>
|
||||
#include <QMediaPlayer>
|
||||
#include <QMenu>
|
||||
@@ -14,7 +8,14 @@
|
||||
#include <QObject>
|
||||
#include <QSystemTrayIcon>
|
||||
|
||||
using namespace QMatrixClient;
|
||||
#include "connection.h"
|
||||
#include "csapi/list_public_rooms.h"
|
||||
#include "notifications/manager.h"
|
||||
#include "room.h"
|
||||
#include "settings.h"
|
||||
#include "user.h"
|
||||
|
||||
using namespace Quotient;
|
||||
|
||||
class Controller : public QObject {
|
||||
Q_OBJECT
|
||||
|
||||
@@ -7,11 +7,14 @@
|
||||
|
||||
#include "accountlistmodel.h"
|
||||
#include "controller.h"
|
||||
#include "csapi/joining.h"
|
||||
#include "csapi/leaving.h"
|
||||
#include "emojimodel.h"
|
||||
#include "imageclipboard.h"
|
||||
#include "matriximageprovider.h"
|
||||
#include "messageeventmodel.h"
|
||||
#include "notifications/manager.h"
|
||||
#include "publicroomlistmodel.h"
|
||||
#include "room.h"
|
||||
#include "roomlistmodel.h"
|
||||
#include "spectralroom.h"
|
||||
@@ -19,9 +22,6 @@
|
||||
#include "trayicon.h"
|
||||
#include "userlistmodel.h"
|
||||
|
||||
#include "csapi/joining.h"
|
||||
#include "csapi/leaving.h"
|
||||
|
||||
using namespace QMatrixClient;
|
||||
|
||||
int main(int argc, char* argv[]) {
|
||||
@@ -41,6 +41,7 @@ int main(int argc, char* argv[]) {
|
||||
qmlRegisterType<RoomListModel>("Spectral", 0, 1, "RoomListModel");
|
||||
qmlRegisterType<UserListModel>("Spectral", 0, 1, "UserListModel");
|
||||
qmlRegisterType<MessageEventModel>("Spectral", 0, 1, "MessageEventModel");
|
||||
qmlRegisterType<PublicRoomListModel>("Spectral", 0, 1, "PublicRoomListModel");
|
||||
qmlRegisterType<EmojiModel>("Spectral", 0, 1, "EmojiModel");
|
||||
qmlRegisterType<NotificationsManager>("Spectral", 0, 1,
|
||||
"NotificationsManager");
|
||||
|
||||
89
src/publicroomlistmodel.cpp
Normal file
89
src/publicroomlistmodel.cpp
Normal file
@@ -0,0 +1,89 @@
|
||||
#include "publicroomlistmodel.h"
|
||||
|
||||
#include "csapi/list_public_rooms.h"
|
||||
|
||||
PublicRoomListModel::PublicRoomListModel(QObject* parent)
|
||||
: QAbstractListModel(parent) {}
|
||||
|
||||
void PublicRoomListModel::setConnection(Connection* conn) {
|
||||
if (m_connection == conn)
|
||||
return;
|
||||
|
||||
beginResetModel();
|
||||
|
||||
nextBatch = "";
|
||||
attempted = false;
|
||||
rooms.clear();
|
||||
|
||||
if (m_connection) {
|
||||
m_connection->disconnect(this);
|
||||
}
|
||||
|
||||
endResetModel();
|
||||
|
||||
m_connection = conn;
|
||||
|
||||
if (m_connection) {
|
||||
next();
|
||||
}
|
||||
|
||||
emit connectionChanged();
|
||||
}
|
||||
|
||||
void PublicRoomListModel::next(int count) {
|
||||
if (count < 1)
|
||||
return;
|
||||
|
||||
if (attempted && nextBatch.isEmpty())
|
||||
return;
|
||||
|
||||
auto job = m_connection->callApi<GetPublicRoomsJob>(count, nextBatch);
|
||||
|
||||
connect(job, &BaseJob::success, this, [=] {
|
||||
auto resp = job->data();
|
||||
nextBatch = resp.nextBatch;
|
||||
|
||||
this->beginInsertRows({}, rooms.count(),
|
||||
rooms.count() + resp.chunk.count());
|
||||
rooms.append(resp.chunk);
|
||||
this->endInsertRows();
|
||||
});
|
||||
|
||||
connect(job, &BaseJob::finished, this, [=] { attempted = true; });
|
||||
}
|
||||
|
||||
QVariant PublicRoomListModel::data(const QModelIndex& index, int role) const {
|
||||
if (!index.isValid())
|
||||
return QVariant();
|
||||
|
||||
if (index.row() >= rooms.count()) {
|
||||
qDebug() << "PublicRoomListModel, something's wrong: index.row() >= "
|
||||
"rooms.count()";
|
||||
return {};
|
||||
}
|
||||
auto room = rooms.at(index.row());
|
||||
if (role == NameRole) {
|
||||
return room.name;
|
||||
}
|
||||
if (role == TopicRole) {
|
||||
return room.topic;
|
||||
}
|
||||
|
||||
return {};
|
||||
}
|
||||
|
||||
QHash<int, QByteArray> PublicRoomListModel::roleNames() const {
|
||||
QHash<int, QByteArray> roles;
|
||||
|
||||
roles[NameRole] = "name";
|
||||
roles[TopicRole] = "topic";
|
||||
|
||||
return roles;
|
||||
}
|
||||
|
||||
int PublicRoomListModel::rowCount(const QModelIndex& parent) const {
|
||||
if (parent.isValid())
|
||||
return 0;
|
||||
|
||||
return rooms.count();
|
||||
}
|
||||
43
src/publicroomlistmodel.h
Normal file
43
src/publicroomlistmodel.h
Normal file
@@ -0,0 +1,43 @@
|
||||
#ifndef PUBLICROOMLISTMODEL_H
|
||||
#define PUBLICROOMLISTMODEL_H
|
||||
|
||||
#include <QObject>
|
||||
#include <QAbstractListModel>
|
||||
|
||||
#include "connection.h"
|
||||
#include "csapi/definitions/public_rooms_response.h"
|
||||
|
||||
using namespace Quotient;
|
||||
|
||||
class PublicRoomListModel : public QAbstractListModel {
|
||||
Q_OBJECT
|
||||
Q_PROPERTY(Connection* connection READ connection WRITE setConnection NOTIFY connectionChanged)
|
||||
|
||||
public:
|
||||
enum EventRoles { NameRole = Qt::DisplayRole + 1, TopicRole };
|
||||
|
||||
PublicRoomListModel(QObject* parent = nullptr);
|
||||
|
||||
QVariant data(const QModelIndex& index, int role = NameRole) const override;
|
||||
int rowCount(const QModelIndex& parent = QModelIndex()) const override;
|
||||
|
||||
QHash<int, QByteArray> roleNames() const override;
|
||||
|
||||
Connection* connection() const { return m_connection; }
|
||||
void setConnection(Connection* value);
|
||||
|
||||
Q_INVOKABLE void next(int count = 50);
|
||||
|
||||
private:
|
||||
Connection* m_connection = nullptr;
|
||||
|
||||
bool attempted = false;
|
||||
QString nextBatch;
|
||||
|
||||
QVector<PublicRoomsChunk> rooms;
|
||||
|
||||
signals:
|
||||
void connectionChanged();
|
||||
};
|
||||
|
||||
#endif // PUBLICROOMLISTMODEL_H
|
||||
@@ -59,7 +59,7 @@ void RoomListModel::setConnection(Connection* connection) {
|
||||
void RoomListModel::doResetModel() {
|
||||
beginResetModel();
|
||||
m_rooms.clear();
|
||||
for (auto r : m_connection->roomMap()) {
|
||||
for (auto r : m_connection->allRooms()) {
|
||||
doAddRoom(r);
|
||||
}
|
||||
endResetModel();
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
#include "userlistmodel.h"
|
||||
|
||||
#include <QElapsedTimer>
|
||||
#include <QtCore/QDebug>
|
||||
#include <QtGui/QPixmap>
|
||||
|
||||
#include <connection.h>
|
||||
#include <room.h>
|
||||
#include <user.h>
|
||||
|
||||
#include <QElapsedTimer>
|
||||
#include <QtCore/QDebug>
|
||||
#include <QtGui/QPixmap>
|
||||
|
||||
#include "spectraluser.h"
|
||||
|
||||
UserListModel::UserListModel(QObject* parent)
|
||||
@@ -17,7 +17,7 @@ void UserListModel::setRoom(QMatrixClient::Room* room) {
|
||||
if (m_currentRoom == room)
|
||||
return;
|
||||
|
||||
using namespace QMatrixClient;
|
||||
using namespace Quotient;
|
||||
beginResetModel();
|
||||
if (m_currentRoom) {
|
||||
m_currentRoom->disconnect(this);
|
||||
|
||||
Reference in New Issue
Block a user