mirror of
https://github.com/AsamK/signal-cli
synced 2025-08-29 18:40:39 +00:00
Refactor manager update profile method
This commit is contained in:
parent
7587a60387
commit
3666531f8b
8 changed files with 160 additions and 35 deletions
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -22,6 +22,7 @@ import org.asamk.signal.manager.api.StickerPackInvalidException;
|
|||
import org.asamk.signal.manager.api.StickerPackUrl;
|
||||
import org.asamk.signal.manager.api.TypingAction;
|
||||
import org.asamk.signal.manager.api.UpdateGroup;
|
||||
import org.asamk.signal.manager.api.UpdateProfile;
|
||||
import org.asamk.signal.manager.api.UserStatus;
|
||||
import org.asamk.signal.manager.groups.GroupId;
|
||||
import org.asamk.signal.manager.groups.GroupInviteLinkUrl;
|
||||
|
@ -138,19 +139,13 @@ public class DbusManagerImpl implements Manager {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void setProfile(
|
||||
final String givenName,
|
||||
final String familyName,
|
||||
final String about,
|
||||
final String aboutEmoji,
|
||||
final Optional<File> avatar
|
||||
) throws IOException {
|
||||
signal.updateProfile(emptyIfNull(givenName),
|
||||
emptyIfNull(familyName),
|
||||
emptyIfNull(about),
|
||||
emptyIfNull(aboutEmoji),
|
||||
avatar == null ? "" : avatar.map(File::getPath).orElse(""),
|
||||
avatar != null && avatar.isEmpty());
|
||||
public void updateProfile(UpdateProfile updateProfile) throws IOException {
|
||||
signal.updateProfile(emptyIfNull(updateProfile.getGivenName()),
|
||||
emptyIfNull(updateProfile.getFamilyName()),
|
||||
emptyIfNull(updateProfile.getAbout()),
|
||||
emptyIfNull(updateProfile.getAboutEmoji()),
|
||||
updateProfile.getAvatar() == null ? "" : updateProfile.getAvatar().getPath(),
|
||||
updateProfile.isDeleteAvatar());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -17,6 +17,7 @@ import org.asamk.signal.manager.api.StickerPackInvalidException;
|
|||
import org.asamk.signal.manager.api.TypingAction;
|
||||
import org.asamk.signal.manager.api.UnregisteredRecipientException;
|
||||
import org.asamk.signal.manager.api.UpdateGroup;
|
||||
import org.asamk.signal.manager.api.UpdateProfile;
|
||||
import org.asamk.signal.manager.api.UserStatus;
|
||||
import org.asamk.signal.manager.groups.GroupId;
|
||||
import org.asamk.signal.manager.groups.GroupInviteLinkUrl;
|
||||
|
@ -662,10 +663,15 @@ public class DbusSignalImpl implements Signal {
|
|||
about = nullIfEmpty(about);
|
||||
aboutEmoji = nullIfEmpty(aboutEmoji);
|
||||
avatarPath = nullIfEmpty(avatarPath);
|
||||
Optional<File> avatarFile = removeAvatar
|
||||
? Optional.empty()
|
||||
: avatarPath == null ? null : Optional.of(new File(avatarPath));
|
||||
m.setProfile(givenName, familyName, about, aboutEmoji, avatarFile);
|
||||
File avatarFile = removeAvatar || avatarPath == null ? null : new File(avatarPath);
|
||||
m.updateProfile(UpdateProfile.newBuilder()
|
||||
.withGivenName(givenName)
|
||||
.withFamilyName(familyName)
|
||||
.withAbout(about)
|
||||
.withAboutEmoji(aboutEmoji)
|
||||
.withAvatar(avatarFile)
|
||||
.withDeleteAvatar(removeAvatar)
|
||||
.build());
|
||||
} catch (IOException e) {
|
||||
throw new Error.Failure(e.getMessage());
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue