import org.asamk.signal.manager.helper.AccountFileUpdater;
import org.asamk.signal.manager.helper.Context;
import org.asamk.signal.manager.helper.RecipientHelper.RegisteredUser;
+import org.asamk.signal.manager.jobs.SyncStorageJob;
import org.asamk.signal.manager.storage.AttachmentStore;
import org.asamk.signal.manager.storage.AvatarStore;
import org.asamk.signal.manager.storage.SignalAccount;
import java.util.stream.Stream;
import io.reactivex.rxjava3.disposables.CompositeDisposable;
+import io.reactivex.rxjava3.schedulers.Schedulers;
public class ManagerImpl implements Manager {
this.notifyAll();
}
});
- disposable.add(account.getIdentityKeyStore().getIdentityChanges().subscribe(serviceId -> {
- logger.trace("Archiving old sessions for {}", serviceId);
- account.getAccountData(ServiceIdType.ACI).getSessionStore().archiveSessions(serviceId);
- account.getAccountData(ServiceIdType.PNI).getSessionStore().archiveSessions(serviceId);
- account.getSenderKeyStore().deleteSharedWith(serviceId);
- final var recipientId = account.getRecipientResolver().resolveRecipient(serviceId);
- final var profile = account.getProfileStore().getProfile(recipientId);
- if (profile != null) {
- account.getProfileStore()
- .storeProfile(recipientId,
- Profile.newBuilder(profile)
- .withUnidentifiedAccessMode(Profile.UnidentifiedAccessMode.UNKNOWN)
- .withLastUpdateTimestamp(0)
- .build());
- }
- }));
+ disposable.add(account.getIdentityKeyStore()
+ .getIdentityChanges()
+ .observeOn(Schedulers.from(executor))
+ .subscribe(serviceId -> {
+ logger.trace("Archiving old sessions for {}", serviceId);
+ account.getAccountData(ServiceIdType.ACI).getSessionStore().archiveSessions(serviceId);
+ account.getAccountData(ServiceIdType.PNI).getSessionStore().archiveSessions(serviceId);
+ account.getSenderKeyStore().deleteSharedWith(serviceId);
+ final var recipientId = account.getRecipientResolver().resolveRecipient(serviceId);
+ final var profile = account.getProfileStore().getProfile(recipientId);
+ if (profile != null) {
+ account.getProfileStore()
+ .storeProfile(recipientId,
+ Profile.newBuilder(profile)
+ .withUnidentifiedAccessMode(Profile.UnidentifiedAccessMode.UNKNOWN)
+ .withLastUpdateTimestamp(0)
+ .build());
+ }
+ }));
}
@Override
}
@Override
- public void updateConfiguration(
- Configuration configuration
- ) throws NotPrimaryDeviceException {
- if (!account.isPrimaryDevice()) {
- throw new NotPrimaryDeviceException();
- }
-
+ public void updateConfiguration(Configuration configuration) {
final var configurationStore = account.getConfigurationStore();
if (configuration.readReceipts().isPresent()) {
configurationStore.setReadReceipts(configuration.readReceipts().get());
configurationStore.setLinkPreviews(configuration.linkPreviews().get());
}
context.getSyncHelper().sendConfigurationMessage();
+ syncRemoteStorage();
}
@Override
if (recipientIdOptional.isPresent()) {
context.getContactHelper().setContactHidden(recipientIdOptional.get(), true);
account.removeRecipient(recipientIdOptional.get());
+ syncRemoteStorage();
}
}
final var recipientIdOptional = context.getRecipientHelper().resolveRecipientOptional(recipient);
if (recipientIdOptional.isPresent()) {
account.removeRecipient(recipientIdOptional.get());
+ syncRemoteStorage();
}
}
final var recipientIdOptional = context.getRecipientHelper().resolveRecipientOptional(recipient);
if (recipientIdOptional.isPresent()) {
account.getContactStore().deleteContact(recipientIdOptional.get());
+ syncRemoteStorage();
}
}
}
context.getContactHelper()
.setContactName(context.getRecipientHelper().resolveRecipient(recipient), givenName, familyName);
+ syncRemoteStorage();
}
@Override
public void setContactsBlocked(
Collection<RecipientIdentifier.Single> recipients, boolean blocked
- ) throws NotPrimaryDeviceException, IOException, UnregisteredRecipientException {
- if (!account.isPrimaryDevice()) {
- throw new NotPrimaryDeviceException();
- }
+ ) throws IOException, UnregisteredRecipientException {
if (recipients.isEmpty()) {
return;
}
context.getProfileHelper().rotateProfileKey();
}
context.getSyncHelper().sendBlockedList();
+ syncRemoteStorage();
}
@Override
public void setGroupsBlocked(
final Collection<GroupId> groupIds, final boolean blocked
- ) throws GroupNotFoundException, NotPrimaryDeviceException, IOException {
- if (!account.isPrimaryDevice()) {
- throw new NotPrimaryDeviceException();
- }
+ ) throws GroupNotFoundException, IOException {
if (groupIds.isEmpty()) {
return;
}
context.getProfileHelper().rotateProfileKey();
}
context.getSyncHelper().sendBlockedList();
+ syncRemoteStorage();
}
@Override
} catch (NotAGroupMemberException | GroupNotFoundException | GroupSendingNotAllowedException e) {
throw new AssertionError(e);
}
+ syncRemoteStorage();
}
@Override
}
@Override
- public void requestAllSyncData() throws IOException {
+ public void requestAllSyncData() {
context.getSyncHelper().requestAllSyncData();
- retrieveRemoteStorage();
+ syncRemoteStorage();
}
- void retrieveRemoteStorage() throws IOException {
- context.getStorageHelper().readDataFromStorage();
+ void syncRemoteStorage() {
+ context.getJobExecutor().enqueueJob(new SyncStorageJob());
}
@Override