+ saveIdentity(name, identityKey, TrustLevel.TRUSTED_UNVERIFIED, null);
+ }
+
+ /**
+ * Adds or updates the given identityKey for the user name and sets the trustLevel and added timestamp.
+ *
+ * @param name User name, i.e. phone number
+ * @param identityKey The user's public key
+ * @param trustLevel
+ * @param added Added timestamp, if null and the key is newly added, the current time is used.
+ */
+ public void saveIdentity(String name, IdentityKey identityKey, TrustLevel trustLevel, Date added) {
+ List<Identity> identities = trustedKeys.get(name);
+ if (identities == null) {
+ identities = new ArrayList<>();
+ trustedKeys.put(name, identities);
+ } else {
+ for (Identity id : identities) {
+ if (!id.identityKey.equals(identityKey))
+ continue;
+
+ id.trustLevel = trustLevel;
+ if (added != null) {
+ id.added = added;
+ }
+ return;
+ }
+ }
+ identities.add(new Identity(identityKey, trustLevel, added != null ? added : new Date()));