]> nmode's Git Repositories - signal-cli/blobdiff - lib/src/main/java/org/asamk/signal/manager/helper/PreKeyHelper.java
Refresh pre keys for PNI identity
[signal-cli] / lib / src / main / java / org / asamk / signal / manager / helper / PreKeyHelper.java
index 52e443dad39e9491bb1fd11172b6e9183ea4406f..ea5ccdabd1545f04a80132fdd734174639c24aca 100644 (file)
@@ -45,32 +45,31 @@ public class PreKeyHelper {
     }
 
     public void refreshPreKeys(ServiceIdType serviceIdType) throws IOException {
-        if (serviceIdType != ServiceIdType.ACI) {
-            // TODO implement
+        final var oneTimePreKeys = generatePreKeys(serviceIdType);
+        final var identityKeyPair = account.getIdentityKeyPair(serviceIdType);
+        if (identityKeyPair == null) {
             return;
         }
-        var oneTimePreKeys = generatePreKeys();
-        final var identityKeyPair = account.getAciIdentityKeyPair();
-        var signedPreKeyRecord = generateSignedPreKey(identityKeyPair);
+        final var signedPreKeyRecord = generateSignedPreKey(serviceIdType, identityKeyPair);
 
         dependencies.getAccountManager()
                 .setPreKeys(serviceIdType, identityKeyPair.getPublicKey(), signedPreKeyRecord, oneTimePreKeys);
     }
 
-    private List<PreKeyRecord> generatePreKeys() {
-        final var offset = account.getPreKeyIdOffset();
+    private List<PreKeyRecord> generatePreKeys(ServiceIdType serviceIdType) {
+        final var offset = account.getPreKeyIdOffset(serviceIdType);
 
         var records = KeyUtils.generatePreKeyRecords(offset, ServiceConfig.PREKEY_BATCH_SIZE);
-        account.addPreKeys(records);
+        account.addPreKeys(serviceIdType, records);
 
         return records;
     }
 
-    private SignedPreKeyRecord generateSignedPreKey(IdentityKeyPair identityKeyPair) {
-        final var signedPreKeyId = account.getNextSignedPreKeyId();
+    private SignedPreKeyRecord generateSignedPreKey(ServiceIdType serviceIdType, IdentityKeyPair identityKeyPair) {
+        final var signedPreKeyId = account.getNextSignedPreKeyId(serviceIdType);
 
         var record = KeyUtils.generateSignedPreKeyRecord(identityKeyPair, signedPreKeyId);
-        account.addSignedPreKey(record);
+        account.addSignedPreKey(serviceIdType, record);
 
         return record;
     }