Page MenuHomePhorge

D238.1759550939.diff
No OneTemporary

Size
20 KB
Referenced Files
None
Subscribers
None

D238.1759550939.diff

diff --git a/CMakeLists.txt b/CMakeLists.txt
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -18,7 +18,7 @@
set(libkazv_SOVERSION 7)
set(CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake" ${CMAKE_MODULE_PATH})
-set(CMAKE_CXX_STANDARD 17)
+set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra")
option(libkazv_BUILD_TESTS "Build tests" ON)
diff --git a/src/base/basejob.hpp b/src/base/basejob.hpp
--- a/src/base/basejob.hpp
+++ b/src/base/basejob.hpp
@@ -30,12 +30,10 @@
using BytesBody = Bytes;
using JsonBody = JsonWrap;
using FileBody = FileDesc;
- struct EmptyBody {};
+ struct EmptyBody {
+ friend bool operator==(EmptyBody, EmptyBody) = default;
+ };
using Body = std::variant<EmptyBody, JsonBody, BytesBody, FileBody>;
- inline bool operator==(EmptyBody, EmptyBody)
- {
- return true;
- }
inline bool isBodyJson(Body body) {
return std::holds_alternative<JsonBody>(body);
@@ -47,7 +45,8 @@
CancelFutureIfFailed
};
- struct Response {
+ struct Response
+ {
using StatusCode = int;
StatusCode statusCode;
Body body;
@@ -62,24 +61,28 @@
json dataJson(const std::string &key) const;
std::string dataStr(const std::string &key) const;
std::string jobId() const;
+ friend bool operator==(const Response &a, const Response &b) = default;
};
- inline bool operator==(Response a, Response b)
- {
- return a.statusCode == b.statusCode
- && a.body == b.body
- && a.header == b.header
- && a.extraData == b.extraData;
- }
-
-
class BaseJob
{
public:
- struct Get {};
- struct Post {};
- struct Put {};
- struct Delete {};
+ struct Get
+ {
+ friend bool operator==(BaseJob::Get, BaseJob::Get) = default;
+ };
+ struct Post
+ {
+ friend bool operator==(BaseJob::Post, BaseJob::Post) = default;
+ };
+ struct Put
+ {
+ friend bool operator==(BaseJob::Put, BaseJob::Put) = default;
+ };
+ struct Delete
+ {
+ friend bool operator==(BaseJob::Delete, BaseJob::Delete) = default;
+ };
using Method = std::variant<Get, Post, Put, Delete>;
static Get GET;
@@ -161,19 +164,12 @@
void attachData(JsonWrap data);
private:
- friend bool operator==(BaseJob a, BaseJob b);
+ friend bool operator==(const BaseJob &a, const BaseJob &b);
+ friend bool operator!=(const BaseJob &a, const BaseJob &b);
struct Private;
std::unique_ptr<Private> m_d;
};
- bool operator==(BaseJob a, BaseJob b);
- bool operator!=(BaseJob a, BaseJob b);
- inline bool operator==(BaseJob::Get, BaseJob::Get) { return true; }
- inline bool operator==(BaseJob::Post, BaseJob::Post) { return true; }
- inline bool operator==(BaseJob::Put, BaseJob::Put) { return true; }
- inline bool operator==(BaseJob::Delete, BaseJob::Delete) { return true; }
-
-
namespace detail
{
template<class T>
diff --git a/src/base/basejob.cpp b/src/base/basejob.cpp
--- a/src/base/basejob.cpp
+++ b/src/base/basejob.cpp
@@ -43,6 +43,8 @@
std::optional<std::string> queueId;
JobQueuePolicy queuePolicy;
std::optional<FileDesc> responseFile;
+
+ friend bool operator==(const Private &a, const Private &b) = default;
};
BaseJob::Private::Private(std::string serverUrl,
@@ -277,19 +279,15 @@
return "";
}
- bool operator==(BaseJob a, BaseJob b)
+ bool operator==(const BaseJob &a, const BaseJob &b)
{
- return a.m_d->fullRequestUrl == b.m_d->fullRequestUrl
- && a.m_d->method == b.m_d->method
- && a.m_d->returnType == b.m_d->returnType
- && a.m_d->body == b.m_d->body
- && a.m_d->query == b.m_d->query
- && a.m_d->header == b.m_d->header
- && a.m_d->data == b.m_d->data
- && a.m_d->jobId == b.m_d->jobId;
+ return a.m_d == b.m_d || (
+ a.m_d && b.m_d
+ && *(a.m_d) == *(b.m_d)
+ );
}
- bool operator!=(BaseJob a, BaseJob b)
+ bool operator!=(const BaseJob &a, const BaseJob &b)
{
return !(a == b);
}
diff --git a/src/base/event.hpp b/src/base/event.hpp
--- a/src/base/event.hpp
+++ b/src/base/event.hpp
@@ -99,16 +99,15 @@
ar & m_json & m_decryptedJson & m_decrypted & m_encrypted;
}
+ friend bool operator==(const Event &a, const Event &b);
+ inline friend bool operator!=(const Event &a, const Event &b) { return !(a == b); };
+
private:
JsonWrap m_json;
JsonWrap m_decryptedJson;
DecryptionStatus m_decrypted{NotDecrypted};
bool m_encrypted{false};
};
-
- bool operator==(const Event &a, const Event &b);
- inline bool operator!=(const Event &a, const Event &b) { return !(a == b); };
-
}
BOOST_CLASS_VERSION(Kazv::Event, 0)
diff --git a/src/base/file-desc.hpp b/src/base/file-desc.hpp
--- a/src/base/file-desc.hpp
+++ b/src/base/file-desc.hpp
@@ -262,7 +262,7 @@
*/
inline std::optional<std::string> contentType() const { return m_contentType; }
- bool operator==(const FileDesc &that) const;
+ friend bool operator==(const FileDesc &a, const FileDesc &b) = default;
private:
bool m_inMemory;
diff --git a/src/base/file-desc.cpp b/src/base/file-desc.cpp
--- a/src/base/file-desc.cpp
+++ b/src/base/file-desc.cpp
@@ -41,12 +41,4 @@
std::istreambuf_iterator<CharT>());
return DumbFileProvider{std::move(content)};
}
-
- bool FileDesc::operator==(const FileDesc &that) const
- {
- return m_inMemory == that.m_inMemory
- && m_content == that.m_content
- && m_name == that.m_name
- && m_contentType == that.m_contentType;
- }
}
diff --git a/src/base/jsonwrap.hpp b/src/base/jsonwrap.hpp
--- a/src/base/jsonwrap.hpp
+++ b/src/base/jsonwrap.hpp
@@ -27,6 +27,8 @@
struct Private
{
json j;
+ friend bool operator==(const Private &a, const Private &b) = default;
+ friend bool operator!=(const Private &a, const Private &b) = default;
};
immer::box<Private> m_d;
@@ -50,6 +52,8 @@
m_d = immer::box<Private>(Private{json::parse(std::move(j))});
}
BOOST_SERIALIZATION_SPLIT_MEMBER()
+ friend bool operator==(const JsonWrap &a, const JsonWrap &b) = default;
+ friend bool operator!=(const JsonWrap &a, const JsonWrap &b) = default;
};
}
@@ -67,13 +71,4 @@
w = Kazv::JsonWrap(j);
}
};
-
-}
-
-namespace Kazv
-{
- inline bool operator==(JsonWrap a, JsonWrap b)
- {
- return a.get() == b.get();
- }
}
diff --git a/src/client/actions/send.cpp b/src/client/actions/send.cpp
--- a/src/client/actions/send.cpp
+++ b/src/client/actions/send.cpp
@@ -161,7 +161,7 @@
if (!type.has_value()) {
type = origJson["type"];
} else {
- if (type.value() != origJson["type"]) {
+ if (origJson["type"] != type.value()) {
return { std::move(m), failEffect(
"MOE_KAZV_MXC_TYPE_NOT_SAME",
"The to-device messages' type must be the same"
diff --git a/src/client/clientutil.hpp b/src/client/clientutil.hpp
--- a/src/client/clientutil.hpp
+++ b/src/client/clientutil.hpp
@@ -56,6 +56,7 @@
struct KeyOfState {
std::string type;
std::string stateKey;
+ friend bool operator==(const KeyOfState &a, const KeyOfState &b) = default;
};
template<class Archive>
void serialize(Archive &ar, KeyOfState &m, std::uint32_t const /* version */)
@@ -63,11 +64,6 @@
ar & m.type & m.stateKey;
}
- inline bool operator==(KeyOfState a, KeyOfState b)
- {
- return a.type == b.type && a.stateKey == b.stateKey;
- }
-
inline KeyOfState keyOfState(Event e) {
return {e.type(), e.stateKey()};
}
diff --git a/src/client/device-list-tracker.hpp b/src/client/device-list-tracker.hpp
--- a/src/client/device-list-tracker.hpp
+++ b/src/client/device-list-tracker.hpp
@@ -38,11 +38,10 @@
std::string curve25519Key;
std::optional<std::string> displayName;
DeviceTrustLevel trustLevel{Unseen};
+ friend bool operator==(const DeviceKeyInfo &a, const DeviceKeyInfo &b) = default;
+ friend bool operator!=(const DeviceKeyInfo &a, const DeviceKeyInfo &b) = default;
};
- bool operator==(DeviceKeyInfo a, DeviceKeyInfo b);
- bool operator!=(DeviceKeyInfo a, DeviceKeyInfo b);
-
template<class Archive>
void serialize(Archive &ar, DeviceKeyInfo &i, std::uint32_t const /*version*/)
{
diff --git a/src/client/device-list-tracker.cpp b/src/client/device-list-tracker.cpp
--- a/src/client/device-list-tracker.cpp
+++ b/src/client/device-list-tracker.cpp
@@ -179,18 +179,4 @@
{
return deviceLists[userId];
}
-
- bool operator==(DeviceKeyInfo a, DeviceKeyInfo b)
- {
- return a.deviceId == b.deviceId
- && a.ed25519Key == b.ed25519Key
- && a.curve25519Key == b.curve25519Key
- && a.displayName == b.displayName
- && a.trustLevel == b.trustLevel;
- }
-
- bool operator!=(DeviceKeyInfo a, DeviceKeyInfo b)
- {
- return !(a == b);
- }
}
diff --git a/src/client/encrypted-file.cpp b/src/client/encrypted-file.cpp
--- a/src/client/encrypted-file.cpp
+++ b/src/client/encrypted-file.cpp
@@ -14,6 +14,7 @@
std::string key;
std::string iv;
std::string sha256Hash;
+ friend bool operator==(const Private &a, const Private &b) = default;
};
EncryptedFileDesc::EncryptedFileDesc()
@@ -102,10 +103,9 @@
bool EncryptedFileDesc::operator==(const EncryptedFileDesc &that) const
{
- return (m_d == that.m_d
- || (mxcUri() == that.mxcUri()
- && key() == that.key()
- && iv() == that.iv()
- && sha256Hash() == that.sha256Hash()));
+ return m_d == that.m_d || (
+ m_d && that.m_d
+ && *(m_d) == *(that.m_d)
+ );
}
}
diff --git a/src/client/room/local-echo.hpp b/src/client/room/local-echo.hpp
--- a/src/client/room/local-echo.hpp
+++ b/src/client/room/local-echo.hpp
@@ -26,19 +26,9 @@
std::string txnId;
Event event;
Status status{Sending};
+ friend bool operator==(const LocalEchoDesc &a, const LocalEchoDesc &b) = default;
+ friend bool operator!=(const LocalEchoDesc &a, const LocalEchoDesc &b) = default;
};
-
- inline bool operator==(const LocalEchoDesc &a, const LocalEchoDesc &b)
- {
- return a.txnId == b.txnId
- && a.event == b.event
- && a.status == b.status;
- }
-
- inline bool operator!=(const LocalEchoDesc &a, const LocalEchoDesc &b)
- {
- return !(a == b);
- }
}
namespace boost::serialization
diff --git a/src/client/room/room-model.hpp b/src/client/room/room-model.hpp
--- a/src/client/room/room-model.hpp
+++ b/src/client/room/room-model.hpp
@@ -32,6 +32,9 @@
{
std::string txnId;
immer::map<std::string, immer::map<std::string, Event>> messages;
+
+ friend bool operator==(const PendingRoomKeyEvent &a, const PendingRoomKeyEvent &b) = default;
+ friend bool operator!=(const PendingRoomKeyEvent &a, const PendingRoomKeyEvent &b) = default;
};
PendingRoomKeyEvent makePendingRoomKeyEventV0(std::string txnId, Event event, immer::map<std::string, immer::flex_vector<std::string>> devices);
@@ -40,6 +43,8 @@
{
std::string eventId;
Timestamp timestamp;
+ friend bool operator==(const ReadReceipt &a, const ReadReceipt &b) = default;
+ friend bool operator!=(const ReadReceipt &a, const ReadReceipt &b) = default;
};
template<class Archive>
@@ -48,18 +53,15 @@
ar & r.eventId & r.timestamp;
}
- bool operator==(const ReadReceipt &a, const ReadReceipt &b);
- bool operator!=(const ReadReceipt &a, const ReadReceipt &b);
struct EventReader
{
std::string userId;
Timestamp timestamp;
+ friend bool operator==(const EventReader &a, const EventReader &b) = default;
+ friend bool operator!=(const EventReader &a, const EventReader &b) = default;
};
- bool operator==(const EventReader &a, const EventReader &b);
- bool operator!=(const EventReader &a, const EventReader &b);
-
struct AddStateEventsAction
{
immer::flex_vector<Event> stateEvents;
@@ -173,16 +175,6 @@
std::string myUserId;
};
- inline bool operator==(const PendingRoomKeyEvent &a, const PendingRoomKeyEvent &b)
- {
- return a.txnId == b.txnId && a.messages == b.messages;
- }
-
- inline bool operator!=(const PendingRoomKeyEvent &a, const PendingRoomKeyEvent &b)
- {
- return !(a == b);
- }
-
inline const double ROOM_TAG_DEFAULT_ORDER = 2;
template<class Archive>
@@ -352,42 +344,12 @@
>;
static RoomModel update(RoomModel r, Action a);
+
+ friend bool operator==(const RoomModel &a, const RoomModel &b) = default;
};
using RoomAction = RoomModel::Action;
- inline bool operator==(const RoomModel &a, const RoomModel &b)
- {
- return a.roomId == b.roomId
- && a.stateEvents == b.stateEvents
- && a.inviteState == b.inviteState
- && a.timeline == b.timeline
- && a.messages == b.messages
- && a.accountData == b.accountData
- && a.membership == b.membership
- && a.paginateBackToken == b.paginateBackToken
- && a.canPaginateBack == b.canPaginateBack
- && a.timelineGaps == b.timelineGaps
- && a.ephemeral == b.ephemeral
- && a.localDraft == b.localDraft
- && a.encrypted == b.encrypted
- && a.shouldRotateSessionKey == b.shouldRotateSessionKey
- && a.membersFullyLoaded == b.membersFullyLoaded
- && a.heroIds == b.heroIds
- && a.localEchoes == b.localEchoes
- && a.pendingRoomKeyEvents == b.pendingRoomKeyEvents
- && a.reverseEventRelationships == b.reverseEventRelationships
- && a.joinedMemberCount == b.joinedMemberCount
- && a.localReadMarker == b.localReadMarker
- && a.localUnreadCount == b.localUnreadCount
- && a.localNotificationCount == b.localNotificationCount
- && a.readReceipts == b.readReceipts
- && a.eventReadUsers == b.eventReadUsers
- && a.undecryptedEvents == b.undecryptedEvents
- && a.unreadNotificationEventIds == b.unreadNotificationEventIds
- ;
- }
-
struct UpdateRoomAction
{
std::string roomId;
@@ -406,15 +368,12 @@
UpdateRoomAction
>;
static RoomListModel update(RoomListModel l, Action a);
+
+ friend bool operator==(const RoomListModel &a, const RoomListModel &b) = default;
};
using RoomListAction = RoomListModel::Action;
- inline bool operator==(const RoomListModel &a, const RoomListModel &b)
- {
- return a.rooms == b.rooms;
- }
-
template<class Archive>
void serialize(Archive &ar, RoomModel &r, std::uint32_t const version)
{
diff --git a/src/client/room/room-model.cpp b/src/client/room/room-model.cpp
--- a/src/client/room/room-model.cpp
+++ b/src/client/room/room-model.cpp
@@ -53,26 +53,6 @@
return PendingRoomKeyEvent{txnId, messages};
}
- bool operator==(const ReadReceipt &a, const ReadReceipt &b)
- {
- return a.eventId == b.eventId && a.timestamp == b.timestamp;
- }
-
- bool operator!=(const ReadReceipt &a, const ReadReceipt &b)
- {
- return !(a == b);
- }
-
- bool operator==(const EventReader &a, const EventReader &b)
- {
- return a.userId == b.userId && a.timestamp == b.timestamp;
- }
-
- bool operator!=(const EventReader &a, const EventReader &b)
- {
- return !(a == b);
- }
-
auto sortKeyForTimelineEvent(Event e) -> std::tuple<Timestamp, std::string>
{
return std::make_tuple(e.originServerTs(), e.id());
diff --git a/src/crypto/crypto-util.hpp b/src/crypto/crypto-util.hpp
--- a/src/crypto/crypto-util.hpp
+++ b/src/crypto/crypto-util.hpp
@@ -24,6 +24,7 @@
{
std::string roomId;
std::string sessionId;
+ friend bool operator==(const KeyOfGroupSession &a, const KeyOfGroupSession &b) = default;
};
/**
@@ -47,22 +48,11 @@
});
}
- inline bool operator==(KeyOfGroupSession a, KeyOfGroupSession b)
- {
- return a.roomId == b.roomId
- && a.sessionId == b.sessionId;
- }
-
struct KeyOfOutboundSession
{
std::string userId;
std::string deviceId;
- };
-
- inline bool operator==(KeyOfOutboundSession a, KeyOfOutboundSession b)
- {
- return a.userId == b.userId
- && a.deviceId == b.deviceId;
+ friend bool operator==(const KeyOfOutboundSession &a, const KeyOfOutboundSession &b) = default;
};
[[nodiscard]] inline ByteArray genRandom(int len)
diff --git a/src/crypto/inbound-group-session-p.hpp b/src/crypto/inbound-group-session-p.hpp
--- a/src/crypto/inbound-group-session-p.hpp
+++ b/src/crypto/inbound-group-session-p.hpp
@@ -19,6 +19,8 @@
{
std::string eventId;
Timestamp originServerTs;
+ friend bool operator==(const KeyOfDecryptedEvent &a, const KeyOfDecryptedEvent &b) = default;
+ friend bool operator!=(const KeyOfDecryptedEvent &a, const KeyOfDecryptedEvent &b) = default;
};
inline void to_json(nlohmann::json &j, const KeyOfDecryptedEvent &k)
@@ -34,17 +36,6 @@
k.originServerTs = j.at("originServerTs");
}
- inline bool operator==(KeyOfDecryptedEvent a, KeyOfDecryptedEvent b)
- {
- return a.eventId == b.eventId
- && a.originServerTs == b.originServerTs;
- }
-
- inline bool operator!=(KeyOfDecryptedEvent a, KeyOfDecryptedEvent b)
- {
- return !(a == b);
- }
-
struct InboundGroupSessionPrivate
{
InboundGroupSessionPrivate();
diff --git a/src/tests/client/profile-test.cpp b/src/tests/client/profile-test.cpp
--- a/src/tests/client/profile-test.cpp
+++ b/src/tests/client/profile-test.cpp
@@ -62,8 +62,8 @@
store.dispatch(ProcessResponseAction{resp})
.then([](auto stat) {
REQUIRE(stat.success());
- REQUIRE(stat.dataStr("avatarUrl") == getUserProfileResponseJson["avatar_url"]);
- REQUIRE(stat.dataStr("displayName") == getUserProfileResponseJson["displayname"]);
+ REQUIRE(stat.dataStr("avatarUrl") == getUserProfileResponseJson["avatar_url"].template get<std::string>());
+ REQUIRE(stat.dataStr("displayName") == getUserProfileResponseJson["displayname"].template get<std::string>());
});
}
}
diff --git a/src/tests/crypto/inbound-group-session-test.cpp b/src/tests/crypto/inbound-group-session-test.cpp
--- a/src/tests/crypto/inbound-group-session-test.cpp
+++ b/src/tests/crypto/inbound-group-session-test.cpp
@@ -21,7 +21,7 @@
auto session = sessionJson.template get<InboundGroupSession>();
REQUIRE(session.valid());
REQUIRE(!session.isImported());
- REQUIRE(session.ed25519Key() == sessionJson["ed25519Key"]);
+ REQUIRE(session.ed25519Key() == sessionJson["ed25519Key"].template get<std::string>());
auto encrypted = resource["megolmEncrypted"];
auto plainText = resource["megolmPlainText"];
auto a = Crypto();
diff --git a/src/tests/crypto/outbound-group-session-test.cpp b/src/tests/crypto/outbound-group-session-test.cpp
--- a/src/tests/crypto/outbound-group-session-test.cpp
+++ b/src/tests/crypto/outbound-group-session-test.cpp
@@ -19,7 +19,7 @@
auto sessionJson = resource["a"]["outboundGroupSessions"]["!foo:example.com"];
auto session = sessionJson.template get<OutboundGroupSession>();
REQUIRE(session.valid());
- REQUIRE(session.initialSessionKey() == sessionJson["initialSessionKey"]);
+ REQUIRE(session.initialSessionKey() == sessionJson["initialSessionKey"].template get<std::string>());
}
TEST_CASE("OutboundGroupSession serialization roundtrip")
diff --git a/src/tests/store-test.cpp b/src/tests/store-test.cpp
--- a/src/tests/store-test.cpp
+++ b/src/tests/store-test.cpp
@@ -14,6 +14,9 @@
struct BackInserter
{
+ BackInserter(std::function<void(int)> f)
+ : insertFunc(f)
+ {}
BackInserter(const BackInserter &) = delete;
BackInserter(BackInserter &&) = default;
@@ -28,7 +31,7 @@
std::vector<int> results;
- BackInserter bi = { [&results](int a) { results.push_back(a); } };
+ BackInserter bi([&results](int a) { results.push_back(a); });
using Model = int;
using Action = int;

File Metadata

Mime Type
text/plain
Expires
Fri, Oct 3, 9:08 PM (21 h, 36 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
494114
Default Alt Text
D238.1759550939.diff (20 KB)

Event Timeline