Page Menu
Home
Phorge
Search
Configure Global Search
Log In
Files
F114425
D107.1732548076.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Award Token
Flag For Later
Size
6 KB
Referenced Files
None
Subscribers
None
D107.1732548076.diff
View Options
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 = [=, &l](const auto &id, const auto &room) {
+ auto oldRoom = m.roomList.rooms[id];
+ const auto &newRoom = l.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,97 @@
}
})"_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);
+
+static auto removeNotificationsJson = [](auto r) {
+ auto j = R"({
+ "next_batch": "some-example-value",
+ "rooms": {
+ "join": {
+ "!exampleroomid:example.com": {
+ "timeline": {
+ "events": [],
+ "limited": false
+ }
+ }
+ }
+ }
+})"_json;
+ j["rooms"]["join"]["!exampleroomid:example.com"]["ephemeral"] = {
+ {"events", {
+ r,
+ }}
+ };
+ return j;
+}(receiptJson);
+
TEST_CASE("use sync response to update client model", "[client][sync]")
{
using namespace Kazv::CursorOp;
@@ -425,3 +516,56 @@
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"
+ });
+
+ THEN("it changed later") {
+ auto resp = makeResponse(
+ "Sync",
+ withResponseJsonBody(removeNotificationsJson)
+ | withResponseDataKV("is", "incremental")
+ );
+ auto [nextNext, _] = processResponse(next, SyncResponse{resp});
+
+ auto room = nextNext.roomList.rooms.at("!exampleroomid:example.com");
+ REQUIRE(room.unreadNotificationEventIds
+ == immer::flex_vector<std::string>{
+ "$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
Details
Attached
Mime Type
text/plain
Expires
Mon, Nov 25, 7:21 AM (12 h, 17 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
39917
Default Alt Text
D107.1732548076.diff (6 KB)
Attached To
Mode
D107: Update local notifications when syncing
Attached
Detach File
Event Timeline
Log In to Comment