Rename group v2 helper

This commit is contained in:
AsamK 2021-05-15 10:15:16 +02:00
parent a91e3f762e
commit b972522d74
2 changed files with 25 additions and 23 deletions

View file

@ -26,7 +26,7 @@ import org.asamk.signal.manager.groups.GroupInviteLinkUrl;
import org.asamk.signal.manager.groups.GroupNotFoundException; import org.asamk.signal.manager.groups.GroupNotFoundException;
import org.asamk.signal.manager.groups.GroupUtils; import org.asamk.signal.manager.groups.GroupUtils;
import org.asamk.signal.manager.groups.NotAGroupMemberException; import org.asamk.signal.manager.groups.NotAGroupMemberException;
import org.asamk.signal.manager.helper.GroupHelper; import org.asamk.signal.manager.helper.GroupV2Helper;
import org.asamk.signal.manager.helper.PinHelper; import org.asamk.signal.manager.helper.PinHelper;
import org.asamk.signal.manager.helper.ProfileHelper; import org.asamk.signal.manager.helper.ProfileHelper;
import org.asamk.signal.manager.helper.UnidentifiedAccessHelper; import org.asamk.signal.manager.helper.UnidentifiedAccessHelper;
@ -191,7 +191,7 @@ public class Manager implements Closeable {
private final UnidentifiedAccessHelper unidentifiedAccessHelper; private final UnidentifiedAccessHelper unidentifiedAccessHelper;
private final ProfileHelper profileHelper; private final ProfileHelper profileHelper;
private final GroupHelper groupHelper; private final GroupV2Helper groupV2Helper;
private final PinHelper pinHelper; private final PinHelper pinHelper;
private final AvatarStore avatarStore; private final AvatarStore avatarStore;
private final AttachmentStore attachmentStore; private final AttachmentStore attachmentStore;
@ -259,7 +259,7 @@ public class Manager implements Closeable {
unidentified -> unidentified ? getOrCreateUnidentifiedMessagePipe() : getOrCreateMessagePipe(), unidentified -> unidentified ? getOrCreateUnidentifiedMessagePipe() : getOrCreateMessagePipe(),
() -> messageReceiver, () -> messageReceiver,
this::resolveSignalServiceAddress); this::resolveSignalServiceAddress);
this.groupHelper = new GroupHelper(this::getRecipientProfileKeyCredential, this.groupV2Helper = new GroupV2Helper(this::getRecipientProfileKeyCredential,
this::getRecipientProfile, this::getRecipientProfile,
account::getSelfRecipientId, account::getSelfRecipientId,
groupsV2Operations, groupsV2Operations,
@ -773,7 +773,7 @@ public class Manager implements Closeable {
account.getGroupStore().updateGroup(groupInfoV1); account.getGroupStore().updateGroup(groupInfoV1);
} else { } else {
final var groupInfoV2 = (GroupInfoV2) g; final var groupInfoV2 = (GroupInfoV2) g;
final var groupGroupChangePair = groupHelper.leaveGroup(groupInfoV2); final var groupGroupChangePair = groupV2Helper.leaveGroup(groupInfoV2);
groupInfoV2.setGroup(groupGroupChangePair.first(), this::resolveRecipient); groupInfoV2.setGroup(groupGroupChangePair.first(), this::resolveRecipient);
messageBuilder = getGroupUpdateMessageBuilder(groupInfoV2, groupGroupChangePair.second().toByteArray()); messageBuilder = getGroupUpdateMessageBuilder(groupInfoV2, groupGroupChangePair.second().toByteArray());
account.getGroupStore().updateGroup(groupInfoV2); account.getGroupStore().updateGroup(groupInfoV2);
@ -797,7 +797,7 @@ public class Manager implements Closeable {
members.remove(selfRecipientId); members.remove(selfRecipientId);
} }
var gv2Pair = groupHelper.createGroupV2(name == null ? "" : name, var gv2Pair = groupV2Helper.createGroup(name == null ? "" : name,
members == null ? Set.of() : members, members == null ? Set.of() : members,
avatarFile); avatarFile);
@ -917,7 +917,7 @@ public class Manager implements Closeable {
) throws IOException { ) throws IOException {
Pair<Long, List<SendMessageResult>> result = null; Pair<Long, List<SendMessageResult>> result = null;
if (group.isPendingMember(account.getSelfRecipientId())) { if (group.isPendingMember(account.getSelfRecipientId())) {
var groupGroupChangePair = groupHelper.acceptInvite(group); var groupGroupChangePair = groupV2Helper.acceptInvite(group);
result = sendUpdateGroupV2Message(group, groupGroupChangePair.first(), groupGroupChangePair.second()); result = sendUpdateGroupV2Message(group, groupGroupChangePair.first(), groupGroupChangePair.second());
} }
@ -925,7 +925,7 @@ public class Manager implements Closeable {
final var newMembers = new HashSet<>(members); final var newMembers = new HashSet<>(members);
newMembers.removeAll(group.getMembers()); newMembers.removeAll(group.getMembers());
if (newMembers.size() > 0) { if (newMembers.size() > 0) {
var groupGroupChangePair = groupHelper.updateGroupV2(group, newMembers); var groupGroupChangePair = groupV2Helper.addMembers(group, newMembers);
result = sendUpdateGroupV2Message(group, groupGroupChangePair.first(), groupGroupChangePair.second()); result = sendUpdateGroupV2Message(group, groupGroupChangePair.first(), groupGroupChangePair.second());
} }
} }
@ -935,20 +935,20 @@ public class Manager implements Closeable {
existingRemoveMembers.retainAll(group.getMembers()); existingRemoveMembers.retainAll(group.getMembers());
existingRemoveMembers.remove(getSelfRecipientId());// self can be removed with sendQuitGroupMessage existingRemoveMembers.remove(getSelfRecipientId());// self can be removed with sendQuitGroupMessage
if (existingRemoveMembers.size() > 0) { if (existingRemoveMembers.size() > 0) {
var groupGroupChangePair = groupHelper.removeMembers(group, existingRemoveMembers); var groupGroupChangePair = groupV2Helper.removeMembers(group, existingRemoveMembers);
result = sendUpdateGroupV2Message(group, groupGroupChangePair.first(), groupGroupChangePair.second()); result = sendUpdateGroupV2Message(group, groupGroupChangePair.first(), groupGroupChangePair.second());
} }
var pendingRemoveMembers = new HashSet<>(removeMembers); var pendingRemoveMembers = new HashSet<>(removeMembers);
pendingRemoveMembers.retainAll(group.getPendingMembers()); pendingRemoveMembers.retainAll(group.getPendingMembers());
if (pendingRemoveMembers.size() > 0) { if (pendingRemoveMembers.size() > 0) {
var groupGroupChangePair = groupHelper.revokeInvitedMembers(group, pendingRemoveMembers); var groupGroupChangePair = groupV2Helper.revokeInvitedMembers(group, pendingRemoveMembers);
result = sendUpdateGroupV2Message(group, groupGroupChangePair.first(), groupGroupChangePair.second()); result = sendUpdateGroupV2Message(group, groupGroupChangePair.first(), groupGroupChangePair.second());
} }
} }
if (result == null || name != null || description != null || avatarFile != null) { if (result == null || name != null || description != null || avatarFile != null) {
var groupGroupChangePair = groupHelper.updateGroupV2(group, name, description, avatarFile); var groupGroupChangePair = groupV2Helper.updateGroup(group, name, description, avatarFile);
if (avatarFile != null) { if (avatarFile != null) {
avatarStore.storeGroupAvatar(group.getGroupId(), avatarStore.storeGroupAvatar(group.getGroupId(),
outputStream -> IOUtils.copyFileToStream(avatarFile, outputStream)); outputStream -> IOUtils.copyFileToStream(avatarFile, outputStream));
@ -962,9 +962,9 @@ public class Manager implements Closeable {
public Pair<GroupId, List<SendMessageResult>> joinGroup( public Pair<GroupId, List<SendMessageResult>> joinGroup(
GroupInviteLinkUrl inviteLinkUrl GroupInviteLinkUrl inviteLinkUrl
) throws IOException, GroupLinkNotActiveException { ) throws IOException, GroupLinkNotActiveException {
final var groupJoinInfo = groupHelper.getDecryptedGroupJoinInfo(inviteLinkUrl.getGroupMasterKey(), final var groupJoinInfo = groupV2Helper.getDecryptedGroupJoinInfo(inviteLinkUrl.getGroupMasterKey(),
inviteLinkUrl.getPassword()); inviteLinkUrl.getPassword());
final var groupChange = groupHelper.joinGroup(inviteLinkUrl.getGroupMasterKey(), final var groupChange = groupV2Helper.joinGroup(inviteLinkUrl.getGroupMasterKey(),
inviteLinkUrl.getPassword(), inviteLinkUrl.getPassword(),
groupJoinInfo); groupJoinInfo);
final var group = getOrMigrateGroup(inviteLinkUrl.getGroupMasterKey(), final var group = getOrMigrateGroup(inviteLinkUrl.getGroupMasterKey(),
@ -1762,10 +1762,12 @@ public class Manager implements Closeable {
if (signedGroupChange != null if (signedGroupChange != null
&& groupInfoV2.getGroup() != null && groupInfoV2.getGroup() != null
&& groupInfoV2.getGroup().getRevision() + 1 == revision) { && groupInfoV2.getGroup().getRevision() + 1 == revision) {
group = groupHelper.getUpdatedDecryptedGroup(groupInfoV2.getGroup(), signedGroupChange, groupMasterKey); group = groupV2Helper.getUpdatedDecryptedGroup(groupInfoV2.getGroup(),
signedGroupChange,
groupMasterKey);
} }
if (group == null) { if (group == null) {
group = groupHelper.getDecryptedGroup(groupSecretParams); group = groupV2Helper.getDecryptedGroup(groupSecretParams);
} }
if (group != null) { if (group != null) {
storeProfileKeysFromMembers(group); storeProfileKeysFromMembers(group);
@ -2577,7 +2579,7 @@ public class Manager implements Closeable {
final var group = account.getGroupStore().getGroup(groupId); final var group = account.getGroupStore().getGroup(groupId);
if (group instanceof GroupInfoV2 && ((GroupInfoV2) group).getGroup() == null) { if (group instanceof GroupInfoV2 && ((GroupInfoV2) group).getGroup() == null) {
final var groupSecretParams = GroupSecretParams.deriveFromMasterKey(((GroupInfoV2) group).getMasterKey()); final var groupSecretParams = GroupSecretParams.deriveFromMasterKey(((GroupInfoV2) group).getMasterKey());
((GroupInfoV2) group).setGroup(groupHelper.getDecryptedGroup(groupSecretParams), this::resolveRecipient); ((GroupInfoV2) group).setGroup(groupV2Helper.getDecryptedGroup(groupSecretParams), this::resolveRecipient);
account.getGroupStore().updateGroup(group); account.getGroupStore().updateGroup(group);
} }
return group; return group;

View file

@ -43,9 +43,9 @@ import java.util.Set;
import java.util.UUID; import java.util.UUID;
import java.util.stream.Collectors; import java.util.stream.Collectors;
public class GroupHelper { public class GroupV2Helper {
private final static Logger logger = LoggerFactory.getLogger(GroupHelper.class); private final static Logger logger = LoggerFactory.getLogger(GroupV2Helper.class);
private final ProfileKeyCredentialProvider profileKeyCredentialProvider; private final ProfileKeyCredentialProvider profileKeyCredentialProvider;
@ -61,7 +61,7 @@ public class GroupHelper {
private final SignalServiceAddressResolver addressResolver; private final SignalServiceAddressResolver addressResolver;
public GroupHelper( public GroupV2Helper(
final ProfileKeyCredentialProvider profileKeyCredentialProvider, final ProfileKeyCredentialProvider profileKeyCredentialProvider,
final ProfileProvider profileProvider, final ProfileProvider profileProvider,
final SelfRecipientIdProvider selfRecipientIdProvider, final SelfRecipientIdProvider selfRecipientIdProvider,
@ -100,11 +100,11 @@ public class GroupHelper {
groupAuthorizationProvider.getAuthorizationForToday(groupSecretParams)); groupAuthorizationProvider.getAuthorizationForToday(groupSecretParams));
} }
public Pair<GroupInfoV2, DecryptedGroup> createGroupV2( public Pair<GroupInfoV2, DecryptedGroup> createGroup(
String name, Set<RecipientId> members, File avatarFile String name, Set<RecipientId> members, File avatarFile
) throws IOException { ) throws IOException {
final var avatarBytes = readAvatarBytes(avatarFile); final var avatarBytes = readAvatarBytes(avatarFile);
final var newGroup = buildNewGroupV2(name, members, avatarBytes); final var newGroup = buildNewGroup(name, members, avatarBytes);
if (newGroup == null) { if (newGroup == null) {
return null; return null;
} }
@ -141,7 +141,7 @@ public class GroupHelper {
return avatarBytes; return avatarBytes;
} }
private GroupsV2Operations.NewGroup buildNewGroupV2( private GroupsV2Operations.NewGroup buildNewGroup(
String name, Set<RecipientId> members, byte[] avatar String name, Set<RecipientId> members, byte[] avatar
) { ) {
final var profileKeyCredential = profileKeyCredentialProvider.getProfileKeyCredential(selfRecipientIdProvider.getSelfRecipientId()); final var profileKeyCredential = profileKeyCredentialProvider.getProfileKeyCredential(selfRecipientIdProvider.getSelfRecipientId());
@ -195,7 +195,7 @@ public class GroupHelper {
return true; return true;
} }
public Pair<DecryptedGroup, GroupChange> updateGroupV2( public Pair<DecryptedGroup, GroupChange> updateGroup(
GroupInfoV2 groupInfoV2, String name, String description, File avatarFile GroupInfoV2 groupInfoV2, String name, String description, File avatarFile
) throws IOException { ) throws IOException {
final var groupSecretParams = GroupSecretParams.deriveFromMasterKey(groupInfoV2.getMasterKey()); final var groupSecretParams = GroupSecretParams.deriveFromMasterKey(groupInfoV2.getMasterKey());
@ -224,7 +224,7 @@ public class GroupHelper {
return commitChange(groupInfoV2, change); return commitChange(groupInfoV2, change);
} }
public Pair<DecryptedGroup, GroupChange> updateGroupV2( public Pair<DecryptedGroup, GroupChange> addMembers(
GroupInfoV2 groupInfoV2, Set<RecipientId> newMembers GroupInfoV2 groupInfoV2, Set<RecipientId> newMembers
) throws IOException { ) throws IOException {
final var groupSecretParams = GroupSecretParams.deriveFromMasterKey(groupInfoV2.getMasterKey()); final var groupSecretParams = GroupSecretParams.deriveFromMasterKey(groupInfoV2.getMasterKey());