Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions app/src/main/java/org/session/libsignal/utilities/HTTP.kt
Original file line number Diff line number Diff line change
Expand Up @@ -162,8 +162,8 @@ object HTTP {
private val httpCallSemaphore = Semaphore(20)

private suspend fun Call.await(): Response {
return withContext(Dispatchers.IO) {
httpCallSemaphore.withPermit {
return httpCallSemaphore.withPermit {
withContext(Dispatchers.IO) {
execute()
}
}
Expand Down
15 changes: 13 additions & 2 deletions app/src/main/java/org/thoughtcrime/securesms/groups/GroupPoller.kt
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,9 @@ class GroupPoller @AssistedInject constructor(
).also { emit(it) }

// Notify all pending tokens
pendingTokens.forEach { it.resultCallback.send(pollResult) }
pendingTokens.forEach {
it.resultCallback.trySend(pollResult)
}
pendingTokens.clear()
}
}.stateIn(scope, SharingStarted.Eagerly, State())
Expand All @@ -135,10 +137,12 @@ class GroupPoller @AssistedInject constructor(
appVisibilityManager.isAppVisible.first { visible -> visible }

// As soon as the app becomes visible, start polling
Log.d(TAG, "Requesting routine poll for group($groupId)")
if (requestPollOnce().hasNonRetryableError()) {
Log.v(TAG, "Error polling group $groupId and stopped polling")
break
}
Log.d(TAG, "Routine poll done once for group($groupId)")

// As long as the app is visible, keep polling
while (true) {
Expand All @@ -152,10 +156,14 @@ class GroupPoller @AssistedInject constructor(
break
}

Log.d(TAG, "Requesting routine poll for group($groupId)")

if (requestPollOnce().hasNonRetryableError()) {
Log.v(TAG, "Error polling group $groupId and stopped polling")
return@launch
}

Log.d(TAG, "Routine poll done once for group($groupId)")
}
}
}
Expand Down Expand Up @@ -226,6 +234,8 @@ class GroupPoller @AssistedInject constructor(
throw NonRetryableException("Group has been kicked")
}

Log.v(TAG, "Start polling group($groupId) message snode = ${snode.ip}")

val adminKey = group.adminKey

val pollingTasks = mutableListOf<Pair<String, Deferred<*>>>()
Expand Down Expand Up @@ -270,7 +280,6 @@ class GroupPoller @AssistedInject constructor(
Namespace.GROUP_MESSAGES()
).orEmpty()

Log.v(TAG, "Retrieving group($groupId) message since lastHash = $lastHash, snode = ${snode.publicKeySet}")

SnodeAPI.sendBatchRequest(
snode = snode,
Expand Down Expand Up @@ -356,6 +365,8 @@ class GroupPoller @AssistedInject constructor(
}
}

Log.d(TAG, "Group($groupId) polling completed, success = ${result.isSuccess}")

if (result.isFailure) {
val error = result.exceptionOrNull()
Log.e(TAG, "Error polling group", error)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ class GroupPollerManager @Inject constructor(
pollFactory: GroupPoller.Factory,
@param:ManagerScope private val managerScope: CoroutineScope,
) : OnAppStartupComponent {
private val groupPollerSemaphore = Semaphore(5)
private val groupPollerSemaphore = Semaphore(20)

@Suppress("OPT_IN_USAGE")
private val groupPollers: StateFlow<Map<AccountId, GroupPollerHandle>> =
Expand Down