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

Wrap receiver in broadcast so that receiver can be called multiple times #2411

Open
wants to merge 7 commits into
base: main
Choose a base branch
from

Conversation

bitfriend
Copy link
Contributor

Will replace Mutext<Option<Receiver<...>>> with BroadcastStream<Receiver<...>>.

@bitfriend bitfriend added the rust label Dec 7, 2024
Copy link

codecov bot commented Dec 7, 2024

Codecov Report

Attention: Patch coverage is 4.62963% with 103 lines in your changes missing coverage. Please review.

Project coverage is 27.71%. Comparing base (3849fc0) to head (8ff8191).
Report is 38 commits behind head on main.

Files with missing lines Patch % Lines
native/acter/src/api/verification.rs 2.91% 100 Missing ⚠️
native/acter/src/api/device.rs 40.00% 3 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2411      +/-   ##
==========================================
+ Coverage   27.25%   27.71%   +0.46%     
==========================================
  Files         645      649       +4     
  Lines       43480    43724     +244     
==========================================
+ Hits        11849    12117     +268     
+ Misses      31631    31607      -24     
Flag Coverage Δ
integration-test 37.92% <4.62%> (+1.06%) ⬆️
unittest 19.39% <ø> (-0.13%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

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

Comment on lines 39 to 46
#[derive(Clone, Debug)]
#[derive(Clone, Debug, Default)]
pub struct VerificationEvent {
client: SdkClient,
controller: VerificationController,
event_type: String,
flow_id: String,
sender: OwnedUserId,
sender: String,
/// event content
content: HashMap<String, String>,
/// emoji array
emojis: Vec<VerificationEmoji>,
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

impl Stream<Item = VerificationEvent> needs for VerificationEvent to derive Default trait.
I removed client and controller fields from VerificationEvent, because they didn't derive Default.

Copy link
Contributor

Choose a reason for hiding this comment

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

this seems wrong. why does it need to be Default?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It needs Default trait.
image

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed by 2e26894

@bitfriend bitfriend marked this pull request as ready for review December 9, 2024 15:28
@bitfriend bitfriend requested a review from gnunicorn December 9, 2024 15:28
Comment on lines 24 to 26
final Client client;

const CrossSigning({super.key, required this.client});
Copy link
Contributor

Choose a reason for hiding this comment

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

Why? this is a Consumer, thus ref.read(alwaysClient) should be used... Passing around complex objects to many widget is not a great pattern. Please refactor this accordingly.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed by 2e26894

@bitfriend bitfriend requested a review from gnunicorn December 11, 2024 05:58
Copy link
Contributor

@gnunicorn gnunicorn left a comment

Choose a reason for hiding this comment

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

I think this can be simplified further.

Comment on lines 1130 to 1132
pub fn verification_event_rx(&self) -> impl Stream<Item = OptionVerificationEvent> {
BroadcastStream::new(self.verification_controller.event_rx.resubscribe())
.map(|o| OptionVerificationEvent::new(o.ok()))
Copy link
Contributor

Choose a reason for hiding this comment

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

Do I understand correctly that this entire new type and the wrapping and all is due to that event sometimes being None? Wouldn't .filter_map do enough for us here?

Suggested change
pub fn verification_event_rx(&self) -> impl Stream<Item = OptionVerificationEvent> {
BroadcastStream::new(self.verification_controller.event_rx.resubscribe())
.map(|o| OptionVerificationEvent::new(o.ok()))
pub fn verification_event_rx(&self) -> impl Stream<Item = VerificationEvent> {
BroadcastStream::new(self.verification_controller.event_rx.resubscribe())
.filter_map(|o| o.ok())

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed by 8ff8191

@gnunicorn gnunicorn added the merge post release only Merge this only after the new release has been cut label Dec 11, 2024
@bitfriend bitfriend requested a review from gnunicorn December 11, 2024 18:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
merge post release only Merge this only after the new release has been cut rust
Projects
Status: Backlog
Development

Successfully merging this pull request may close these issues.

2 participants