X-Git-Url: https://git.nmode.ca/signal-cli/blobdiff_plain/7d802fb8c5152c5fc089052e5915c7f588057e53..23df85ff909bd1bc8088c429ffd63ea3af6591c6:/lib/src/main/java/org/asamk/signal/manager/Manager.java diff --git a/lib/src/main/java/org/asamk/signal/manager/Manager.java b/lib/src/main/java/org/asamk/signal/manager/Manager.java index 11ee137d..cb28c45b 100644 --- a/lib/src/main/java/org/asamk/signal/manager/Manager.java +++ b/lib/src/main/java/org/asamk/signal/manager/Manager.java @@ -167,6 +167,7 @@ import java.util.Map; import java.util.Set; import java.util.UUID; import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeoutException; import java.util.stream.Collectors; @@ -189,6 +190,8 @@ public class Manager implements Closeable { private final SignalServiceMessageReceiver messageReceiver; private final ClientZkProfileOperations clientZkProfileOperations; + private final ExecutorService executor = Executors.newCachedThreadPool(); + private SignalServiceMessagePipe messagePipe = null; private SignalServiceMessagePipe unidentifiedMessagePipe = null; @@ -362,22 +365,33 @@ public class Manager implements Closeable { } /** - * @param avatar if avatar is null the image from the local avatar store is used (if present), - * if it's Optional.absent(), the avatar will be removed + * @param name if null, the previous name will be kept + * @param about if null, the previous about text will be kept + * @param aboutEmoji if null, the previous about emoji will be kept + * @param avatar if avatar is null the image from the local avatar store is used (if present), + * if it's Optional.absent(), the avatar will be removed */ - public void setProfile(String name, Optional avatar) throws IOException { - // TODO - String about = null; - String aboutEmoji = null; + public void setProfile(String name, String about, String aboutEmoji, Optional avatar) throws IOException { + SignalProfileEntry profileEntry = account.getProfileStore().getProfileEntry(getSelfAddress()); + SignalProfile profile = profileEntry == null ? null : profileEntry.getProfile(); + SignalProfile newProfile = new SignalProfile(profile == null ? null : profile.getIdentityKey(), + name != null ? name : profile == null || profile.getName() == null ? "" : profile.getName(), + about != null ? about : profile == null || profile.getAbout() == null ? "" : profile.getAbout(), + aboutEmoji != null + ? aboutEmoji + : profile == null || profile.getAboutEmoji() == null ? "" : profile.getAboutEmoji(), + profile == null ? null : profile.getUnidentifiedAccess(), + account.isUnrestrictedUnidentifiedAccess(), + profile == null ? null : profile.getCapabilities()); try (final StreamDetails streamDetails = avatar == null ? avatarStore.retrieveProfileAvatar(getSelfAddress()) : avatar.isPresent() ? Utils.createStreamDetailsFromFile(avatar.get()) : null) { accountManager.setVersionedProfile(account.getUuid(), account.getProfileKey(), - name, - about, - aboutEmoji, + newProfile.getName(), + newProfile.getAbout(), + newProfile.getAboutEmoji(), streamDetails); } @@ -389,6 +403,12 @@ public class Manager implements Closeable { avatarStore.deleteProfileAvatar(getSelfAddress()); } } + account.getProfileStore() + .updateProfile(getSelfAddress(), + account.getProfileKey(), + System.currentTimeMillis(), + newProfile, + profileEntry == null ? null : profileEntry.getProfileKeyCredential()); try { sendSyncMessage(SignalServiceSyncMessage.forFetchLatest(SignalServiceSyncMessage.FetchType.LOCAL_PROFILE)); @@ -509,7 +529,6 @@ public class Manager implements Closeable { } private SignalServiceMessageSender createMessageSender() { - final ExecutorService executor = null; return new SignalServiceMessageSender(serviceEnvironmentConfig.getSignalServiceConfiguration(), account.getUuid(), account.getUsername(), @@ -2516,6 +2535,8 @@ public class Manager implements Closeable { } void close(boolean closeAccount) throws IOException { + executor.shutdown(); + if (messagePipe != null) { messagePipe.shutdown(); messagePipe = null;