From d25a9fb3a4f04cb49f15ffa97e1b3e1440192cb8 Mon Sep 17 00:00:00 2001 From: Black Hat Date: Wed, 25 Dec 2019 19:53:50 +0800 Subject: [PATCH] Working public room directory. Fix "no known servers". Rename all QMatrixClient to Quotient. --- .../Spectral/Dialog/AccountDetailDialog.qml | 6 +- imports/Spectral/Dialog/JoinRoomDialog.qml | 160 ++++++++++++++---- imports/Spectral/Panel/RoomListPanel.qml | 18 +- src/controller.cpp | 10 +- src/main.cpp | 3 +- src/matriximageprovider.cpp | 4 +- src/messageeventmodel.cpp | 49 +++--- src/messageeventmodel.h | 6 +- src/publicroomlistmodel.cpp | 23 +++ src/publicroomlistmodel.h | 11 +- src/spectralroom.cpp | 121 +++++++------ src/spectralroom.h | 25 +-- src/spectraluser.h | 6 +- src/userlistmodel.cpp | 16 +- 14 files changed, 297 insertions(+), 161 deletions(-) diff --git a/imports/Spectral/Dialog/AccountDetailDialog.qml b/imports/Spectral/Dialog/AccountDetailDialog.qml index 3ec590159..2846ec6fd 100644 --- a/imports/Spectral/Dialog/AccountDetailDialog.qml +++ b/imports/Spectral/Dialog/AccountDetailDialog.qml @@ -97,14 +97,14 @@ Dialog { Layout.preferredHeight: 48 color: MPalette.foreground - icon: "\ue7ff" + icon: "\ue5d2" } Label { Layout.fillWidth: true color: MPalette.foreground - text: "Start a Chat" + text: "Explore Rooms" } } @@ -113,7 +113,7 @@ Dialog { onPrimaryClicked: { joinRoomDialog.createObject(ApplicationWindow.overlay, {"controller": spectralController, "connection": spectralController.connection}).open() - root.destroy() + root.close() } } } diff --git a/imports/Spectral/Dialog/JoinRoomDialog.qml b/imports/Spectral/Dialog/JoinRoomDialog.qml index 52060d8cb..76d7a1d00 100644 --- a/imports/Spectral/Dialog/JoinRoomDialog.qml +++ b/imports/Spectral/Dialog/JoinRoomDialog.qml @@ -21,7 +21,7 @@ Dialog { id: root - title: "Start a Chat" + title: "Explore Rooms" contentItem: ColumnLayout { spacing: 0 @@ -30,17 +30,39 @@ Dialog { Layout.fillWidth: true AutoTextField { + property bool isRoomAlias: text.match(/#(.+):(.+)/g) + property var room: isRoomAlias ? connection.roomByAlias(text) : null + property bool isJoined: room != null + Layout.fillWidth: true id: identifierField - placeholderText: "Room Alias/User ID" + placeholderText: "Find a room..." - Keys.onReturnPressed: { + onEditingFinished: { keyword = text } } + Button { + id: joinButton + + visible: identifierField.isRoomAlias + + text: identifierField.isJoined ? "View" : "Join" + highlighted: true + flat: identifierField.isJoined + + onClicked: { + if (identifierField.isJoined) { + roomListForm.joinRoom(identifierField.room) + } else { + spectralController.joinRoom(connection, identifierField.text) + } + } + } + ComboBox { Layout.maximumWidth: 120 @@ -88,14 +110,13 @@ Dialog { keyword: root.keyword } - delegate: Item { + delegate: Control { width: publicRoomsListView.width - height: 40 + height: 48 - RowLayout { - anchors.fill: parent - anchors.margins: 4 + padding: 8 + contentItem: RowLayout { spacing: 8 Avatar { @@ -109,20 +130,52 @@ Dialog { ColumnLayout { Layout.fillWidth: true Layout.fillHeight: true - Layout.alignment: Qt.AlignHCenter spacing: 0 - Label { + RowLayout { Layout.fillWidth: true Layout.fillHeight: true - text: name - color: MPalette.foreground - font.pixelSize: 13 - textFormat: Text.PlainText - elide: Text.ElideRight - wrapMode: Text.NoWrap + spacing: 4 + + Label { + Layout.fillWidth: true + Layout.fillHeight: true + + text: name + color: MPalette.foreground + font.pixelSize: 13 + textFormat: Text.PlainText + elide: Text.ElideRight + wrapMode: Text.NoWrap + } + + Label { + visible: allowGuests + + text: "GUESTS CAN JOIN" + color: MPalette.lighter + font.pixelSize: 10 + padding: 4 + + background: Rectangle { + color: MPalette.banner + } + } + + Label { + visible: worldReadable + + text: "WORLD READABLE" + color: MPalette.lighter + font.pixelSize: 10 + padding: 4 + + background: Rectangle { + color: MPalette.banner + } + } } Label { @@ -139,10 +192,67 @@ Dialog { wrapMode: Text.NoWrap } } - } - RippleEffect { - anchors.fill: parent + MaterialIcon { + Layout.preferredWidth: 16 + Layout.preferredHeight: 16 + + icon: "\ue7fc" + color: MPalette.lighter + font.pixelSize: 16 + } + + Label { + Layout.preferredWidth: 36 + + text: memberCount + color: MPalette.lighter + font.pixelSize: 12 + } + + Control { + Layout.preferredWidth: 32 + Layout.preferredHeight: 32 + + visible: isJoined + + contentItem: MaterialIcon { + icon: "\ue89e" + color: MPalette.lighter + font.pixelSize: 20 + } + + background: RippleEffect { + circular: true + + onClicked: { + roomListForm.joinRoom(connection.room(roomID)) + root.close() + } + } + } + + Control { + Layout.preferredWidth: 32 + Layout.preferredHeight: 32 + + visible: !isJoined + + contentItem: MaterialIcon { + icon: "\ue7f0" + color: MPalette.lighter + font.pixelSize: 20 + } + + background: RippleEffect { + circular: true + + onClicked: { + spectralController.joinRoom(connection, roomID) + root.close() + } + } + } } } @@ -155,17 +265,5 @@ Dialog { } } - // 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() } diff --git a/imports/Spectral/Panel/RoomListPanel.qml b/imports/Spectral/Panel/RoomListPanel.qml index 358822824..cbd64b636 100644 --- a/imports/Spectral/Panel/RoomListPanel.qml +++ b/imports/Spectral/Panel/RoomListPanel.qml @@ -296,13 +296,7 @@ Item { if (category === RoomType.Invited) { acceptInvitationDialog.createObject(ApplicationWindow.overlay, {"room": currentRoom}).open() } else { - if (enteredRoom) { - leaveRoom(enteredRoom) - enteredRoom.displayed = false - } - enterRoom(currentRoom) - enteredRoom = currentRoom - currentRoom.displayed = true + joinRoom(currentRoom) } } onSecondaryClicked: roomListContextMenu.createObject(parent, {"room": currentRoom}).popup() @@ -427,4 +421,14 @@ Item { AcceptInvitationDialog {} } + + function joinRoom(room) { + if (enteredRoom) { + leaveRoom(enteredRoom) + enteredRoom.displayed = false + } + enterRoom(room) + enteredRoom = room + room.displayed = true + } } diff --git a/src/controller.cpp b/src/controller.cpp index 371d517f7..a655576e3 100644 --- a/src/controller.cpp +++ b/src/controller.cpp @@ -195,7 +195,7 @@ void Controller::addConnection(Connection* c) { c->sync(30000); }); - using namespace QMatrixClient; + using namespace Quotient; setBusy(true); @@ -213,7 +213,7 @@ void Controller::dropConnection(Connection* c) { } void Controller::invokeLogin() { - using namespace QMatrixClient; + using namespace Quotient; const auto accounts = SettingsGroup("Accounts").childGroups(); for (const auto& accountId : accounts) { AccountSettings account{accountId}; @@ -342,7 +342,11 @@ bool Controller::saveAccessTokenToKeyChain(const AccountSettings& account, } void Controller::joinRoom(Connection* c, const QString& alias) { - auto joinRoomJob = c->joinRoom(alias); + if (!alias.contains(":")) + return; + + auto knownServer = alias.mid(alias.indexOf(":") + 1); + auto joinRoomJob = c->joinRoom(alias, QStringList{knownServer}); joinRoomJob->connect(joinRoomJob, &JoinRoomJob::failure, [=] { emit errorOccured("Join Room Failed", joinRoomJob->errorString()); }); diff --git a/src/main.cpp b/src/main.cpp index f7e12b45d..f7676fdcc 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -22,7 +22,7 @@ #include "trayicon.h" #include "userlistmodel.h" -using namespace QMatrixClient; +using namespace Quotient; int main(int argc, char* argv[]) { QApplication::setAttribute(Qt::AA_EnableHighDpiScaling); @@ -53,6 +53,7 @@ int main(int argc, char* argv[]) { qRegisterMetaType("User*"); qRegisterMetaType("const User*"); + qRegisterMetaType("const Quotient::User*"); qRegisterMetaType("Room*"); qRegisterMetaType("Connection*"); qRegisterMetaType("MessageEventType"); diff --git a/src/matriximageprovider.cpp b/src/matriximageprovider.cpp index 13c4ca5b2..e99870f1a 100644 --- a/src/matriximageprovider.cpp +++ b/src/matriximageprovider.cpp @@ -6,9 +6,9 @@ #include #include -using QMatrixClient::BaseJob; +using Quotient::BaseJob; -ThumbnailResponse::ThumbnailResponse(QMatrixClient::Connection* c, +ThumbnailResponse::ThumbnailResponse(Quotient::Connection* c, QString id, const QSize& size) : c(c), diff --git a/src/messageeventmodel.cpp b/src/messageeventmodel.cpp index fa2978c3f..7e05151a9 100644 --- a/src/messageeventmodel.cpp +++ b/src/messageeventmodel.cpp @@ -1,14 +1,13 @@ #include "messageeventmodel.h" #include -#include -#include - #include #include #include #include #include +#include +#include #include #include // for qmlRegisterType() @@ -42,7 +41,7 @@ QHash MessageEventModel::roleNames() const { MessageEventModel::MessageEventModel(QObject* parent) : QAbstractListModel(parent), m_currentRoom(nullptr) { - using namespace QMatrixClient; + using namespace Quotient; qmlRegisterType(); qRegisterMetaType(); qmlRegisterUncreatableType( @@ -64,7 +63,7 @@ void MessageEventModel::setRoom(SpectralRoom* room) { if (room) { lastReadEventId = room->readMarkerEventId(); - using namespace QMatrixClient; + using namespace Quotient; connect(m_currentRoom, &Room::aboutToAddNewMessages, this, [=](RoomEventsRange events) { beginInsertRows({}, timelineBaseIndex(), @@ -207,12 +206,12 @@ int MessageEventModel::refreshEventRoles(const QString& id, return row; } -inline bool hasValidTimestamp(const QMatrixClient::TimelineItem& ti) { +inline bool hasValidTimestamp(const Quotient::TimelineItem& ti) { return ti->timestamp().isValid(); } QDateTime MessageEventModel::makeMessageTimestamp( - const QMatrixClient::Room::rev_iter_t& baseIt) const { + const Quotient::Room::rev_iter_t& baseIt) const { const auto& timeline = m_currentRoom->messageEvents(); auto ts = baseIt->event()->timestamp(); if (ts.isValid()) @@ -220,7 +219,7 @@ QDateTime MessageEventModel::makeMessageTimestamp( // The event is most likely redacted or just invalid. // Look for the nearest date around and slap zero time to it. - using QMatrixClient::TimelineItem; + using Quotient::TimelineItem; auto rit = std::find_if(baseIt, timeline.rend(), hasValidTimestamp); if (rit != timeline.rend()) return {rit->event()->timestamp().date(), {0, 0}, Qt::LocalTime}; @@ -269,16 +268,18 @@ int MessageEventModel::rowCount(const QModelIndex& parent) const { return m_currentRoom->timelineSize(); } -inline QVariantMap userAtEvent(SpectralUser* user, SpectralRoom* room, const RoomEvent& evt) { - return QVariantMap{ - {"isLocalUser", user->id() == room->localUser()->id()}, - {"id", user->id()}, - {"avatarMediaId", user->avatarMediaId(room)}, - {"avatarUrl", user->avatarUrl(room)}, - {"displayName", user->displayname(room)}, - {"color", user->color()}, - {"object", QVariant::fromValue(user)}, - }; +inline QVariantMap userAtEvent(SpectralUser* user, + SpectralRoom* room, + const RoomEvent& evt) { + return QVariantMap{ + {"isLocalUser", user->id() == room->localUser()->id()}, + {"id", user->id()}, + {"avatarMediaId", user->avatarMediaId(room)}, + {"avatarUrl", user->avatarUrl(room)}, + {"displayName", user->displayname(room)}, + {"color", user->color()}, + {"object", QVariant::fromValue(user)}, + }; } QVariant MessageEventModel::data(const QModelIndex& idx, int role) const { @@ -340,9 +341,10 @@ QVariant MessageEventModel::data(const QModelIndex& idx, int role) const { return EventTypeRegistry::getMatrixType(evt.type()); if (role == AuthorRole) { - auto author = static_cast(isPending ? m_currentRoom->localUser() - : m_currentRoom->user(evt.senderId())); - return userAtEvent(author, m_currentRoom, evt); + auto author = static_cast( + isPending ? m_currentRoom->localUser() + : m_currentRoom->user(evt.senderId())); + return userAtEvent(author, m_currentRoom, evt); } if (role == ContentTypeRole) { @@ -455,8 +457,9 @@ QVariant MessageEventModel::data(const QModelIndex& idx, int role) const { return QVariantMap{ {"eventId", replyEventId}, {"display", m_currentRoom->eventToString(replyEvt, Qt::RichText)}, - {"author", - userAtEvent(static_cast(m_currentRoom->user(replyEvt.senderId())), m_currentRoom, evt)}}; + {"author", userAtEvent(static_cast( + m_currentRoom->user(replyEvt.senderId())), + m_currentRoom, evt)}}; } if (role == ShowAuthorRole) { diff --git a/src/messageeventmodel.h b/src/messageeventmodel.h index 398aff2c4..8b773667e 100644 --- a/src/messageeventmodel.h +++ b/src/messageeventmodel.h @@ -1,11 +1,11 @@ #ifndef MESSAGEEVENTMODEL_H #define MESSAGEEVENTMODEL_H +#include + #include "room.h" #include "spectralroom.h" -#include - class MessageEventModel : public QAbstractListModel { Q_OBJECT Q_PROPERTY(SpectralRoom* room READ room WRITE setRoom NOTIFY roomChanged) @@ -72,7 +72,7 @@ class MessageEventModel : public QAbstractListModel { int timelineBaseIndex() const; QDateTime makeMessageTimestamp( - const QMatrixClient::Room::rev_iter_t& baseIt) const; + const Quotient::Room::rev_iter_t& baseIt) const; QString renderDate(QDateTime timestamp) const; void refreshLastUserEvents(int baseRow); diff --git a/src/publicroomlistmodel.cpp b/src/publicroomlistmodel.cpp index a7e1e0943..cf8c0be13 100644 --- a/src/publicroomlistmodel.cpp +++ b/src/publicroomlistmodel.cpp @@ -167,6 +167,24 @@ QVariant PublicRoomListModel::data(const QModelIndex& index, int role) const { if (role == TopicRole) { return room.topic; } + if (role == RoomIDRole) { + return room.roomId; + } + if (role == MemberCountRole) { + return room.numJoinedMembers; + } + if (role == AllowGuestsRole) { + return room.guestCanJoin; + } + if (role == WorldReadableRole) { + return room.worldReadable; + } + if (role == IsJoinedRole) { + if (!m_connection) + return {}; + + return m_connection->room(room.roomId, JoinState::Join) != nullptr; + } return {}; } @@ -177,6 +195,11 @@ QHash PublicRoomListModel::roleNames() const { roles[NameRole] = "name"; roles[AvatarRole] = "avatar"; roles[TopicRole] = "topic"; + roles[RoomIDRole] = "roomID"; + roles[MemberCountRole] = "memberCount"; + roles[AllowGuestsRole] = "allowGuests"; + roles[WorldReadableRole] = "worldReadable"; + roles[IsJoinedRole] = "isJoined"; return roles; } diff --git a/src/publicroomlistmodel.h b/src/publicroomlistmodel.h index 1fa7a5240..24add9887 100644 --- a/src/publicroomlistmodel.h +++ b/src/publicroomlistmodel.h @@ -20,7 +20,16 @@ class PublicRoomListModel : public QAbstractListModel { Q_PROPERTY(bool hasMore READ hasMore NOTIFY hasMoreChanged) public: - enum EventRoles { NameRole = Qt::DisplayRole + 1, AvatarRole, TopicRole }; + enum EventRoles { + NameRole = Qt::DisplayRole + 1, + AvatarRole, + TopicRole, + RoomIDRole, + MemberCountRole, + AllowGuestsRole, + WorldReadableRole, + IsJoinedRole, + }; PublicRoomListModel(QObject* parent = nullptr); diff --git a/src/spectralroom.cpp b/src/spectralroom.cpp index 905d7158a..110752bcb 100644 --- a/src/spectralroom.cpp +++ b/src/spectralroom.cpp @@ -1,8 +1,16 @@ #include "spectralroom.h" -#include "connection.h" -#include "user.h" +#include +#include +#include +#include +#include +#include +#include +#include + +#include "connection.h" #include "csapi/account-data.h" #include "csapi/content-repo.h" #include "csapi/leaving.h" @@ -14,18 +22,7 @@ #include "events/roommessageevent.h" #include "events/typingevent.h" #include "jobs/downloadfilejob.h" - -#include - -#include -#include -#include -#include -#include -#include - -#include - +#include "user.h" #include "utils.h" SpectralRoom::SpectralRoom(Connection* connection, @@ -117,8 +114,7 @@ QString SpectralRoom::lastEvent() const { continue; return user(evt->senderId())->displayname() + - (evt->isStateEvent() ? " " : ": ") + - eventToString(*evt); + (evt->isStateEvent() ? " " : ": ") + eventToString(*evt); } return ""; } @@ -127,7 +123,7 @@ bool SpectralRoom::isEventHighlighted(const RoomEvent* e) const { return highlights.contains(e); } -void SpectralRoom::checkForHighlights(const QMatrixClient::TimelineItem& ti) { +void SpectralRoom::checkForHighlights(const Quotient::TimelineItem& ti) { auto localUserId = localUser()->id(); if (ti->senderId() == localUserId) return; @@ -230,20 +226,21 @@ QString SpectralRoom::avatarMediaId() const { } QString SpectralRoom::eventToString(const RoomEvent& evt, - Qt::TextFormat format, bool removeReply) const { + Qt::TextFormat format, + bool removeReply) const { const bool prettyPrint = (format == Qt::RichText); - using namespace QMatrixClient; + using namespace Quotient; return visit( evt, [prettyPrint, removeReply](const RoomMessageEvent& e) { using namespace MessageEventContent; if (prettyPrint && e.hasTextContent() && - e.mimeType().name() != "text/plain") { + e.mimeType().name() != "text/plain") { auto htmlBody = static_cast(e.content())->body; if (removeReply) { - htmlBody.remove(utils::removeRichReplyRegex); + htmlBody.remove(utils::removeRichReplyRegex); } htmlBody.replace(utils::userPillRegExp, "\\1"); htmlBody.replace(utils::strikethroughRegExp, "\\1"); @@ -255,24 +252,23 @@ QString SpectralRoom::eventToString(const RoomEvent& evt, auto fileCaption = e.content()->fileInfo()->originalName.toHtmlEscaped(); if (fileCaption.isEmpty()) { - fileCaption = prettyPrint - ? QMatrixClient::prettyPrint(e.plainBody()) - : e.plainBody(); + fileCaption = prettyPrint ? Quotient::prettyPrint(e.plainBody()) + : e.plainBody(); } else if (e.content()->fileInfo()->originalName != e.plainBody()) { - fileCaption = e.plainBody() + " | " + fileCaption; + fileCaption = e.plainBody() + " | " + fileCaption; } return !fileCaption.isEmpty() ? fileCaption : tr("a file"); } if (prettyPrint) { - auto plainBody = e.plainBody(); - if (removeReply) { - plainBody.remove(utils::removeReplyRegex); - } - return QMatrixClient::prettyPrint(plainBody); + auto plainBody = e.plainBody(); + if (removeReply) { + plainBody.remove(utils::removeReplyRegex); + } + return Quotient::prettyPrint(plainBody); } if (removeReply) { - return e.plainBody().remove(utils::removeReplyRegex); + return e.plainBody().remove(utils::removeReplyRegex); } return e.plainBody(); }, @@ -364,9 +360,8 @@ QString SpectralRoom::eventToString(const RoomEvent& evt, return (e.topic().isEmpty()) ? tr("cleared the topic") : tr("set the topic to: %1") - .arg(prettyPrint - ? QMatrixClient::prettyPrint(e.topic()) - : e.topic()); + .arg(prettyPrint ? Quotient::prettyPrint(e.topic()) + : e.topic()); }, [](const RoomAvatarEvent&) { return tr("changed the room avatar"); }, [](const EncryptionEvent&) { @@ -486,21 +481,20 @@ void SpectralRoom::postPlainMessage(const QString& text, if (isReply) { const auto& replyEvt = **replyIt; - QJsonObject json{ - {"msgtype", msgTypeToString(type)}, - {"body", "> <" + replyEvt.senderId() + "> " + eventToString(replyEvt) + - "\n\n" + text}, - {"format", "org.matrix.custom.html"}, - {"m.relates_to", - QJsonObject{ - {"m.in_reply_to", QJsonObject{{"event_id", replyEventId}}}}}, - {"formatted_body", - "
In reply to " + replyEvt.senderId() + "
" + - eventToString(replyEvt, Qt::RichText) + - "
" + text.toHtmlEscaped()}}; + QJsonObject json{{"msgtype", msgTypeToString(type)}, + {"body", "> <" + replyEvt.senderId() + "> " + + eventToString(replyEvt) + "\n\n" + text}, + {"format", "org.matrix.custom.html"}, + {"m.relates_to", + QJsonObject{{"m.in_reply_to", + QJsonObject{{"event_id", replyEventId}}}}}, + {"formatted_body", + "
In reply to " + replyEvt.senderId() + + "
" + eventToString(replyEvt, Qt::RichText) + + "
" + text.toHtmlEscaped()}}; postJson("m.room.message", json); return; @@ -521,21 +515,20 @@ void SpectralRoom::postHtmlMessage(const QString& text, if (isReply) { const auto& replyEvt = **replyIt; - QJsonObject json{ - {"msgtype", msgTypeToString(type)}, - {"body", "> <" + replyEvt.senderId() + "> " + eventToString(replyEvt) + - "\n\n" + text}, - {"format", "org.matrix.custom.html"}, - {"m.relates_to", - QJsonObject{ - {"m.in_reply_to", QJsonObject{{"event_id", replyEventId}}}}}, - {"formatted_body", - "
In reply to " + replyEvt.senderId() + "
" + - eventToString(replyEvt, Qt::RichText) + - "
" + html}}; + QJsonObject json{{"msgtype", msgTypeToString(type)}, + {"body", "> <" + replyEvt.senderId() + "> " + + eventToString(replyEvt) + "\n\n" + text}, + {"format", "org.matrix.custom.html"}, + {"m.relates_to", + QJsonObject{{"m.in_reply_to", + QJsonObject{{"event_id", replyEventId}}}}}, + {"formatted_body", + "
In reply to " + replyEvt.senderId() + + "
" + eventToString(replyEvt, Qt::RichText) + + "
" + html}}; postJson("m.room.message", json); return; diff --git a/src/spectralroom.h b/src/spectralroom.h index b7ed4e730..a051091e9 100644 --- a/src/spectralroom.h +++ b/src/spectralroom.h @@ -1,13 +1,6 @@ #ifndef SpectralRoom_H #define SpectralRoom_H -#include "room.h" -#include "spectraluser.h" - -#include -#include -#include - #include #include #include @@ -16,7 +9,14 @@ #include #include -using namespace QMatrixClient; +#include +#include +#include + +#include "room.h" +#include "spectraluser.h" + +using namespace Quotient; class SpectralRoom : public Room { Q_OBJECT @@ -37,7 +37,7 @@ class SpectralRoom : public Room { QVariantList getUsersTyping() const; QString lastEvent() const; - bool isEventHighlighted(const QMatrixClient::RoomEvent* e) const; + bool isEventHighlighted(const Quotient::RoomEvent* e) const; QDateTime lastActiveTime() const; @@ -70,16 +70,17 @@ class SpectralRoom : public Room { QString avatarMediaId() const; QString eventToString(const RoomEvent& evt, - Qt::TextFormat format = Qt::PlainText, bool removeReply = true) const; + Qt::TextFormat format = Qt::PlainText, + bool removeReply = true) const; private: QString m_cachedInput; - QSet highlights; + QSet highlights; bool m_hasFileUploading = false; int m_fileUploadingProgress = 0; - void checkForHighlights(const QMatrixClient::TimelineItem& ti); + void checkForHighlights(const Quotient::TimelineItem& ti); void onAddNewTimelineEvents(timeline_iter_t from) override; void onAddHistoricalTimelineEvents(rev_iter_t from) override; diff --git a/src/spectraluser.h b/src/spectraluser.h index 3cb773496..93dec4bdc 100644 --- a/src/spectraluser.h +++ b/src/spectraluser.h @@ -1,12 +1,12 @@ #ifndef SpectralUser_H #define SpectralUser_H +#include + #include "room.h" #include "user.h" -#include - -using namespace QMatrixClient; +using namespace Quotient; class SpectralUser : public User { Q_OBJECT diff --git a/src/userlistmodel.cpp b/src/userlistmodel.cpp index 016cb0bfc..6ab23ce93 100644 --- a/src/userlistmodel.cpp +++ b/src/userlistmodel.cpp @@ -13,7 +13,7 @@ UserListModel::UserListModel(QObject* parent) : QAbstractListModel(parent), m_currentRoom(nullptr) {} -void UserListModel::setRoom(QMatrixClient::Room* room) { +void UserListModel::setRoom(Quotient::Room* room) { if (m_currentRoom == room) return; @@ -50,7 +50,7 @@ void UserListModel::setRoom(QMatrixClient::Room* room) { emit roomChanged(); } -QMatrixClient::User* UserListModel::userAt(QModelIndex index) const { +Quotient::User* UserListModel::userAt(QModelIndex index) const { if (index.row() < 0 || index.row() >= m_users.size()) return nullptr; return m_users.at(index.row()); @@ -89,16 +89,16 @@ int UserListModel::rowCount(const QModelIndex& parent) const { return m_users.count(); } -void UserListModel::userAdded(QMatrixClient::User* user) { +void UserListModel::userAdded(Quotient::User* user) { auto pos = findUserPos(user); beginInsertRows(QModelIndex(), pos, pos); m_users.insert(pos, user); endInsertRows(); - connect(user, &QMatrixClient::User::avatarChanged, this, + connect(user, &Quotient::User::avatarChanged, this, &UserListModel::avatarChanged); } -void UserListModel::userRemoved(QMatrixClient::User* user) { +void UserListModel::userRemoved(Quotient::User* user) { auto pos = findUserPos(user); if (pos != m_users.size()) { beginRemoveRows(QModelIndex(), pos, pos); @@ -109,7 +109,7 @@ void UserListModel::userRemoved(QMatrixClient::User* user) { qWarning() << "Trying to remove a room member not in the user list"; } -void UserListModel::refresh(QMatrixClient::User* user, QVector roles) { +void UserListModel::refresh(Quotient::User* user, QVector roles) { auto pos = findUserPos(user); if (pos != m_users.size()) emit dataChanged(index(pos), index(pos), roles); @@ -117,8 +117,8 @@ void UserListModel::refresh(QMatrixClient::User* user, QVector roles) { qWarning() << "Trying to access a room member not in the user list"; } -void UserListModel::avatarChanged(QMatrixClient::User* user, - const QMatrixClient::Room* context) { +void UserListModel::avatarChanged(Quotient::User* user, + const Quotient::Room* context) { if (context == m_currentRoom) refresh(user, {AvatarRole}); }