+ private void storeProfileKeyFromChange(final DecryptedGroupChange decryptedGroupChange) {
+ final var profileKeyFromChange = context.getGroupV2Helper()
+ .getAuthoritativeProfileKeyFromChange(decryptedGroupChange);
+
+ if (profileKeyFromChange != null) {
+ final var serviceId = profileKeyFromChange.first();
+ final var profileKey = profileKeyFromChange.second();
+ final var recipientId = account.getRecipientStore().resolveRecipient(serviceId);
+ account.getProfileStore().storeProfileKey(recipientId, profileKey);
+ }
+ }
+
+ private void storeProfileKeysFromHistory(
+ final GroupSecretParams groupSecretParams,
+ final GroupInfoV2 localGroup,
+ final DecryptedGroup newDecryptedGroup
+ ) throws NotAGroupMemberException {
+ final var revisionWeWereAdded = context.getGroupV2Helper().findRevisionWeWereAdded(newDecryptedGroup);
+ final var localRevision = localGroup.getGroup() == null ? 0 : localGroup.getGroup().getRevision();
+ var fromRevision = Math.max(revisionWeWereAdded, localRevision);
+ final var newProfileKeys = new HashMap<RecipientId, ProfileKey>();
+ while (true) {
+ final var page = context.getGroupV2Helper().getDecryptedGroupHistoryPage(groupSecretParams, fromRevision);
+ page.getResults()
+ .stream()
+ .map(DecryptedGroupHistoryEntry::getChange)
+ .filter(Optional::isPresent)
+ .map(Optional::get)
+ .map(context.getGroupV2Helper()::getAuthoritativeProfileKeyFromChange)
+ .filter(Objects::nonNull)
+ .forEach(p -> {
+ final var serviceId = p.first();
+ final var profileKey = p.second();
+ final var recipientId = account.getRecipientStore().resolveRecipient(serviceId);
+ newProfileKeys.put(recipientId, profileKey);
+ });
+ if (!page.getPagingData().hasMorePages()) {
+ break;
+ }
+ fromRevision = page.getPagingData().getNextPageRevision();
+ }
+
+ newProfileKeys.forEach(account.getProfileStore()::storeProfileKey);
+ }
+