Refactor manager update profile method

This commit is contained in:
AsamK 2022-05-21 09:29:58 +02:00
parent 7587a60387
commit 3666531f8b
8 changed files with 160 additions and 35 deletions

View file

@ -7,11 +7,11 @@ import net.sourceforge.argparse4j.inf.Subparser;
import org.asamk.signal.commands.exceptions.CommandException;
import org.asamk.signal.commands.exceptions.IOErrorException;
import org.asamk.signal.manager.Manager;
import org.asamk.signal.manager.api.UpdateProfile;
import org.asamk.signal.output.OutputWriter;
import java.io.File;
import java.io.IOException;
import java.util.Optional;
public class UpdateProfileCommand implements JsonRpcLocalCommand {
@ -44,12 +44,17 @@ public class UpdateProfileCommand implements JsonRpcLocalCommand {
var avatarPath = ns.getString("avatar");
boolean removeAvatar = Boolean.TRUE.equals(ns.getBoolean("remove-avatar"));
Optional<File> avatarFile = removeAvatar
? Optional.empty()
: avatarPath == null ? null : Optional.of(new File(avatarPath));
File avatarFile = removeAvatar || avatarPath == null ? null : new File(avatarPath);
try {
m.setProfile(givenName, familyName, about, aboutEmoji, avatarFile);
m.updateProfile(UpdateProfile.newBuilder()
.withGivenName(givenName)
.withFamilyName(familyName)
.withAbout(about)
.withAboutEmoji(aboutEmoji)
.withAvatar(avatarFile)
.withDeleteAvatar(removeAvatar)
.build());
} catch (IOException e) {
throw new IOErrorException("Update profile error: " + e.getMessage(), e);
}