Fix crash for leave gv1.

This commit is contained in:
Sagar
2025-05-02 18:57:03 +05:30
committed by Cody Henthorne
parent 3c77a3d7aa
commit 51851fa5fe
5 changed files with 24 additions and 5 deletions

View File

@@ -362,6 +362,8 @@ public class NewConversationActivity extends ContactSelectionActivity
handleManualRefresh();
displaySnackbar(R.string.NewConversationActivity__s_has_been_blocked, recipient.getDisplayName(this));
contactsFragment.reset();
}, (throwable) -> {
displaySnackbar(R.string.NewConversationActivity__block_failed);
}));
})
);

View File

@@ -171,14 +171,19 @@ class ConversationSettingsRepository(
}
}
fun block(recipientId: RecipientId) {
SignalExecutors.BOUNDED.execute {
@WorkerThread
fun block(recipientId: RecipientId): GroupChangeResult {
return try {
val recipient = Recipient.resolved(recipientId)
if (recipient.isGroup) {
RecipientUtil.block(context, recipient)
} else {
RecipientUtil.blockNonGroup(context, recipient)
}
GroupChangeResult.SUCCESS
} catch (e: Exception) {
Log.w(TAG, "Failed to block recipient.", e)
GroupChangeResult.failure(GroupChangeFailureReason.fromException(e))
}
}

View File

@@ -266,7 +266,15 @@ sealed class ConversationSettingsViewModel(
}
override fun block() {
repository.block(recipientId)
viewModelScope.launch {
val result = withContext(SignalDispatchers.IO) {
repository.block(recipientId)
}
if (!result.isSuccess) {
internalEvents.onNext(ConversationSettingsEvent.ShowBlockGroupError(result.getFailureReason()))
}
}
}
override fun unblock() {

View File

@@ -80,7 +80,8 @@ public final class GroupManager {
throws GroupChangeBusyException, GroupChangeFailedException, IOException
{
if (!groupId.isV2()) {
throw new GroupChangeFailedException("Not gv2");
Log.w(TAG, "Not gv2");
return;
}
try (GroupManagerV2.GroupEditor edit = new GroupManagerV2(context).edit(groupId.requireV2())) {
@@ -101,7 +102,8 @@ public final class GroupManager {
throws IOException, GroupChangeBusyException, GroupChangeFailedException
{
if (!groupId.isV2()) {
throw new GroupChangeFailedException("Not gv2");
Log.w(TAG, "Not gv2");
return;
}
leaveGroup(context, groupId.requireV2(), true);

View File

@@ -5843,6 +5843,8 @@
<string name="NewConversationActivity__s_has_been_removed">%1$s has been removed</string>
<!-- Snackbar message after blocking a contact -->
<string name="NewConversationActivity__s_has_been_blocked">%1$s has been blocked</string>
<!-- Snackbar message when blocking a contact has failed -->
<string name="NewConversationActivity__block_failed">Block failed</string>
<!-- Dialog title when remove target contact is in system contacts -->
<string name="NewConversationActivity__unable_to_remove_s">Unable to remove %1$s</string>
<!-- Dialog message when remove target contact is in system contacts -->