use of org.signal.storageservice.protos.groups.local.DecryptedMember in project Signal-Android by WhisperSystems.
the class DecryptedGroupUtil method removeMember.
/**
* Removes the uuid from the full members of a group.
* <p>
* Generally not expected to have to do this, just in the case of leaving a group where you cannot
* get the new group state as you are not in the group any longer.
*/
public static DecryptedGroup removeMember(DecryptedGroup group, UUID uuid, int revision) {
DecryptedGroup.Builder builder = DecryptedGroup.newBuilder(group);
ByteString uuidString = UuidUtil.toByteString(uuid);
boolean removed = false;
ArrayList<DecryptedMember> decryptedMembers = new ArrayList<>(builder.getMembersList());
Iterator<DecryptedMember> membersList = decryptedMembers.iterator();
while (membersList.hasNext()) {
if (uuidString.equals(membersList.next().getUuid())) {
membersList.remove();
removed = true;
}
}
if (removed) {
return builder.clearMembers().addAllMembers(decryptedMembers).setRevision(revision).build();
} else {
return group;
}
}
use of org.signal.storageservice.protos.groups.local.DecryptedMember in project Signal-Android by WhisperSystems.
the class DecryptedGroupUtil method applyPromotePendingMemberActions.
protected static void applyPromotePendingMemberActions(DecryptedGroup.Builder builder, List<DecryptedMember> promotePendingMembersList) throws NotAbleToApplyGroupV2ChangeException {
for (DecryptedMember newMember : promotePendingMembersList) {
int index = findPendingIndexByUuid(builder.getPendingMembersList(), newMember.getUuid());
if (index == -1) {
throw new NotAbleToApplyGroupV2ChangeException();
}
builder.removePendingMembers(index);
builder.addMembers(newMember);
}
}
use of org.signal.storageservice.protos.groups.local.DecryptedMember in project Signal-Android by WhisperSystems.
the class GroupChangeReconstruct method reconstructGroupChange.
/**
* Given a {@param fromState} and a {@param toState} creates a {@link DecryptedGroupChange} that would take the {@param fromState} to the {@param toState}.
*/
public static DecryptedGroupChange reconstructGroupChange(DecryptedGroup fromState, DecryptedGroup toState) {
DecryptedGroupChange.Builder builder = DecryptedGroupChange.newBuilder().setRevision(toState.getRevision());
if (!fromState.getTitle().equals(toState.getTitle())) {
builder.setNewTitle(DecryptedString.newBuilder().setValue(toState.getTitle()));
}
if (!fromState.getDescription().equals(toState.getDescription())) {
builder.setNewDescription(DecryptedString.newBuilder().setValue(toState.getDescription()));
}
if (!fromState.getIsAnnouncementGroup().equals(toState.getIsAnnouncementGroup())) {
builder.setNewIsAnnouncementGroup(toState.getIsAnnouncementGroup());
}
if (!fromState.getAvatar().equals(toState.getAvatar())) {
builder.setNewAvatar(DecryptedString.newBuilder().setValue(toState.getAvatar()));
}
if (!fromState.getDisappearingMessagesTimer().equals(toState.getDisappearingMessagesTimer())) {
builder.setNewTimer(toState.getDisappearingMessagesTimer());
}
if (!fromState.getAccessControl().getAttributes().equals(toState.getAccessControl().getAttributes())) {
builder.setNewAttributeAccess(toState.getAccessControl().getAttributes());
}
if (!fromState.getAccessControl().getMembers().equals(toState.getAccessControl().getMembers())) {
builder.setNewMemberAccess(toState.getAccessControl().getMembers());
}
Set<ByteString> fromStateMemberUuids = membersToSetOfUuids(fromState.getMembersList());
Set<ByteString> toStateMemberUuids = membersToSetOfUuids(toState.getMembersList());
Set<ByteString> pendingMembersListA = pendingMembersToSetOfUuids(fromState.getPendingMembersList());
Set<ByteString> pendingMembersListB = pendingMembersToSetOfUuids(toState.getPendingMembersList());
Set<ByteString> requestingMembersListA = requestingMembersToSetOfUuids(fromState.getRequestingMembersList());
Set<ByteString> requestingMembersListB = requestingMembersToSetOfUuids(toState.getRequestingMembersList());
Set<ByteString> removedPendingMemberUuids = subtract(pendingMembersListA, pendingMembersListB);
Set<ByteString> removedRequestingMemberUuids = subtract(requestingMembersListA, requestingMembersListB);
Set<ByteString> newPendingMemberUuids = subtract(pendingMembersListB, pendingMembersListA);
Set<ByteString> newRequestingMemberUuids = subtract(requestingMembersListB, requestingMembersListA);
Set<ByteString> removedMemberUuids = subtract(fromStateMemberUuids, toStateMemberUuids);
Set<ByteString> newMemberUuids = subtract(toStateMemberUuids, fromStateMemberUuids);
Set<ByteString> addedByInvitationUuids = intersect(newMemberUuids, removedPendingMemberUuids);
Set<ByteString> addedByRequestApprovalUuids = intersect(newMemberUuids, removedRequestingMemberUuids);
Set<DecryptedMember> addedMembersByInvitation = intersectByUUID(toState.getMembersList(), addedByInvitationUuids);
Set<DecryptedMember> addedMembersByRequestApproval = intersectByUUID(toState.getMembersList(), addedByRequestApprovalUuids);
Set<DecryptedMember> addedMembers = intersectByUUID(toState.getMembersList(), subtract(newMemberUuids, addedByInvitationUuids, addedByRequestApprovalUuids));
Set<DecryptedPendingMember> uninvitedMembers = intersectPendingByUUID(fromState.getPendingMembersList(), subtract(removedPendingMemberUuids, addedByInvitationUuids));
Set<DecryptedRequestingMember> rejectedRequestMembers = intersectRequestingByUUID(fromState.getRequestingMembersList(), subtract(removedRequestingMemberUuids, addedByRequestApprovalUuids));
for (DecryptedMember member : intersectByUUID(fromState.getMembersList(), removedMemberUuids)) {
builder.addDeleteMembers(member.getUuid());
}
for (DecryptedMember member : addedMembers) {
builder.addNewMembers(member);
}
for (DecryptedMember member : addedMembersByInvitation) {
builder.addPromotePendingMembers(member);
}
for (DecryptedPendingMember uninvitedMember : uninvitedMembers) {
builder.addDeletePendingMembers(DecryptedPendingMemberRemoval.newBuilder().setUuid(uninvitedMember.getUuid()).setUuidCipherText(uninvitedMember.getUuidCipherText()));
}
for (DecryptedPendingMember invitedMember : intersectPendingByUUID(toState.getPendingMembersList(), newPendingMemberUuids)) {
builder.addNewPendingMembers(invitedMember);
}
Set<ByteString> consistentMemberUuids = intersect(fromStateMemberUuids, toStateMemberUuids);
Set<DecryptedMember> changedMembers = intersectByUUID(subtract(toState.getMembersList(), fromState.getMembersList()), consistentMemberUuids);
Map<ByteString, DecryptedMember> membersUuidMap = uuidMap(fromState.getMembersList());
for (DecryptedMember newState : changedMembers) {
DecryptedMember oldState = membersUuidMap.get(newState.getUuid());
if (oldState.getRole() != newState.getRole()) {
builder.addModifyMemberRoles(DecryptedModifyMemberRole.newBuilder().setUuid(newState.getUuid()).setRole(newState.getRole()));
}
if (!oldState.getProfileKey().equals(newState.getProfileKey())) {
builder.addModifiedProfileKeys(newState);
}
}
if (!fromState.getAccessControl().getAddFromInviteLink().equals(toState.getAccessControl().getAddFromInviteLink())) {
builder.setNewInviteLinkAccess(toState.getAccessControl().getAddFromInviteLink());
}
for (DecryptedRequestingMember requestingMember : intersectRequestingByUUID(toState.getRequestingMembersList(), newRequestingMemberUuids)) {
builder.addNewRequestingMembers(requestingMember);
}
for (DecryptedRequestingMember requestingMember : rejectedRequestMembers) {
builder.addDeleteRequestingMembers(requestingMember.getUuid());
}
for (DecryptedMember member : addedMembersByRequestApproval) {
builder.addPromoteRequestingMembers(DecryptedApproveMember.newBuilder().setUuid(member.getUuid()).setRole(member.getRole()));
}
if (!fromState.getInviteLinkPassword().equals(toState.getInviteLinkPassword())) {
builder.setNewInviteLinkPassword(toState.getInviteLinkPassword());
}
return builder.build();
}
use of org.signal.storageservice.protos.groups.local.DecryptedMember in project Signal-Android by WhisperSystems.
the class GroupChangeUtil method resolveConflict.
private static void resolveConflict(DecryptedGroup groupState, DecryptedGroupChange conflictingChange, ChangeSetModifier changeSetModifier) {
HashMap<ByteString, DecryptedMember> fullMembersByUuid = new HashMap<>(groupState.getMembersCount());
HashMap<ByteString, DecryptedPendingMember> pendingMembersByUuid = new HashMap<>(groupState.getPendingMembersCount());
HashMap<ByteString, DecryptedRequestingMember> requestingMembersByUuid = new HashMap<>(groupState.getMembersCount());
for (DecryptedMember member : groupState.getMembersList()) {
fullMembersByUuid.put(member.getUuid(), member);
}
for (DecryptedPendingMember member : groupState.getPendingMembersList()) {
pendingMembersByUuid.put(member.getUuid(), member);
}
for (DecryptedRequestingMember member : groupState.getRequestingMembersList()) {
requestingMembersByUuid.put(member.getUuid(), member);
}
resolveField3AddMembers(conflictingChange, changeSetModifier, fullMembersByUuid, pendingMembersByUuid);
resolveField4DeleteMembers(conflictingChange, changeSetModifier, fullMembersByUuid);
resolveField5ModifyMemberRoles(conflictingChange, changeSetModifier, fullMembersByUuid);
resolveField6ModifyProfileKeys(conflictingChange, changeSetModifier, fullMembersByUuid);
resolveField7AddPendingMembers(conflictingChange, changeSetModifier, fullMembersByUuid, pendingMembersByUuid);
resolveField8DeletePendingMembers(conflictingChange, changeSetModifier, pendingMembersByUuid);
resolveField9PromotePendingMembers(conflictingChange, changeSetModifier, pendingMembersByUuid);
resolveField10ModifyTitle(groupState, conflictingChange, changeSetModifier);
resolveField11ModifyAvatar(groupState, conflictingChange, changeSetModifier);
resolveField12modifyDisappearingMessagesTimer(groupState, conflictingChange, changeSetModifier);
resolveField13modifyAttributesAccess(groupState, conflictingChange, changeSetModifier);
resolveField14modifyAttributesAccess(groupState, conflictingChange, changeSetModifier);
resolveField15modifyAddFromInviteLinkAccess(groupState, conflictingChange, changeSetModifier);
resolveField16AddRequestingMembers(conflictingChange, changeSetModifier, fullMembersByUuid, pendingMembersByUuid);
resolveField17DeleteMembers(conflictingChange, changeSetModifier, requestingMembersByUuid);
resolveField18PromoteRequestingMembers(conflictingChange, changeSetModifier, requestingMembersByUuid);
resolveField20ModifyDescription(groupState, conflictingChange, changeSetModifier);
resolveField21ModifyAnnouncementsOnly(groupState, conflictingChange, changeSetModifier);
}
use of org.signal.storageservice.protos.groups.local.DecryptedMember in project Signal-Android by WhisperSystems.
the class GroupChangeUtil method resolveField6ModifyProfileKeys.
private static void resolveField6ModifyProfileKeys(DecryptedGroupChange conflictingChange, ChangeSetModifier result, HashMap<ByteString, DecryptedMember> fullMembersByUuid) {
List<DecryptedMember> modifyProfileKeysList = conflictingChange.getModifiedProfileKeysList();
for (int i = modifyProfileKeysList.size() - 1; i >= 0; i--) {
DecryptedMember member = modifyProfileKeysList.get(i);
DecryptedMember memberInGroup = fullMembersByUuid.get(member.getUuid());
if (memberInGroup == null || member.getProfileKey().equals(memberInGroup.getProfileKey())) {
result.removeModifyMemberProfileKeys(i);
}
}
}
Aggregations