mirror of
https://github.com/signalapp/Signal-Android.git
synced 2026-02-22 18:55:12 +00:00
Enforce limit for total number of blocked requests.
This commit is contained in:
committed by
Greyson Parrelli
parent
b3d9a85fa2
commit
6890973ce8
@@ -105,7 +105,7 @@ public class ApplicationDependencyProvider implements ApplicationDependencies.Pr
|
||||
|
||||
@Override
|
||||
public @NonNull GroupsV2Operations provideGroupsV2Operations() {
|
||||
return new GroupsV2Operations(provideClientZkOperations());
|
||||
return new GroupsV2Operations(provideClientZkOperations(), FeatureFlags.groupLimits().getHardLimit());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -283,19 +283,16 @@ public final class GroupManager {
|
||||
@NonNull RecipientId recipientId)
|
||||
throws GroupChangeBusyException, IOException, GroupChangeFailedException, GroupNotAMemberException, GroupInsufficientRightsException
|
||||
{
|
||||
GroupDatabase.GroupRecord groupRecord = SignalDatabase.groups().requireGroup(groupId);
|
||||
Recipient recipient = Recipient.resolved(recipientId);
|
||||
GroupDatabase.V2GroupProperties groupProperties = SignalDatabase.groups().requireGroup(groupId).requireV2GroupProperties();
|
||||
Recipient recipient = Recipient.resolved(recipientId);
|
||||
|
||||
if (groupRecord.requireV2GroupProperties().getBannedMembers().contains(recipient.requireServiceId().uuid())) {
|
||||
if (groupProperties.getBannedMembers().contains(recipient.requireServiceId().uuid())) {
|
||||
Log.i(TAG, "Attempt to ban already banned recipient: " + recipientId);
|
||||
return;
|
||||
}
|
||||
|
||||
ByteString uuid = UuidUtil.toByteString(recipient.requireServiceId().uuid());
|
||||
boolean rejectJoinRequest = groupRecord.requireV2GroupProperties().getDecryptedGroup().getRequestingMembersList().stream().anyMatch(m -> m.getUuid().equals(uuid));
|
||||
|
||||
try (GroupManagerV2.GroupEditor editor = new GroupManagerV2(context).edit(groupId.requireV2())) {
|
||||
editor.ban(Collections.singleton(recipient.requireServiceId().uuid()), rejectJoinRequest);
|
||||
editor.ban(recipient.requireServiceId().uuid());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -309,6 +309,7 @@ final class GroupManagerV2 {
|
||||
final class GroupEditor extends LockOwner {
|
||||
|
||||
private final GroupId.V2 groupId;
|
||||
private final GroupDatabase.V2GroupProperties v2GroupProperties;
|
||||
private final GroupMasterKey groupMasterKey;
|
||||
private final GroupSecretParams groupSecretParams;
|
||||
private final GroupsV2Operations.GroupOperations groupOperations;
|
||||
@@ -316,10 +317,10 @@ final class GroupManagerV2 {
|
||||
GroupEditor(@NonNull GroupId.V2 groupId, @NonNull Closeable lock) {
|
||||
super(lock);
|
||||
|
||||
GroupDatabase.GroupRecord groupRecord = groupDatabase.requireGroup(groupId);
|
||||
GroupDatabase.V2GroupProperties v2GroupProperties = groupRecord.requireV2GroupProperties();
|
||||
GroupDatabase.GroupRecord groupRecord = groupDatabase.requireGroup(groupId);
|
||||
|
||||
this.groupId = groupId;
|
||||
this.v2GroupProperties = groupRecord.requireV2GroupProperties();
|
||||
this.groupMasterKey = v2GroupProperties.getGroupMasterKey();
|
||||
this.groupSecretParams = GroupSecretParams.deriveFromMasterKey(groupMasterKey);
|
||||
this.groupOperations = groupsV2Operations.forGroup(groupSecretParams);
|
||||
@@ -428,7 +429,7 @@ final class GroupManagerV2 {
|
||||
.map(r -> Recipient.resolved(r).requireServiceId().uuid())
|
||||
.collect(Collectors.toSet());
|
||||
|
||||
return commitChangeWithConflictResolution(groupOperations.createRefuseGroupJoinRequest(uuids, true));
|
||||
return commitChangeWithConflictResolution(groupOperations.createRefuseGroupJoinRequest(uuids, true, v2GroupProperties.getDecryptedGroup().getBannedMembersList()));
|
||||
}
|
||||
|
||||
@WorkerThread
|
||||
@@ -463,7 +464,11 @@ final class GroupManagerV2 {
|
||||
@NonNull GroupManager.GroupActionResult ejectMember(@NonNull ServiceId serviceId, boolean allowWhenBlocked, boolean ban)
|
||||
throws GroupChangeFailedException, GroupInsufficientRightsException, IOException, GroupNotAMemberException
|
||||
{
|
||||
return commitChangeWithConflictResolution(groupOperations.createRemoveMembersChange(Collections.singleton(serviceId.uuid()), ban), allowWhenBlocked);
|
||||
return commitChangeWithConflictResolution(groupOperations.createRemoveMembersChange(Collections.singleton(serviceId.uuid()),
|
||||
ban,
|
||||
ban ? v2GroupProperties.getDecryptedGroup().getBannedMembersList()
|
||||
: Collections.emptyList()),
|
||||
allowWhenBlocked);
|
||||
}
|
||||
|
||||
@WorkerThread
|
||||
@@ -530,11 +535,18 @@ final class GroupManagerV2 {
|
||||
return commitChangeWithConflictResolution(groupOperations.createAcceptInviteChange(groupCandidate.getProfileKeyCredential().get()));
|
||||
}
|
||||
|
||||
public GroupManager.GroupActionResult ban(Set<UUID> uuids, boolean rejectJoinRequest) throws GroupChangeFailedException, GroupNotAMemberException, GroupInsufficientRightsException, IOException {
|
||||
return commitChangeWithConflictResolution(groupOperations.createBanUuidsChange(uuids, rejectJoinRequest));
|
||||
public GroupManager.GroupActionResult ban(UUID uuid)
|
||||
throws GroupChangeFailedException, GroupNotAMemberException, GroupInsufficientRightsException, IOException
|
||||
{
|
||||
ByteString uuidByteString = UuidUtil.toByteString(uuid);
|
||||
boolean rejectJoinRequest = v2GroupProperties.getDecryptedGroup().getRequestingMembersList().stream().anyMatch(m -> m.getUuid().equals(uuidByteString));
|
||||
|
||||
return commitChangeWithConflictResolution(groupOperations.createBanUuidsChange(Collections.singleton(uuid), rejectJoinRequest, v2GroupProperties.getDecryptedGroup().getBannedMembersList()));
|
||||
}
|
||||
|
||||
public GroupManager.GroupActionResult unban(Set<UUID> uuids) throws GroupChangeFailedException, GroupNotAMemberException, GroupInsufficientRightsException, IOException {
|
||||
public GroupManager.GroupActionResult unban(Set<UUID> uuids)
|
||||
throws GroupChangeFailedException, GroupNotAMemberException, GroupInsufficientRightsException, IOException
|
||||
{
|
||||
return commitChangeWithConflictResolution(groupOperations.createUnbanUuidsChange(uuids));
|
||||
}
|
||||
|
||||
@@ -1102,7 +1114,7 @@ final class GroupManagerV2 {
|
||||
|
||||
GroupChange signedGroupChange;
|
||||
try {
|
||||
signedGroupChange = commitCancelChangeWithConflictResolution(groupOperations.createRefuseGroupJoinRequest(uuids, false));
|
||||
signedGroupChange = commitCancelChangeWithConflictResolution(groupOperations.createRefuseGroupJoinRequest(uuids, false, Collections.emptyList()));
|
||||
} catch (GroupLinkNotActiveException e) {
|
||||
Log.d(TAG, "Unexpected unable to leave group due to group link off");
|
||||
throw new GroupChangeFailedException(e);
|
||||
|
||||
@@ -43,7 +43,8 @@ public class AccountManagerFactory {
|
||||
deviceId,
|
||||
password,
|
||||
BuildConfig.SIGNAL_AGENT,
|
||||
FeatureFlags.okHttpAutomaticRetry());
|
||||
FeatureFlags.okHttpAutomaticRetry(),
|
||||
FeatureFlags.groupLimits().getHardLimit());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -65,7 +66,14 @@ public class AccountManagerFactory {
|
||||
}
|
||||
|
||||
return new SignalServiceAccountManager(new SignalServiceNetworkAccess(context).getConfiguration(number),
|
||||
null, null, number, deviceId, password, BuildConfig.SIGNAL_AGENT, FeatureFlags.okHttpAutomaticRetry());
|
||||
null,
|
||||
null,
|
||||
number,
|
||||
deviceId,
|
||||
password,
|
||||
BuildConfig.SIGNAL_AGENT,
|
||||
FeatureFlags.okHttpAutomaticRetry(),
|
||||
FeatureFlags.groupLimits().getHardLimit());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user