mirror of
https://github.com/vanitasvitae/Smack.git
synced 2024-06-17 08:54:49 +02:00
Postpone prekey deletion
This commit is contained in:
parent
0cd3318b12
commit
45574e6bbb
|
@ -143,7 +143,7 @@ public class SignalOmemoStoreConnector
|
|||
|
||||
@Override
|
||||
public void removePreKey(int i) {
|
||||
omemoStore.removeOmemoPreKey(getOurDevice(), i);
|
||||
omemoStore.removeOrQueueOmemoPreKey(getOurDevice(), i);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -20,7 +20,9 @@ import static org.jivesoftware.smackx.omemo.util.OmemoConstants.PRE_KEY_COUNT_PE
|
|||
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.SortedSet;
|
||||
import java.util.TreeMap;
|
||||
import java.util.logging.Level;
|
||||
|
@ -56,6 +58,9 @@ import org.jxmpp.jid.BareJid;
|
|||
public abstract class OmemoStore<T_IdKeyPair, T_IdKey, T_PreKey, T_SigPreKey, T_Sess, T_Addr, T_ECPub, T_Bundle, T_Ciph> {
|
||||
private static final Logger LOGGER = Logger.getLogger(OmemoStore.class.getName());
|
||||
|
||||
private final Map<OmemoDevice, Boolean> postponePreKeyDeletion = new HashMap<>();
|
||||
private final Map<OmemoDevice, Set<Integer>> preKeyDeletionQueues = new HashMap<>();
|
||||
|
||||
/**
|
||||
* Create a new OmemoStore.
|
||||
*/
|
||||
|
@ -124,6 +129,51 @@ public abstract class OmemoStore<T_IdKeyPair, T_IdKey, T_PreKey, T_SigPreKey, T_
|
|||
return cached;
|
||||
}
|
||||
|
||||
public boolean isPostponingPreKeyDeletion(OmemoDevice userDevice) {
|
||||
synchronized (postponePreKeyDeletion) {
|
||||
Boolean postpone = postponePreKeyDeletion.get(userDevice);
|
||||
if (postpone == null) {
|
||||
postponePreKeyDeletion.put(userDevice, Boolean.FALSE);
|
||||
postpone = Boolean.FALSE;
|
||||
}
|
||||
return postpone;
|
||||
}
|
||||
}
|
||||
|
||||
public void postponePreKeyDeletion(OmemoDevice userDevice) {
|
||||
synchronized (postponePreKeyDeletion) {
|
||||
postponePreKeyDeletion.put(userDevice, Boolean.TRUE);
|
||||
}
|
||||
}
|
||||
|
||||
public void resumePreKeyDeletion(OmemoDevice userDevice) {
|
||||
synchronized (postponePreKeyDeletion) {
|
||||
postponePreKeyDeletion.put(userDevice, Boolean.FALSE);
|
||||
deleteQueuedPreKeys(userDevice);
|
||||
}
|
||||
}
|
||||
|
||||
public void queuePreKeyForDeletion(OmemoDevice userDevice, int deviceId) {
|
||||
Set<Integer> preKeyIds = preKeyDeletionQueues.get(userDevice);
|
||||
if (preKeyIds == null) {
|
||||
preKeyIds = new HashSet<>();
|
||||
preKeyDeletionQueues.put(userDevice, preKeyIds);
|
||||
}
|
||||
preKeyIds.add(deviceId);
|
||||
}
|
||||
|
||||
public void deleteQueuedPreKeys(OmemoDevice userDevice) {
|
||||
Set<Integer> queuedPreKeys = preKeyDeletionQueues.get(userDevice);
|
||||
if (queuedPreKeys == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
for (Integer id : queuedPreKeys) {
|
||||
removeOmemoPreKey(userDevice, id);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Renew our singed preKey. This should be done once every 7-14 days.
|
||||
* The old signed PreKey should be kept for around a month or so (look it up in the XEP).
|
||||
|
@ -407,6 +457,16 @@ public abstract class OmemoStore<T_IdKeyPair, T_IdKey, T_PreKey, T_SigPreKey, T_
|
|||
}
|
||||
}
|
||||
|
||||
public void removeOrQueueOmemoPreKey(OmemoDevice userDevice, int preKeyId) {
|
||||
synchronized (postponePreKeyDeletion) {
|
||||
if (isPostponingPreKeyDeletion(userDevice)) {
|
||||
queuePreKeyForDeletion(userDevice, preKeyId);
|
||||
} else {
|
||||
removeOmemoPreKey(userDevice, preKeyId);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove a preKey from storage. This is called, when a contact used one of our preKeys to establish a session
|
||||
* with us.
|
||||
|
|
Loading…
Reference in a new issue