Search in sources :

Example 1 with BadGroupIdException

use of org.thoughtcrime.securesms.groups.BadGroupIdException in project Signal-Android by WhisperSystems.

the class ReviewCardDialogFragment method onViewCreated.

@Override
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
    try {
        initializeViewModel();
    } catch (BadGroupIdException e) {
        throw new IllegalStateException(e);
    }
    TextView description = view.findViewById(R.id.description);
    RecyclerView recycler = view.findViewById(R.id.recycler);
    ReviewCardAdapter adapter = new ReviewCardAdapter(getNoGroupsInCommonResId(), getGroupsInCommonResId(), new AdapterCallbacks());
    recycler.setAdapter(adapter);
    viewModel.getReviewCards().observe(getViewLifecycleOwner(), cards -> {
        adapter.submitList(cards);
        description.setText(getString(getDescriptionResId(), cards.size()));
    });
    viewModel.getReviewEvents().observe(getViewLifecycleOwner(), this::onReviewEvent);
}
Also used : TextView(android.widget.TextView) RecyclerView(androidx.recyclerview.widget.RecyclerView) BadGroupIdException(org.thoughtcrime.securesms.groups.BadGroupIdException)

Example 2 with BadGroupIdException

use of org.thoughtcrime.securesms.groups.BadGroupIdException in project Signal-Android by WhisperSystems.

the class ThreadDatabase method applyStorageSyncUpdate.

public void applyStorageSyncUpdate(@NonNull RecipientId recipientId, @NonNull SignalAccountRecord record) {
    SQLiteDatabase db = databaseHelper.getSignalWritableDatabase();
    db.beginTransaction();
    try {
        applyStorageSyncUpdate(recipientId, record.isNoteToSelfArchived(), record.isNoteToSelfForcedUnread());
        ContentValues clearPinnedValues = new ContentValues();
        clearPinnedValues.put(PINNED, 0);
        db.update(TABLE_NAME, clearPinnedValues, null, null);
        int pinnedPosition = 1;
        for (SignalAccountRecord.PinnedConversation pinned : record.getPinnedConversations()) {
            ContentValues pinnedValues = new ContentValues();
            pinnedValues.put(PINNED, pinnedPosition);
            Recipient pinnedRecipient;
            if (pinned.getContact().isPresent()) {
                pinnedRecipient = Recipient.externalPush(pinned.getContact().get());
            } else if (pinned.getGroupV1Id().isPresent()) {
                try {
                    pinnedRecipient = Recipient.externalGroupExact(context, GroupId.v1(pinned.getGroupV1Id().get()));
                } catch (BadGroupIdException e) {
                    Log.w(TAG, "Failed to parse pinned groupV1 ID!", e);
                    pinnedRecipient = null;
                }
            } else if (pinned.getGroupV2MasterKey().isPresent()) {
                try {
                    pinnedRecipient = Recipient.externalGroupExact(context, GroupId.v2(new GroupMasterKey(pinned.getGroupV2MasterKey().get())));
                } catch (InvalidInputException e) {
                    Log.w(TAG, "Failed to parse pinned groupV2 master key!", e);
                    pinnedRecipient = null;
                }
            } else {
                Log.w(TAG, "Empty pinned conversation on the AccountRecord?");
                pinnedRecipient = null;
            }
            if (pinnedRecipient != null) {
                db.update(TABLE_NAME, pinnedValues, RECIPIENT_ID + " = ?", SqlUtil.buildArgs(pinnedRecipient.getId()));
            }
            pinnedPosition++;
        }
        db.setTransactionSuccessful();
    } finally {
        db.endTransaction();
    }
    notifyConversationListListeners();
}
Also used : ContentValues(android.content.ContentValues) InvalidInputException(org.signal.zkgroup.InvalidInputException) SignalAccountRecord(org.whispersystems.signalservice.api.storage.SignalAccountRecord) Recipient(org.thoughtcrime.securesms.recipients.Recipient) GroupMasterKey(org.signal.zkgroup.groups.GroupMasterKey) BadGroupIdException(org.thoughtcrime.securesms.groups.BadGroupIdException)

Example 3 with BadGroupIdException

use of org.thoughtcrime.securesms.groups.BadGroupIdException in project Signal-Android by WhisperSystems.

the class MessageDecryptionUtil method toExceptionMetadata.

private static ExceptionMetadata toExceptionMetadata(@NonNull UnsupportedDataMessageException e) throws NoSenderException {
    String sender = e.getSender();
    if (sender == null)
        throw new NoSenderException();
    GroupId groupId = null;
    if (e.getGroup().isPresent()) {
        try {
            groupId = GroupUtil.idFromGroupContext(e.getGroup().get());
        } catch (BadGroupIdException ex) {
            Log.w(TAG, "Bad group id found in unsupported data message", ex);
        }
    }
    return new ExceptionMetadata(sender, e.getSenderDevice(), groupId);
}
Also used : ExceptionMetadata(org.thoughtcrime.securesms.messages.MessageContentProcessor.ExceptionMetadata) BadGroupIdException(org.thoughtcrime.securesms.groups.BadGroupIdException) GroupId(org.thoughtcrime.securesms.groups.GroupId)

Example 4 with BadGroupIdException

use of org.thoughtcrime.securesms.groups.BadGroupIdException in project Signal-Android by signalapp.

the class ThreadDatabase method applyStorageSyncUpdate.

public void applyStorageSyncUpdate(@NonNull RecipientId recipientId, @NonNull SignalAccountRecord record) {
    SQLiteDatabase db = databaseHelper.getSignalWritableDatabase();
    db.beginTransaction();
    try {
        applyStorageSyncUpdate(recipientId, record.isNoteToSelfArchived(), record.isNoteToSelfForcedUnread());
        ContentValues clearPinnedValues = new ContentValues();
        clearPinnedValues.put(PINNED, 0);
        db.update(TABLE_NAME, clearPinnedValues, null, null);
        int pinnedPosition = 1;
        for (SignalAccountRecord.PinnedConversation pinned : record.getPinnedConversations()) {
            ContentValues pinnedValues = new ContentValues();
            pinnedValues.put(PINNED, pinnedPosition);
            Recipient pinnedRecipient;
            if (pinned.getContact().isPresent()) {
                pinnedRecipient = Recipient.externalPush(pinned.getContact().get());
            } else if (pinned.getGroupV1Id().isPresent()) {
                try {
                    pinnedRecipient = Recipient.externalGroupExact(context, GroupId.v1(pinned.getGroupV1Id().get()));
                } catch (BadGroupIdException e) {
                    Log.w(TAG, "Failed to parse pinned groupV1 ID!", e);
                    pinnedRecipient = null;
                }
            } else if (pinned.getGroupV2MasterKey().isPresent()) {
                try {
                    pinnedRecipient = Recipient.externalGroupExact(context, GroupId.v2(new GroupMasterKey(pinned.getGroupV2MasterKey().get())));
                } catch (InvalidInputException e) {
                    Log.w(TAG, "Failed to parse pinned groupV2 master key!", e);
                    pinnedRecipient = null;
                }
            } else {
                Log.w(TAG, "Empty pinned conversation on the AccountRecord?");
                pinnedRecipient = null;
            }
            if (pinnedRecipient != null) {
                db.update(TABLE_NAME, pinnedValues, RECIPIENT_ID + " = ?", SqlUtil.buildArgs(pinnedRecipient.getId()));
            }
            pinnedPosition++;
        }
        db.setTransactionSuccessful();
    } finally {
        db.endTransaction();
    }
    notifyConversationListListeners();
}
Also used : ContentValues(android.content.ContentValues) InvalidInputException(org.signal.zkgroup.InvalidInputException) SignalAccountRecord(org.whispersystems.signalservice.api.storage.SignalAccountRecord) Recipient(org.thoughtcrime.securesms.recipients.Recipient) GroupMasterKey(org.signal.zkgroup.groups.GroupMasterKey) BadGroupIdException(org.thoughtcrime.securesms.groups.BadGroupIdException)

Example 5 with BadGroupIdException

use of org.thoughtcrime.securesms.groups.BadGroupIdException in project Signal-Android by signalapp.

the class PushProcessMessageJob method createParameters.

@WorkerThread
@NonNull
private static Parameters createParameters(@Nullable SignalServiceContent content, @Nullable ExceptionMetadata exceptionMetadata) {
    Context context = ApplicationDependencies.getApplication();
    String queueName = QUEUE_PREFIX;
    Parameters.Builder builder = new Parameters.Builder().setMaxAttempts(Parameters.UNLIMITED);
    if (content != null) {
        SignalServiceGroupContext signalServiceGroupContext = GroupUtil.getGroupContextIfPresent(content);
        if (signalServiceGroupContext != null) {
            try {
                GroupId groupId = GroupUtil.idFromGroupContext(signalServiceGroupContext);
                queueName = getQueueName(Recipient.externalPossiblyMigratedGroup(context, groupId).getId());
                if (groupId.isV2()) {
                    int localRevision = SignalDatabase.groups().getGroupV2Revision(groupId.requireV2());
                    if (signalServiceGroupContext.getGroupV2().get().getRevision() > localRevision || SignalDatabase.groups().getGroupV1ByExpectedV2(groupId.requireV2()).isPresent()) {
                        Log.i(TAG, "Adding network constraint to group-related job.");
                        builder.addConstraint(NetworkConstraint.KEY).setLifespan(TimeUnit.DAYS.toMillis(30));
                    }
                }
            } catch (BadGroupIdException e) {
                Log.w(TAG, "Bad groupId! Using default queue. ID: " + content.getTimestamp());
            }
        } else if (content.getSyncMessage().isPresent() && content.getSyncMessage().get().getSent().isPresent() && content.getSyncMessage().get().getSent().get().getDestination().isPresent()) {
            queueName = getQueueName(RecipientId.fromHighTrust(content.getSyncMessage().get().getSent().get().getDestination().get()));
        } else {
            queueName = getQueueName(RecipientId.fromHighTrust(content.getSender()));
        }
    } else if (exceptionMetadata != null) {
        Recipient recipient = exceptionMetadata.getGroupId() != null ? Recipient.externalPossiblyMigratedGroup(context, exceptionMetadata.getGroupId()) : Recipient.external(context, exceptionMetadata.getSender());
        queueName = getQueueName(recipient.getId());
    }
    builder.setQueue(queueName);
    return builder.build();
}
Also used : Context(android.content.Context) SignalServiceGroupContext(org.whispersystems.signalservice.api.messages.SignalServiceGroupContext) Recipient(org.thoughtcrime.securesms.recipients.Recipient) BadGroupIdException(org.thoughtcrime.securesms.groups.BadGroupIdException) SignalServiceGroupContext(org.whispersystems.signalservice.api.messages.SignalServiceGroupContext) NetworkConstraint(org.thoughtcrime.securesms.jobmanager.impl.NetworkConstraint) GroupId(org.thoughtcrime.securesms.groups.GroupId) WorkerThread(androidx.annotation.WorkerThread) NonNull(androidx.annotation.NonNull)

Aggregations

BadGroupIdException (org.thoughtcrime.securesms.groups.BadGroupIdException)16 GroupId (org.thoughtcrime.securesms.groups.GroupId)10 Recipient (org.thoughtcrime.securesms.recipients.Recipient)10 NonNull (androidx.annotation.NonNull)6 ContentValues (android.content.ContentValues)2 Context (android.content.Context)2 TextView (android.widget.TextView)2 WorkerThread (androidx.annotation.WorkerThread)2 Toolbar (androidx.appcompat.widget.Toolbar)2 RecyclerView (androidx.recyclerview.widget.RecyclerView)2 InvalidInputException (org.signal.zkgroup.InvalidInputException)2 GroupMasterKey (org.signal.zkgroup.groups.GroupMasterKey)2 GroupDatabase (org.thoughtcrime.securesms.database.GroupDatabase)2 SyncMessageId (org.thoughtcrime.securesms.database.MessageDatabase.SyncMessageId)2 MessageId (org.thoughtcrime.securesms.database.model.MessageId)2 PendingRetryReceiptModel (org.thoughtcrime.securesms.database.model.PendingRetryReceiptModel)2 Data (org.thoughtcrime.securesms.jobmanager.Data)2 NetworkConstraint (org.thoughtcrime.securesms.jobmanager.impl.NetworkConstraint)2 RefreshAttributesJob (org.thoughtcrime.securesms.jobs.RefreshAttributesJob)2 SendRetryReceiptJob (org.thoughtcrime.securesms.jobs.SendRetryReceiptJob)2