Fix a potential crash when handling member removal offline (#1025)

* Fix a potential crash handling member removal

* Change how the class is instantiated

* Additional GH triggers
pull/1712/head
SessionHero01 4 weeks ago committed by GitHub
parent 635cee1585
commit 5cfc87e38f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -4,7 +4,7 @@ on:
push: push:
branches: [ "dev", "master" ] branches: [ "dev", "master" ]
pull_request: pull_request:
types: [synchronize] types: [opened, synchronize, reopened]
concurrency: concurrency:

@ -169,7 +169,7 @@ public class ApplicationContext extends Application implements DefaultLifecycleO
@Inject ConfigUploader configUploader; @Inject ConfigUploader configUploader;
@Inject AdminStateSync adminStateSync; @Inject AdminStateSync adminStateSync;
@Inject DestroyedGroupSync destroyedGroupSync; @Inject DestroyedGroupSync destroyedGroupSync;
@Inject RemoveGroupMemberHandler removeGroupMemberHandler; @Inject RemoveGroupMemberHandler removeGroupMemberHandler; // Exists here only to start upon app starts
@Inject SnodeClock snodeClock; @Inject SnodeClock snodeClock;
@Inject ExpiringMessageManager expiringMessageManager; @Inject ExpiringMessageManager expiringMessageManager;
@Inject TypingStatusRepository typingStatusRepository; @Inject TypingStatusRepository typingStatusRepository;
@ -302,7 +302,6 @@ public class ApplicationContext extends Application implements DefaultLifecycleO
snodeClock.start(); snodeClock.start();
pushRegistrationHandler.run(); pushRegistrationHandler.run();
configUploader.start(); configUploader.start();
removeGroupMemberHandler.start();
destroyedGroupSync.start(); destroyedGroupSync.start();
adminStateSync.start(); adminStateSync.start();
cleanupInvitationHandler.start(); cleanupInvitationHandler.start();

@ -3,6 +3,7 @@ package org.thoughtcrime.securesms.groups.handler
import android.content.Context import android.content.Context
import com.google.protobuf.ByteString import com.google.protobuf.ByteString
import dagger.hilt.android.qualifiers.ApplicationContext import dagger.hilt.android.qualifiers.ApplicationContext
import kotlinx.coroutines.DelicateCoroutinesApi
import kotlinx.coroutines.ExperimentalCoroutinesApi import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.GlobalScope import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.Job import kotlinx.coroutines.Job
@ -49,6 +50,7 @@ private const val TAG = "RemoveGroupMemberHandler"
* *
* It automatically does so by listening to the config updates changes and checking for any pending removals. * It automatically does so by listening to the config updates changes and checking for any pending removals.
*/ */
@OptIn(DelicateCoroutinesApi::class, ExperimentalCoroutinesApi::class)
@Singleton @Singleton
class RemoveGroupMemberHandler @Inject constructor( class RemoveGroupMemberHandler @Inject constructor(
@ApplicationContext private val context: Context, @ApplicationContext private val context: Context,
@ -59,13 +61,8 @@ class RemoveGroupMemberHandler @Inject constructor(
private val storage: StorageProtocol, private val storage: StorageProtocol,
private val groupScope: GroupScope, private val groupScope: GroupScope,
) { ) {
private var job: Job? = null init {
GlobalScope.launch {
@OptIn(ExperimentalCoroutinesApi::class)
fun start() {
require(job == null) { "Already started" }
job = GlobalScope.launch {
textSecurePreferences textSecurePreferences
.watchLocalNumber() .watchLocalNumber()
.flatMapLatest { localNumber -> .flatMapLatest { localNumber ->
@ -80,14 +77,17 @@ class RemoveGroupMemberHandler @Inject constructor(
val adminKey = configFactory.getGroup(update.groupId)?.adminKey val adminKey = configFactory.getGroup(update.groupId)?.adminKey
if (adminKey != null) { if (adminKey != null) {
groupScope.launch(update.groupId, "Handle possible group removals") { groupScope.launch(update.groupId, "Handle possible group removals") {
processPendingRemovalsForGroup(update.groupId, adminKey) try {
processPendingRemovalsForGroup(update.groupId, adminKey)
} catch (ec: Exception) {
Log.e("RemoveGroupMemberHandler", "Error processing pending removals", ec)
}
} }
} }
} }
} }
} }
private suspend fun processPendingRemovalsForGroup( private suspend fun processPendingRemovalsForGroup(
groupAccountId: AccountId, groupAccountId: AccountId,
adminKey: ByteArray adminKey: ByteArray

Loading…
Cancel
Save