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

Sync polls' push rules (PSG-77, PSG-1097) #7320

Merged
merged 24 commits into from
Feb 1, 2023

Conversation

alfogrillo
Copy link
Contributor

Description

This PR syncs the poll rules with the ones of normal messages.

  • Poll started, poll ended events should be in sync with normal messages.
  • Poll started, poll ended events (one to one) should be in sync with normal messages (one to one).

Dependency

matrix-org/matrix-ios-sdk#1702

Result

poc

@alfogrillo alfogrillo requested review from a team and Anderas and removed request for a team January 30, 2023 17:01
@codecov
Copy link

codecov bot commented Jan 30, 2023

Codecov Report

Base: 12.02% // Head: 12.01% // Decreases project coverage by -0.01% ⚠️

Coverage data is based on head (a1f07e2) compared to base (ff6fab7).
Patch coverage: 0.00% of modified lines in pull request are covered.

Additional details and impacted files
@@             Coverage Diff             @@
##           develop    #7320      +/-   ##
===========================================
- Coverage    12.02%   12.01%   -0.01%     
===========================================
  Files         1630     1631       +1     
  Lines       161272   161473     +201     
  Branches     66073    66252     +179     
===========================================
+ Hits         19391    19404      +13     
- Misses      141237   141420     +183     
- Partials       644      649       +5     
Flag Coverage Δ
uitests 55.36% <0.00%> (-0.28%) ⬇️

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

Impacted Files Coverage Δ
Riot/Categories/MXRoom+Riot.m 0.00% <0.00%> (ø)
...iot/Modules/Common/Recents/RecentsViewController.m 8.70% <0.00%> (ø)
...Modules/Common/Recents/Views/RecentTableViewCell.m 0.00% <0.00%> (ø)
...ntextMenu/ActionProviders/RoomActionProvider.swift 0.00% <0.00%> (ø)
...ontextMenu/Services/RoomContextActionService.swift 0.00% <0.00%> (ø)
...ontrollers/MXKNotificationSettingsViewController.m 0.00% <0.00%> (ø)
...ules/MatrixKit/Models/RoomList/MXKRecentCellData.m 0.00% <0.00%> (ø)
...atrixKit/Views/PushRule/MXKPushRuleTableViewCell.m 0.00% <0.00%> (ø)
Riot/Modules/Room/MXKRoomViewController.m 0.00% <0.00%> (ø)
...ications/Model/Mock/MockNotificationPushRule.swift 0.00% <0.00%> (ø)
... and 21 more

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

☔ View full report at Codecov.
📢 Do you have feedback about the report comment? Let us know in this issue.

@alfogrillo alfogrillo changed the title Sync polls rules (PSG-77, PSG-1097) Sync polls' push rules (PSG-77, PSG-1097) Jan 30, 2023
private extension MXNotificationSettingsService {
func enableRule(rule: MXPushRule, enabled: Bool, completion: ((Result<Void, Error>) -> Void)?) {
session.notificationCenter.enableRule(rule, isEnabled: enabled) { error in
completion?(error.result)
Copy link
Contributor

Choose a reason for hiding this comment

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

Hm this looks a bit confusing. If I understand correctly error.result will either give you error or success, but the reader would not know this without looking at the implementation of the result extension. Being explicit via some if let/else may mean more lines of code but is in my opinion clearer.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah it's just converting an objective-c style Error? to a swifty Result<Void, Error>.
I'll prefer to keep the extension because I need it several times.

Copy link
Contributor

Choose a reason for hiding this comment

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

Isn't it just this?

if let error = error {
    completion(.failure(error)
} else {
    completion(.success(()))
}

You do use error.result several times but with similar level of ambiguity, see this:

switch error.result {
case .success:
  self?.enableRule(rule: rule, enabled: enabled, completion: completion)
case .failure:
  completion?(error.result)
}

This is even longer than doing the if/else and we have to unpack error.result twice so it really looks like the wrong kind of API to me

@@ -40,5 +40,16 @@ protocol NotificationSettingsServiceType {
/// - ruleId: The id of the rule.
/// - enabled: Whether the rule should be enabled or disabled.
/// - actions: The actions to update with.
func updatePushRuleActions(for ruleId: String, enabled: Bool, actions: NotificationActions?)
/// - completion: The completion of the operation.
func updatePushRuleActions(for ruleId: String, enabled: Bool, actions: NotificationActions?, completion: ((Result<Void, Error>) -> Void)?)
Copy link
Contributor

@Anderas Anderas Jan 31, 2023

Choose a reason for hiding this comment

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

As a speculative thought what would happen if we made this method async throws and having the
completion variant (which is used less often and only with obj-c) the extension if even necessary? I think it would make the code more readable. It also seems that you have already added async code elsewhere in this PR

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think it should work as well.
I preferred to keep the non async version in the first place to minimize the refactor I needed to do.
But at this point it should be an easy one.

Copy link
Contributor

Choose a reason for hiding this comment

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

I think it may also help with some of the Result<Void, Error> workarounds and magic

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I refactored several things trying to leverage more async/await to make the code easier to be read.
I also found some already existing memory leak and I fixed that as well.
6850633

Copy link
Contributor

@Anderas Anderas left a comment

Choose a reason for hiding this comment

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

Thanks for the concurrency refactor, I think it looks and reads so much better than with those clunky callbacks 👍 . Also great find for the memory leaks

@sonarcloud
Copy link

sonarcloud bot commented Feb 1, 2023

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

No Coverage information No Coverage information
No Duplication information No Duplication information

@alfogrillo alfogrillo merged commit 2c98b8d into develop Feb 1, 2023
@alfogrillo alfogrillo deleted the alfogrillo/sync_polls_rules branch February 1, 2023 11:47
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.

2 participants