+ Pair<DecryptedGroup, GroupChange> updateSelfProfileKey(GroupInfoV2 groupInfoV2) throws IOException {
+ Optional<DecryptedMember> selfInGroup = groupInfoV2.getGroup() == null
+ ? Optional.empty()
+ : DecryptedGroupUtil.findMemberByUuid(groupInfoV2.getGroup().getMembersList(), getSelfAci().uuid());
+ if (selfInGroup.isEmpty()) {
+ logger.trace("Not updating group, self not in group " + groupInfoV2.getGroupId().toBase64());
+ return null;
+ }
+
+ final var profileKey = context.getAccount().getProfileKey();
+ if (Arrays.equals(profileKey.serialize(), selfInGroup.get().getProfileKey().toByteArray())) {
+ logger.trace("Not updating group, own Profile Key is already up to date in group "
+ + groupInfoV2.getGroupId().toBase64());
+ return null;
+ }
+ logger.debug("Updating own profile key in group " + groupInfoV2.getGroupId().toBase64());
+
+ final var selfRecipientId = context.getAccount().getSelfRecipientId();
+ final var profileKeyCredential = context.getProfileHelper().getRecipientProfileKeyCredential(selfRecipientId);
+ if (profileKeyCredential == null) {
+ logger.trace("Cannot update profile key as self does not have a versioned profile");
+ return null;
+ }
+
+ final GroupsV2Operations.GroupOperations groupOperations = getGroupOperations(groupInfoV2);
+ final var change = groupOperations.createUpdateProfileKeyCredentialChange(profileKeyCredential);
+ change.setSourceUuid(getSelfAci().toByteString());
+ return commitChange(groupInfoV2, change);
+ }
+