diff --git a/autotests/texthandlertest.cpp b/autotests/texthandlertest.cpp index 74d1578af..be4de1e07 100644 --- a/autotests/texthandlertest.cpp +++ b/autotests/texthandlertest.cpp @@ -71,7 +71,6 @@ private Q_SLOTS: void linkPreviewsReject(); }; -#ifdef QUOTIENT_07 void TextHandlerTest::initTestCase() { connection = Connection::makeMockConnection(QStringLiteral("@bob:kde.org")); @@ -204,7 +203,6 @@ void TextHandlerTest::initTestCase() SyncRoomData roomData(QStringLiteral("@bob:kde.org"), JoinState::Join, json.object()); room->update(std::move(roomData)); } -#endif void TextHandlerTest::allowedAttributes() { @@ -479,7 +477,6 @@ void TextHandlerTest::receiveRichtextIn() QCOMPARE(testTextHandler.handleRecieveRichText(), testOutputString); } -#ifdef QUOTIENT_07 void TextHandlerTest::receiveRichMxcUrl() { const QString testInputString = QStringLiteral( @@ -497,7 +494,6 @@ void TextHandlerTest::receiveRichMxcUrl() QCOMPARE(testTextHandler.handleRecieveRichText(Qt::RichText, room, room->messageEvents().at(0).get()), testOutputString); } -#endif /** * For when your rich input string has a plain text url left in. diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index cb019bf32..9a8fdfaf8 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -112,8 +112,6 @@ add_library(neochat STATIC events/imagepackevent.h events/joinrulesevent.cpp events/joinrulesevent.h - events/stickerevent.cpp - events/stickerevent.h models/reactionmodel.cpp models/reactionmodel.h delegatesizehelper.cpp @@ -124,6 +122,8 @@ add_library(neochat STATIC models/locationsmodel.h locationhelper.cpp locationhelper.h + events/pollevent.cpp + pollhandler.cpp ) ecm_qt_declare_logging_category(neochat @@ -146,14 +146,6 @@ target_link_libraries(neochat-app PRIVATE neochat ) -if(Quotient${QUOTIENT_SUFFIX}_VERSION_MINOR GREATER 6) - target_compile_definitions(neochat PUBLIC QUOTIENT_07) - target_sources(neochat PRIVATE events/pollevent.cpp pollhandler.cpp) -else() - target_compile_definitions(neochat PUBLIC QUOTIENT_VERSION=\"${Quotient${QUOTIENT_SUFFIX}_VERSION}\") - target_sources(neochat PRIVATE neochataccountregistry.cpp) -endif() - ecm_add_app_icon(NEOCHAT_ICON ICONS ${CMAKE_SOURCE_DIR}/128-logo.png) target_sources(neochat-app PRIVATE ${NEOCHAT_ICON}) diff --git a/src/controller.cpp b/src/controller.cpp index 632cfe423..f00266cba 100644 --- a/src/controller.cpp +++ b/src/controller.cpp @@ -31,11 +31,7 @@ #include -#ifdef QUOTIENT_07 #include "accountregistry.h" -#else -#include "neochataccountregistry.h" -#endif #include #include @@ -44,9 +40,7 @@ #include #include -#ifdef QUOTIENT_07 #include -#endif #include "neochatconfig.h" #include "neochatroom.h" @@ -108,13 +102,8 @@ Controller::Controller(QObject *parent) } #endif -#ifdef QUOTIENT_07 connect(&Accounts, &AccountRegistry::accountCountChanged, this, &Controller::activeConnectionIndexChanged); -#else - connect(&AccountRegistry::instance(), &AccountRegistry::accountCountChanged, this, &Controller::activeConnectionIndexChanged); -#endif -#ifdef QUOTIENT_07 static int oldAccountCount = 0; connect(&Accounts, &AccountRegistry::accountCountChanged, this, [this]() { if (Accounts.size() > oldAccountCount) { @@ -125,7 +114,6 @@ Controller::Controller(QObject *parent) } oldAccountCount = Accounts.size(); }); -#endif QTimer::singleShot(0, this, [this] { m_pushRuleModel = new PushRuleModel; @@ -160,18 +148,10 @@ void Controller::logout(Connection *conn, bool serverSideLogout) job.start(); loop.exec(); -#ifdef QUOTIENT_07 if (Accounts.count() > 1) { -#else - if (AccountRegistry::instance().count() > 1) { -#endif // Only set the connection if the the account being logged out is currently active if (conn == activeConnection()) { -#ifdef QUOTIENT_07 setActiveConnection(Accounts.accounts()[0]); -#else - setActiveConnection(AccountRegistry::instance().accounts()[0]); -#endif } } else { setActiveConnection(nullptr); @@ -186,11 +166,7 @@ void Controller::addConnection(Connection *c) { Q_ASSERT_X(c, __FUNCTION__, "Attempt to add a null connection"); -#ifdef QUOTIENT_07 Accounts.add(c); -#else - AccountRegistry::instance().add(c); -#endif c->setLazyLoading(true); @@ -220,15 +196,8 @@ void Controller::dropConnection(Connection *c) { Q_ASSERT_X(c, __FUNCTION__, "Attempt to drop a null connection"); -#ifndef QUOTIENT_07 - AccountRegistry::instance().drop(c); -#endif - Q_EMIT connectionDropped(c); Q_EMIT accountCountChanged(); -#ifndef QUOTIENT_07 - c->deleteLater(); -#endif } void Controller::invokeLogin() @@ -401,11 +370,7 @@ bool Controller::setAvatar(Connection *connection, const QUrl &avatarSource) User *localUser = connection->user(); QString decoded = avatarSource.path(); if (decoded.isEmpty()) { -#ifdef QUOTIENT_07 connection->callApi(localUser->id(), avatarSource); -#else - connection->callApi(localUser->id(), QString()); -#endif return true; } if (QImageReader(decoded).read().isNull()) { @@ -416,11 +381,7 @@ bool Controller::setAvatar(Connection *connection, const QUrl &avatarSource) } NeochatChangePasswordJob::NeochatChangePasswordJob(const QString &newPassword, bool logoutDevices, const Omittable &auth) -#ifdef QUOTIENT_07 : BaseJob(HttpVerb::Post, QStringLiteral("ChangePasswordJob"), "/_matrix/client/r0/account/password") -#else - : BaseJob(HttpVerb::Post, QStringLiteral("ChangePasswordJob"), QStringLiteral("/_matrix/client/r0/account/password")) -#endif { QJsonObject _data; addParam<>(_data, QStringLiteral("new_password"), newPassword); @@ -431,11 +392,7 @@ NeochatChangePasswordJob::NeochatChangePasswordJob(const QString &newPassword, b int Controller::accountCount() const { -#ifdef QUOTIENT_07 return Accounts.count(); -#else - return AccountRegistry::instance().count(); -#endif } void Controller::setQuitOnLastWindowClosed() @@ -522,11 +479,7 @@ void Controller::saveWindowGeometry() } NeochatDeleteDeviceJob::NeochatDeleteDeviceJob(const QString &deviceId, const Omittable &auth) -#ifdef QUOTIENT_07 : Quotient::BaseJob(HttpVerb::Delete, QStringLiteral("DeleteDeviceJob"), QStringLiteral("/_matrix/client/r0/devices/%1").arg(deviceId).toLatin1()) -#else - : Quotient::BaseJob(HttpVerb::Delete, QStringLiteral("DeleteDeviceJob"), QStringLiteral("/_matrix/client/r0/devices/%1").arg(deviceId)) -#endif { QJsonObject _data; addParam(_data, QStringLiteral("auth"), auth); @@ -632,11 +585,7 @@ bool Controller::hasWindowSystem() const bool Controller::encryptionSupported() const { -#ifdef QUOTIENT_07 return Quotient::encryptionSupported(); -#else - return false; -#endif } void Controller::forceRefreshTextDocument(QQuickTextDocument *textDocument, QQuickItem *item) @@ -677,29 +626,16 @@ void Controller::setApplicationProxy() int Controller::activeConnectionIndex() const { -#ifdef QUOTIENT_07 auto result = std::find_if(Accounts.accounts().begin(), Accounts.accounts().end(), [this](const auto &it) { return it == m_connection; }); return result - Accounts.accounts().begin(); -#else - for (int i = 0; i < AccountRegistry::instance().rowCount(); i++) { - if (AccountRegistry::instance().data(AccountRegistry::instance().index(i, 0), AccountRegistry::UserIdRole).toString() == m_connection->userId()) { - return i; - } - } - return 0; -#endif } int Controller::quotientMinorVersion() const { -// TODO libQuotient 0.7: Replace with version function from libQuotient -#ifdef QUOTIENT_07 + // TODO libQuotient 0.7: Replace with version function from libQuotient return 7; -#else - return 6; -#endif } bool Controller::isFlatpak() const diff --git a/src/events/imagepackevent.cpp b/src/events/imagepackevent.cpp index e95f81c90..96f3c4c91 100644 --- a/src/events/imagepackevent.cpp +++ b/src/events/imagepackevent.cpp @@ -11,11 +11,7 @@ ImagePackEventContent::ImagePackEventContent(const QJsonObject &json) if (json.contains(QStringLiteral("pack"))) { pack = ImagePackEventContent::Pack{ fromJson>(json["pack"].toObject()["display_name"]), -#ifdef QUOTIENT_07 fromJson>(json["pack"].toObject()["avatar_url"]), -#else - QUrl(), -#endif fromJson>(json["pack"].toObject()["usage"]), fromJson>(json["pack"].toObject()["attribution"]), }; @@ -27,21 +23,13 @@ ImagePackEventContent::ImagePackEventContent(const QJsonObject &json) for (const auto &k : keys) { Omittable info; if (json["images"][k].toObject().contains(QStringLiteral("info"))) { -#ifdef QUOTIENT_07 info = EventContent::ImageInfo(QUrl(json["images"][k]["url"].toString()), json["images"][k]["info"].toObject(), k); -#else - info = EventContent::ImageInfo(QUrl(json["images"][k]["url"].toString()), json["images"][k].toObject(), k); -#endif } else { info = none; } images += ImagePackImage{ k, -#ifdef QUOTIENT_07 fromJson(json["images"][k]["url"].toString()), -#else - QUrl(), -#endif fromJson>(json["images"][k]["body"]), info, fromJson>(json["images"][k]["usage"]), diff --git a/src/events/imagepackevent.h b/src/events/imagepackevent.h index af5880796..2df1722b8 100644 --- a/src/events/imagepackevent.h +++ b/src/events/imagepackevent.h @@ -83,23 +83,11 @@ public: * * @sa Quotient::StateEvent, ImagePackEventContent */ -#ifdef QUOTIENT_07 class ImagePackEvent : public KeyedStateEventBase -#else -class ImagePackEvent : public StateEvent -#endif { public: -#ifdef QUOTIENT_07 QUO_EVENT(ImagePackEvent, "im.ponies.room_emotes") using KeyedStateEventBase::KeyedStateEventBase; -#else - DEFINE_EVENT_TYPEID("im.ponies.room_emotes", ImagePackEvent) - explicit ImagePackEvent(const QJsonObject &obj) - : StateEvent(typeId(), obj) - { - } -#endif }; REGISTER_EVENT_TYPE(ImagePackEvent) diff --git a/src/events/joinrulesevent.h b/src/events/joinrulesevent.h index 977786e7c..bad154a1e 100644 --- a/src/events/joinrulesevent.h +++ b/src/events/joinrulesevent.h @@ -14,25 +14,13 @@ namespace Quotient * * @sa Quotient::StateEvent */ -#ifdef QUOTIENT_07 class JoinRulesEvent : public StateEvent -#else -class JoinRulesEvent : public StateEventBase -#endif { public: -#ifdef QUOTIENT_07 QUO_EVENT(JoinRulesEvent, "m.room.join_rules") -#else - DEFINE_EVENT_TYPEID("m.room.join_rules", JoinRulesEvent) -#endif explicit JoinRulesEvent(const QJsonObject &obj) -#ifdef QUOTIENT_07 : StateEvent(obj) -#else - : StateEventBase(typeId(), obj) -#endif { } diff --git a/src/events/stickerevent.cpp b/src/events/stickerevent.cpp deleted file mode 100644 index 6fd9591b5..000000000 --- a/src/events/stickerevent.cpp +++ /dev/null @@ -1,35 +0,0 @@ -// SPDX-FileCopyrightText: 2020 Carl Schwan -// SPDX-License-Identifier: LGPL-2.1-or-later - -#include "stickerevent.h" - -using namespace Quotient; - -StickerEvent::StickerEvent(const QJsonObject &obj) -#ifdef QUOTIENT_07 - : RoomEvent(obj) -#else - : RoomEvent(typeId(), obj) -#endif - , m_imageContent(EventContent::ImageContent(obj["content"_ls].toObject())) -{ -} - -QString StickerEvent::body() const -{ - return content("body"_ls); -} - -const EventContent::ImageContent &StickerEvent::image() const -{ - return m_imageContent; -} - -QUrl StickerEvent::url() const -{ -#ifdef QUOTIENT_07 - return m_imageContent.url(); -#else - return m_imageContent.url; -#endif -} diff --git a/src/events/stickerevent.h b/src/events/stickerevent.h deleted file mode 100644 index c6dfbe7dc..000000000 --- a/src/events/stickerevent.h +++ /dev/null @@ -1,55 +0,0 @@ -// SPDX-FileCopyrightText: 2020 Carl Schwan -// SPDX-License-Identifier: LGPL-2.1-or-later - -#pragma once - -#include -#include - -namespace Quotient -{ -/** - * @class StickerEvent - * - * Class to define a sticker event. - * - * Sticker messages are specialised image messages that are displayed without - * controls (e.g. no "download" link, or light-box view on click, as would be - * displayed for for m.image events). - * - * @sa Quotient::RoomEvent - */ -class StickerEvent : public RoomEvent -{ -public: -#ifdef QUOTIENT_07 - QUO_EVENT(StickerEvent, "m.sticker") -#else - DEFINE_EVENT_TYPEID("m.sticker", StickerEvent) -#endif - - explicit StickerEvent(const QJsonObject &obj); - - /** - * @brief A textual representation or associated description of the sticker image. - * - * This could be the alt text of the original image, or a message to accompany - * and further describe the sticker. - */ - QString body() const; - - /** - * @brief Metadata about the image referred to in url including a thumbnail representation. - */ - const EventContent::ImageContent &image() const; - - /** - * @brief The URL to the sticker image. This must be a valid mxc:// URI. - */ - QUrl url() const; - -private: - EventContent::ImageContent m_imageContent; -}; -REGISTER_EVENT_TYPE(StickerEvent) -} diff --git a/src/linkpreviewer.cpp b/src/linkpreviewer.cpp index 4fee72bfc..521aadd3b 100644 --- a/src/linkpreviewer.cpp +++ b/src/linkpreviewer.cpp @@ -69,14 +69,7 @@ void LinkPreviewer::loadUrlPreview() auto imageUrl = QUrl(json["og:image"].toString()); if (imageUrl.isValid() && imageUrl.scheme() == QStringLiteral("mxc")) { -#ifdef QUOTIENT_07 m_imageSource = conn->makeMediaUrl(imageUrl); -#else - QUrlQuery q(imageUrl.query()); - q.addQueryItem(QStringLiteral("user_id"), conn->userId()); - imageUrl.setQuery(q); - m_imageSource = imageUrl; -#endif } else { m_imageSource = QUrl(); } diff --git a/src/login.cpp b/src/login.cpp index 59a7be097..65693667d 100644 --- a/src/login.cpp +++ b/src/login.cpp @@ -3,11 +3,7 @@ #include "login.h" -#ifdef QUOTIENT_07 #include -#else -#include "neochataccountregistry.h" -#endif #include #include @@ -47,11 +43,7 @@ void Login::init() return; } -#ifdef QUOTIENT_07 m_isLoggedIn = Accounts.isLoggedIn(m_matrixId); -#else - m_isLoggedIn = AccountRegistry::instance().isLoggedIn(m_matrixId); -#endif Q_EMIT isLoggedInChanged(); if (m_isLoggedIn) { return; diff --git a/src/main.cpp b/src/main.cpp index 634f4af27..ea6aba754 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -28,12 +28,7 @@ #include "neochat-version.h" -#ifdef QUOTIENT_07 #include -#else -#include "neochataccountregistry.h" -#endif - #include #include #include @@ -70,6 +65,8 @@ #include "models/serverlistmodel.h" #include "models/sortfilterroomlistmodel.h" #include "models/sortfilterspacelistmodel.h" +#include "models/statefiltermodel.h" +#include "models/stickermodel.h" #include "models/userdirectorylistmodel.h" #include "models/userfiltermodel.h" #include "models/userlistmodel.h" @@ -78,18 +75,12 @@ #include "neochatroom.h" #include "neochatuser.h" #include "notificationsmanager.h" -#ifdef QUOTIENT_07 #include "pollhandler.h" -#endif -#include "models/statefiltermodel.h" -#include "models/stickermodel.h" #include "roommanager.h" #include "spacehierarchycache.h" #include "urlhelper.h" #include "windowcontroller.h" -#ifdef QUOTIENT_07 #include -#endif #ifdef HAVE_COLORSCHEME #include "colorschemer.h" #endif @@ -179,14 +170,10 @@ int main(int argc, char *argv[]) about.addComponent(QStringLiteral("libQuotient"), i18n("A Qt5 library to write cross-platform clients for Matrix"), -#ifdef QUOTIENT_07 i18nc(" (built against )", "%1 (built against %2)", Quotient::versionString(), QStringLiteral(Quotient_VERSION_STRING)), -#else - QStringLiteral(QUOTIENT_VERSION), -#endif QStringLiteral("https://github.com/quotient-im/libquotient"), KAboutLicense::LGPL_V2_1); @@ -229,11 +216,7 @@ int main(int argc, char *argv[]) qmlRegisterSingletonInstance("org.kde.neochat", 1, 0, "LoginHelper", login); qmlRegisterSingletonInstance("org.kde.neochat", 1, 0, "UrlHelper", &urlHelper); qmlRegisterSingletonInstance("org.kde.neochat", 1, 0, "EmojiModel", &EmojiModel::instance()); -#ifdef QUOTIENT_07 qmlRegisterSingletonInstance("org.kde.neochat", 1, 0, "AccountRegistry", &Quotient::Accounts); -#else - qmlRegisterSingletonInstance("org.kde.neochat", 1, 0, "AccountRegistry", &Quotient::AccountRegistry::instance()); -#endif qmlRegisterSingletonInstance("org.kde.neochat", 1, 0, "SpaceHierarchyCache", &SpaceHierarchyCache::instance()); qmlRegisterSingletonInstance("org.kde.neochat", 1, 0, "CustomEmojiModel", &CustomEmojiModel::instance()); qmlRegisterType("org.kde.neochat", 1, 0, "ActionsHandler"); @@ -260,9 +243,7 @@ int main(int argc, char *argv[]) qmlRegisterType("org.kde.neochat", 1, 0, "SearchModel"); qmlRegisterType("org.kde.neochat", 1, 0, "LiveLocationsModel"); qmlRegisterType("org.kde.neochat", 1, 0, "LocationsModel"); -#ifdef QUOTIENT_07 qmlRegisterType("org.kde.neochat", 1, 0, "PollHandler"); -#endif qmlRegisterType("org.kde.neochat", 1, 0, "PushRuleModel"); qmlRegisterType("org.kde.neochat", 1, 0, "StickerModel"); qmlRegisterType("org.kde.neochat", 1, 0, "ImagePacksModel"); @@ -288,12 +269,10 @@ int main(int argc, char *argv[]) qRegisterMetaType("NeoChatUser*"); qRegisterMetaType("GetRoomEventsJob*"); qRegisterMetaType("QMimeType"); -#ifdef QUOTIENT_07 #ifdef Quotient_E2EE_ENABLED qRegisterMetaType("KeyVerificationSession*"); qmlRegisterUncreatableType("org.kde.neochat", 1, 0, "KeyVerificationSession", {}); qRegisterMetaType>("QVector"); -#endif #endif qmlRegisterSingletonType("org.kde.neochat", 1, 0, "About", [](QQmlEngine *engine, QJSEngine *) -> QJSValue { return engine->toScriptValue(KAboutData::applicationData()); diff --git a/src/models/accountemoticonmodel.cpp b/src/models/accountemoticonmodel.cpp index b46c5966e..0b6e3444f 100644 --- a/src/models/accountemoticonmodel.cpp +++ b/src/models/accountemoticonmodel.cpp @@ -27,11 +27,7 @@ QVariant AccountEmoticonModel::data(const QModelIndex &index, int role) const const auto &row = index.row(); const auto &image = m_images->images[row]; if (role == UrlRole) { -#ifdef QUOTIENT_07 return m_connection->makeMediaUrl(image.url); -#else - return QUrl(); -#endif } if (role == BodyRole) { if (image.body) { @@ -142,11 +138,7 @@ QCoro::Task AccountEmoticonModel::doSetEmoticonImage(int index, QUrl sourc if (job->error() != BaseJob::NoError) { co_return; } -#ifdef QUOTIENT_07 m_images->images[index].url = job->contentUri().toString(); -#else - m_images->images[index].url = job->contentUri(); -#endif m_images->images[index].info = none; QJsonObject data; m_images->fillJson(&data); diff --git a/src/models/actionsmodel.cpp b/src/models/actionsmodel.cpp index ee4d5a8dc..ca7c903ea 100644 --- a/src/models/actionsmodel.cpp +++ b/src/models/actionsmodel.cpp @@ -191,7 +191,6 @@ QVector actions{ Q_EMIT room->showMessage(NeoChatRoom::Error, i18nc("'' does not look like a matrix id.", "'%1' does not look like a matrix id.", text)); return QString(); } -#ifdef QUOTIENT_07 const RoomMemberEvent *roomMemberEvent = room->currentState().get(text); if (roomMemberEvent && roomMemberEvent->membership() == Membership::Invite) { Q_EMIT room->showMessage(NeoChatRoom::Info, i18nc(" is already invited to this room.", "%1 is already invited to this room.", text)); @@ -201,7 +200,6 @@ QVector actions{ Q_EMIT room->showMessage(NeoChatRoom::Info, i18nc(" is banned from this room.", "%1 is banned from this room.", text)); return QString(); } -#endif if (room->localUser()->id() == text) { Q_EMIT room->showMessage(NeoChatRoom::Positive, i18n("You are already in this room.")); return QString(); @@ -243,7 +241,6 @@ QVector actions{ kli18n(""), kli18n("Joins the given room"), }, -#ifdef QUOTIENT_07 Action{ QStringLiteral("knock"), [](const QString &text, NeoChatRoom *room) { @@ -276,7 +273,6 @@ QVector actions{ kli18n(" []"), kli18n("Requests to join the given room"), }, -#endif Action{ QStringLiteral("j"), [](const QString &text, NeoChatRoom *room) { @@ -435,13 +431,11 @@ QVector actions{ Q_EMIT room->showMessage(NeoChatRoom::Error, i18nc("'' does not look like a matrix id.", "'%1' does not look like a matrix id.", text)); return QString(); } -#ifdef QUOTIENT_07 auto state = room->currentState().get(parts[0]); if (state && state->membership() == Membership::Ban) { Q_EMIT room->showMessage(NeoChatRoom::Info, i18nc(" is already banned from this room.", "%1 is already banned from this room.", text)); return QString(); } -#endif auto plEvent = room->getCurrentState(); if (plEvent->ban() > plEvent->powerLevelForUser(room->localUser()->id())) { Q_EMIT room->showMessage(NeoChatRoom::Error, i18n("You are not allowed to ban users from this room.")); @@ -477,13 +471,11 @@ QVector actions{ Q_EMIT room->showMessage(NeoChatRoom::Error, i18n("You are not allowed to unban users from this room.")); return QString(); } -#ifdef QUOTIENT_07 auto state = room->currentState().get(text); if (state && state->membership() != Membership::Ban) { Q_EMIT room->showMessage(NeoChatRoom::Info, i18nc(" is not banned from this room.", "%1 is not banned from this room.", text)); return QString(); } -#endif room->unban(text); Q_EMIT room->showMessage(NeoChatRoom::Positive, i18nc(" was unbanned from this room.", "%1 was unbanned from this room.", text)); @@ -510,12 +502,10 @@ QVector actions{ Q_EMIT room->showMessage(NeoChatRoom::Error, i18n("You cannot kick yourself from the room.")); return QString(); } -#ifdef QUOTIENT_07 if (!room->isMember(parts[0])) { Q_EMIT room->showMessage(NeoChatRoom::Error, i18nc(" is not in this room", "%1 is not in this room.", parts[0])); return QString(); } -#endif auto plEvent = room->getCurrentState(); auto kick = plEvent->kick(); if (plEvent->powerLevelForUser(room->localUser()->id()) < kick) { diff --git a/src/models/customemojimodel.cpp b/src/models/customemojimodel.cpp index 237b6b612..b653136f2 100644 --- a/src/models/customemojimodel.cpp +++ b/src/models/customemojimodel.cpp @@ -62,11 +62,7 @@ void CustomEmojiModel::addEmoji(const QString &name, const QUrl &location) auto emojiData = json["images"].toObject(); QString url; -#ifdef QUOTIENT_07 url = job->contentUri().toString(); -#else - url = job->contentUri(); -#endif QImage image(location.toLocalFile()); QJsonObject imageInfo; diff --git a/src/models/imagepacksmodel.cpp b/src/models/imagepacksmodel.cpp index a54a9c371..ee911f252 100644 --- a/src/models/imagepacksmodel.cpp +++ b/src/models/imagepacksmodel.cpp @@ -33,13 +33,9 @@ QVariant ImagePacksModel::data(const QModelIndex &index, int role) const } if (role == AvatarUrlRole) { if (event.pack->avatarUrl) { -#ifdef QUOTIENT_07 return m_room->connection()->makeMediaUrl(*event.pack->avatarUrl); -#endif } else if (!event.images.empty()) { -#ifdef QUOTIENT_07 return m_room->connection()->makeMediaUrl(event.images[0].url); -#endif } } return {}; @@ -106,7 +102,6 @@ void ImagePacksModel::reloadImages() auto packs = rooms[roomId].toObject(); const auto &stickerRoom = m_room->connection()->room(roomId); for (const auto &packKey : packs.keys()) { -#ifdef QUOTIENT_07 if (const auto &pack = stickerRoom->currentState().get(packKey)) { const auto packContent = pack->content(); if ((!packContent.pack || !packContent.pack->usage || (packContent.pack->usage->contains("emoticon") && showEmoticons()) @@ -115,11 +110,9 @@ void ImagePacksModel::reloadImages() m_events += packContent; } } -#endif } } } -#ifdef QUOTIENT_07 // Load emoticons from the current room auto events = m_room->currentState().eventsOfType("im.ponies.room_emotes"); @@ -132,7 +125,6 @@ void ImagePacksModel::reloadImages() } } } -#endif Q_EMIT imagesLoaded(); endResetModel(); } diff --git a/src/models/messageeventmodel.cpp b/src/models/messageeventmodel.cpp index 4685b96f4..0bf705418 100644 --- a/src/models/messageeventmodel.cpp +++ b/src/models/messageeventmodel.cpp @@ -14,9 +14,7 @@ #include #include -#ifdef QUOTIENT_07 #include "events/pollevent.h" -#endif #include "events/stickerevent.h" #include @@ -117,11 +115,7 @@ void MessageEventModel::setRoom(NeoChatRoom *room) if (m_currentRoom->timelineSize() < 10 && !room->allHistoryLoaded()) { room->getPreviousContent(50); } -#ifdef QUOTIENT_07 lastReadEventId = room->lastFullyReadEventId(); -#else - lastReadEventId = room->readMarkerEventId(); -#endif connect(m_currentRoom, &NeoChatRoom::replyLoaded, this, [this](const auto &eventId, const auto &replyId) { Q_UNUSED(replyId); auto row = eventIdToRow(eventId); @@ -191,11 +185,7 @@ void MessageEventModel::setRoom(NeoChatRoom *room) } if (!m_lastReadEventIndex.isValid()) { // no read marker, so see if we need to create one. -#ifdef QUOTIENT_07 moveReadMarker(m_currentRoom->lastFullyReadEventId()); -#else - moveReadMarker(m_currentRoom->readMarkerEventId()); -#endif } if (biggest < m_currentRoom->maxTimelineIndex()) { auto rowBelowInserted = m_currentRoom->maxTimelineIndex() - biggest + timelineBaseIndex() - 1; @@ -264,9 +254,6 @@ void MessageEventModel::setRoom(NeoChatRoom *room) connect(m_currentRoom, &Room::fileTransferProgress, this, &MessageEventModel::refreshEvent); connect(m_currentRoom, &Room::fileTransferCompleted, this, &MessageEventModel::refreshEvent); connect(m_currentRoom, &Room::fileTransferFailed, this, &MessageEventModel::refreshEvent); -#ifndef QUOTIENT_07 - connect(m_currentRoom, &Room::fileTransferCancelled, this, &MessageEventModel::refreshEvent); -#endif connect(m_currentRoom->connection(), &Connection::ignoredUsersListChanged, this, [this] { beginResetModel(); endResetModel(); @@ -532,14 +519,12 @@ QVariant MessageEventModel::data(const QModelIndex &idx, int role) const if (is(evt)) { return DelegateType::Encrypted; } -#ifdef QUOTIENT_07 if (is(evt)) { if (evt.isRedacted()) { return DelegateType::Message; } return DelegateType::Poll; } -#endif return DelegateType::Other; } @@ -811,7 +796,6 @@ QVariant MessageEventModel::data(const QModelIndex &idx, int role) const } if (role == ReadMarkersRole) { -#ifdef QUOTIENT_07 auto userIds_temp = room()->userIdsAtEvent(evt.id()); userIds_temp.remove(m_currentRoom->localUser()->id()); @@ -819,19 +803,11 @@ QVariant MessageEventModel::data(const QModelIndex &idx, int role) const if (userIds.count() > 5) { userIds = userIds.mid(0, 5); } -#else - auto userIds = room()->usersAtEventId(evt.id()); - userIds.removeAll(m_currentRoom->localUser()); -#endif QVariantList users; users.reserve(userIds.size()); for (const auto &userId : userIds) { -#ifdef QUOTIENT_07 auto user = static_cast(m_currentRoom->user(userId)); -#else - auto user = static_cast(userId); -#endif users += m_currentRoom->getUser(user); } @@ -839,13 +815,8 @@ QVariant MessageEventModel::data(const QModelIndex &idx, int role) const } if (role == ExcessReadMarkersRole) { -#ifdef QUOTIENT_07 auto userIds = room()->userIdsAtEvent(evt.id()); userIds.remove(m_currentRoom->localUser()->id()); -#else - auto userIds = room()->usersAtEventId(evt.id()); - userIds.removeAll(m_currentRoom->localUser()); -#endif if (userIds.count() > 5) { return QStringLiteral("+ ") + QString::number(userIds.count() - 5); @@ -855,24 +826,16 @@ QVariant MessageEventModel::data(const QModelIndex &idx, int role) const } if (role == ReadMarkersStringRole) { -#ifdef QUOTIENT_07 auto userIds = room()->userIdsAtEvent(evt.id()); userIds.remove(m_currentRoom->localUser()->id()); -#else - auto userIds = room()->usersAtEventId(evt.id()); - userIds.removeAll(m_currentRoom->localUser()); -#endif + /** * The string ends up in the form * "x users: user1DisplayName, user2DisplayName, etc." */ QString readMarkersString = i18np("1 user: ", "%1 users: ", userIds.size()); for (const auto &userId : userIds) { -#ifdef QUOTIENT_07 auto user = static_cast(m_currentRoom->user(userId)); -#else - auto user = static_cast(userId); -#endif readMarkersString += user->displayname(m_currentRoom) + i18nc("list separator", ", "); } readMarkersString.chop(2); @@ -880,13 +843,8 @@ QVariant MessageEventModel::data(const QModelIndex &idx, int role) const } if (role == ShowReadMarkersRole) { -#ifdef QUOTIENT_07 auto userIds = room()->userIdsAtEvent(evt.id()); userIds.remove(m_currentRoom->localUser()->id()); -#else - auto userIds = room()->usersAtEventId(evt.id()); - userIds.removeAll(m_currentRoom->localUser()); -#endif return userIds.size() > 0; } @@ -907,14 +865,12 @@ QVariant MessageEventModel::data(const QModelIndex &idx, int role) const } if (role == VerifiedRole) { -#ifdef QUOTIENT_07 #ifdef Quotient_E2EE_ENABLED if (evt.originalEvent()) { auto encrypted = dynamic_cast(evt.originalEvent()); Q_ASSERT(encrypted); return m_currentRoom->connection()->isVerifiedSession(encrypted->sessionId().toLatin1()); } -#endif #endif return false; } @@ -966,22 +922,14 @@ QVariantMap MessageEventModel::getMediaInfoForEvent(const RoomEvent &event) cons // Get the file info for the event. const EventContent::FileInfo *fileInfo; -#ifdef QUOTIENT_07 if (event.is()) { auto roomMessageEvent = eventCast(&event); -#else - if (auto roomMessageEvent = eventCast(&event)) { -#endif if (!roomMessageEvent->hasFileContent()) { return {}; } fileInfo = roomMessageEvent->content()->fileInfo(); -#ifdef QUOTIENT_07 } else if (event.is()) { auto stickerEvent = eventCast(&event); -#else - } else if (auto stickerEvent = eventCast(&event)) { -#endif fileInfo = &stickerEvent->image(); } else { return {}; @@ -995,7 +943,6 @@ QVariantMap MessageEventModel::getMediaInfoFromFileInfo(const EventContent::File QVariantMap mediaInfo; // Get the mxc URL for the media. -#ifdef QUOTIENT_07 if (!fileInfo->url().isValid() || eventId.isEmpty()) { mediaInfo["source"] = QUrl(); } else { @@ -1007,13 +954,6 @@ QVariantMap MessageEventModel::getMediaInfoFromFileInfo(const EventContent::File mediaInfo["source"] = QUrl(); } } -#else - auto url = QUrl(m_currentRoom->connection()->homeserver().toString() + "/_matrix/media/r0/download/" + fileInfo->url.toString().remove("mxc://")); - QUrlQuery q(url.query()); - q.addQueryItem("allow_remote", "true"); - url.setQuery(q); - mediaInfo["source"] = url; -#endif auto mimeType = fileInfo->mimeType; // Add the MIME type for the media if available. diff --git a/src/models/publicroomlistmodel.cpp b/src/models/publicroomlistmodel.cpp index de0cc3d83..a8f3f1de4 100644 --- a/src/models/publicroomlistmodel.cpp +++ b/src/models/publicroomlistmodel.cpp @@ -132,11 +132,7 @@ void PublicRoomListModel::next(int count) return; } -#ifdef QUOTIENT_07 job = m_connection->callApi(m_server, count, nextBatch, QueryPublicRoomsJob::Filter{m_keyword, {}}); -#else - job = m_connection->callApi(m_server, count, nextBatch, QueryPublicRoomsJob::Filter{m_keyword}); -#endif connect(job, &BaseJob::finished, this, [this] { attempted = true; @@ -192,11 +188,7 @@ QVariant PublicRoomListModel::data(const QModelIndex &index, int role) const if (avatarUrl.isEmpty()) { return ""; } -#ifdef QUOTIENT_07 return avatarUrl.url().remove(0, 6); -#else - return avatarUrl.remove(0, 6); -#endif } if (role == TopicRole) { return room.topic; diff --git a/src/models/roomlistmodel.cpp b/src/models/roomlistmodel.cpp index 3c9a6c9bc..2cb4562e0 100644 --- a/src/models/roomlistmodel.cpp +++ b/src/models/roomlistmodel.cpp @@ -23,11 +23,6 @@ #include #include -#ifndef QUOTIENT_07 -#include "notificationsmanager.h" -#include -#endif - using namespace Quotient; Q_DECLARE_METATYPE(Quotient::JoinState) @@ -181,71 +176,9 @@ void RoomListModel::connectRoomSignals(NeoChatRoom *room) connect(room, &Room::pendingEventMerged, this, [this, room] { refresh(room, {LastEventRole, SubtitleTextRole}); }); -#ifndef QUOTIENT_07 - connect(room, &Room::notificationCountChanged, this, &RoomListModel::handleNotifications); -#endif - -#ifndef QUOTIENT_07 - connect(room, &Room::notificationCountChanged, this, &RoomListModel::refreshNotificationCount); -#else connect(room, &Room::unreadStatsChanged, this, &RoomListModel::refreshNotificationCount); -#endif } -#ifndef QUOTIENT_07 -void RoomListModel::handleNotifications() -{ - static bool initial = true; - static QStringList oldNotifications; - auto job = m_connection->callApi(); - - connect(job, &BaseJob::success, this, [this, job]() { - const auto notifications = job->jsonData()["notifications"].toArray(); - if (initial) { - initial = false; - for (const auto &n : notifications) { - oldNotifications += n.toObject()["event"].toObject()["event_id"].toString(); - } - return; - } - for (const auto &n : notifications) { - const auto notification = n.toObject(); - if (notification["read"].toBool()) { - oldNotifications.removeOne(notification["event"].toObject()["event_id"].toString()); - continue; - } - if (oldNotifications.contains(notification["event"].toObject()["event_id"].toString())) { - continue; - } - oldNotifications += notification["event"].toObject()["event_id"].toString(); - - auto room = m_connection->room(notification["room_id"].toString()); - auto currentRoom = RoomManager::instance().currentRoom(); - bool roomIsActive = currentRoom && room->id() == currentRoom->id(); - - // If room exists, room is NOT active OR the application is NOT active, show notification - if (room && !(roomIsActive && QGuiApplication::applicationState() == Qt::ApplicationActive)) { - // The room might have been deleted (for example rejected invitation). - auto sender = room->user(notification["event"].toObject()["sender"].toString()); - - QImage avatar_image; - if (!sender->avatarUrl(room).isEmpty()) { - avatar_image = sender->avatar(128, room); - } else { - avatar_image = room->avatar(128); - } - NotificationsManager::instance().postNotification(dynamic_cast(room), - sender->displayname(room), - notification["event"].toObject()["content"].toObject()["body"].toString(), - avatar_image, - notification["event"].toObject()["event_id"].toString(), - true); - } - } - }); -} -#endif - int RoomListModel::notificationCount() const { return m_notificationCount; diff --git a/src/models/roomlistmodel.h b/src/models/roomlistmodel.h index 335cd017e..eb0d73c2f 100644 --- a/src/models/roomlistmodel.h +++ b/src/models/roomlistmodel.h @@ -166,9 +166,6 @@ private: QString m_activeSpaceId = ""; void connectRoomSignals(NeoChatRoom *room); -#ifndef QUOTIENT_07 - void handleNotifications(); -#endif Q_SIGNALS: void connectionChanged(); diff --git a/src/models/searchmodel.cpp b/src/models/searchmodel.cpp index dea415300..468e188b0 100644 --- a/src/models/searchmodel.cpp +++ b/src/models/searchmodel.cpp @@ -9,9 +9,6 @@ #include #include -#ifdef QUOTIENT_07 -#endif - using namespace Quotient; // TODO search only in the current room @@ -34,7 +31,6 @@ void SearchModel::setSearchText(const QString &searchText) void SearchModel::search() { -#ifdef QUOTIENT_07 Q_ASSERT(m_connection); setSearching(true); if (m_job) { @@ -71,7 +67,6 @@ void SearchModel::search() m_job = nullptr; // TODO error handling }); -#endif } Connection *SearchModel::connection() const @@ -87,7 +82,6 @@ void SearchModel::setConnection(Connection *connection) QVariant SearchModel::data(const QModelIndex &index, int role) const { -#ifdef QUOTIENT_07 auto row = index.row(); const auto &event = *m_result->results[row].result; switch (role) { @@ -174,18 +168,14 @@ QVariant SearchModel::data(const QModelIndex &index, int role) const return event.contentJson()["m.relates_to"].toObject()["m.in_reply_to"].toObject()["event_id"].toString(); } return MessageEventModel::DelegateType::Message; -#endif - return {}; } int SearchModel::rowCount(const QModelIndex &parent) const { Q_UNUSED(parent); -#ifdef QUOTIENT_07 if (m_result.has_value()) { return m_result->results.size(); } -#endif return 0; } @@ -236,7 +226,6 @@ void SearchModel::setRoom(NeoChatRoom *room) m_room = room; Q_EMIT roomChanged(); -#ifdef QUOTIENT_07 connect(m_room, &NeoChatRoom::replyLoaded, this, [this](const auto &eventId, const auto &replyId) { Q_UNUSED(replyId); const auto &results = m_result->results; @@ -249,7 +238,6 @@ void SearchModel::setRoom(NeoChatRoom *room) auto row = it - results.begin(); Q_EMIT dataChanged(index(row, 0), index(row, 0), {ReplyRole, ReplyMediaInfoRole, ReplyAuthorRole}); }); -#endif } // TODO deduplicate with messageeventmodel diff --git a/src/models/searchmodel.h b/src/models/searchmodel.h index 2b481aa95..74247c0f4 100644 --- a/src/models/searchmodel.h +++ b/src/models/searchmodel.h @@ -6,9 +6,7 @@ #include #include -#ifdef QUOTIENT_07 #include -#endif namespace Quotient { @@ -137,10 +135,8 @@ private: QString m_searchText; Quotient::Connection *m_connection = nullptr; NeoChatRoom *m_room = nullptr; -#ifdef QUOTIENT_07 Quotient::Omittable m_result = Quotient::none; Quotient::SearchJob *m_job = nullptr; -#endif bool m_searching = false; }; diff --git a/src/models/serverlistmodel.cpp b/src/models/serverlistmodel.cpp index 66c4f3b1e..6db86f947 100644 --- a/src/models/serverlistmodel.cpp +++ b/src/models/serverlistmodel.cpp @@ -95,11 +95,7 @@ void ServerListModel::checkServer(const QString &url) KConfigGroup serverGroup(&dataResource, "Servers"); if (!serverGroup.hasKey(url)) { -#ifdef QUOTIENT_07 if (Quotient::isJobPending(m_checkServerJob)) { -#else - if (Quotient::isJobRunning(m_checkServerJob)) { -#endif m_checkServerJob->abandon(); } diff --git a/src/models/statemodel.cpp b/src/models/statemodel.cpp index 906e37c7f..7555f5f68 100644 --- a/src/models/statemodel.cpp +++ b/src/models/statemodel.cpp @@ -14,7 +14,6 @@ QHash StateModel::roleNames() const } QVariant StateModel::data(const QModelIndex &index, int role) const { -#ifdef QUOTIENT_07 auto row = index.row(); switch (role) { case TypeRole: @@ -22,18 +21,13 @@ QVariant StateModel::data(const QModelIndex &index, int role) const case StateKeyRole: return m_stateEvents[row].second; } -#endif return {}; } int StateModel::rowCount(const QModelIndex &parent) const { Q_UNUSED(parent); -#ifdef QUOTIENT_07 return m_room->currentState().events().size(); -#else - return 0; -#endif } NeoChatRoom *StateModel::room() const @@ -47,16 +41,12 @@ void StateModel::setRoom(NeoChatRoom *room) Q_EMIT roomChanged(); beginResetModel(); m_stateEvents.clear(); -#ifdef QUOTIENT_07 m_stateEvents = m_room->currentState().events().keys(); -#endif endResetModel(); connect(room, &NeoChatRoom::changed, this, [this] { beginResetModel(); m_stateEvents.clear(); -#ifdef QUOTIENT_07 m_stateEvents = m_room->currentState().events().keys(); -#endif endResetModel(); }); } @@ -64,11 +54,7 @@ void StateModel::setRoom(NeoChatRoom *room) QByteArray StateModel::stateEventJson(const QModelIndex &index) { auto row = index.row(); -#ifdef QUOTIENT_07 return QJsonDocument(m_room->currentState().events()[m_stateEvents[row]]->fullJson()).toJson(); -#else - return {}; -#endif } #include "moc_statemodel.cpp" diff --git a/src/models/stickermodel.cpp b/src/models/stickermodel.cpp index c6529f147..2ad9b3d8b 100644 --- a/src/models/stickermodel.cpp +++ b/src/models/stickermodel.cpp @@ -22,9 +22,7 @@ QVariant StickerModel::data(const QModelIndex &index, int role) const const auto &row = index.row(); const auto &image = m_images[row]; if (role == UrlRole) { -#ifdef QUOTIENT_07 return m_room->connection()->makeMediaUrl(image.url); -#endif } if (role == BodyRole) { if (image.body) { diff --git a/src/models/userdirectorylistmodel.cpp b/src/models/userdirectorylistmodel.cpp index b3e5f5346..675c75bf2 100644 --- a/src/models/userdirectorylistmodel.cpp +++ b/src/models/userdirectorylistmodel.cpp @@ -146,11 +146,7 @@ QVariant UserDirectoryListModel::data(const QModelIndex &index, int role) const if (avatarUrl.isEmpty()) { return ""; } -#ifdef QUOTIENT_07 return avatarUrl.url().remove(0, 6); -#else - return avatarUrl.remove(0, 6); -#endif } if (role == UserIDRole) { return user.userId; diff --git a/src/models/userlistmodel.cpp b/src/models/userlistmodel.cpp index 06db08f6d..aeec2bada 100644 --- a/src/models/userlistmodel.cpp +++ b/src/models/userlistmodel.cpp @@ -82,11 +82,7 @@ QVariant UserListModel::data(const QModelIndex &index, int role) const return pl->powerLevelForUser(user->id()); } if (role == PowerLevelStringRole) { -#ifdef QUOTIENT_07 auto pl = m_currentRoom->currentState().get(); -#else - auto pl = m_currentRoom->getCurrentState(); -#endif // User might not in the room yet, in this case pl can be nullptr. // e.g. When invited but user not accepted or denied the invitation. if (!pl) { @@ -124,15 +120,9 @@ void UserListModel::userAdded(Quotient::User *user) beginInsertRows(QModelIndex(), pos, pos); m_users.insert(pos, user); endInsertRows(); -#ifdef QUOTIENT_07 connect(user, &User::defaultAvatarChanged, this, [this, user]() { refreshUser(user, {AvatarRole}); }); -#else - connect(user, &Quotient::User::avatarChanged, this, [this, user]() { - refreshUser(user, {AvatarRole}); - }); -#endif } void UserListModel::userRemoved(Quotient::User *user) @@ -170,15 +160,9 @@ void UserListModel::refreshAllUsers() std::sort(m_users.begin(), m_users.end(), m_currentRoom->memberSorter()); for (User *user : std::as_const(m_users)) { -#ifdef QUOTIENT_07 connect(user, &User::defaultAvatarChanged, this, [this, user]() { refreshUser(user, {AvatarRole}); }); -#else - connect(user, &User::avatarChanged, this, [this, user]() { - refreshUser(user, {AvatarRole}); - }); -#endif } connect(m_currentRoom->connection(), &Connection::loggedOut, this, [this]() { setRoom(nullptr); diff --git a/src/neochataccountregistry.cpp b/src/neochataccountregistry.cpp deleted file mode 100644 index 8e0134823..000000000 --- a/src/neochataccountregistry.cpp +++ /dev/null @@ -1,107 +0,0 @@ -// SPDX-FileCopyrightText: Kitsune Ral -// SPDX-FileCopyrightText: Tobias Fella -// SPDX-License-Identifier: LGPL-2.1-or-later - -#include "neochataccountregistry.h" - -#include - -using namespace Quotient; - -void AccountRegistry::add(Connection *c) -{ - if (m_accounts.contains(c)) - return; - beginInsertRows(QModelIndex(), m_accounts.size(), m_accounts.size()); - m_accounts += c; - endInsertRows(); - emit accountCountChanged(); -} - -void AccountRegistry::drop(Connection *c) -{ - beginRemoveRows(QModelIndex(), m_accounts.indexOf(c), m_accounts.indexOf(c)); - m_accounts.removeOne(c); - endRemoveRows(); - Q_ASSERT(!m_accounts.contains(c)); - emit accountCountChanged(); -} - -bool AccountRegistry::isLoggedIn(const QString &userId) const -{ - return std::any_of(m_accounts.cbegin(), m_accounts.cend(), [&userId](Connection *a) { - return a->userId() == userId; - }); -} - -bool AccountRegistry::contains(Connection *c) const -{ - return m_accounts.contains(c); -} - -AccountRegistry::AccountRegistry() = default; - -QVariant AccountRegistry::data(const QModelIndex &index, int role) const -{ - if (!index.isValid()) { - return {}; - } - - if (index.row() >= m_accounts.count()) { - return {}; - } - - const auto account = m_accounts[index.row()]; - - switch (role) { - case ConnectionRole: - return QVariant::fromValue(account); - case UserIdRole: - return QVariant::fromValue(account->userId()); - default: - return {}; - } - - return {}; -} - -int AccountRegistry::rowCount(const QModelIndex &parent) const -{ - if (parent.isValid()) { - return 0; - } - - return m_accounts.count(); -} - -QHash AccountRegistry::roleNames() const -{ - return {{ConnectionRole, "connection"}, {UserIdRole, "userId"}}; -} - -bool AccountRegistry::isEmpty() const -{ - return m_accounts.isEmpty(); -} - -int AccountRegistry::count() const -{ - return m_accounts.count(); -} - -const QVector AccountRegistry::accounts() const -{ - return m_accounts; -} - -Connection *AccountRegistry::get(const QString &userId) -{ - for (const auto &connection : m_accounts) { - if (connection->userId() == userId) { - return connection; - } - } - return nullptr; -} - -#include "moc_neochataccountregistry.cpp" diff --git a/src/neochataccountregistry.h b/src/neochataccountregistry.h deleted file mode 100644 index 221ec7b33..000000000 --- a/src/neochataccountregistry.h +++ /dev/null @@ -1,54 +0,0 @@ -// SPDX-FileCopyrightText: 2020 Kitsune Ral -// SPDX-FileCopyrightText: Tobias Fella -// SPDX-License-Identifier: LGPL-2.1-or-later - -#pragma once - -#include -#include -#include - -namespace Quotient -{ -class Connection; - -class AccountRegistry : public QAbstractListModel -{ - Q_OBJECT - Q_PROPERTY(int accountCount READ count NOTIFY accountCountChanged); - -public: - enum EventRoles { - ConnectionRole = Qt::UserRole + 1, - UserIdRole = Qt::DisplayRole, - }; - - static AccountRegistry &instance() - { - static AccountRegistry _instance; - return _instance; - } - - const QVector accounts() const; - void add(Connection *a); - void drop(Connection *a); - bool isLoggedIn(const QString &userId) const; - bool isEmpty() const; - int count() const; - bool contains(Connection *) const; - Connection *get(const QString &userId); - - [[nodiscard]] QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override; - [[nodiscard]] int rowCount(const QModelIndex &parent = QModelIndex()) const override; - - [[nodiscard]] QHash roleNames() const override; - -Q_SIGNALS: - void accountCountChanged(); - -private: - AccountRegistry(); - - QVector m_accounts; -}; -} diff --git a/src/neochatroom.cpp b/src/neochatroom.cpp index 735b51ff0..0afec308a 100644 --- a/src/neochatroom.cpp +++ b/src/neochatroom.cpp @@ -35,22 +35,15 @@ #include #include -#ifndef QUOTIENT_07 -#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) -#include -#endif -#endif #include #include "controller.h" #include "events/joinrulesevent.h" -#include "neochatconfig.h" -#include "notificationsmanager.h" -#ifdef QUOTIENT_07 #include "events/pollevent.h" -#endif #include "events/stickerevent.h" #include "filetransferpseudojob.h" +#include "neochatconfig.h" +#include "notificationsmanager.h" #include "texthandler.h" #include @@ -195,17 +188,9 @@ QCoro::Task NeoChatRoom::doUploadFile(QUrl url, QString body) } else { content = new EventContent::FileContent(url, fileInfo.size(), mime, fileInfo.fileName()); } -#ifdef QUOTIENT_07 QString txnId = postFile(body.isEmpty() ? url.fileName() : body, content); -#else - QString txnId = postFile(body.isEmpty() ? url.fileName() : body, url, false); -#endif setHasFileUploading(true); -#ifdef QUOTIENT_07 connect(this, &Room::fileTransferCompleted, [this, txnId](const QString &id, FileSourceInfo) { -#else - connect(this, &Room::fileTransferCompleted, [this, txnId](const QString &id, const QUrl & /*localFile*/, const QUrl & /*mxcUrl*/) { -#endif if (id == txnId) { setFileUploadingProgress(0); setHasFileUploading(false); @@ -302,22 +287,16 @@ const RoomEvent *NeoChatRoom::lastEvent() const continue; } -#ifdef QUOTIENT_07 if (auto lastEvent = eventCast(event)) { -#else - if (auto lastEvent = eventCast(event)) { -#endif return lastEvent; } if (auto lastEvent = eventCast(event)) { return lastEvent; } -#ifdef QUOTIENT_07 if (auto lastEvent = eventCast(event)) { return lastEvent; } -#endif } if (m_cachedEvent != nullptr) { @@ -506,11 +485,7 @@ QString NeoChatRoom::eventToString(const RoomEvent &evt, Qt::TextFormat format, const bool prettyPrint = (format == Qt::RichText); using namespace Quotient; -#ifdef QUOTIENT_07 return switchOnType( -#else - return visit( -#endif evt, [this, format, stripNewlines](const RoomMessageEvent &e) { using namespace MessageEventContent; @@ -557,13 +532,8 @@ QString NeoChatRoom::eventToString(const RoomEvent &evt, Qt::TextFormat format, // FIXME: Rewind to the name that was at the time of this event auto subjectName = this->htmlSafeMemberName(e.userId()); if (e.membership() == MembershipType::Leave) { -#ifdef QUOTIENT_07 if (e.prevContent() && e.prevContent()->displayName) { subjectName = sanitized(*e.prevContent()->displayName).toHtmlEscaped(); -#else - if (e.prevContent() && e.prevContent()->displayName.isEmpty()) { - subjectName = sanitized(e.prevContent()->displayName).toHtmlEscaped(); -#endif } } @@ -611,11 +581,7 @@ QString NeoChatRoom::eventToString(const RoomEvent &evt, Qt::TextFormat format, } if (e.avatarUrl().isEmpty()) { text += i18nc("their refers to a singular user", "cleared their avatar"); -#ifdef QUOTIENT_07 } else if (!e.prevContent()->avatarUrl) { -#else - } else if (e.prevContent()->avatarUrl.isEmpty()) { -#endif text += i18n("set an avatar"); } else { text += i18nc("their refers to a singular user", "updated their avatar"); @@ -700,21 +666,15 @@ QString NeoChatRoom::eventToString(const RoomEvent &evt, Qt::TextFormat format, return e.stateKey().isEmpty() ? i18n("updated %1 state", e.matrixType()) : i18n("updated %1 state for %2", e.matrixType(), e.stateKey().toHtmlEscaped()); }, -#ifdef QUOTIENT_07 [](const PollStartEvent &e) { return e.question(); }, -#endif i18n("Unknown event")); } QString NeoChatRoom::eventToGenericString(const RoomEvent &evt) const { -#ifdef QUOTIENT_07 return switchOnType( -#else - return visit( -#endif evt, [](const RoomMessageEvent &e) { Q_UNUSED(e) @@ -756,11 +716,7 @@ QString NeoChatRoom::eventToGenericString(const RoomEvent &evt) const } if (e.avatarUrl().isEmpty()) { text += i18nc("their refers to a singular user", "cleared their avatar"); -#ifdef QUOTIENT_07 } else if (!e.prevContent()->avatarUrl) { -#else - } else if (e.prevContent()->avatarUrl.isEmpty()) { -#endif text += i18n("set an avatar"); } else { text += i18nc("their refers to a singular user", "updated their avatar"); @@ -829,29 +785,19 @@ QString NeoChatRoom::eventToGenericString(const RoomEvent &evt) const } return i18n("updated the state"); }, -#ifdef QUOTIENT_07 [](const PollStartEvent &e) { Q_UNUSED(e); return i18n("started a poll"); }, -#endif i18n("Unknown event")); } void NeoChatRoom::changeAvatar(const QUrl &localFile) { const auto job = connection()->uploadFile(localFile.toLocalFile()); -#ifdef QUOTIENT_07 if (isJobPending(job)) { -#else - if (isJobRunning(job)) { -#endif connect(job, &BaseJob::success, this, [this, job] { -#ifdef QUOTIENT_07 connection()->callApi(id(), "m.room.avatar", QString(), QJsonObject{{"url", job->contentUri().toString()}}); -#else - connection()->callApi(id(), "m.room.avatar", QString(), QJsonObject{{"url", job->contentUri()}}); -#endif }); } } @@ -987,17 +933,7 @@ void NeoChatRoom::toggleReaction(const QString &eventId, const QString &reaction bool NeoChatRoom::containsUser(const QString &userID) const { -#ifdef QUOTIENT_07 return memberState(userID) != Membership::Leave; -#else - auto u = Room::user(userID); - - if (!u) { - return false; - } - - return Room::memberJoinState(u) != JoinState::Leave; -#endif } bool NeoChatRoom::canSendEvent(const QString &eventType) const @@ -1015,24 +951,12 @@ bool NeoChatRoom::canSendState(const QString &eventType) const auto pl = plEvent->powerLevelForState(eventType); auto currentPl = plEvent->powerLevelForUser(localUser()->id()); -#ifndef QUOTIENT_07 - if (eventType == "m.room.history_visibility" || eventType == "org.matrix.room.preview_urls") { - return false; - } else { - return currentPl >= pl; - } -#else return currentPl >= pl; -#endif } bool NeoChatRoom::readMarkerLoaded() const { -#ifdef QUOTIENT_07 const auto it = findInTimeline(lastFullyReadEventId()); -#else - const auto it = findInTimeline(readMarkerEventId()); -#endif return it != historyEdge(); } @@ -1067,21 +991,13 @@ void NeoChatRoom::setJoinRule(const QString &joinRule) qWarning() << "Power level too low to set join rules"; return; } -#ifdef QUOTIENT_07 setState("m.room.join_rules", "", QJsonObject{{"join_rule", joinRule}}); -#else - setState(QJsonObject{{"type", "m.room.join_rules"}, {"state_key", ""}, {"content", QJsonObject{{"join_rule", joinRule}}}}); -#endif // Not emitting joinRuleChanged() here, since that would override the change in the UI with the *current* value, which is not the *new* value. } QString NeoChatRoom::historyVisibility() const { -#ifdef QUOTIENT_07 return currentState().get("m.room.history_visibility")->contentJson()["history_visibility"_ls].toString(); -#else - return getCurrentState("m.room.history_visibility")->contentJson()["history_visibility"_ls].toString(); -#endif } void NeoChatRoom::setHistoryVisibility(const QString &historyVisibilityRule) @@ -1091,23 +1007,13 @@ void NeoChatRoom::setHistoryVisibility(const QString &historyVisibilityRule) return; } -#ifdef QUOTIENT_07 setState("m.room.history_visibility", "", QJsonObject{{"history_visibility", historyVisibilityRule}}); -#else - qWarning() << "Quotient 0.7 required to set history visibility"; - return; -#endif - // Not emitting historyVisibilityChanged() here, since that would override the change in the UI with the *current* value, which is not the *new* value. } bool NeoChatRoom::defaultUrlPreviewState() const { -#ifdef QUOTIENT_07 auto urlPreviewsDisabled = currentState().get("org.matrix.room.preview_urls"); -#else - auto urlPreviewsDisabled = getCurrentState("org.matrix.room.preview_urls"); -#endif // Some rooms will not have this state event set so check for a nullptr return. if (urlPreviewsDisabled != nullptr) { @@ -1153,12 +1059,7 @@ void NeoChatRoom::setDefaultUrlPreviewState(const bool &defaultUrlPreviewState) * * You just have to set disable to true to disable URL previews by default. */ -#ifdef QUOTIENT_07 setState("org.matrix.room.preview_urls", "", QJsonObject{{"disable", !defaultUrlPreviewState}}); -#else - qWarning() << "Quotient 0.7 required to set room default url preview setting"; - return; -#endif } bool NeoChatRoom::urlPreviewEnabled() const @@ -1196,32 +1097,20 @@ void NeoChatRoom::setUserPowerLevel(const QString &userID, const int &powerLevel qWarning() << "Power level too low to set user power levels"; return; } -#ifdef QUOTIENT_07 if (!isMember(userID)) { -#else - if (memberJoinState(user(userID)) == JoinState::Join) { -#endif qWarning() << "User is not a member of this room so power level cannot be set"; return; } int clampPowerLevel = std::clamp(powerLevel, 0, 100); -#ifdef QUOTIENT_07 auto powerLevelContent = currentState().get("m.room.power_levels")->contentJson(); -#else - auto powerLevelContent = getCurrentState()->contentJson(); -#endif auto powerLevelUserOverrides = powerLevelContent["users"].toObject(); if (powerLevelUserOverrides[userID] != clampPowerLevel) { powerLevelUserOverrides[userID] = clampPowerLevel; powerLevelContent["users"] = powerLevelUserOverrides; -#ifdef QUOTIENT_07 setState("m.room.power_levels", "", powerLevelContent); -#else - setState(QJsonObject{{"type", "m.room.power_levels"}, {"state_key", ""}, {"content", powerLevelContent}}); -#endif } } @@ -1233,11 +1122,7 @@ int NeoChatRoom::getUserPowerLevel(const QString &userId) const int NeoChatRoom::powerLevel(const QString &eventName, const bool &isStateEvent) const { -#ifdef QUOTIENT_07 const auto powerLevelEvent = currentState().get(); -#else - const auto powerLevelEvent = getCurrentState(); -#endif if (eventName == "ban") { return powerLevelEvent->ban(); } else if (eventName == "kick") { @@ -1261,11 +1146,7 @@ int NeoChatRoom::powerLevel(const QString &eventName, const bool &isStateEvent) void NeoChatRoom::setPowerLevel(const QString &eventName, const int &newPowerLevel, const bool &isStateEvent) { -#ifdef QUOTIENT_07 auto powerLevelContent = currentState().get("m.room.power_levels")->contentJson(); -#else - auto powerLevelContent = getCurrentState()->contentJson(); -#endif int clampPowerLevel = std::clamp(newPowerLevel, 0, 100); int powerLevel = 0; @@ -1294,11 +1175,7 @@ void NeoChatRoom::setPowerLevel(const QString &eventName, const int &newPowerLev } } -#ifdef QUOTIENT_07 setState("m.room.power_levels", "", powerLevelContent); -#else - setState(QJsonObject{{"type", "m.room.power_levels"}, {"state_key", ""}, {"content", powerLevelContent}}); -#endif } int NeoChatRoom::defaultUserPowerLevel() const @@ -1521,11 +1398,7 @@ bool NeoChatRoom::isSpace() return false; } -#ifdef QUOTIENT_07 return creationEvent->roomType() == RoomType::Space; -#else - return false; -#endif } PushNotificationState::State NeoChatRoom::pushNotificationState() const @@ -1919,15 +1792,12 @@ void NeoChatRoom::editLastMessage() bool NeoChatRoom::canEncryptRoom() const { -#ifdef QUOTIENT_07 #ifdef Quotient_E2EE_ENABLED return !usesEncryption() && canSendState("m.room.encryption"); -#endif #endif return false; } -#ifdef QUOTIENT_07 PollHandler *NeoChatRoom::poll(const QString &eventId) { if (!m_polls.contains(eventId)) { @@ -1938,7 +1808,6 @@ PollHandler *NeoChatRoom::poll(const QString &eventId) } return m_polls[eventId]; } -#endif bool NeoChatRoom::downloadTempFile(const QString &eventId) { @@ -2054,7 +1923,6 @@ QByteArray NeoChatRoom::roomAcountDataJson(const QString &eventType) QUrl NeoChatRoom::avatarForMember(NeoChatUser *user) const { -#ifdef QUOTIENT_07 const auto &url = memberAvatarUrl(user->id()); if (url.isEmpty()) { return {}; @@ -2065,13 +1933,6 @@ QUrl NeoChatRoom::avatarForMember(NeoChatUser *user) const } else { return QUrl(); } -#else - QUrl url(QStringLiteral("mxc://%1").arg(user->avatarMediaId())); - QUrlQuery q(url.query()); - q.addQueryItem(QStringLiteral("user_id"), user->id()); - url.setQuery(q); - return url; -#endif } const RoomEvent *NeoChatRoom::getReplyForEvent(const RoomEvent &event) const diff --git a/src/neochatroom.h b/src/neochatroom.h index 3d88c349b..08370acb2 100644 --- a/src/neochatroom.h +++ b/src/neochatroom.h @@ -592,16 +592,6 @@ public: QString htmlSafeDisplayName() const; -#ifndef QUOTIENT_07 - /** - * @brief Get a display name for the user with html escaped. - */ - Q_INVOKABLE QString htmlSafeMemberName(const QString &userId) const - { - return safeMemberName(userId).toHtmlEscaped(); - } -#endif - /** * @brief Get subtitle text for room * @@ -812,7 +802,6 @@ public: */ Q_INVOKABLE void editLastMessage(); -#ifdef QUOTIENT_07 /** * @brief Get a PollHandler object for the given event Id. * @@ -824,7 +813,6 @@ public: * @sa PollHandler */ Q_INVOKABLE PollHandler *poll(const QString &eventId); -#endif /** * @brief Get the full Json data for a given room account data event. @@ -873,9 +861,7 @@ private: QVector m_mentions; QVector m_editMentions; QString m_savedText; -#ifdef QUOTIENT_07 QCache m_polls; -#endif std::vector> m_extraEvents; private Q_SLOTS: diff --git a/src/notificationsmanager.cpp b/src/notificationsmanager.cpp index 592a3bc81..bf8a14339 100644 --- a/src/notificationsmanager.cpp +++ b/src/notificationsmanager.cpp @@ -11,11 +11,7 @@ #include #include -#ifdef QUOTIENT_07 #include -#else -#include "neochataccountregistry.h" -#endif #include #include @@ -41,7 +37,6 @@ NotificationsManager::NotificationsManager(QObject *parent) { } -#ifdef QUOTIENT_07 void NotificationsManager::handleNotifications(QPointer connection) { if (!m_connActiveJob.contains(connection->user()->id())) { @@ -53,7 +48,6 @@ void NotificationsManager::handleNotifications(QPointer connection) }); } } -#endif void NotificationsManager::processNotificationJob(QPointer connection, Quotient::GetNotificationsJob *job, bool initialization) { @@ -219,11 +213,7 @@ void NotificationsManager::postNotification(NeoChatRoom *room, return; } if (room->localUser()->id() != Controller::instance().activeConnection()->userId()) { -#ifdef QUOTIENT_07 Controller::instance().setActiveConnection(Accounts.get(room->localUser()->id())); -#else - Controller::instance().setActiveConnection(AccountRegistry::instance().get(room->localUser()->id())); -#endif } RoomManager::instance().enterRoom(room); }); diff --git a/src/notificationsmanager.h b/src/notificationsmanager.h index d57ed41c7..769afabe4 100644 --- a/src/notificationsmanager.h +++ b/src/notificationsmanager.h @@ -77,12 +77,10 @@ public: */ void clearInvitationNotification(const QString &roomId); -#ifdef QUOTIENT_07 /** * @brief Handle the notifications for the given connection. */ void handleNotifications(QPointer connection); -#endif private: explicit NotificationsManager(QObject *parent = nullptr); diff --git a/src/roommanager.cpp b/src/roommanager.cpp index 3613f7bb4..588fb10d1 100644 --- a/src/roommanager.cpp +++ b/src/roommanager.cpp @@ -11,9 +11,7 @@ #include #include #include -#ifdef QUOTIENT_07 #include -#endif #include #include @@ -166,16 +164,12 @@ UriResolveResult RoomManager::visitUser(User *user, const QString &action) { if (action == "mention" || action.isEmpty()) { // send it has QVariantMap because the properties in the -#ifdef QUOTIENT_07 user->load(); -#endif Q_EMIT showUserDetail(user); } else if (action == "_interactive") { user->requestDirectChat(); } else if (action == "chat") { -#ifdef QUOTIENT_07 user->load(); -#endif Q_EMIT askDirectChatConfirmation(user); } else { return Quotient::IncorrectAction; @@ -218,8 +212,6 @@ void RoomManager::joinRoom(Quotient::Connection *account, const QString &roomAli }); } -// TODO: maybe need use the function upstream later -#ifdef QUOTIENT_07 void RoomManager::knockRoom(Quotient::Connection *account, const QString &roomAliasOrId, const QString &reason, const QStringList &viaServers) { auto *const job = account->callApi(roomAliasOrId, viaServers, reason); @@ -237,7 +229,6 @@ void RoomManager::knockRoom(Quotient::Connection *account, const QString &roomAl } }); } -#endif bool RoomManager::visitNonMatrix(const QUrl &url) { diff --git a/src/roommanager.h b/src/roommanager.h index 54b4106bb..0fc45a9a3 100644 --- a/src/roommanager.h +++ b/src/roommanager.h @@ -133,8 +133,6 @@ public: */ Q_INVOKABLE bool visitNonMatrix(const QUrl &url) override; - // TODO: it need also override in the feature? -#ifdef QUOTIENT_07 /** * @brief Knock a room. * @@ -142,7 +140,6 @@ public: * knocking on rooms. */ void knockRoom(Quotient::Connection *account, const QString &roomAliasOrId, const QString &reason, const QStringList &viaServers); -#endif /** * @brief Open the given resource. diff --git a/src/spacehierarchycache.cpp b/src/spacehierarchycache.cpp index f08d68941..a9a3914f3 100644 --- a/src/spacehierarchycache.cpp +++ b/src/spacehierarchycache.cpp @@ -3,9 +3,7 @@ #include "spacehierarchycache.h" -#ifdef QUOTIENT_07 #include -#endif #include #include "controller.h" @@ -26,7 +24,6 @@ SpaceHierarchyCache::SpaceHierarchyCache(QObject *parent) void SpaceHierarchyCache::cacheSpaceHierarchy() { -#ifdef QUOTIENT_07 auto connection = Controller::instance().activeConnection(); if (!connection) { return; @@ -45,7 +42,6 @@ void SpaceHierarchyCache::cacheSpaceHierarchy() }); } } -#endif } void SpaceHierarchyCache::populateSpaceHierarchy(const QString &spaceId) @@ -54,7 +50,6 @@ void SpaceHierarchyCache::populateSpaceHierarchy(const QString &spaceId) if (!connection) { return; } -#ifdef QUOTIENT_07 auto job = connection->callApi(spaceId); connect(job, &BaseJob::success, this, [this, job, spaceId]() { @@ -68,7 +63,6 @@ void SpaceHierarchyCache::populateSpaceHierarchy(const QString &spaceId) m_spaceHierarchy.insert(spaceId, roomList); Q_EMIT spaceHierarchyChanged(); }); -#endif } void SpaceHierarchyCache::addSpaceToHierarchy(Quotient::Room *room) diff --git a/src/texthandler.cpp b/src/texthandler.cpp index 90add156a..b0f67fd53 100644 --- a/src/texthandler.cpp +++ b/src/texthandler.cpp @@ -100,18 +100,10 @@ QString TextHandler::handleRecieveRichText(Qt::TextFormat inputFormat, const Neo QRegularExpressionMatchIterator i = TextRegex::mxcImage.globalMatch(m_dataBuffer); while (i.hasNext()) { const QRegularExpressionMatch match = i.next(); -#ifdef QUOTIENT_07 const QUrl mediaUrl = room->makeMediaUrl(event->id(), QUrl(QStringLiteral("mxc://") + match.captured(2) + u'/' + match.captured(3))); m_dataBuffer.replace(match.captured(0), QStringLiteral("'); -#else - auto url = room->connection()->homeserver(); - auto base = url.scheme() + QStringLiteral("://") + url.host() + (url.port() != -1 ? ':' + QString::number(url.port()) : QString()); - m_dataBuffer.replace(match.captured(0), - QStringLiteral("'); -#endif } } @@ -330,11 +322,7 @@ bool TextHandler::isAllowedLink(const QString &link, bool isImg) const QUrl linkUrl = QUrl(link); if (isImg) { -#ifdef QUOTIENT_07 return !linkUrl.isRelative() && linkUrl.scheme() == "mxc"; -#else - return !linkUrl.isRelative() && (linkUrl.scheme() == "mxc" || linkUrl.scheme() == "https"); -#endif } else { return !linkUrl.isRelative() && allowedLinkSchemes.contains(linkUrl.scheme()); }