Page MenuHomePhorge

D107.1732287531.diff
No OneTemporary

Size
5 KB
Referenced Files
None
Subscribers
None

D107.1732287531.diff

diff --git a/src/client/actions/sync.cpp b/src/client/actions/sync.cpp
--- a/src/client/actions/sync.cpp
+++ b/src/client/actions/sync.cpp
@@ -60,6 +60,8 @@
auto l = std::move(m.roomList);
auto eventsToEmit = KazvEventList{}.transient();
+ auto pushRules = PushRulesDesc(m.accountData["m.push_rules"]);
+
auto updateRoomImpl =
[&l](auto id, auto a) {
l = RoomListModel::update(
@@ -141,15 +143,28 @@
}
};
+ auto updateRoomNotifications = [=, &client=m](const auto &id, const auto &room) {
+ auto oldRoom = m.roomList.rooms[id];
+ const auto &newRoom = client.roomList.rooms[id];
+ updateRoomImpl(id, AddLocalNotificationsAction{
+ room.timeline.events,
+ pushRules,
+ m.userId,
+ });
+
+ if (oldRoom.readReceipts[m.userId].eventId
+ != newRoom.readReceipts[m.userId].eventId) {
+ updateRoomImpl(id, RemoveReadLocalNotificationsAction{m.userId});
+ }
+ };
+
auto updateJoinedRoom =
[=](const auto &id, const auto &room) {
updateSingleRoom(id, room, RoomMembership::Join);
if (room.ephemeral) {
updateRoomImpl(id, AddEphemeralAction{room.ephemeral.value().events});
}
- // TODO update other info such as
- // notification and summary
-
+ updateRoomNotifications(id, room);
updateRoomSummary(id, room);
};
@@ -247,6 +262,12 @@
m.syncToken = r.nextBatch();
+ // Load account data first because it contains push rules
+ // which can affect the processing of rooms
+ if (accountData) {
+ m.addTriggers(loadAccountDataFromSyncInPlace(m, std::move(accountData.value().events)));
+ }
+
if (rooms) {
m.addTriggers(loadRoomsFromSyncInPlace(m, std::move(rooms.value())));
}
@@ -255,10 +276,6 @@
m.addTriggers(loadPresenceFromSyncInPlace(m, std::move(presence.value().events)));
}
- if (accountData) {
- m.addTriggers(loadAccountDataFromSyncInPlace(m, std::move(accountData.value().events)));
- }
-
m.addTriggers(loadToDeviceFromSyncInPlace(m, r.toDevice()));
auto is = r.dataStr("is");
diff --git a/src/tests/client/sync-test.cpp b/src/tests/client/sync-test.cpp
--- a/src/tests/client/sync-test.cpp
+++ b/src/tests/client/sync-test.cpp
@@ -17,7 +17,7 @@
#include <cursorutil.hpp>
#include <sdk-model.hpp>
#include <client/client.hpp>
-
+#include <client/actions/sync.hpp>
#include "client-test-util.hpp"
#include "factory.hpp"
@@ -249,6 +249,75 @@
}
})"_json;
+static auto addNotificationsJson = R"({
+ "next_batch": "some-example-value",
+ "account_data": {
+ "events": [
+ {
+ "type": "m.push_rules",
+ "content": {
+ "global": {
+ "override": [{
+ "rule_id": "moe.kazv.mxc.catch_all",
+ "default": true,
+ "enabled": true,
+ "conditions": [],
+ "actions": ["notify"]
+ }]
+ }
+ }
+ }
+ ]
+ },
+ "rooms": {
+ "join": {
+ "!exampleroomid:example.com": {
+ "timeline": {
+ "events": [
+ {
+ "content": { "example": "foo" },
+ "event_id": "$example:example.com",
+ "sender": "@example:example.org",
+ "origin_server_ts": 1432735824653,
+ "type": "m.room.message"
+ },
+ {
+ "content": { "example": "foo2" },
+ "event_id": "$example2:example.com",
+ "sender": "@example:example.org",
+ "origin_server_ts": 1432735824953,
+ "type": "m.room.message"
+ }
+ ],
+ "limited": false
+ }
+ }
+ }
+ }
+})"_json;
+
+static auto receiptJson = R"({
+ "type": "m.receipt",
+ "content": {
+ "$example:example.com": {
+ "m.read": {
+ "@bob:example.com": {
+ "ts": 1432735824653
+ }
+ }
+ }
+ }
+})"_json;
+
+static auto addAndRemoveNotificationsJson = [](auto a, auto r) {
+ a["rooms"]["join"]["!exampleroomid:example.com"]["ephemeral"] = {
+ {"events", {
+ r,
+ }}
+ };
+ return a;
+}(addNotificationsJson, receiptJson);
+
TEST_CASE("use sync response to update client model", "[client][sync]")
{
using namespace Kazv::CursorOp;
@@ -425,3 +494,41 @@
REQUIRE(localEchoes.size() == 1);
REQUIRE(localEchoes[0].txnId == "some-other-txnid");
}
+
+TEST_CASE("updating local notifications", "[client][sync]")
+{
+ ClientModel m = makeClient(
+ withRoom(makeRoom(
+ withRoomId("!exampleroomid:example.com"))));
+
+ WHEN("the receipt for the current user did not change") {
+ auto resp = makeResponse(
+ "Sync",
+ withResponseJsonBody(addNotificationsJson)
+ | withResponseDataKV("is", "incremental")
+ );
+ auto [next, _] = processResponse(m, SyncResponse{resp});
+
+ auto room = next.roomList.rooms.at("!exampleroomid:example.com");
+ REQUIRE(room.unreadNotificationEventIds
+ == immer::flex_vector<std::string>{
+ "$example:example.com",
+ "$example2:example.com"
+ });
+ }
+
+ WHEN("the receipt for the current user changed") {
+ auto resp = makeResponse(
+ "Sync",
+ withResponseJsonBody(addAndRemoveNotificationsJson)
+ | withResponseDataKV("is", "incremental")
+ );
+ auto [next, _] = processResponse(m, SyncResponse{resp});
+
+ auto room = next.roomList.rooms.at("!exampleroomid:example.com");
+ REQUIRE(room.unreadNotificationEventIds
+ == immer::flex_vector<std::string>{
+ "$example2:example.com"
+ });
+ }
+}

File Metadata

Mime Type
text/plain
Expires
Fri, Nov 22, 6:58 AM (4 h, 27 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
38887
Default Alt Text
D107.1732287531.diff (5 KB)

Event Timeline