Public room directory.
This commit is contained in:
@@ -155,6 +155,7 @@ set(spectral_SRCS
|
|||||||
src/spectraluser.cpp
|
src/spectraluser.cpp
|
||||||
src/trayicon.cpp
|
src/trayicon.cpp
|
||||||
src/userlistmodel.cpp
|
src/userlistmodel.cpp
|
||||||
|
src/publicroomlistmodel.cpp
|
||||||
src/utils.cpp
|
src/utils.cpp
|
||||||
src/main.cpp
|
src/main.cpp
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -111,7 +111,7 @@ Dialog {
|
|||||||
RippleEffect {
|
RippleEffect {
|
||||||
anchors.fill: parent
|
anchors.fill: parent
|
||||||
|
|
||||||
onPrimaryClicked: joinRoomDialog.createObject(ApplicationWindow.overlay).open()
|
onPrimaryClicked: joinRoomDialog.createObject(ApplicationWindow.overlay, {"controller": spectralController, "connection": spectralController.connection}).open()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -3,10 +3,17 @@ import QtQuick.Controls 2.12
|
|||||||
import QtQuick.Layouts 1.12
|
import QtQuick.Layouts 1.12
|
||||||
|
|
||||||
import Spectral.Component 2.0
|
import Spectral.Component 2.0
|
||||||
|
import Spectral.Setting 0.1
|
||||||
|
|
||||||
|
import Spectral 0.1
|
||||||
|
|
||||||
Dialog {
|
Dialog {
|
||||||
|
property var controller
|
||||||
|
property var connection
|
||||||
|
|
||||||
anchors.centerIn: parent
|
anchors.centerIn: parent
|
||||||
width: 360
|
width: 360
|
||||||
|
height: window.height - 100
|
||||||
|
|
||||||
id: root
|
id: root
|
||||||
|
|
||||||
@@ -20,19 +27,66 @@ Dialog {
|
|||||||
|
|
||||||
placeholderText: "Room Alias/User ID"
|
placeholderText: "Room Alias/User ID"
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
standardButtons: Dialog.Ok | Dialog.Cancel
|
MenuSeparator {
|
||||||
|
Layout.fillWidth: true
|
||||||
|
}
|
||||||
|
|
||||||
onAccepted: {
|
AutoListView {
|
||||||
var identifier = identifierField.text
|
Layout.fillWidth: true
|
||||||
var firstChar = identifier.charAt(0)
|
Layout.fillHeight: true
|
||||||
if (firstChar == "@") {
|
|
||||||
spectralController.createDirectChat(spectralController.connection, identifier)
|
id: publicRoomsListView
|
||||||
} else if (firstChar == "!" || firstChar == "#") {
|
|
||||||
spectralController.joinRoom(spectralController.connection, identifier)
|
spacing: 8
|
||||||
|
|
||||||
|
model: PublicRoomListModel {
|
||||||
|
connection: root.connection
|
||||||
|
}
|
||||||
|
|
||||||
|
delegate: ColumnLayout {
|
||||||
|
width: publicRoomsListView.width
|
||||||
|
|
||||||
|
Label {
|
||||||
|
Layout.fillWidth: true
|
||||||
|
|
||||||
|
text: name ? name : "No name"
|
||||||
|
color: MPalette.foreground
|
||||||
|
font.pixelSize: 13
|
||||||
|
textFormat: Text.PlainText
|
||||||
|
elide: Text.ElideRight
|
||||||
|
wrapMode: Text.NoWrap
|
||||||
|
}
|
||||||
|
|
||||||
|
Label {
|
||||||
|
Layout.fillWidth: true
|
||||||
|
|
||||||
|
visible: text
|
||||||
|
|
||||||
|
text: topic ? topic.replace(/(\r\n\t|\n|\r\t)/gm," ") : ""
|
||||||
|
color: MPalette.lighter
|
||||||
|
font.pixelSize: 10
|
||||||
|
textFormat: Text.PlainText
|
||||||
|
elide: Text.ElideRight
|
||||||
|
wrapMode: Text.NoWrap
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
ScrollBar.vertical: ScrollBar {}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// standardButtons: Dialog.Ok | Dialog.Cancel
|
||||||
|
|
||||||
|
// onAccepted: {
|
||||||
|
// var identifier = identifierField.text
|
||||||
|
// var firstChar = identifier.charAt(0)
|
||||||
|
// if (firstChar == "@") {
|
||||||
|
// spectralController.createDirectChat(spectralController.connection, identifier)
|
||||||
|
// } else if (firstChar == "!" || firstChar == "#") {
|
||||||
|
// spectralController.joinRoom(spectralController.connection, identifier)
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
|
||||||
onClosed: destroy()
|
onClosed: destroy()
|
||||||
}
|
}
|
||||||
|
|||||||
Submodule include/SortFilterProxyModel updated: 770789ee48...36befddf5d
Submodule include/libQuotient updated: 5937127b73...04960510df
@@ -1,19 +1,6 @@
|
|||||||
#include "controller.h"
|
#include "controller.h"
|
||||||
|
|
||||||
#include "settings.h"
|
#include <qt5keychain/keychain.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 <QClipboard>
|
#include <QClipboard>
|
||||||
#include <QFile>
|
#include <QFile>
|
||||||
@@ -33,7 +20,17 @@
|
|||||||
#include <QtNetwork/QAuthenticator>
|
#include <QtNetwork/QAuthenticator>
|
||||||
#include <QtNetwork/QNetworkReply>
|
#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) {
|
Controller::Controller(QObject* parent) : QObject(parent) {
|
||||||
QApplication::setQuitOnLastWindowClosed(false);
|
QApplication::setQuitOnLastWindowClosed(false);
|
||||||
@@ -386,7 +383,7 @@ void Controller::changeAvatar(Connection* conn, QUrl localFile) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void Controller::markAllMessagesAsRead(Connection* conn) {
|
void Controller::markAllMessagesAsRead(Connection* conn) {
|
||||||
for (auto room : conn->roomMap().values()) {
|
for (auto room : conn->allRooms()) {
|
||||||
room->markAllMessagesAsRead();
|
room->markAllMessagesAsRead();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,12 +1,6 @@
|
|||||||
#ifndef CONTROLLER_H
|
#ifndef CONTROLLER_H
|
||||||
#define CONTROLLER_H
|
#define CONTROLLER_H
|
||||||
|
|
||||||
#include "connection.h"
|
|
||||||
#include "notifications/manager.h"
|
|
||||||
#include "room.h"
|
|
||||||
#include "settings.h"
|
|
||||||
#include "user.h"
|
|
||||||
|
|
||||||
#include <QApplication>
|
#include <QApplication>
|
||||||
#include <QMediaPlayer>
|
#include <QMediaPlayer>
|
||||||
#include <QMenu>
|
#include <QMenu>
|
||||||
@@ -14,7 +8,14 @@
|
|||||||
#include <QObject>
|
#include <QObject>
|
||||||
#include <QSystemTrayIcon>
|
#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 {
|
class Controller : public QObject {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|||||||
@@ -7,11 +7,14 @@
|
|||||||
|
|
||||||
#include "accountlistmodel.h"
|
#include "accountlistmodel.h"
|
||||||
#include "controller.h"
|
#include "controller.h"
|
||||||
|
#include "csapi/joining.h"
|
||||||
|
#include "csapi/leaving.h"
|
||||||
#include "emojimodel.h"
|
#include "emojimodel.h"
|
||||||
#include "imageclipboard.h"
|
#include "imageclipboard.h"
|
||||||
#include "matriximageprovider.h"
|
#include "matriximageprovider.h"
|
||||||
#include "messageeventmodel.h"
|
#include "messageeventmodel.h"
|
||||||
#include "notifications/manager.h"
|
#include "notifications/manager.h"
|
||||||
|
#include "publicroomlistmodel.h"
|
||||||
#include "room.h"
|
#include "room.h"
|
||||||
#include "roomlistmodel.h"
|
#include "roomlistmodel.h"
|
||||||
#include "spectralroom.h"
|
#include "spectralroom.h"
|
||||||
@@ -19,9 +22,6 @@
|
|||||||
#include "trayicon.h"
|
#include "trayicon.h"
|
||||||
#include "userlistmodel.h"
|
#include "userlistmodel.h"
|
||||||
|
|
||||||
#include "csapi/joining.h"
|
|
||||||
#include "csapi/leaving.h"
|
|
||||||
|
|
||||||
using namespace QMatrixClient;
|
using namespace QMatrixClient;
|
||||||
|
|
||||||
int main(int argc, char* argv[]) {
|
int main(int argc, char* argv[]) {
|
||||||
@@ -41,6 +41,7 @@ int main(int argc, char* argv[]) {
|
|||||||
qmlRegisterType<RoomListModel>("Spectral", 0, 1, "RoomListModel");
|
qmlRegisterType<RoomListModel>("Spectral", 0, 1, "RoomListModel");
|
||||||
qmlRegisterType<UserListModel>("Spectral", 0, 1, "UserListModel");
|
qmlRegisterType<UserListModel>("Spectral", 0, 1, "UserListModel");
|
||||||
qmlRegisterType<MessageEventModel>("Spectral", 0, 1, "MessageEventModel");
|
qmlRegisterType<MessageEventModel>("Spectral", 0, 1, "MessageEventModel");
|
||||||
|
qmlRegisterType<PublicRoomListModel>("Spectral", 0, 1, "PublicRoomListModel");
|
||||||
qmlRegisterType<EmojiModel>("Spectral", 0, 1, "EmojiModel");
|
qmlRegisterType<EmojiModel>("Spectral", 0, 1, "EmojiModel");
|
||||||
qmlRegisterType<NotificationsManager>("Spectral", 0, 1,
|
qmlRegisterType<NotificationsManager>("Spectral", 0, 1,
|
||||||
"NotificationsManager");
|
"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() {
|
void RoomListModel::doResetModel() {
|
||||||
beginResetModel();
|
beginResetModel();
|
||||||
m_rooms.clear();
|
m_rooms.clear();
|
||||||
for (auto r : m_connection->roomMap()) {
|
for (auto r : m_connection->allRooms()) {
|
||||||
doAddRoom(r);
|
doAddRoom(r);
|
||||||
}
|
}
|
||||||
endResetModel();
|
endResetModel();
|
||||||
|
|||||||
@@ -1,13 +1,13 @@
|
|||||||
#include "userlistmodel.h"
|
#include "userlistmodel.h"
|
||||||
|
|
||||||
#include <QElapsedTimer>
|
|
||||||
#include <QtCore/QDebug>
|
|
||||||
#include <QtGui/QPixmap>
|
|
||||||
|
|
||||||
#include <connection.h>
|
#include <connection.h>
|
||||||
#include <room.h>
|
#include <room.h>
|
||||||
#include <user.h>
|
#include <user.h>
|
||||||
|
|
||||||
|
#include <QElapsedTimer>
|
||||||
|
#include <QtCore/QDebug>
|
||||||
|
#include <QtGui/QPixmap>
|
||||||
|
|
||||||
#include "spectraluser.h"
|
#include "spectraluser.h"
|
||||||
|
|
||||||
UserListModel::UserListModel(QObject* parent)
|
UserListModel::UserListModel(QObject* parent)
|
||||||
@@ -17,7 +17,7 @@ void UserListModel::setRoom(QMatrixClient::Room* room) {
|
|||||||
if (m_currentRoom == room)
|
if (m_currentRoom == room)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
using namespace QMatrixClient;
|
using namespace Quotient;
|
||||||
beginResetModel();
|
beginResetModel();
|
||||||
if (m_currentRoom) {
|
if (m_currentRoom) {
|
||||||
m_currentRoom->disconnect(this);
|
m_currentRoom->disconnect(this);
|
||||||
|
|||||||
Reference in New Issue
Block a user