Skip to content
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

fix(base): Rewrite RoomNotableTags #3111

Merged
merged 14 commits into from
Feb 9, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 10 additions & 10 deletions crates/matrix-sdk-base/src/rooms/normal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1277,7 +1277,7 @@ mod tests {
use assign::assign;
#[cfg(feature = "experimental-sliding-sync")]
use matrix_sdk_common::deserialized_responses::SyncTimelineEvent;
use matrix_sdk_test::{async_test, test_json, ALICE, BOB, CAROL};
use matrix_sdk_test::{async_test, ALICE, BOB, CAROL};
use ruma::{
api::client::sync::sync_events::v3::RoomSummary as RumaSummary,
events::{
Expand All @@ -1293,14 +1293,14 @@ mod tests {
},
name::RoomNameEventContent,
},
tag::{TagInfo, TagName},
AnySyncStateEvent, StateEventType, StateUnsigned, SyncStateEvent,
},
room_alias_id, room_id,
serde::Raw,
user_id, MilliSecondsSinceUnixEpoch, OwnedEventId, OwnedUserId, UserId,
};
use serde_json::{json, Value};
use serde_json::json;
use stream_assert::{assert_pending, assert_ready};

#[cfg(feature = "experimental-sliding-sync")]
use super::SyncInfo;
Expand All @@ -1309,7 +1309,7 @@ mod tests {
use crate::latest_event::LatestEvent;
use crate::{
store::{MemoryStore, StateChanges, StateStore},
DisplayName, MinimalStateEvent, OriginalMinimalStateEvent,
BaseClient, DisplayName, MinimalStateEvent, OriginalMinimalStateEvent, SessionMeta,
};

#[test]
Expand Down Expand Up @@ -1870,10 +1870,11 @@ mod tests {
#[cfg(feature = "experimental-sliding-sync")]
async fn test_setting_the_latest_event_doesnt_cause_a_room_info_update() {
// Given a room,
let client = crate::BaseClient::new();

let client = BaseClient::new();

client
.set_session_meta(crate::SessionMeta {
.set_session_meta(SessionMeta {
user_id: user_id!("@alice:example.org").into(),
device_id: ruma::device_id!("AYEAYEAYE").into(),
})
Expand All @@ -1898,16 +1899,15 @@ mod tests {
room.on_latest_event_decrypted(event.clone(), 0, &mut changes);

// The subscriber isn't notified at this point.
stream_assert::assert_pending!(room_info_subscriber);
assert_pending!(room_info_subscriber);

// Then updating the room info will store the event,
client.apply_changes(&changes);
assert_eq!(room.latest_event().unwrap().event_id(), event.event_id());

// And wake up the subscriber.
use futures_util::FutureExt as _;
assert!(room_info_subscriber.next().now_or_never().is_some());
stream_assert::assert_pending!(room_info_subscriber);
assert_ready!(room_info_subscriber);
assert_pending!(room_info_subscriber);
}

#[test]
Expand Down
26 changes: 11 additions & 15 deletions crates/matrix-sdk/tests/integration/room/tags.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,20 +81,20 @@ async fn synced_client_with_room(
}

#[async_test]
async fn when_set_is_favorite_is_run_with_true_then_set_tag_api_is_called() {
async fn when_set_is_favourite_is_run_with_true_then_set_tag_api_is_called() {
let room_id = room_id!("!test:example.org");
let mut ev_builder = SyncResponseBuilder::new();
let (_client, room, server) = synced_client_with_room(&mut ev_builder, room_id).await;

mock_tag_api(&server, TagName::Favorite, TagOperation::Set, 1).await;

room.set_is_favorite(true, Option::default()).await.unwrap();
room.set_is_favourite(true, Option::default()).await.unwrap();

server.verify().await;
}

#[async_test]
async fn when_set_is_favorite_is_run_with_true_and_low_priority_tag_was_set_then_set_tag_and_remove_tag_apis_are_called(
async fn when_set_is_favourite_is_run_with_true_and_low_priority_tag_was_set_then_set_tag_and_remove_tag_apis_are_called(
) {
let room_id = room_id!("!test:example.org");
let mut ev_builder = SyncResponseBuilder::new();
Expand All @@ -106,20 +106,20 @@ async fn when_set_is_favorite_is_run_with_true_and_low_priority_tag_was_set_then
mock_tag_api(&server, TagName::Favorite, TagOperation::Set, 1).await;
mock_tag_api(&server, TagName::LowPriority, TagOperation::Remove, 1).await;

room.set_is_favorite(true, Option::default()).await.unwrap();
room.set_is_favourite(true, Option::default()).await.unwrap();

server.verify().await;
}

#[async_test]
async fn when_set_is_favorite_is_run_with_false_then_delete_tag_api_is_called() {
async fn when_set_is_favourite_is_run_with_false_then_delete_tag_api_is_called() {
let room_id = room_id!("!test:example.org");
let mut ev_builder = SyncResponseBuilder::new();
let (_client, room, server) = synced_client_with_room(&mut ev_builder, room_id).await;

mock_tag_api(&server, TagName::Favorite, TagOperation::Remove, 1).await;

room.set_is_favorite(false, Option::default()).await.unwrap();
room.set_is_favourite(false, Option::default()).await.unwrap();

server.verify().await;
}
Expand Down Expand Up @@ -169,22 +169,20 @@ async fn when_set_is_low_priority_is_run_with_false_then_delete_tag_api_is_calle
}

#[async_test]
async fn when_favorite_tag_is_set_in_sync_response_then_notable_tags_is_favorite_is_true() {
async fn when_favorite_tag_is_set_in_sync_response_then_notable_tags_is_favourite_is_true() {
Hywan marked this conversation as resolved.
Show resolved Hide resolved
bnjbvr marked this conversation as resolved.
Show resolved Hide resolved
let room_id = room_id!("!test:example.org");
let mut ev_builder = SyncResponseBuilder::new();
let (client, room, server) = synced_client_with_room(&mut ev_builder, room_id).await;

let (initial_notable_tags, mut notable_tags_stream) = room.notable_tags_stream().await;

assert!(!initial_notable_tags.is_favorite);
assert!(!room.is_favourite());

// Ensure the notable tags stream is updated when the favorite tag is set on
// sync
let tags = BTreeMap::from([(TagName::Favorite, TagInfo::default())]);
mock_sync_with_tags(&server, &mut ev_builder, room_id, tags).await;
sync_once(&client, &server).await;

assert!(notable_tags_stream.next().await.unwrap().is_favorite);
assert!(room.is_favourite());
}

#[async_test]
Expand All @@ -193,15 +191,13 @@ async fn when_low_priority_tag_is_set_in_sync_response_then_notable_tags_is_low_
let mut ev_builder = SyncResponseBuilder::new();
let (client, room, server) = synced_client_with_room(&mut ev_builder, room_id).await;

let (initial_notable_tags, mut notable_tags_stream) = room.notable_tags_stream().await;

assert!(!initial_notable_tags.is_low_priority);
assert!(!room.is_low_priority());

// Ensure the notable tags stream is updated when the low_priority tag is set on
// sync
let tags = BTreeMap::from([(TagName::LowPriority, TagInfo::default())]);
mock_sync_with_tags(&server, &mut ev_builder, room_id, tags).await;
sync_once(&client, &server).await;

assert!(notable_tags_stream.next().await.unwrap().is_low_priority);
assert!(room.is_low_priority());
}