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

View file

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

View file

@ -9,8 +9,10 @@ import org.asamk.signal.commands.exceptions.IOErrorException;
import org.asamk.signal.commands.exceptions.UserErrorException; import org.asamk.signal.commands.exceptions.UserErrorException;
import org.asamk.signal.manager.Manager; import org.asamk.signal.manager.Manager;
import org.asamk.signal.manager.NotMasterDeviceException; import org.asamk.signal.manager.NotMasterDeviceException;
import org.asamk.signal.manager.api.Configuration;
import java.io.IOException; import java.io.IOException;
import java.util.Optional;
public class UpdateConfigurationCommand implements JsonRpcLocalCommand { public class UpdateConfigurationCommand implements JsonRpcLocalCommand {
@ -45,7 +47,10 @@ public class UpdateConfigurationCommand implements JsonRpcLocalCommand {
final var typingIndicators = ns.getBoolean("typing-indicators"); final var typingIndicators = ns.getBoolean("typing-indicators");
final var linkPreviews = ns.getBoolean("link-previews"); final var linkPreviews = ns.getBoolean("link-previews");
try { try {
m.updateConfiguration(readReceipts, unidentifiedDeliveryIndicators, typingIndicators, linkPreviews); m.updateConfiguration(new Configuration(Optional.ofNullable(readReceipts),
Optional.ofNullable(unidentifiedDeliveryIndicators),
Optional.ofNullable(typingIndicators),
Optional.ofNullable(linkPreviews)));
} catch (IOException e) { } catch (IOException e) {
throw new IOErrorException("UpdateAccount error: " + e.getMessage(), e); throw new IOErrorException("UpdateAccount error: " + e.getMessage(), e);
} catch (NotMasterDeviceException e) { } catch (NotMasterDeviceException e) {

View file

@ -7,6 +7,7 @@ import org.asamk.signal.manager.Manager;
import org.asamk.signal.manager.NotMasterDeviceException; import org.asamk.signal.manager.NotMasterDeviceException;
import org.asamk.signal.manager.StickerPackInvalidException; import org.asamk.signal.manager.StickerPackInvalidException;
import org.asamk.signal.manager.UntrustedIdentityException; import org.asamk.signal.manager.UntrustedIdentityException;
import org.asamk.signal.manager.api.Configuration;
import org.asamk.signal.manager.api.Device; import org.asamk.signal.manager.api.Device;
import org.asamk.signal.manager.api.Group; import org.asamk.signal.manager.api.Group;
import org.asamk.signal.manager.api.Identity; import org.asamk.signal.manager.api.Identity;
@ -106,12 +107,12 @@ public class DbusManagerImpl implements Manager {
} }
@Override @Override
public void updateConfiguration( public Configuration getConfiguration() {
final Boolean readReceipts, throw new UnsupportedOperationException();
final Boolean unidentifiedDeliveryIndicators, }
final Boolean typingIndicators,
final Boolean linkPreviews @Override
) throws IOException { public void updateConfiguration(Configuration configuration) throws IOException {
throw new UnsupportedOperationException(); throw new UnsupportedOperationException();
} }