Page MenuHomePhorge

D27.1733020649.diff
No OneTemporary

Size
7 KB
Referenced Files
None
Subscribers
None

D27.1733020649.diff

diff --git a/src/client/actions/encryption.cpp b/src/client/actions/encryption.cpp
--- a/src/client/actions/encryption.cpp
+++ b/src/client/actions/encryption.cpp
@@ -613,16 +613,16 @@
ClientResult updateClient(ClientModel m, PrepareForSharingRoomKeyAction a)
{
- auto encryptedEvent = m.olmEncrypt(a.e, a.devices, a.random);
+ auto messages = m.olmEncryptSplit(a.e, a.devices, a.random);
- auto txnId = getTxnId(a.e, m);
+ auto txnId = getTxnId(Event(), m);
m.roomList = RoomListModel::update(
std::move(m.roomList),
UpdateRoomAction{
a.roomId,
AddPendingRoomKeyAction{
- PendingRoomKeyEvent{txnId, encryptedEvent, a.devices}
+ PendingRoomKeyEvent{txnId, messages}
}
}
);
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
@@ -31,10 +31,11 @@
struct PendingRoomKeyEvent
{
std::string txnId;
- Event event;
- immer::map<std::string, immer::flex_vector<std::string>> devices;
+ immer::map<std::string, immer::map<std::string, Event>> messages;
};
+ PendingRoomKeyEvent makePendingRoomKeyEventV0(std::string txnId, Event event, immer::map<std::string, immer::flex_vector<std::string>> devices);
+
struct ReadReceipt
{
std::string eventId;
@@ -154,7 +155,7 @@
inline bool operator==(const PendingRoomKeyEvent &a, const PendingRoomKeyEvent &b)
{
- return a.txnId == b.txnId && a.event == b.event && a.devices == b.devices;
+ return a.txnId == b.txnId && a.messages == b.messages;
}
inline bool operator!=(const PendingRoomKeyEvent &a, const PendingRoomKeyEvent &b)
@@ -167,7 +168,17 @@
template<class Archive>
void serialize(Archive &ar, PendingRoomKeyEvent &e, std::uint32_t const version)
{
- ar & e.txnId & e.event & e.devices;
+ if (version < 1) {
+ // loading an older version where there is only one event
+ std::string txnId;
+ Event event;
+ immer::map<std::string, immer::flex_vector<std::string>> devices;
+ ar & txnId & event & devices;
+ e = makePendingRoomKeyEventV0(
+ std::move(txnId), std::move(event), std::move(devices));
+ } else {
+ ar & e.txnId & e.messages;
+ }
}
struct RoomModel
@@ -413,7 +424,7 @@
}
}
-BOOST_CLASS_VERSION(Kazv::PendingRoomKeyEvent, 0)
+BOOST_CLASS_VERSION(Kazv::PendingRoomKeyEvent, 1)
BOOST_CLASS_VERSION(Kazv::ReadReceipt, 0)
BOOST_CLASS_VERSION(Kazv::RoomModel, 6)
BOOST_CLASS_VERSION(Kazv::RoomListModel, 0)
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
@@ -22,6 +22,22 @@
namespace Kazv
{
+ PendingRoomKeyEvent makePendingRoomKeyEventV0(std::string txnId, Event event, immer::map<std::string, immer::flex_vector<std::string>> devices)
+ {
+ immer::map<std::string, immer::map<std::string, Event>> messages;
+ for (auto [userId, deviceIds] : devices) {
+ messages = setIn(std::move(messages), immer::map<std::string, Event>(), userId);
+ for (auto deviceId : deviceIds) {
+ messages = setIn(
+ std::move(messages),
+ event,
+ userId, deviceId
+ );
+ }
+ }
+ return PendingRoomKeyEvent{txnId, messages};
+ }
+
bool operator==(const ReadReceipt &a, const ReadReceipt &b)
{
return a.eventId == b.eventId && a.timestamp == b.timestamp;
diff --git a/src/client/room/room.cpp b/src/client/room/room.cpp
--- a/src/client/room/room.cpp
+++ b/src/client/room/room.cpp
@@ -579,8 +579,7 @@
)));
}
auto pending = maybePending.value();
- auto event = pending.event;
- return ctx.dispatch(SendToDeviceMessageAction{event, pending.devices})
+ return ctx.dispatch(SendMultipleToDeviceMessagesAction{pending.messages})
.then([ctx, rid, txnId](const auto &sendToDeviceStatus) {
if (!sendToDeviceStatus.success()) {
return ctx.createResolvedPromise(sendToDeviceStatus);
diff --git a/src/tests/client/encryption-test.cpp b/src/tests/client/encryption-test.cpp
--- a/src/tests/client/encryption-test.cpp
+++ b/src/tests/client/encryption-test.cpp
@@ -33,7 +33,6 @@
auto nextRoom = next.roomList.rooms.at("!exampleroomid:example.com");
REQUIRE(nextRoom.pendingRoomKeyEvents.size() == 1);
- REQUIRE(nextRoom.pendingRoomKeyEvents[0].event.encrypted());
}
TEST_CASE("encrypted event will keep a copy of m.relates_to in plaintext", "[client][encryption]")
diff --git a/src/tests/client/room/local-echo-test.cpp b/src/tests/client/room/local-echo-test.cpp
--- a/src/tests/client/room/local-echo-test.cpp
+++ b/src/tests/client/room/local-echo-test.cpp
@@ -51,9 +51,8 @@
|| std::holds_alternative<QueryKeysAction>(action)
|| std::holds_alternative<SendMessageAction>(action)) {
return ph.createResolved(EffectStatus(true, json::object()));
- } else if (std::holds_alternative<SendToDeviceMessageAction>(action)) {
- auto a = std::get<SendToDeviceMessageAction>(action);
- kzo.client.dbg() << "to device encrypted? " << a.event.encrypted() << std::endl;
+ } else if (std::holds_alternative<SendMultipleToDeviceMessagesAction>(action)) {
+ auto a = std::get<SendMultipleToDeviceMessagesAction>(action);
return ph.createResolved(EffectStatus(true, json::object()));
} else if (std::holds_alternative<ClaimKeysAction>(action)) {
return ph.createResolved(EffectStatus(true, json::object({{"keyEvent", json::object({})}})));
@@ -63,7 +62,12 @@
return store.dispatch(UpdateRoomAction{
a.roomId,
AddPendingRoomKeyAction{
- PendingRoomKeyEvent{txnId, Event(json{{"type", "m.room.encrypted"}, {"content", {{"whatever", "ok"}}}}), a.devices}
+ makePendingRoomKeyEventV0(
+ txnId,
+ Event(json{{"type", "m.room.encrypted"}, {"content", {{"whatever", "ok"}}}}),
+ // Mocking the device list
+ {{"@foo:example.com", {"device1", "device2"}}}
+ )
}
}).then([txnId](auto &&) {
return EffectStatus{true, json::object({{"txnId", txnId}})};
@@ -450,7 +454,7 @@
auto mockContext = getMockContext(sgph, ctx, [&saveLocalEchoCalled,
&sendMessageCalled, &megOlmEncryptCalled, &sendToDeviceCalled, &olmEncryptCalled, &resending](const auto &a) {
- if (std::holds_alternative<SendToDeviceMessageAction>(a)) {
+ if (std::holds_alternative<SendMultipleToDeviceMessagesAction>(a)) {
auto sendKeyData = json{
{"error", "Bad request"},
{"errorCode", "400"},
@@ -660,3 +664,19 @@
REQUIRE(r.localEchoes().make().get().size() == 1);
REQUIRE(r.localEchoes().make().get()[0].txnId == "some-txn-id");
}
+
+TEST_CASE("makePendingRoomKeyEventV0()", "[client][room][local-echo]")
+{
+ auto devices = immer::map<std::string, immer::flex_vector<std::string>>{
+ {"@foo:example.com", {"device1"}},
+ {"@bar:example.com", {"device2", "device3"}},
+ };
+ std::string txnId = "xxx";
+ Event event = json{{"type", "m.room.encrypted"}, {"content", {{"whatever", "ok"}}}};
+ auto e = makePendingRoomKeyEventV0(txnId, event, devices);
+ auto expected = immer::map<std::string, immer::map<std::string, Event>>{
+ {"@foo:example.com", {{"device1", event}}},
+ {"@bar:example.com", {{"device2", event}, {"device3", event}}},
+ };
+ REQUIRE(e.messages == expected);
+}

File Metadata

Mime Type
text/plain
Expires
Sat, Nov 30, 6:37 PM (16 h, 12 s)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
41418
Default Alt Text
D27.1733020649.diff (7 KB)

Event Timeline