Skip to content

Commit

Permalink
Add additional account restore logging, prevent double avatar fetch.
Browse files Browse the repository at this point in the history
  • Loading branch information
greyson-signal committed May 29, 2020
1 parent 67a8ec0 commit 9d39db6
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 6 deletions.
@@ -1,11 +1,14 @@
package org.thoughtcrime.securesms.jobs;

import android.app.job.JobScheduler;

import androidx.annotation.NonNull;

import org.thoughtcrime.securesms.dependencies.ApplicationDependencies;
import org.thoughtcrime.securesms.jobmanager.Data;
import org.thoughtcrime.securesms.jobmanager.Job;
import org.thoughtcrime.securesms.jobmanager.JobManager;
import org.thoughtcrime.securesms.jobmanager.JobTracker;
import org.thoughtcrime.securesms.jobmanager.impl.NetworkConstraint;
import org.thoughtcrime.securesms.keyvalue.SignalStore;
import org.thoughtcrime.securesms.logging.Log;
Expand Down Expand Up @@ -67,6 +70,7 @@ protected void onRun() throws Exception {
SignalServiceAccountManager accountManager = ApplicationDependencies.getSignalServiceAccountManager();
StorageKey storageServiceKey = SignalStore.storageServiceValues().getOrCreateStorageKey();

Log.i(TAG, "Retrieving manifest...");
Optional<SignalStorageManifest> manifest = accountManager.getStorageManifest(storageServiceKey);

if (!manifest.isPresent()) {
Expand All @@ -82,6 +86,7 @@ protected void onRun() throws Exception {
return;
}

Log.i(TAG, "Retrieving account record...");
List<SignalStorageRecord> records = accountManager.readStorageRecords(storageServiceKey, Collections.singletonList(accountId.get()));
SignalStorageRecord record = records.size() > 0 ? records.get(0) : null;

Expand All @@ -96,16 +101,34 @@ protected void onRun() throws Exception {
return;
}


Log.i(TAG, "Applying changes locally...");
StorageId selfStorageId = StorageId.forAccount(Recipient.self().getStorageServiceId());
StorageSyncHelper.applyAccountStorageSyncUpdates(context, selfStorageId, accountRecord);
StorageSyncHelper.applyAccountStorageSyncUpdates(context, selfStorageId, accountRecord, false);

JobManager jobManager = ApplicationDependencies.getJobManager();

if (accountRecord.getAvatarUrlPath().isPresent()) {
jobManager.runSynchronously(new RetrieveProfileAvatarJob(Recipient.self(), accountRecord.getAvatarUrlPath().get()), LIFESPAN/2);
Log.i(TAG, "Fetching avatar...");
Optional<JobTracker.JobState> state = jobManager.runSynchronously(new RetrieveProfileAvatarJob(Recipient.self(), accountRecord.getAvatarUrlPath().get()), LIFESPAN/2);

if (state.isPresent()) {
Log.i(TAG, "Avatar retrieved successfully. " + state.get());
} else {
Log.w(TAG, "Avatar retrieval did not complete in time (or otherwise failed).");
}
} else {
Log.i(TAG, "No avatar present. Not fetching.");
}

jobManager.runSynchronously(new RefreshAttributesJob(), LIFESPAN/2);
Log.i(TAG, "Refreshing attributes...");
Optional<JobTracker.JobState> state = jobManager.runSynchronously(new RefreshAttributesJob(), LIFESPAN/2);

if (state.isPresent()) {
Log.i(TAG, "Attributes refreshed successfully. " + state.get());
} else {
Log.w(TAG, "Attribute refresh did not complete in time (or otherwise failed).");
}
}

@Override
Expand Down
Expand Up @@ -404,18 +404,19 @@ public static void applyAccountStorageSyncUpdates(@NonNull Context context, Opti
if (!update.isPresent()) {
return;
}
applyAccountStorageSyncUpdates(context, update.get().getOld().getId(), update.get().getNew());
applyAccountStorageSyncUpdates(context, update.get().getOld().getId(), update.get().getNew(), true);
}

public static void applyAccountStorageSyncUpdates(@NonNull Context context, @NonNull StorageId storageId, @NonNull SignalAccountRecord update) {
public static void applyAccountStorageSyncUpdates(@NonNull Context context, @NonNull StorageId storageId, @NonNull SignalAccountRecord update, boolean fetchProfile) {
DatabaseFactory.getRecipientDatabase(context).applyStorageSyncUpdates(storageId, update);
DatabaseFactory.getThreadDatabase(context).setArchived(Recipient.self().getId(), update.isNoteToSelfArchived());

TextSecurePreferences.setReadReceiptsEnabled(context, update.isReadReceiptsEnabled());
TextSecurePreferences.setTypingIndicatorsEnabled(context, update.isTypingIndicatorsEnabled());
TextSecurePreferences.setShowUnidentifiedDeliveryIndicatorsEnabled(context, update.isSealedSenderIndicatorsEnabled());
TextSecurePreferences.setLinkPreviewsEnabled(context, update.isLinkPreviewsEnabled());
if (update.getAvatarUrlPath().isPresent()) {

if (fetchProfile && update.getAvatarUrlPath().isPresent()) {
ApplicationDependencies.getJobManager().add(new RetrieveProfileAvatarJob(Recipient.self(), update.getAvatarUrlPath().get()));
}
}
Expand Down

0 comments on commit 9d39db6

Please sign in to comment.