Search in sources :

Example 16 with BadGroupIdException

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

the class PushProcessMessageQueueJobMigration method migratePushProcessMessageJob.

@NonNull
private static JobData migratePushProcessMessageJob(@NonNull Context context, @NonNull JobData jobData) throws IOException {
    Data data = jobData.getData();
    String suffix = "";
    if (data.getInt("message_state") == 0) {
        SignalServiceContent content = SignalServiceContent.deserialize(Base64.decode(data.getString("message_content")));
        if (content != null && content.getDataMessage().isPresent() && content.getDataMessage().get().getGroupContext().isPresent()) {
            Log.i(TAG, "Migrating a group message.");
            try {
                GroupId groupId = GroupUtil.idFromGroupContext(content.getDataMessage().get().getGroupContext().get());
                Recipient recipient = Recipient.externalGroupExact(context, groupId);
                suffix = recipient.getId().toQueueKey();
            } catch (BadGroupIdException e) {
                Log.w(TAG, "Bad groupId! Using default queue.");
            }
        } else if (content != null) {
            Log.i(TAG, "Migrating an individual message.");
            suffix = RecipientId.from(content.getSender()).toQueueKey();
        }
    } else {
        Log.i(TAG, "Migrating an exception message.");
        String exceptionSender = data.getString("exception_sender");
        GroupId exceptionGroup = GroupId.parseNullableOrThrow(data.getStringOrDefault("exception_groupId", null));
        if (exceptionGroup != null) {
            suffix = Recipient.externalGroupExact(context, exceptionGroup).getId().toQueueKey();
        } else if (exceptionSender != null) {
            suffix = Recipient.external(context, exceptionSender).getId().toQueueKey();
        }
    }
    return jobData.withQueueKey("__PUSH_PROCESS_JOB__" + suffix);
}
Also used : SignalServiceContent(org.whispersystems.signalservice.api.messages.SignalServiceContent) Data(org.thoughtcrime.securesms.jobmanager.Data) Recipient(org.thoughtcrime.securesms.recipients.Recipient) BadGroupIdException(org.thoughtcrime.securesms.groups.BadGroupIdException) GroupId(org.thoughtcrime.securesms.groups.GroupId) 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