Skip to content

Commit 5cfc87e

Browse files
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
1 parent 635cee1 commit 5cfc87e

File tree

3 files changed

+11
-12
lines changed

3 files changed

+11
-12
lines changed

.github/workflows/build_and_test.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ on:
44
push:
55
branches: [ "dev", "master" ]
66
pull_request:
7-
types: [synchronize]
7+
types: [opened, synchronize, reopened]
88

99

1010
concurrency:

app/src/main/java/org/thoughtcrime/securesms/ApplicationContext.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ public class ApplicationContext extends Application implements DefaultLifecycleO
169169
@Inject ConfigUploader configUploader;
170170
@Inject AdminStateSync adminStateSync;
171171
@Inject DestroyedGroupSync destroyedGroupSync;
172-
@Inject RemoveGroupMemberHandler removeGroupMemberHandler;
172+
@Inject RemoveGroupMemberHandler removeGroupMemberHandler; // Exists here only to start upon app starts
173173
@Inject SnodeClock snodeClock;
174174
@Inject ExpiringMessageManager expiringMessageManager;
175175
@Inject TypingStatusRepository typingStatusRepository;
@@ -302,7 +302,6 @@ public void onCreate() {
302302
snodeClock.start();
303303
pushRegistrationHandler.run();
304304
configUploader.start();
305-
removeGroupMemberHandler.start();
306305
destroyedGroupSync.start();
307306
adminStateSync.start();
308307
cleanupInvitationHandler.start();

app/src/main/java/org/thoughtcrime/securesms/groups/handler/RemoveGroupMemberHandler.kt

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package org.thoughtcrime.securesms.groups.handler
33
import android.content.Context
44
import com.google.protobuf.ByteString
55
import dagger.hilt.android.qualifiers.ApplicationContext
6+
import kotlinx.coroutines.DelicateCoroutinesApi
67
import kotlinx.coroutines.ExperimentalCoroutinesApi
78
import kotlinx.coroutines.GlobalScope
89
import kotlinx.coroutines.Job
@@ -49,6 +50,7 @@ private const val TAG = "RemoveGroupMemberHandler"
4950
*
5051
* It automatically does so by listening to the config updates changes and checking for any pending removals.
5152
*/
53+
@OptIn(DelicateCoroutinesApi::class, ExperimentalCoroutinesApi::class)
5254
@Singleton
5355
class RemoveGroupMemberHandler @Inject constructor(
5456
@ApplicationContext private val context: Context,
@@ -59,13 +61,8 @@ class RemoveGroupMemberHandler @Inject constructor(
5961
private val storage: StorageProtocol,
6062
private val groupScope: GroupScope,
6163
) {
62-
private var job: Job? = null
63-
64-
@OptIn(ExperimentalCoroutinesApi::class)
65-
fun start() {
66-
require(job == null) { "Already started" }
67-
68-
job = GlobalScope.launch {
64+
init {
65+
GlobalScope.launch {
6966
textSecurePreferences
7067
.watchLocalNumber()
7168
.flatMapLatest { localNumber ->
@@ -80,14 +77,17 @@ class RemoveGroupMemberHandler @Inject constructor(
8077
val adminKey = configFactory.getGroup(update.groupId)?.adminKey
8178
if (adminKey != null) {
8279
groupScope.launch(update.groupId, "Handle possible group removals") {
83-
processPendingRemovalsForGroup(update.groupId, adminKey)
80+
try {
81+
processPendingRemovalsForGroup(update.groupId, adminKey)
82+
} catch (ec: Exception) {
83+
Log.e("RemoveGroupMemberHandler", "Error processing pending removals", ec)
84+
}
8485
}
8586
}
8687
}
8788
}
8889
}
8990

90-
9191
private suspend fun processPendingRemovalsForGroup(
9292
groupAccountId: AccountId,
9393
adminKey: ByteArray

0 commit comments

Comments
 (0)