Skip to content
This repository was archived by the owner on Mar 26, 2024. It is now read-only.

Commit e4913c9

Browse files
committed
Make sure we can clear marked_unread with the beeper_inbox_state endpoint
1 parent 61528d0 commit e4913c9

File tree

2 files changed

+39
-2
lines changed

2 files changed

+39
-2
lines changed

synapse/rest/client/account_data.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -189,13 +189,13 @@ async def on_PUT(
189189

190190
body = parse_json_object_from_request(request)
191191

192-
if body.get("marked_unread"):
192+
if "marked_unread" in body:
193193
marked_unread = {"unread": body["marked_unread"], "ts": ts}
194194
await self.handler.add_account_data_to_room(
195195
user_id, room_id, "m.marked_unread", marked_unread
196196
)
197197

198-
if body.get("done"):
198+
if "done" in body:
199199
done = {"updated_ts": ts, "at_ts": ts + body["done"].get("at_delta", 0)}
200200
await self.handler.add_account_data_to_room(
201201
user_id, room_id, "com.beeper.inbox.done", done

tests/rest/client/test_account_data.py

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,3 +132,40 @@ def test_beeper_inbox_state_endpoint(self) -> None:
132132
)
133133
self.assertEqual(marked_unread["unread"], True)
134134
self.assertEqual(marked_unread["ts"], ts)
135+
136+
def test_beeper_inbox_state_endpoint_can_clear_unread(self) -> None:
137+
store = self.hs.get_datastores().main
138+
139+
user_id = self.register_user("user", "password")
140+
tok = self.login("user", "password")
141+
142+
room_id = self.helper.create_room_as(user_id, tok=tok)
143+
channel = self.make_request(
144+
"PUT",
145+
f"/user/{user_id}/rooms/{room_id}/beeper_inbox_state",
146+
{"marked_unread": False},
147+
access_token=tok,
148+
)
149+
150+
self.assertEqual(channel.code, 200, channel.result)
151+
152+
# FIXME: I give up, I don't know how to mock time in tests
153+
# ts = self.clock.time_msec()
154+
ts = 400
155+
156+
self.assertEqual(channel.code, 200, channel.result)
157+
self.assertIsNone(
158+
self.get_success(
159+
store.get_account_data_for_room_and_type(
160+
user_id, room_id, "com.beeper.inbox.done"
161+
)
162+
)
163+
)
164+
165+
marked_unread = self.get_success(
166+
store.get_account_data_for_room_and_type(
167+
user_id, room_id, "m.marked_unread"
168+
)
169+
)
170+
self.assertEqual(marked_unread["unread"], False)
171+
self.assertEqual(marked_unread["ts"], ts)

0 commit comments

Comments
 (0)