Fix some issues with avatar syncing.

- We weren't falling back to system avatars when no profile was present
- We weren't triggering a sync when the setting changed
This commit is contained in:
Greyson Parrelli 2021-05-12 17:08:13 -04:00
parent d8256013a3
commit 70db617229
2 changed files with 16 additions and 7 deletions

View file

@ -3,6 +3,8 @@ package org.thoughtcrime.securesms.components.settings.app.chats
import androidx.lifecycle.LiveData
import androidx.lifecycle.ViewModel
import androidx.lifecycle.ViewModelProvider
import org.thoughtcrime.securesms.dependencies.ApplicationDependencies
import org.thoughtcrime.securesms.jobs.MultiDeviceContactUpdateJob
import org.thoughtcrime.securesms.keyvalue.SignalStore
import org.thoughtcrime.securesms.storage.StorageSyncHelper
import org.thoughtcrime.securesms.util.ConversationUtil
@ -35,6 +37,7 @@ class ChatsSettingsViewModel(private val repository: ChatsSettingsRepository) :
store.update { it.copy(useAddressBook = enabled) }
SignalStore.settings().isPreferSystemContactPhotos = enabled
refreshDebouncer.publish { ConversationUtil.refreshRecipientShortcuts() }
ApplicationDependencies.getJobManager().add(MultiDeviceContactUpdateJob(true))
StorageSyncHelper.scheduleSyncForDataChange()
}

View file

@ -275,17 +275,23 @@ public class MultiDeviceContactUpdateJob extends BaseJob {
}
private Optional<SignalServiceAttachmentStream> getAvatar(@NonNull RecipientId recipientId, @Nullable Uri uri) {
Optional<SignalServiceAttachmentStream> avatarStream = Optional.absent();
Optional<SignalServiceAttachmentStream> stream;
if (SignalStore.settings().isPreferSystemContactPhotos()) {
avatarStream = getSystemAvatar(uri);
stream = getSystemAvatar(uri);
if (!stream.isPresent()) {
stream = getProfileAvatar(recipientId);
}
} else {
stream = getProfileAvatar(recipientId);
if (!stream.isPresent()) {
stream = getSystemAvatar(uri);
}
}
if (avatarStream.isPresent()) {
return avatarStream;
} else {
return getProfileAvatar(recipientId);
}
return stream;
}
private Optional<SignalServiceAttachmentStream> getProfileAvatar(@NonNull RecipientId recipientId) {