Search in sources :

Example 6 with MultiDeviceProfileContentUpdateJob

use of org.thoughtcrime.securesms.jobs.MultiDeviceProfileContentUpdateJob in project Signal-Android by signalapp.

the class EditSelfProfileRepository method uploadProfile.

@Override
public void uploadProfile(@NonNull ProfileName profileName, @NonNull String displayName, boolean displayNameChanged, @NonNull String description, boolean descriptionChanged, @Nullable byte[] avatar, boolean avatarChanged, @NonNull Consumer<UploadResult> uploadResultConsumer) {
    SimpleTask.run(() -> {
        SignalDatabase.recipients().setProfileName(Recipient.self().getId(), profileName);
        if (avatarChanged) {
            try {
                AvatarHelper.setAvatar(context, Recipient.self().getId(), avatar != null ? new ByteArrayInputStream(avatar) : null);
            } catch (IOException e) {
                return UploadResult.ERROR_IO;
            }
        }
        ApplicationDependencies.getJobManager().startChain(new ProfileUploadJob()).then(Arrays.asList(new MultiDeviceProfileKeyUpdateJob(), new MultiDeviceProfileContentUpdateJob())).enqueue();
        RegistrationUtil.maybeMarkRegistrationComplete(context);
        if (avatar != null) {
            SignalStore.misc().markHasEverHadAnAvatar();
        }
        return UploadResult.SUCCESS;
    }, uploadResultConsumer::accept);
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) MultiDeviceProfileKeyUpdateJob(org.thoughtcrime.securesms.jobs.MultiDeviceProfileKeyUpdateJob) IOException(java.io.IOException) ProfileUploadJob(org.thoughtcrime.securesms.jobs.ProfileUploadJob) MultiDeviceProfileContentUpdateJob(org.thoughtcrime.securesms.jobs.MultiDeviceProfileContentUpdateJob)

Example 7 with MultiDeviceProfileContentUpdateJob

use of org.thoughtcrime.securesms.jobs.MultiDeviceProfileContentUpdateJob in project Signal-Android by signalapp.

the class RegistrationCompleteFragment method onViewCreated.

@Override
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
    super.onViewCreated(view, savedInstanceState);
    FragmentActivity activity = requireActivity();
    RegistrationViewModel viewModel = new ViewModelProvider(activity).get(RegistrationViewModel.class);
    if (SignalStore.storageService().needsAccountRestore()) {
        Log.i(TAG, "Performing pin restore");
        activity.startActivity(new Intent(activity, PinRestoreActivity.class));
    } else if (!viewModel.isReregister()) {
        boolean needsProfile = Recipient.self().getProfileName().isEmpty() || !AvatarHelper.hasAvatar(activity, Recipient.self().getId());
        boolean needsPin = !SignalStore.kbsValues().hasPin();
        Log.i(TAG, "Pin restore flow not required." + " profile name: " + Recipient.self().getProfileName().isEmpty() + " profile avatar: " + !AvatarHelper.hasAvatar(activity, Recipient.self().getId()) + " needsPin:" + needsPin);
        Intent startIntent = MainActivity.clearTop(activity);
        if (needsPin) {
            startIntent = chainIntents(CreateKbsPinActivity.getIntentForPinCreate(requireContext()), startIntent);
        }
        if (needsProfile) {
            startIntent = chainIntents(EditProfileActivity.getIntentForUserProfile(activity), startIntent);
        }
        if (!needsProfile && !needsPin) {
            ApplicationDependencies.getJobManager().startChain(new ProfileUploadJob()).then(Arrays.asList(new MultiDeviceProfileKeyUpdateJob(), new MultiDeviceProfileContentUpdateJob())).enqueue();
            RegistrationUtil.maybeMarkRegistrationComplete(requireContext());
        }
        activity.startActivity(startIntent);
    }
    activity.finish();
    ActivityNavigator.applyPopAnimationsToPendingTransition(activity);
}
Also used : FragmentActivity(androidx.fragment.app.FragmentActivity) Intent(android.content.Intent) MultiDeviceProfileKeyUpdateJob(org.thoughtcrime.securesms.jobs.MultiDeviceProfileKeyUpdateJob) ProfileUploadJob(org.thoughtcrime.securesms.jobs.ProfileUploadJob) MultiDeviceProfileContentUpdateJob(org.thoughtcrime.securesms.jobs.MultiDeviceProfileContentUpdateJob) RegistrationViewModel(org.thoughtcrime.securesms.registration.viewmodel.RegistrationViewModel) ViewModelProvider(androidx.lifecycle.ViewModelProvider) PinRestoreActivity(org.thoughtcrime.securesms.pin.PinRestoreActivity)

Example 8 with MultiDeviceProfileContentUpdateJob

use of org.thoughtcrime.securesms.jobs.MultiDeviceProfileContentUpdateJob in project Signal-Android by WhisperSystems.

the class EditSelfProfileRepository method uploadProfile.

@Override
public void uploadProfile(@NonNull ProfileName profileName, @NonNull String displayName, boolean displayNameChanged, @NonNull String description, boolean descriptionChanged, @Nullable byte[] avatar, boolean avatarChanged, @NonNull Consumer<UploadResult> uploadResultConsumer) {
    SimpleTask.run(() -> {
        SignalDatabase.recipients().setProfileName(Recipient.self().getId(), profileName);
        if (avatarChanged) {
            try {
                AvatarHelper.setAvatar(context, Recipient.self().getId(), avatar != null ? new ByteArrayInputStream(avatar) : null);
            } catch (IOException e) {
                return UploadResult.ERROR_IO;
            }
        }
        ApplicationDependencies.getJobManager().startChain(new ProfileUploadJob()).then(Arrays.asList(new MultiDeviceProfileKeyUpdateJob(), new MultiDeviceProfileContentUpdateJob())).enqueue();
        RegistrationUtil.maybeMarkRegistrationComplete(context);
        if (avatar != null) {
            SignalStore.misc().markHasEverHadAnAvatar();
        }
        return UploadResult.SUCCESS;
    }, uploadResultConsumer::accept);
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) MultiDeviceProfileKeyUpdateJob(org.thoughtcrime.securesms.jobs.MultiDeviceProfileKeyUpdateJob) IOException(java.io.IOException) ProfileUploadJob(org.thoughtcrime.securesms.jobs.ProfileUploadJob) MultiDeviceProfileContentUpdateJob(org.thoughtcrime.securesms.jobs.MultiDeviceProfileContentUpdateJob)

Example 9 with MultiDeviceProfileContentUpdateJob

use of org.thoughtcrime.securesms.jobs.MultiDeviceProfileContentUpdateJob in project Signal-Android by WhisperSystems.

the class ManageProfileRepository method setAvatar.

public void setAvatar(@NonNull Context context, @NonNull byte[] data, @NonNull String contentType, @NonNull Consumer<Result> callback) {
    SignalExecutors.UNBOUNDED.execute(() -> {
        try {
            ProfileUtil.uploadProfileWithAvatar(context, new StreamDetails(new ByteArrayInputStream(data), contentType, data.length));
            AvatarHelper.setAvatar(context, Recipient.self().getId(), new ByteArrayInputStream(data));
            SignalStore.misc().markHasEverHadAnAvatar();
            ApplicationDependencies.getJobManager().add(new MultiDeviceProfileContentUpdateJob());
            callback.accept(Result.SUCCESS);
        } catch (IOException e) {
            Log.w(TAG, "Failed to upload profile during avatar change.", e);
            callback.accept(Result.FAILURE_NETWORK);
        }
    });
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) StreamDetails(org.whispersystems.signalservice.api.util.StreamDetails) IOException(java.io.IOException) MultiDeviceProfileContentUpdateJob(org.thoughtcrime.securesms.jobs.MultiDeviceProfileContentUpdateJob)

Example 10 with MultiDeviceProfileContentUpdateJob

use of org.thoughtcrime.securesms.jobs.MultiDeviceProfileContentUpdateJob in project Signal-Android by WhisperSystems.

the class ManageProfileRepository method setName.

public void setName(@NonNull Context context, @NonNull ProfileName profileName, @NonNull Consumer<Result> callback) {
    SignalExecutors.UNBOUNDED.execute(() -> {
        try {
            ProfileUtil.uploadProfileWithName(context, profileName);
            SignalDatabase.recipients().setProfileName(Recipient.self().getId(), profileName);
            ApplicationDependencies.getJobManager().add(new MultiDeviceProfileContentUpdateJob());
            callback.accept(Result.SUCCESS);
        } catch (IOException e) {
            Log.w(TAG, "Failed to upload profile during name change.", e);
            callback.accept(Result.FAILURE_NETWORK);
        }
    });
}
Also used : IOException(java.io.IOException) MultiDeviceProfileContentUpdateJob(org.thoughtcrime.securesms.jobs.MultiDeviceProfileContentUpdateJob)

Aggregations

MultiDeviceProfileContentUpdateJob (org.thoughtcrime.securesms.jobs.MultiDeviceProfileContentUpdateJob)12 IOException (java.io.IOException)10 ByteArrayInputStream (java.io.ByteArrayInputStream)4 MultiDeviceProfileKeyUpdateJob (org.thoughtcrime.securesms.jobs.MultiDeviceProfileKeyUpdateJob)4 ProfileUploadJob (org.thoughtcrime.securesms.jobs.ProfileUploadJob)4 Intent (android.content.Intent)2 FragmentActivity (androidx.fragment.app.FragmentActivity)2 ViewModelProvider (androidx.lifecycle.ViewModelProvider)2 PinRestoreActivity (org.thoughtcrime.securesms.pin.PinRestoreActivity)2 RegistrationViewModel (org.thoughtcrime.securesms.registration.viewmodel.RegistrationViewModel)2 StreamDetails (org.whispersystems.signalservice.api.util.StreamDetails)2