-
Notifications
You must be signed in to change notification settings - Fork 119
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
When subscribed to a new_topic, send endpoints to all apps #70
Open
karmanyaahm
wants to merge
7
commits into
binwiederhier:main
Choose a base branch
from
karmanyaahm:remote-resub
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
a09374b
re new_endpoint on new_topic from server
karmanyaahm 9d38118
Extract the socket message->notification flow into SubscriberService …
karmanyaahm eb1c830
make things slightly nicer?
karmanyaahm 235f354
clean
karmanyaahm c7d0fb1
ok everything works now
karmanyaahm b341956
minor
karmanyaahm 61f57dd
put sendEndpoint on register back in
karmanyaahm File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -94,6 +94,13 @@ class BroadcastReceiver : android.content.BroadcastReceiver() { | |
// Note, this may fail due to a SQL constraint exception, see https://github.com/binwiederhier/ntfy/issues/185 | ||
repository.addSubscription(subscription) | ||
distributor.sendEndpoint(appId, connectorToken, endpoint) | ||
/* We need to stop sending the endpoint here once everyone has the new server, | ||
the foreground service will do that after registering with the server. | ||
That will avoid a race condition where the application server | ||
is rejected before ntfy even establishes that this topic exists. | ||
This is fine from an application perspective, because other distributors can't even register | ||
without a connection to the push server. | ||
Unless the app registers twice. Then it'll get the endpoint anyway.*/ | ||
|
||
// Refresh (and maybe start) foreground service | ||
SubscriberServiceManager.refresh(app) | ||
|
@@ -143,5 +150,26 @@ class BroadcastReceiver : android.content.BroadcastReceiver() { | |
private const val TOPIC_RANDOM_ID_LENGTH = 12 | ||
|
||
val mutex = Mutex() // https://github.com/binwiederhier/ntfy/issues/230 | ||
|
||
// TODO Where's the best place to put this function? This seems to be the only place | ||
// with the access to the locks, but also globally accessible | ||
// but also, broadcast receiver is for *receiving Android broadcasts* | ||
public fun sendRegistration(context: Context, baseUrl : String, topic : String) { | ||
val app = context.applicationContext as Application | ||
val repository = app.repository | ||
val distributor = Distributor(app) | ||
GlobalScope.launch(Dispatchers.IO) { | ||
// We're doing all of this inside a critical section, because of possible races. | ||
// See https://github.com/binwiederhier/ntfy/issues/230 for details. | ||
|
||
mutex.withLock { | ||
val existingSubscription = repository.getSubscription(baseUrl, topic) ?: return@launch | ||
val appId = existingSubscription.upAppId ?: return@launch | ||
val connectorToken = existingSubscription.upConnectorToken ?: return@launch | ||
val endpoint = topicUrlUp(existingSubscription.baseUrl, existingSubscription.topic) | ||
distributor.sendEndpoint(appId, connectorToken, endpoint) | ||
Comment on lines
+153
to
+170
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Where should I put this function? |
||
} | ||
} | ||
} | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should that work? Or do I need to make a whole chain of contexts being passed down and stored? Not really sure what context is used for when creating the repository downstream. It seems to work as is.