]> nmode's Git Repositories - signal-cli/blobdiff - lib/src/main/java/org/asamk/signal/manager/Manager.java
Proposal for the Manager class to manage an ExecutorService for all SignalServiceMess...
[signal-cli] / lib / src / main / java / org / asamk / signal / manager / Manager.java
index 11ee137d9fa0be905e761d907233e46beef52a50..cb28c45b6b2b0bcadeef5cae3f47580e263e67e0 100644 (file)
@@ -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<File> avatar) throws IOException {
-        // TODO
-        String about = null;
-        String aboutEmoji = null;
+    public void setProfile(String name, String about, String aboutEmoji, Optional<File> 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;