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);
}
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();
}
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);
}
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();
}
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();
}
Aggregations