-
Notifications
You must be signed in to change notification settings - Fork 261
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(base): New RoomInfoNotableUpdateReasons::READ_RECEIPT
#3680
Changes from all commits
657b046
efd9a75
168f285
b046794
a4e47fd
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -275,6 +275,11 @@ impl BaseClient { | |
); | ||
|
||
if prev_read_receipts != room_info.read_receipts { | ||
room_info_notable_updates | ||
.entry(room_id.clone()) | ||
.or_default() | ||
.insert(RoomInfoNotableUpdateReasons::READ_RECEIPT); | ||
|
||
changes.add_room(room_info); | ||
} | ||
} | ||
|
@@ -806,7 +811,7 @@ mod tests { | |
rooms::normal::{RoomHero, RoomInfoNotableUpdateReasons}, | ||
store::MemoryStore, | ||
test_utils::logged_in_base_client, | ||
BaseClient, Room, RoomState, | ||
BaseClient, Room, RoomInfoNotableUpdate, RoomState, | ||
}; | ||
|
||
#[async_test] | ||
|
@@ -1847,6 +1852,92 @@ mod tests { | |
} | ||
} | ||
|
||
#[async_test] | ||
async fn test_recency_timestamp_can_trigger_a_notable_update_reason() { | ||
// Given a logged-in client | ||
let client = logged_in_base_client(None).await; | ||
let mut room_info_notable_update_stream = client.room_info_notable_update_receiver(); | ||
let room_id = room_id!("!r:e.uk"); | ||
|
||
// When I send sliding sync response containing a room with a recency timestamp. | ||
let room = assign!(v4::SlidingSyncRoom::new(), { | ||
timestamp: Some(MilliSecondsSinceUnixEpoch(42u32.into())), | ||
}); | ||
let response = response_with_room(room_id, room); | ||
client.process_sliding_sync(&response, &()).await.expect("Failed to process sync"); | ||
|
||
// Then a room info notable update is NOT received, because it's the first time | ||
// the room is seen. | ||
assert_matches!( | ||
room_info_notable_update_stream.recv().await, | ||
Ok(RoomInfoNotableUpdate { room_id: received_room_id, reasons: received_reasons }) => { | ||
assert_eq!(received_room_id, room_id); | ||
assert!(!received_reasons.contains(RoomInfoNotableUpdateReasons::RECENCY_TIMESTAMP)); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Does this pass?
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I prefer to test the reason is not present, in case other reasons may exist. We don't care about the other reasons at this step. Tests are less likely to break in the future if these kind of assertions. |
||
} | ||
); | ||
|
||
// When I send sliding sync response containing a room with a recency timestamp. | ||
let room = assign!(v4::SlidingSyncRoom::new(), { | ||
timestamp: Some(MilliSecondsSinceUnixEpoch(43u32.into())), | ||
}); | ||
let response = response_with_room(room_id, room); | ||
client.process_sliding_sync(&response, &()).await.expect("Failed to process sync"); | ||
|
||
// Then a room info notable update is received. | ||
assert_matches!( | ||
room_info_notable_update_stream.recv().await, | ||
Ok(RoomInfoNotableUpdate { room_id: received_room_id, reasons: received_reasons }) => { | ||
assert_eq!(received_room_id, room_id); | ||
assert!(received_reasons.contains(RoomInfoNotableUpdateReasons::RECENCY_TIMESTAMP)); | ||
} | ||
); | ||
} | ||
|
||
#[async_test] | ||
async fn test_read_receipt_can_trigger_a_notable_update_reason() { | ||
// Given a logged-in client | ||
let client = logged_in_base_client(None).await; | ||
let mut room_info_notable_update_stream = client.room_info_notable_update_receiver(); | ||
|
||
// When I send sliding sync response containing a new room. | ||
let room_id = room_id!("!r:e.uk"); | ||
let room = v4::SlidingSyncRoom::new(); | ||
let response = response_with_room(room_id, room); | ||
client.process_sliding_sync(&response, &()).await.expect("Failed to process sync"); | ||
|
||
// Then a room info notable update is NOT received. | ||
assert_matches!( | ||
room_info_notable_update_stream.recv().await, | ||
Ok(RoomInfoNotableUpdate { room_id: received_room_id, reasons: received_reasons }) => { | ||
assert_eq!(received_room_id, room_id); | ||
assert!(!received_reasons.contains(RoomInfoNotableUpdateReasons::READ_RECEIPT)); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same as before, can this be a check that reasons is empty? |
||
} | ||
); | ||
|
||
// When I send sliding sync response containing a couple of events with no read | ||
// receipt. | ||
let room_id = room_id!("!r:e.uk"); | ||
let events = vec![ | ||
make_raw_event("m.room.message", "$3"), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This entire test suite should be revisited. Later. For another time. But I agree! |
||
make_raw_event("m.room.message", "$4"), | ||
make_raw_event("m.read", "$5"), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Technically this is wrong, as this will create a There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There is no There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. All I'm saying is that the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since you've approved the PR, I understand it's fine for this particular test. The read receipt mechanism is already pretty well test. Here we only want to test the notable update reason is triggered, which is fine for the moment. |
||
]; | ||
let room = assign!(v4::SlidingSyncRoom::new(), { | ||
timeline: events, | ||
}); | ||
let response = response_with_room(room_id, room); | ||
client.process_sliding_sync(&response, &()).await.expect("Failed to process sync"); | ||
|
||
// Then a room info notable update is received. | ||
assert_matches!( | ||
room_info_notable_update_stream.recv().await, | ||
Ok(RoomInfoNotableUpdate { room_id: received_room_id, reasons: received_reasons }) => { | ||
assert_eq!(received_room_id, room_id); | ||
assert!(received_reasons.contains(RoomInfoNotableUpdateReasons::READ_RECEIPT)); | ||
} | ||
); | ||
} | ||
|
||
async fn choose_event_to_cache(events: &[SyncTimelineEvent]) -> Option<SyncTimelineEvent> { | ||
let room = make_room(); | ||
let mut room_info = room.clone_info(); | ||
|
@@ -1883,20 +1974,22 @@ mod tests { | |
) | ||
} | ||
|
||
fn make_event(typ: &str, id: &str) -> SyncTimelineEvent { | ||
SyncTimelineEvent::new( | ||
Raw::from_json_string( | ||
json!({ | ||
"type": typ, | ||
"event_id": id, | ||
"content": { "msgtype": "m.text", "body": "my msg" }, | ||
"sender": "@u:h.uk", | ||
"origin_server_ts": 12344445, | ||
}) | ||
.to_string(), | ||
) | ||
.unwrap(), | ||
fn make_raw_event(typ: &str, id: &str) -> Raw<AnySyncTimelineEvent> { | ||
Raw::from_json_string( | ||
json!({ | ||
"type": typ, | ||
"event_id": id, | ||
"content": { "msgtype": "m.text", "body": "my msg" }, | ||
"sender": "@u:h.uk", | ||
"origin_server_ts": 12344445, | ||
}) | ||
.to_string(), | ||
) | ||
.unwrap() | ||
} | ||
|
||
fn make_event(typ: &str, id: &str) -> SyncTimelineEvent { | ||
SyncTimelineEvent::new(make_raw_event(typ, id)) | ||
} | ||
|
||
fn make_encrypted_event(id: &str) -> SyncTimelineEvent { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please fold 0e73620 into the commits it belongs to (consider git-absorb next time!)