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

Tags: introduce RoomNotableTags #3071

Merged
merged 3 commits into from
Jan 30, 2024
Merged

Tags: introduce RoomNotableTags #3071

merged 3 commits into from
Jan 30, 2024

Conversation

ganfra
Copy link
Contributor

@ganfra ganfra commented Jan 29, 2024

Handles "Expose a way to have is_favorite: bool live in the bindings" from #3005

@ganfra ganfra requested a review from a team as a code owner January 29, 2024 20:14
@ganfra ganfra requested review from bnjbvr and removed request for a team January 29, 2024 20:14
Copy link

codecov bot commented Jan 29, 2024

Codecov Report

Attention: 7 lines in your changes are missing coverage. Please review.

Comparison is base (6e38925) 83.70% compared to head (6669dab) 83.69%.
Report is 3 commits behind head on main.

Files Patch % Lines
crates/matrix-sdk-base/src/client.rs 63.63% 4 Missing ⚠️
crates/matrix-sdk-base/src/rooms/normal.rs 80.00% 2 Missing ⚠️
crates/matrix-sdk-base/src/lib.rs 0.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #3071      +/-   ##
==========================================
- Coverage   83.70%   83.69%   -0.01%     
==========================================
  Files         222      222              
  Lines       23357    23385      +28     
==========================================
+ Hits        19550    19573      +23     
- Misses       3807     3812       +5     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Comment on lines 532 to 540
#[derive(uniffi::Record)]
pub struct RoomNotableTags {
is_favorite: bool,
}
impl From<SdkNotableTags> for RoomNotableTags {
fn from(value: SdkNotableTags) -> Self {
RoomNotableTags { is_favorite: value.is_favorite }
}
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems like it could be replaced by a #[cfg_attr(feature = "uniffi", derive(uniffi::Record)] on the SDK type.

Copy link
Contributor Author

@ganfra ganfra Jan 30, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, I didn't know we're able to expose directly sdk type! It's not done anywhere else, so not sure we want that? @bnjbvr what do you think?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah it's only since recently that this is possible. We do it for two or three enum types, one here.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ganfra looks fine to me. (This is the reason why the namespacing on the Kotlin-side is different for those structs, btw :-))

Copy link
Member

@bnjbvr bnjbvr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

mostly style comments, lgtm otherwise, thanks!

Comment on lines 535 to 536
}
impl From<SdkNotableTags> for RoomNotableTags {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: let the code breathe please :-)

Suggested change
}
impl From<SdkNotableTags> for RoomNotableTags {
}
impl From<SdkNotableTags> for RoomNotableTags {

if let Some(room) = self.store.get_room(room_id) {
let tags = if let Some(AnyRoomAccountDataEvent::Tag(event)) = room_account_data
.get(&RoomAccountDataEventType::Tag)
.and_then(|r| r.deserialize().ok())
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A failure to deserialize will be silent. Can you expand this code a bit so that we log failures to deserialize, please?

Comment on lines 654 to 655
}
/// Returns the current RoomNotableTags and subscribe to changes.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
}
/// Returns the current RoomNotableTags and subscribe to changes.
}
/// Returns the current RoomNotableTags and subscribe to changes.

}
/// Returns the current RoomNotableTags and subscribe to changes.
pub async fn notable_tags_stream(&self) -> (RoomNotableTags, Subscriber<RoomNotableTags>) {
let current_tags = self.tags().await.unwrap_or(None);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: Result::unwrap_or(self, None) is equivalent to Result::ok(self), but it would be nice to either log the error here, or let the caller know that we failed by returning a Result<> ourselves.

/// Computes the provided tags to create a `RoomNotableTags` instance.
pub fn new(tags: Option<Tags>) -> Self {
RoomNotableTags {
is_favorite: tags.map(|tag| tag.contains_key(&TagName::Favorite)).unwrap_or(false),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: map(...).unwrap_or(x) can be rewritten as map_or(x, ...)

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here it could even be: .is_some_and(...).

Comment on lines 1469 to 1475
let (_, mut notable_tags_subscriber) = room.notable_tags_stream().await;
stream_assert::assert_pending!(notable_tags_subscriber);
let notable_tags = RoomNotableTags::new(None);
room.set_notable_tags(notable_tags);
use futures_util::FutureExt as _;
assert!(notable_tags_subscriber.next().now_or_never().is_some());
stream_assert::assert_pending!(notable_tags_subscriber);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

here come the blank lines... 😁

Suggested change
let (_, mut notable_tags_subscriber) = room.notable_tags_stream().await;
stream_assert::assert_pending!(notable_tags_subscriber);
let notable_tags = RoomNotableTags::new(None);
room.set_notable_tags(notable_tags);
use futures_util::FutureExt as _;
assert!(notable_tags_subscriber.next().now_or_never().is_some());
stream_assert::assert_pending!(notable_tags_subscriber);
let (_, mut notable_tags_subscriber) = room.notable_tags_stream().await;
stream_assert::assert_pending!(notable_tags_subscriber);
let notable_tags = RoomNotableTags::new(None);
room.set_notable_tags(notable_tags);
use futures_util::FutureExt as _;
assert!(notable_tags_subscriber.next().now_or_never().is_some());
stream_assert::assert_pending!(notable_tags_subscriber);

Comment on lines 1494 to 1501
let mut changes = StateChanges::new("".to_owned());
let tag_json: &Value = &test_json::TAG;
let tag_raw = Raw::new(tag_json).unwrap().cast();
let tag_event = tag_raw.deserialize().unwrap();
changes.add_room_account_data(room.room_id(), tag_event, tag_raw);
store.save_changes(&changes).await.unwrap();
let (initial_notable_tags, _) = room.notable_tags_stream().await;
assert!(initial_notable_tags.is_favorite);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
let mut changes = StateChanges::new("".to_owned());
let tag_json: &Value = &test_json::TAG;
let tag_raw = Raw::new(tag_json).unwrap().cast();
let tag_event = tag_raw.deserialize().unwrap();
changes.add_room_account_data(room.room_id(), tag_event, tag_raw);
store.save_changes(&changes).await.unwrap();
let (initial_notable_tags, _) = room.notable_tags_stream().await;
assert!(initial_notable_tags.is_favorite);
let mut changes = StateChanges::new("".to_owned());
let tag_json: &Value = &test_json::TAG;
let tag_raw = Raw::new(tag_json).unwrap().cast();
let tag_event = tag_raw.deserialize().unwrap();
changes.add_room_account_data(room.room_id(), tag_event, tag_raw);
store.save_changes(&changes).await.unwrap();
let (initial_notable_tags, _) = room.notable_tags_stream().await;
assert!(initial_notable_tags.is_favorite);

@ganfra ganfra requested a review from bnjbvr January 30, 2024 14:56
@ganfra
Copy link
Contributor Author

ganfra commented Jan 30, 2024

2 new commits :

  • 1st one is about exposing directly the base sdk struct to ffi => not sure about the cargo configs
  • 2nd one takes care of the rest

Copy link
Member

@bnjbvr bnjbvr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm, thanks!

@bnjbvr
Copy link
Member

bnjbvr commented Jan 30, 2024

(Note: clippy isn't happy)

@bnjbvr bnjbvr merged commit 6ef3361 into main Jan 30, 2024
34 checks passed
@bnjbvr bnjbvr deleted the fga/room_notable_tags branch January 30, 2024 15:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants