Skip to content

Commit

Permalink
Relay management fix
Browse files Browse the repository at this point in the history
  • Loading branch information
KoalaSat committed Nov 2, 2024
1 parent 7a75eaf commit cdba8b8
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ interface ApplicationDao {
@Insert(onConflict = OnConflictStrategy.REPLACE)
fun insertRelay(notificationEntity: RelayEntity): Long?

@Query("SELECT * FROM relay where kind = :kind")
fun getRelaysByKind(kind: Int): List<RelayEntity>

@Query("DELETE FROM relay where kind = :kind")
fun deleteRelaysByKind(kind: Int): Int

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ class NotificationsService : Service() {
scope.launch(Dispatchers.IO) {
stopSubscription()
delay(1000)
connectRelays()
startSubscription()
}
}
Expand All @@ -149,6 +150,7 @@ class NotificationsService : Service() {
if (Connectivity.updateNetworkCapabilities(networkCapabilities)) {
stopSubscription()
delay(1000)
connectRelays()
startSubscription()
}
}
Expand Down Expand Up @@ -261,6 +263,7 @@ class NotificationsService : Service() {

private fun stopSubscription() {
Client.unsubscribe(clientListener)
RelayPool.unloadRelays()
}

private fun keepAlive() {
Expand Down Expand Up @@ -313,9 +316,8 @@ class NotificationsService : Service() {
val lastCreatedRelayAt = dao.getLatestRelaysByKind(event.kind)

if (lastCreatedRelayAt == null || lastCreatedRelayAt < event.createdAt) {
stopSubscription()
RelayPool.unloadRelays()
dao.deleteRelaysByKind(event.kind)

event.tags
.filter { it.size > 1 && (it[0] == "relay" || it[0] == "r") }
.forEach {
Expand All @@ -329,6 +331,7 @@ class NotificationsService : Service() {
dao.insertRelay(entity)
}

connectRelays()
startSubscription()
}
}
Expand Down

0 comments on commit cdba8b8

Please sign in to comment.