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 push notifications for UnifiedPush distributors without provided matrix gateway #4040

Open
wants to merge 4 commits into
base: develop
Choose a base branch
from

Conversation

SpiritCroc
Copy link
Contributor

Fixes #3571

Content

We need to account for UnifiedPush distributors not providing a Matrix gateway, to properly use our fallback gateway.
To quote p1gp1g, we need to:

  • return the customGateway if the check returns 200 and discoveryResponse.unifiedpush.gateway == "matrix"
  • return the default gateway if the check returns 200 and there isn't discoveryResponse.unifiedpush.gateway == "matrix"
  • return the default gateway if the check returns 404
  • return the previous gateway if it fails
  • if there isn't a previous gateway, we can use one or the other, it doesn't really matter

Motivation and context

Fixes #3571

Tests

  • Set up a distributor which does feature a matrix gateway, such as ntfy
  • Select ntfy as push distributor
  • Check "Troubleshoot notifications" that the custom gateway is used and push works
  • Set up a distributor which does not feature a matrix gateway, such as gCompat
  • Select "gCompat UP-Distributor" as push distributor
  • Check "Troubleshoot notifications" that the fallback gateway is used and push works

Tested devices

NOTE: I only tested on SchildiChat Next

  • Physical device
  • Emulator
  • OS version(s): 14

Checklist

  • Changes have been tested on an Android device or Android emulator with API 23
  • Pull request is based on the develop branch
  • Pull request title will be used in the release note, it clearly define what will change for the user
  • You've made a self review of your PR

@SpiritCroc SpiritCroc requested a review from a team as a code owner December 14, 2024 09:43
@SpiritCroc SpiritCroc requested review from ganfra and removed request for a team December 14, 2024 09:43
@CLAassistant
Copy link

CLAassistant commented Dec 14, 2024

CLA assistant check
All committers have signed the CLA.

Copy link
Contributor

Thank you for your contribution! Here are a few things to check in the PR to ensure it's reviewed as quickly as possible:

  • Your branch should be based on origin/develop, at least when it was created.
  • The title of the PR will be used for release notes, so it needs to describe the change visible to the user.
  • The test pass locally running ./gradlew test.
  • The code quality check suite pass locally running ./gradlew runQualityChecks.
  • If you modified anything related to the UI, including previews, you'll have to run the Record screenshots GH action in your forked repo: that will generate compatible new screenshots. However, given Github Actions limitations, it will prevent the CI from running temporarily, until you upload a new commit after that one. To do so, just pull the latest changes and push an empty commit.

@bmarty bmarty requested review from bmarty and removed request for ganfra December 17, 2024 09:38
Copy link
Member

@bmarty bmarty 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 change. I do not really like to provide the previous value as a parameter for UnifiedPushGatewayResolver.getGateway() but I do not see any better solution. Returning String? could be an alternative, but it may not fit all the needs.

UnifiedPushConfig.DEFAULT_PUSH_GATEWAY_HTTP_URL
}
} catch (exception: HttpException) {
if (exception.code() == 404) {
Copy link
Member

Choose a reason for hiding this comment

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

Could use HttpURLConnection.HTTP_NOT_FOUND.

@spaetz
Copy link

spaetz commented Dec 17, 2024

I love that functionality, thanks for that. That having said, I agree with bmarty that passing in previousGateway feels really ugly. Returning None/Null/Empty string in the case where we want to use the previous gateway feels much better as in "don't change current value".

That having said, I won't be able to provide patches so whatever is picked, I love it ❤️

@SpiritCroc
Copy link
Contributor Author

Yeah agreed, passing previousGateway isn't very elegant. Seems to be the most straightforward approach to fulfil the spec I got without over-engineering it though. I assume just always returning null from getGateway() and falling back outside to the previous value would work except for the "if there isn't a previous gateway, we can use one or the other, it doesn't really matter" case. If "it doesn't matter" is to be interpreted that we can also fallback to no gateway at all, then that's probably the most elegant way, I don't know right now how relevant this is in practice.

@bmarty bmarty added the Z-Community-PR Issue is solved by a community member's PR label Dec 18, 2024
@bmarty
Copy link
Member

bmarty commented Dec 19, 2024

OK, let's be pragmatic and merge those changes.

There are 2 failing tests, can you handle that please? Else let me know, I can take the point

VectorUnifiedPushMessagingReceiverTest > onNewEndpoint, if registration fails, the endpoint should not be stored FAILED
    java.lang.AssertionError at VectorUnifiedPushMessagingReceiverTest.kt:131

VectorUnifiedPushMessagingReceiverTest > onNewEndpoint run the expected tasks FAILED
    java.lang.AssertionError at VectorUnifiedPushMessagingReceiverTest.kt:91

@SpiritCroc
Copy link
Contributor Author

OK, let's be pragmatic and merge those changes.

There are 2 failing tests, can you handle that please? Else let me know, I can take the point

VectorUnifiedPushMessagingReceiverTest > onNewEndpoint, if registration fails, the endpoint should not be stored FAILED
    java.lang.AssertionError at VectorUnifiedPushMessagingReceiverTest.kt:131

VectorUnifiedPushMessagingReceiverTest > onNewEndpoint run the expected tasks FAILED
    java.lang.AssertionError at VectorUnifiedPushMessagingReceiverTest.kt:91

I probably can look at those again earliest next weekend. I had a quick look before but didn't see immediately what the appropriate fix for these two would be. So if you can fix them earlier that would be great, thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Z-Community-PR Issue is solved by a community member's PR
Projects
None yet
Development

Successfully merging this pull request may close these issues.

UnifiedPush not working with Conversations
4 participants