Implement getConfiguration method in Manager

This commit is contained in:
AsamK 2021-11-07 10:38:26 +01:00
parent a20bbe1246
commit e22cc457ae
5 changed files with 46 additions and 25 deletions

View file

@ -1,5 +1,6 @@
package org.asamk.signal.manager;
import org.asamk.signal.manager.api.Configuration;
import org.asamk.signal.manager.api.Device;
import org.asamk.signal.manager.api.Group;
import org.asamk.signal.manager.api.Identity;
@ -99,12 +100,9 @@ public interface Manager extends Closeable {
void updateAccountAttributes(String deviceName) throws IOException;
void updateConfiguration(
final Boolean readReceipts,
final Boolean unidentifiedDeliveryIndicators,
final Boolean typingIndicators,
final Boolean linkPreviews
) throws IOException, NotMasterDeviceException;
Configuration getConfiguration();
void updateConfiguration(Configuration configuration) throws IOException, NotMasterDeviceException;
void setProfile(
String givenName, String familyName, String about, String aboutEmoji, Optional<File> avatar

View file

@ -17,6 +17,7 @@
package org.asamk.signal.manager;
import org.asamk.signal.manager.actions.HandleAction;
import org.asamk.signal.manager.api.Configuration;
import org.asamk.signal.manager.api.Device;
import org.asamk.signal.manager.api.Group;
import org.asamk.signal.manager.api.Identity;
@ -322,29 +323,35 @@ public class ManagerImpl implements Manager {
account.isDiscoverableByPhoneNumber());
}
@Override
public Configuration getConfiguration() {
final var configurationStore = account.getConfigurationStore();
return new Configuration(java.util.Optional.ofNullable(configurationStore.getReadReceipts()),
java.util.Optional.ofNullable(configurationStore.getUnidentifiedDeliveryIndicators()),
java.util.Optional.ofNullable(configurationStore.getTypingIndicators()),
java.util.Optional.ofNullable(configurationStore.getLinkPreviews()));
}
@Override
public void updateConfiguration(
final Boolean readReceipts,
final Boolean unidentifiedDeliveryIndicators,
final Boolean typingIndicators,
final Boolean linkPreviews
Configuration configuration
) throws IOException, NotMasterDeviceException {
if (!account.isMasterDevice()) {
throw new NotMasterDeviceException();
}
final var configurationStore = account.getConfigurationStore();
if (readReceipts != null) {
configurationStore.setReadReceipts(readReceipts);
if (configuration.readReceipts().isPresent()) {
configurationStore.setReadReceipts(configuration.readReceipts().get());
}
if (unidentifiedDeliveryIndicators != null) {
configurationStore.setUnidentifiedDeliveryIndicators(unidentifiedDeliveryIndicators);
if (configuration.unidentifiedDeliveryIndicators().isPresent()) {
configurationStore.setUnidentifiedDeliveryIndicators(configuration.unidentifiedDeliveryIndicators().get());
}
if (typingIndicators != null) {
configurationStore.setTypingIndicators(typingIndicators);
if (configuration.typingIndicators().isPresent()) {
configurationStore.setTypingIndicators(configuration.typingIndicators().get());
}
if (linkPreviews != null) {
configurationStore.setLinkPreviews(linkPreviews);
if (configuration.linkPreviews().isPresent()) {
configurationStore.setLinkPreviews(configuration.linkPreviews().get());
}
syncHelper.sendConfigurationMessage();
}

View file

@ -0,0 +1,10 @@
package org.asamk.signal.manager.api;
import java.util.Optional;
public record Configuration(
Optional<Boolean> readReceipts,
Optional<Boolean> unidentifiedDeliveryIndicators,
Optional<Boolean> typingIndicators,
Optional<Boolean> linkPreviews
) {}