File indexing completed on 2024-04-28 04:59:30
0001 // SPDX-FileCopyrightText: 2023 James Graham <james.h.graham@protonmail.com> 0002 // SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL 0003 0004 #include <Quotient/events/event.h> 0005 #include <Quotient/syncdata.h> 0006 0007 #include "neochatroom.h" 0008 0009 namespace Quotient 0010 { 0011 class Connection; 0012 } 0013 0014 namespace TestUtils 0015 { 0016 class TestRoom : public NeoChatRoom 0017 { 0018 public: 0019 TestRoom(Quotient::Connection *connection, const QString &roomName, const QString &syncFileName = {}) 0020 : NeoChatRoom(connection, roomName, Quotient::JoinState::Join) 0021 { 0022 syncNewEvents(syncFileName); 0023 } 0024 0025 void update(Quotient::SyncRoomData &&data, bool fromCache = false) 0026 { 0027 Room::updateData(std::move(data), fromCache); 0028 } 0029 0030 void syncNewEvents(const QString &syncFileName) 0031 { 0032 if (!syncFileName.isEmpty()) { 0033 QFile testSyncFile; 0034 testSyncFile.setFileName(QLatin1String(DATA_DIR) + u'/' + syncFileName); 0035 testSyncFile.open(QIODevice::ReadOnly); 0036 const auto testSyncJson = QJsonDocument::fromJson(testSyncFile.readAll()); 0037 Quotient::SyncRoomData roomData(id(), Quotient::JoinState::Join, testSyncJson.object()); 0038 update(std::move(roomData)); 0039 } 0040 } 0041 }; 0042 0043 template<Quotient::EventClass EventT> 0044 inline Quotient::event_ptr_tt<EventT> loadEventFromFile(const QString &eventFileName) 0045 { 0046 if (!eventFileName.isEmpty()) { 0047 QFile testEventFile; 0048 testEventFile.setFileName(QLatin1String(DATA_DIR) + u'/' + eventFileName); 0049 testEventFile.open(QIODevice::ReadOnly); 0050 auto testSyncJson = QJsonDocument::fromJson(testEventFile.readAll()).object(); 0051 return Quotient::loadEvent<EventT>(testSyncJson); 0052 } 0053 return nullptr; 0054 } 0055 }