Adopt libsignal 0.30.0 and ServiceIds for group members.

Co-authored-by: Greyson Parrelli <greyson@signal.org>
This commit is contained in:
Jordan Rose
2023-07-31 10:28:18 -07:00
committed by Greyson Parrelli
parent b11d653fc0
commit a2c3b5d64e
44 changed files with 613 additions and 592 deletions

View File

@@ -153,8 +153,8 @@ class ConversationSettingsRepository(
if (groupRecord.isV2Group) {
val decryptedGroup: DecryptedGroup = groupRecord.requireV2GroupProperties().decryptedGroup
val pendingMembers: List<RecipientId> = decryptedGroup.pendingMembersList
.map(DecryptedPendingMember::getUuid)
.map(GroupProtoUtil::uuidByteStringToRecipientId)
.map(DecryptedPendingMember::getServiceIdBinary)
.map(GroupProtoUtil::serviceIdBinaryToRecipientId)
val members = mutableListOf<RecipientId>()

View File

@@ -50,6 +50,7 @@ import org.thoughtcrime.securesms.util.ViewUtil;
import org.thoughtcrime.securesms.util.concurrent.ListenableFuture;
import org.thoughtcrime.securesms.util.livedata.LiveDataUtil;
import org.thoughtcrime.securesms.verify.VerifyIdentityActivity;
import org.whispersystems.signalservice.api.push.ServiceId;
import org.whispersystems.signalservice.api.push.ServiceId.ACI;
import java.util.Collection;
@@ -291,11 +292,11 @@ public final class ConversationUpdateItem extends FrameLayout
private final Observer<Object> updater;
private LiveGroup liveGroup;
private LiveData<Boolean> liveIsSelfAdmin;
private LiveData<Set<UUID>> liveBannedMembers;
private LiveData<Set<UUID>> liveFullMembers;
private Recipient conversationRecipient;
private LiveGroup liveGroup;
private LiveData<Boolean> liveIsSelfAdmin;
private LiveData<Set<ServiceId>> liveBannedMembers;
private LiveData<Set<UUID>> liveFullMembers;
private Recipient conversationRecipient;
GroupDataManager() {
this.updater = unused -> update();
@@ -341,9 +342,9 @@ public final class ConversationUpdateItem extends FrameLayout
return false;
}
Set<UUID> bannedMembers = liveBannedMembers.getValue();
Set<ServiceId> bannedMembers = liveBannedMembers.getValue();
if (bannedMembers != null) {
return recipient.getServiceId().isPresent() && bannedMembers.contains(recipient.requireServiceId().getRawUuid());
return recipient.getServiceId().isPresent() && bannedMembers.contains(recipient.requireServiceId());
}
return false;
}

View File

@@ -60,7 +60,6 @@ import org.whispersystems.signalservice.api.util.UuidUtil
import java.io.Closeable
import java.security.SecureRandom
import java.util.Optional
import java.util.UUID
import java.util.stream.Collectors
import javax.annotation.CheckReturnValue
@@ -861,8 +860,8 @@ class GroupTable(context: Context?, databaseHelper: SignalDatabase?) : DatabaseT
writableDatabase.withinTransaction { db ->
val record = getGroup(groupIdV1).get()
val newMembers: MutableList<RecipientId> = DecryptedGroupUtil.membersToUuidList(decryptedGroup.membersList).toRecipientIds()
val pendingMembers: List<RecipientId> = DecryptedGroupUtil.pendingToUuidList(decryptedGroup.pendingMembersList).toRecipientIds()
val newMembers: MutableList<RecipientId> = DecryptedGroupUtil.membersToServiceIdList(decryptedGroup.membersList).toRecipientIds()
val pendingMembers: List<RecipientId> = DecryptedGroupUtil.pendingToServiceIdList(decryptedGroup.pendingMembersList).toRecipientIds()
newMembers.addAll(pendingMembers)
val droppedMembers: List<RecipientId> = SetUtil.difference(record.members, newMembers).toList()
@@ -915,11 +914,11 @@ class GroupTable(context: Context?, databaseHelper: SignalDatabase?) : DatabaseT
val change = GroupChangeReconstruct.reconstructGroupChange(existingGroup.get().requireV2GroupProperties().decryptedGroup, decryptedGroup)
val addedMembers: Set<RecipientId> = DecryptedGroupUtil.membersToUuidList(change.newMembersList).toRecipientIds().toSet()
val removedMembers: Set<RecipientId> = DecryptedGroupUtil.removedMembersUuidList(change).toRecipientIds().toSet()
val addedInvites: Set<RecipientId> = DecryptedGroupUtil.pendingToUuidList(change.newPendingMembersList).toRecipientIds().toSet()
val removedInvites: Set<RecipientId> = DecryptedGroupUtil.removedPendingMembersUuidList(change).toRecipientIds().toSet()
val acceptedInvites: Set<RecipientId> = DecryptedGroupUtil.membersToUuidList(change.promotePendingMembersList).toRecipientIds().toSet()
val addedMembers: Set<RecipientId> = DecryptedGroupUtil.membersToServiceIdList(change.newMembersList).toRecipientIds().toSet()
val removedMembers: Set<RecipientId> = DecryptedGroupUtil.removedMembersServiceIdList(change).toRecipientIds().toSet()
val addedInvites: Set<RecipientId> = DecryptedGroupUtil.pendingToServiceIdList(change.newPendingMembersList).toRecipientIds().toSet()
val removedInvites: Set<RecipientId> = DecryptedGroupUtil.removedPendingMembersServiceIdList(change).toRecipientIds().toSet()
val acceptedInvites: Set<RecipientId> = DecryptedGroupUtil.membersToServiceIdList(change.promotePendingMembersList).toRecipientIds().toSet()
unmigratedV1Members -= addedMembers
unmigratedV1Members -= removedMembers
@@ -934,7 +933,7 @@ class GroupTable(context: Context?, databaseHelper: SignalDatabase?) : DatabaseT
if (existingGroup.isPresent && existingGroup.get().isV2Group) {
val change = GroupChangeReconstruct.reconstructGroupChange(existingGroup.get().requireV2GroupProperties().decryptedGroup, decryptedGroup)
val removed: List<UUID> = DecryptedGroupUtil.removedMembersUuidList(change)
val removed: List<ServiceId> = DecryptedGroupUtil.removedMembersServiceIdList(change)
if (removed.isNotEmpty()) {
val distributionId = existingGroup.get().distributionId!!
@@ -1208,8 +1207,8 @@ class GroupTable(context: Context?, databaseHelper: SignalDatabase?) : DatabaseT
DecryptedGroup.parseFrom(decryptedGroupBytes)
}
val bannedMembers: Set<UUID> by lazy {
DecryptedGroupUtil.bannedMembersToUuidSet(decryptedGroup.bannedMembersList)
val bannedMembers: Set<ServiceId> by lazy {
DecryptedGroupUtil.bannedMembersToServiceIdSet(decryptedGroup.bannedMembersList)
}
fun isAdmin(recipient: Recipient): Boolean {
@@ -1243,7 +1242,7 @@ class GroupTable(context: Context?, databaseHelper: SignalDatabase?) : DatabaseT
}
if (memberLevel.isAbsent()) {
memberLevel = DecryptedGroupUtil.findPendingByUuid(decryptedGroup.pendingMembersList, serviceId.get().rawUuid)
memberLevel = DecryptedGroupUtil.findPendingByServiceId(decryptedGroup.pendingMembersList, serviceId.get())
.map { MemberLevel.PENDING_MEMBER }
}
@@ -1265,7 +1264,8 @@ class GroupTable(context: Context?, databaseHelper: SignalDatabase?) : DatabaseT
fun getMemberRecipientIds(memberSet: MemberSet): List<RecipientId> {
val includeSelf = memberSet.includeSelf
val selfAciUuid = SignalStore.account().requireAci().rawUuid
val selfAci = SignalStore.account().requireAci()
val selfAciUuid = selfAci.rawUuid
val recipients: MutableList<RecipientId> = ArrayList(decryptedGroup.membersCount + decryptedGroup.pendingMembersCount)
var unknownMembers = 0
@@ -1280,11 +1280,11 @@ class GroupTable(context: Context?, databaseHelper: SignalDatabase?) : DatabaseT
}
if (memberSet.includePending) {
for (uuid in DecryptedGroupUtil.pendingToUuidList(decryptedGroup.pendingMembersList)) {
if (UuidUtil.UNKNOWN_UUID == uuid) {
for (serviceId in DecryptedGroupUtil.pendingToServiceIdList(decryptedGroup.pendingMembersList)) {
if (serviceId.isUnknown) {
unknownPending++
} else if (includeSelf || selfAciUuid != uuid) {
recipients += RecipientId.from(ACI.from(uuid))
} else if (includeSelf || selfAci != serviceId) {
recipients += RecipientId.from(serviceId)
}
}
}
@@ -1378,11 +1378,11 @@ class GroupTable(context: Context?, databaseHelper: SignalDatabase?) : DatabaseT
val aci = SignalStore.account().requireAci()
return DecryptedGroupUtil.findMemberByUuid(decryptedGroup.membersList, aci.rawUuid).isPresent ||
DecryptedGroupUtil.findPendingByUuid(decryptedGroup.pendingMembersList, aci.rawUuid).isPresent
DecryptedGroupUtil.findPendingByServiceId(decryptedGroup.pendingMembersList, aci).isPresent
}
private fun List<UUID>.toRecipientIds(): MutableList<RecipientId> {
return uuidsToRecipientIds(this)
private fun List<ServiceId>.toRecipientIds(): MutableList<RecipientId> {
return serviceIdsToRecipientIds(this.asSequence())
}
private fun Collection<RecipientId>.serialize(): String {
@@ -1398,15 +1398,14 @@ class GroupTable(context: Context?, databaseHelper: SignalDatabase?) : DatabaseT
}
}
private fun uuidsToRecipientIds(uuids: List<UUID>): MutableList<RecipientId> {
return uuids
.asSequence()
.map { uuid ->
if (uuid == UuidUtil.UNKNOWN_UUID) {
private fun serviceIdsToRecipientIds(serviceIds: Sequence<ServiceId>): MutableList<RecipientId> {
return serviceIds
.map { serviceId ->
if (serviceId.isUnknown) {
Log.w(TAG, "Saw an unknown UUID when mapping to RecipientIds!")
null
} else {
val id = RecipientId.from(ACI.from(uuid))
val id = RecipientId.from(serviceId)
val remapped = RemappedRecords.getInstance().getRecipient(id)
if (remapped.isPresent) {
Log.w(TAG, "Saw that $id remapped to $remapped. Using the mapping.")
@@ -1422,8 +1421,7 @@ class GroupTable(context: Context?, databaseHelper: SignalDatabase?) : DatabaseT
}
private fun getV2GroupMembers(decryptedGroup: DecryptedGroup, shouldRetry: Boolean): List<RecipientId> {
val uuids: List<UUID> = DecryptedGroupUtil.membersToUuidList(decryptedGroup.membersList)
val ids: List<RecipientId> = uuidsToRecipientIds(uuids)
val ids: List<RecipientId> = DecryptedGroupUtil.membersToServiceIdList(decryptedGroup.membersList).toRecipientIds()
return if (RemappedRecords.getInstance().areAnyRemapped(ids)) {
if (shouldRetry) {

View File

@@ -142,7 +142,6 @@ import org.thoughtcrime.securesms.util.Util
import org.thoughtcrime.securesms.util.isStory
import org.whispersystems.signalservice.api.messages.multidevice.ReadMessage
import org.whispersystems.signalservice.api.push.ServiceId
import org.whispersystems.signalservice.api.push.ServiceId.ACI
import org.whispersystems.signalservice.internal.push.SignalServiceProtos.SyncMessage
import java.io.Closeable
import java.io.IOException
@@ -3089,10 +3088,9 @@ open class MessageTable(context: Context?, databaseHelper: SignalDatabase) : Dat
val members: MutableSet<RecipientId> = mutableSetOf()
if (message.isGroupUpdate && message.isV2Group) {
// TODO [greyson][ServiceId] pending members could be ACI's or PNI's
members += message.requireGroupV2Properties().allActivePendingAndRemovedMembers
.distinct()
.map { uuid -> RecipientId.from(ACI.from(uuid)) }
.map { serviceId -> RecipientId.from(serviceId) }
.toList()
members -= Recipient.self().id

View File

@@ -176,7 +176,7 @@ class GroupRecord(
if (isV2Group) {
val serviceId = recipient.serviceId
if (serviceId.isPresent) {
return DecryptedGroupUtil.findPendingByUuid(requireV2GroupProperties().decryptedGroup.pendingMembersList, serviceId.get().rawUuid)
return DecryptedGroupUtil.findPendingByServiceId(requireV2GroupProperties().decryptedGroup.pendingMembersList, serviceId.get())
.isPresent
}
}

View File

@@ -33,6 +33,7 @@ import org.thoughtcrime.securesms.recipients.RecipientId;
import org.thoughtcrime.securesms.util.ExpirationUtil;
import org.thoughtcrime.securesms.util.SpanUtil;
import org.whispersystems.signalservice.api.groupsv2.DecryptedGroupUtil;
import org.whispersystems.signalservice.api.push.ServiceId;
import org.whispersystems.signalservice.api.push.ServiceId.ACI;
import org.whispersystems.signalservice.api.push.ServiceIds;
import org.whispersystems.signalservice.api.util.UuidUtil;
@@ -72,9 +73,9 @@ final class GroupsV2UpdateMessageProducer {
* When the revision of the group is 0, the change is very noisy and only the editor is useful.
*/
UpdateDescription describeNewGroup(@NonNull DecryptedGroup group, @NonNull DecryptedGroupChange decryptedGroupChange) {
Optional<DecryptedPendingMember> selfPending = DecryptedGroupUtil.findPendingByUuid(group.getPendingMembersList(), selfIds.getAci().getRawUuid());
Optional<DecryptedPendingMember> selfPending = DecryptedGroupUtil.findPendingByServiceId(group.getPendingMembersList(), selfIds.getAci());
if (!selfPending.isPresent() && selfIds.getPni() != null) {
selfPending = DecryptedGroupUtil.findPendingByUuid(group.getPendingMembersList(), selfIds.getPni().getRawUuid());
selfPending = DecryptedGroupUtil.findPendingByServiceId(group.getPendingMembersList(), selfIds.getPni());
}
if (selfPending.isPresent()) {
@@ -310,13 +311,13 @@ final class GroupsV2UpdateMessageProducer {
int notYouInviteCount = 0;
for (DecryptedPendingMember invitee : change.getNewPendingMembersList()) {
boolean newMemberIsYou = selfIds.matches(invitee.getUuid());
boolean newMemberIsYou = selfIds.matches(invitee.getServiceIdBinary());
if (newMemberIsYou) {
updates.add(0, updateDescription(R.string.MessageRecord_s_invited_you_to_the_group, change.getEditor(), R.drawable.ic_update_group_add_16));
} else {
if (editorIsYou) {
updates.add(updateDescription(R.string.MessageRecord_you_invited_s_to_the_group, invitee.getUuid(), R.drawable.ic_update_group_add_16));
updates.add(updateDescription(R.string.MessageRecord_you_invited_s_to_the_group, invitee.getServiceIdBinary(), R.drawable.ic_update_group_add_16));
} else {
notYouInviteCount++;
}
@@ -332,7 +333,7 @@ final class GroupsV2UpdateMessageProducer {
int notYouInviteCount = 0;
for (DecryptedPendingMember invitee : change.getNewPendingMembersList()) {
boolean newMemberIsYou = selfIds.matches(invitee.getUuid());
boolean newMemberIsYou = selfIds.matches(invitee.getServiceIdBinary());
if (newMemberIsYou) {
UUID uuid = UuidUtil.fromByteStringOrUnknown(invitee.getAddedByUuid());
@@ -357,14 +358,14 @@ final class GroupsV2UpdateMessageProducer {
int notDeclineCount = 0;
for (DecryptedPendingMemberRemoval invitee : change.getDeletePendingMembersList()) {
boolean decline = invitee.getUuid().equals(change.getEditor());
boolean decline = invitee.getServiceIdBinary().equals(change.getEditor());
if (decline) {
if (editorIsYou) {
updates.add(updateDescription(context.getString(R.string.MessageRecord_you_declined_the_invitation_to_the_group), R.drawable.ic_update_group_decline_16));
} else {
updates.add(updateDescription(context.getString(R.string.MessageRecord_someone_declined_an_invitation_to_the_group), R.drawable.ic_update_group_decline_16));
}
} else if (selfIds.matches(invitee.getUuid())) {
} else if (selfIds.matches(invitee.getServiceIdBinary())) {
updates.add(updateDescription(R.string.MessageRecord_s_revoked_your_invitation_to_the_group, change.getEditor(), R.drawable.ic_update_group_decline_16));
} else {
notDeclineCount++;
@@ -384,7 +385,7 @@ final class GroupsV2UpdateMessageProducer {
int notDeclineCount = 0;
for (DecryptedPendingMemberRemoval invitee : change.getDeletePendingMembersList()) {
boolean inviteeWasYou = selfIds.matches(invitee.getUuid());
boolean inviteeWasYou = selfIds.matches(invitee.getServiceIdBinary());
if (inviteeWasYou) {
updates.add(updateDescription(context.getString(R.string.MessageRecord_an_admin_revoked_your_invitation_to_the_group), R.drawable.ic_update_group_decline_16));
@@ -817,14 +818,14 @@ final class GroupsV2UpdateMessageProducer {
}
private UpdateDescription updateDescription(@StringRes int stringRes,
@NonNull ByteString uuid1Bytes,
@NonNull ByteString serviceId1Bytes,
@DrawableRes int iconResource)
{
ACI aci = ACI.parseOrUnknown(uuid1Bytes);
RecipientId recipientId = RecipientId.from(aci);
ACI serviceId = ACI.parseOrUnknown(serviceId1Bytes);
RecipientId recipientId = RecipientId.from(serviceId);
return UpdateDescription.mentioning(
Collections.singletonList(aci),
Collections.singletonList(serviceId),
() -> {
List<RecipientId> recipientIdList = Collections.singletonList(recipientId);
String templateString = context.getString(stringRes, makePlaceholders(recipientIdList, null));
@@ -835,18 +836,18 @@ final class GroupsV2UpdateMessageProducer {
}
private UpdateDescription updateDescription(@StringRes int stringRes,
@NonNull ByteString uuid1Bytes,
@NonNull ByteString uuid2Bytes,
@NonNull ByteString serviceId1Bytes,
@NonNull ByteString serviceId2Bytes,
@DrawableRes int iconResource)
{
ACI aci1 = ACI.parseOrUnknown(uuid1Bytes);
ACI aci2 = ACI.parseOrUnknown(uuid2Bytes);
ACI serviceId1 = ACI.parseOrUnknown(serviceId1Bytes);
ACI serviceId2 = ACI.parseOrUnknown(serviceId2Bytes);
RecipientId recipientId1 = RecipientId.from(aci1);
RecipientId recipientId2 = RecipientId.from(aci2);
RecipientId recipientId1 = RecipientId.from(serviceId1);
RecipientId recipientId2 = RecipientId.from(serviceId2);
return UpdateDescription.mentioning(
Arrays.asList(aci1, aci2),
Arrays.asList(serviceId1, serviceId2),
() -> {
List<RecipientId> recipientIdList = Arrays.asList(recipientId1, recipientId2);
String templateString = context.getString(stringRes, makePlaceholders(recipientIdList, null));
@@ -858,15 +859,15 @@ final class GroupsV2UpdateMessageProducer {
}
private UpdateDescription updateDescription(@StringRes int stringRes,
@NonNull ByteString uuid1Bytes,
@NonNull ByteString serviceId1Bytes,
@NonNull Object formatArg,
@DrawableRes int iconResource)
{
ACI aci = ACI.parseOrUnknown(uuid1Bytes);
RecipientId recipientId = RecipientId.from(aci);
ACI serviceId = ACI.parseOrUnknown(serviceId1Bytes);
RecipientId recipientId = RecipientId.from(serviceId);
return UpdateDescription.mentioning(
Collections.singletonList(aci),
Collections.singletonList(serviceId),
() -> {
List<RecipientId> recipientIdList = Collections.singletonList(recipientId);
String templateString = context.getString(stringRes, makePlaceholders(recipientIdList, Collections.singletonList(formatArg)));
@@ -879,15 +880,15 @@ final class GroupsV2UpdateMessageProducer {
private UpdateDescription updateDescription(@PluralsRes int stringRes,
int quantity,
@NonNull ByteString uuid1Bytes,
@NonNull ByteString serviceId1Bytes,
@NonNull Object formatArg,
@DrawableRes int iconResource)
{
ACI aci = ACI.parseOrUnknown(uuid1Bytes);
RecipientId recipientId = RecipientId.from(aci);
ACI serviceId = ACI.parseOrUnknown(serviceId1Bytes);
RecipientId recipientId = RecipientId.from(serviceId);
return UpdateDescription.mentioning(
Collections.singletonList(aci),
Collections.singletonList(serviceId),
() -> {
List<RecipientId> recipientIdList = Collections.singletonList(recipientId);
String templateString = context.getResources().getQuantityString(stringRes, quantity, makePlaceholders(recipientIdList, Collections.singletonList(formatArg)));

View File

@@ -346,7 +346,7 @@ public abstract class MessageRecord extends DisplayRecord {
}
DecryptedGroup groupState = decryptedGroupV2Context.getGroupState();
boolean invited = DecryptedGroupUtil.findPendingByUuid(groupState.getPendingMembersList(), SignalStore.account().requireAci().getRawUuid()).isPresent();
boolean invited = DecryptedGroupUtil.findPendingByServiceId(groupState.getPendingMembersList(), SignalStore.account().requireAci()).isPresent();
if (decryptedGroupV2Context.hasChange()) {
UUID changeEditor = UuidUtil.fromByteStringOrNull(decryptedGroupV2Context.getChange().getEditor());

View File

@@ -336,7 +336,7 @@ public final class GroupManager {
throws GroupChangeBusyException, IOException, GroupChangeFailedException, GroupNotAMemberException, GroupInsufficientRightsException
{
try (GroupManagerV2.GroupEditor editor = new GroupManagerV2(context).edit(groupId.requireV2())) {
editor.unban(Collections.singleton(Recipient.resolved(recipientId).requireServiceId().getRawUuid()));
editor.unban(Collections.singleton(Recipient.resolved(recipientId).requireServiceId()));
}
}

View File

@@ -176,7 +176,7 @@ final class GroupManagerV2 {
Map<UUID, UuidCiphertext> uuidCipherTexts = new HashMap<>();
for (Recipient recipient : recipients) {
uuidCipherTexts.put(recipient.requireServiceId().getRawUuid(), clientZkGroupCipher.encryptUuid(recipient.requireServiceId().getRawUuid()));
uuidCipherTexts.put(recipient.requireServiceId().getRawUuid(), clientZkGroupCipher.encrypt(recipient.requireServiceId().getLibSignalServiceId()));
}
return uuidCipherTexts;
@@ -343,7 +343,7 @@ final class GroupManagerV2 {
}
@WorkerThread
@NonNull GroupManager.GroupActionResult addMembers(@NonNull Collection<RecipientId> newMembers, @NonNull Set<UUID> bannedMembers)
@NonNull GroupManager.GroupActionResult addMembers(@NonNull Collection<RecipientId> newMembers, @NonNull Set<ServiceId> bannedMembers)
throws GroupChangeFailedException, GroupInsufficientRightsException, IOException, GroupNotAMemberException, MembershipNotSuitableForV2Exception
{
if (!GroupsV2CapabilityChecker.allHaveServiceId(newMembers)) {
@@ -356,7 +356,7 @@ final class GroupManagerV2 {
groupCandidates = GroupCandidate.withoutExpiringProfileKeyCredentials(groupCandidates);
}
return commitChangeWithConflictResolution(selfAci, groupOperations.createModifyGroupMembershipChange(groupCandidates, bannedMembers, selfAci.getRawUuid()));
return commitChangeWithConflictResolution(selfAci, groupOperations.createModifyGroupMembershipChange(groupCandidates, bannedMembers, selfAci));
}
@WorkerThread
@@ -454,7 +454,7 @@ final class GroupManagerV2 {
throws GroupChangeFailedException, GroupInsufficientRightsException, IOException, GroupNotAMemberException
{
Recipient recipient = Recipient.resolved(recipientId);
return commitChangeWithConflictResolution(selfAci, groupOperations.createChangeMemberRole(recipient.requireServiceId().getRawUuid(), admin ? Member.Role.ADMINISTRATOR : Member.Role.DEFAULT));
return commitChangeWithConflictResolution(selfAci, groupOperations.createChangeMemberRole(recipient.requireAci(), admin ? Member.Role.ADMINISTRATOR : Member.Role.DEFAULT));
}
@WorkerThread
@@ -464,8 +464,8 @@ final class GroupManagerV2 {
GroupRecord groupRecord = groupDatabase.requireGroup(groupId);
DecryptedGroup decryptedGroup = groupRecord.requireV2GroupProperties().getDecryptedGroup();
Optional<DecryptedMember> selfMember = DecryptedGroupUtil.findMemberByUuid(decryptedGroup.getMembersList(), selfAci.getRawUuid());
Optional<DecryptedPendingMember> aciPendingMember = DecryptedGroupUtil.findPendingByUuid(decryptedGroup.getPendingMembersList(), selfAci.getRawUuid());
Optional<DecryptedPendingMember> pniPendingMember = DecryptedGroupUtil.findPendingByUuid(decryptedGroup.getPendingMembersList(), selfPni.getRawUuid());
Optional<DecryptedPendingMember> aciPendingMember = DecryptedGroupUtil.findPendingByServiceId(decryptedGroup.getPendingMembersList(), selfAci);
Optional<DecryptedPendingMember> pniPendingMember = DecryptedGroupUtil.findPendingByServiceId(decryptedGroup.getPendingMembersList(), selfPni);
Optional<DecryptedPendingMember> selfPendingMember = Optional.empty();
ServiceId serviceId = selfAci;
@@ -555,8 +555,8 @@ final class GroupManagerV2 {
return null;
}
Optional<DecryptedPendingMember> aciInPending = DecryptedGroupUtil.findPendingByUuid(group.getPendingMembersList(), selfAci.getRawUuid());
Optional<DecryptedPendingMember> pniInPending = DecryptedGroupUtil.findPendingByUuid(group.getPendingMembersList(), selfPni.getRawUuid());
Optional<DecryptedPendingMember> aciInPending = DecryptedGroupUtil.findPendingByServiceId(group.getPendingMembersList(), selfAci);
Optional<DecryptedPendingMember> pniInPending = DecryptedGroupUtil.findPendingByServiceId(group.getPendingMembersList(), selfPni);
GroupCandidate groupCandidate = groupCandidateHelper.recipientIdToCandidate(Recipient.self().getId());
@@ -584,10 +584,10 @@ final class GroupManagerV2 {
return commitChangeWithConflictResolution(selfAci, groupOperations.createBanUuidsChange(Collections.singleton(uuid), rejectJoinRequest, v2GroupProperties.getDecryptedGroup().getBannedMembersList()));
}
public GroupManager.GroupActionResult unban(Set<UUID> uuids)
public GroupManager.GroupActionResult unban(Set<ServiceId> serviceIds)
throws GroupChangeFailedException, GroupNotAMemberException, GroupInsufficientRightsException, IOException
{
return commitChangeWithConflictResolution(selfAci, groupOperations.createUnbanUuidsChange(uuids));
return commitChangeWithConflictResolution(selfAci, groupOperations.createUnbanServiceIdsChange(serviceIds));
}
@WorkerThread
@@ -704,7 +704,7 @@ final class GroupManagerV2 {
GroupChange.Actions changeActions = change.build();
return GroupChangeUtil.resolveConflict(groupUpdateResult.getLatestServer(),
groupOperations.decryptChange(changeActions, authServiceId.getRawUuid()),
groupOperations.decryptChange(changeActions, authServiceId),
changeActions);
} catch (VerificationFailedException | InvalidGroupStateException ex) {
throw new GroupChangeFailedException(ex);
@@ -1331,9 +1331,8 @@ final class GroupManagerV2 {
}
private static @NonNull List<RecipientId> getPendingMemberRecipientIds(@NonNull List<DecryptedPendingMember> newPendingMembersList) {
// TODO [greyson][ServiceId] Pending members can be ACI's or PNI's
return Stream.of(DecryptedGroupUtil.pendingToUuidList(newPendingMembersList))
.map(uuid -> RecipientId.from(ACI.from(uuid)))
return Stream.of(DecryptedGroupUtil.pendingToServiceIdList(newPendingMembersList))
.map(serviceId -> RecipientId.from(serviceId))
.toList();
}

View File

@@ -19,6 +19,7 @@ import org.thoughtcrime.securesms.recipients.Recipient;
import org.thoughtcrime.securesms.recipients.RecipientId;
import org.whispersystems.signalservice.api.groupsv2.PartialDecryptedGroup;
import org.whispersystems.signalservice.api.push.ServiceId;
import org.whispersystems.signalservice.api.push.ServiceId.ACI;
import org.whispersystems.signalservice.api.util.UuidUtil;
import org.whispersystems.signalservice.internal.push.SignalServiceProtos;
@@ -30,17 +31,17 @@ public final class GroupProtoUtil {
private GroupProtoUtil() {
}
public static int findRevisionWeWereAdded(@NonNull PartialDecryptedGroup partialDecryptedGroup, @NonNull UUID uuid)
public static int findRevisionWeWereAdded(@NonNull PartialDecryptedGroup partialDecryptedGroup, @NonNull ACI self)
throws GroupNotAMemberException
{
ByteString bytes = UuidUtil.toByteString(uuid);
ByteString bytes = self.toByteString();
for (DecryptedMember decryptedMember : partialDecryptedGroup.getMembersList()) {
if (decryptedMember.getUuid().equals(bytes)) {
return decryptedMember.getJoinedAtRevision();
}
}
for (DecryptedPendingMember decryptedMember : partialDecryptedGroup.getPendingMembersList()) {
if (decryptedMember.getUuid().equals(bytes)) {
if (decryptedMember.getServiceIdBinary().equals(bytes)) {
// Assume latest, we don't have any information about when pending members were invited
return partialDecryptedGroup.getRevision();
}
@@ -80,12 +81,12 @@ public final class GroupProtoUtil {
@WorkerThread
public static Recipient pendingMemberToRecipient(@NonNull Context context, @NonNull DecryptedPendingMember pendingMember) {
return pendingMemberServiceIdToRecipient(context, pendingMember.getUuid());
return pendingMemberServiceIdToRecipient(context, pendingMember.getServiceIdBinary());
}
@WorkerThread
public static Recipient pendingMemberServiceIdToRecipient(@NonNull Context context, @NonNull ByteString uuidByteString) {
ServiceId serviceId = ServiceId.parseOrThrow(uuidByteString);
public static Recipient pendingMemberServiceIdToRecipient(@NonNull Context context, @NonNull ByteString serviceIdBinary) {
ServiceId serviceId = ServiceId.parseOrThrow(serviceIdBinary);
if (serviceId.isUnknown()) {
return Recipient.UNKNOWN;
@@ -95,8 +96,8 @@ public final class GroupProtoUtil {
}
@WorkerThread
public static @NonNull RecipientId uuidByteStringToRecipientId(@NonNull ByteString uuidByteString) {
ServiceId serviceId = ServiceId.parseOrThrow(uuidByteString);
public static @NonNull RecipientId serviceIdBinaryToRecipientId(@NonNull ByteString serviceIdBinary) {
ServiceId serviceId = ServiceId.parseOrThrow(serviceIdBinary);
if (serviceId.isUnknown()) {
return RecipientId.UNKNOWN;

View File

@@ -126,13 +126,13 @@ public class GroupsV2Authorization {
}
CallLinkAuthCredential credential = authCredentialResponse.receive(
Recipient.self().requireServiceId().getRawUuid(),
Recipient.self().requireAci().getLibSignalAci(),
Instant.ofEpochSecond(todaySeconds),
genericServerPublicParams
);
return credential.present(
Recipient.self().requireServiceId().getRawUuid(),
Recipient.self().requireAci().getLibSignalAci(),
Instant.ofEpochSecond(todaySeconds),
genericServerPublicParams,
callLinkSecretParams

View File

@@ -144,7 +144,7 @@ public final class LiveGroup {
return Transformations.map(groupRecord, g -> g.isAdmin(Recipient.self()));
}
public LiveData<Set<UUID>> getBannedMembers() {
public LiveData<Set<ServiceId>> getBannedMembers() {
return Transformations.map(groupRecord, g -> g.isV2Group() ? g.requireV2GroupProperties().getBannedMembers() : Collections.emptySet());
}

View File

@@ -51,7 +51,7 @@ public class GroupCandidateHelper {
}
Optional<ExpiringProfileKeyCredential> expiringProfileKeyCredential = Optional.ofNullable(recipient.getExpiringProfileKeyCredential());
GroupCandidate candidate = new GroupCandidate(serviceId.getRawUuid(), expiringProfileKeyCredential);
GroupCandidate candidate = new GroupCandidate(serviceId, expiringProfileKeyCredential);
if (!candidate.hasValidProfileKeyCredential()) {
recipientTable.clearProfileKeyCredential(recipient.getId());

View File

@@ -380,9 +380,7 @@ public class GroupsV2StateProcessor {
boolean addedAsPendingMember = signedGroupChange.getNewPendingMembersList()
.stream()
.map(DecryptedPendingMember::getUuid)
.map(UuidUtil::fromByteStringOrNull)
.filter(Objects::nonNull)
.map(DecryptedPendingMember::getServiceIdBinary)
.anyMatch(serviceIds::matches);
boolean addedAsRequestingMember = signedGroupChange.getNewRequestingMembersList()
@@ -398,9 +396,7 @@ public class GroupsV2StateProcessor {
private boolean notHavingInviteRevoked(@NonNull DecryptedGroupChange signedGroupChange) {
boolean havingInviteRevoked = signedGroupChange.getDeletePendingMembersList()
.stream()
.map(DecryptedPendingMemberRemoval::getUuid)
.map(UuidUtil::fromByteStringOrNull)
.filter(Objects::nonNull)
.map(DecryptedPendingMemberRemoval::getServiceIdBinary)
.anyMatch(serviceIds::matches);
return !havingInviteRevoked;
@@ -434,7 +430,7 @@ public class GroupsV2StateProcessor {
info("Latest revision or not a member, use latest only");
inputGroupState = new GlobalGroupState(localState, Collections.singletonList(new ServerGroupLogEntry(latestServerGroup.getFullyDecryptedGroup(), null)));
} else {
int revisionWeWereAdded = GroupProtoUtil.findRevisionWeWereAdded(latestServerGroup, serviceIds.getAci().getRawUuid());
int revisionWeWereAdded = GroupProtoUtil.findRevisionWeWereAdded(latestServerGroup, serviceIds.getAci());
int logsNeededFrom = localState != null ? Math.max(localState.getRevision(), revisionWeWereAdded) : revisionWeWereAdded;
boolean includeFirstState = forceIncludeFirst ||
@@ -694,7 +690,7 @@ public class GroupsV2StateProcessor {
}
Optional<DecryptedMember> selfAsMemberOptional = DecryptedGroupUtil.findMemberByUuid(newLocalState.getMembersList(), aci.getRawUuid());
Optional<DecryptedPendingMember> selfAsPendingOptional = DecryptedGroupUtil.findPendingByUuid(newLocalState.getPendingMembersList(), aci.getRawUuid());
Optional<DecryptedPendingMember> selfAsPendingOptional = DecryptedGroupUtil.findPendingByServiceId(newLocalState.getPendingMembersList(), aci);
if (selfAsMemberOptional.isPresent()) {
DecryptedMember selfAsMember = selfAsMemberOptional.get();
@@ -835,7 +831,7 @@ public class GroupsV2StateProcessor {
if (changeEditor.isPresent()) {
return changeEditor;
} else {
Optional<DecryptedPendingMember> pendingByUuid = DecryptedGroupUtil.findPendingByUuid(decryptedGroupV2Context.getGroupState().getPendingMembersList(), aci.getRawUuid());
Optional<DecryptedPendingMember> pendingByUuid = DecryptedGroupUtil.findPendingByServiceId(decryptedGroupV2Context.getGroupState().getPendingMembersList(), aci);
if (pendingByUuid.isPresent()) {
return Optional.ofNullable(UuidUtil.fromByteStringOrNull(pendingByUuid.get().getAddedByUuid()));
}

View File

@@ -33,6 +33,7 @@ import org.whispersystems.signalservice.api.groupsv2.DecryptedGroupUtil;
import org.whispersystems.signalservice.api.messages.SendMessageResult;
import org.whispersystems.signalservice.api.messages.SignalServiceDataMessage;
import org.whispersystems.signalservice.api.messages.SignalServiceGroupV2;
import org.whispersystems.signalservice.api.push.ServiceId;
import org.whispersystems.signalservice.api.push.ServiceId.ACI;
import org.whispersystems.signalservice.api.push.exceptions.ServerRejectedException;
import org.whispersystems.signalservice.api.util.UuidUtil;
@@ -72,13 +73,18 @@ public final class PushGroupSilentUpdateSendJob extends BaseJob {
@NonNull DecryptedGroup decryptedGroup,
@NonNull OutgoingMessage groupMessage)
{
List<UUID> memberUuids = DecryptedGroupUtil.toUuidList(decryptedGroup.getMembersList());
List<UUID> pendingUuids = DecryptedGroupUtil.pendingToUuidList(decryptedGroup.getPendingMembersList());
List<UUID> memberUuids = DecryptedGroupUtil.toUuidList(decryptedGroup.getMembersList());
List<ServiceId> pendingServiceIds = DecryptedGroupUtil.pendingToServiceIdList(decryptedGroup.getPendingMembersList());
Set<RecipientId> recipients = Stream.concat(Stream.of(memberUuids), Stream.of(pendingUuids))
.filter(uuid -> !UuidUtil.UNKNOWN_UUID.equals(uuid))
.filter(uuid -> !SignalStore.account().requireAci().getRawUuid().equals(uuid))
.map(uuid -> Recipient.externalPush(ACI.from(uuid)))
Stream<ServiceId> memberServiceIds = Stream.of(memberUuids)
.filter(uuid -> !UuidUtil.UNKNOWN_UUID.equals(uuid))
.filter(uuid -> !SignalStore.account().requireAci().getRawUuid().equals(uuid))
.map(ACI::from);
Stream<ServiceId> filteredPendingServiceIds = Stream.of(pendingServiceIds)
.filterNot(ServiceId::isUnknown);
Set<RecipientId> recipients = Stream.concat(memberServiceIds, filteredPendingServiceIds)
.map(serviceId -> Recipient.externalPush(serviceId))
.filter(recipient -> recipient.getRegistered() != RecipientTable.RegisteredState.NOT_REGISTERED)
.map(Recipient::getId)
.collect(Collectors.toSet());

View File

@@ -166,19 +166,18 @@ public final class MessageGroupContext {
return decryptedGroupV2Context.getChange();
}
public @NonNull List<UUID> getAllActivePendingAndRemovedMembers() {
LinkedList<UUID> memberUuids = new LinkedList<>();
DecryptedGroup groupState = decryptedGroupV2Context.getGroupState();
DecryptedGroupChange groupChange = decryptedGroupV2Context.getChange();
public @NonNull List<ServiceId> getAllActivePendingAndRemovedMembers() {
DecryptedGroup groupState = decryptedGroupV2Context.getGroupState();
DecryptedGroupChange groupChange = decryptedGroupV2Context.getChange();
memberUuids.addAll(DecryptedGroupUtil.membersToUuidList(groupState.getMembersList()));
memberUuids.addAll(DecryptedGroupUtil.pendingToUuidList(groupState.getPendingMembersList()));
memberUuids.addAll(DecryptedGroupUtil.removedMembersUuidList(groupChange));
memberUuids.addAll(DecryptedGroupUtil.removedPendingMembersUuidList(groupChange));
memberUuids.addAll(DecryptedGroupUtil.removedRequestingMembersUuidList(groupChange));
return UuidUtil.filterKnown(memberUuids);
return Stream.of(DecryptedGroupUtil.membersToServiceIdList(groupState.getMembersList()),
DecryptedGroupUtil.pendingToServiceIdList(groupState.getPendingMembersList()),
DecryptedGroupUtil.removedMembersServiceIdList(groupChange),
DecryptedGroupUtil.removedPendingMembersServiceIdList(groupChange),
DecryptedGroupUtil.removedRequestingMembersServiceIdList(groupChange))
.flatMap(Stream::of)
.filterNot(ServiceId::isUnknown)
.toList();
}
@Override

View File

@@ -45,7 +45,7 @@ class SignalCallLinkManager(
linkRootKey: ByteArray,
roomId: ByteArray
): CreateCallLinkCredentialPresentation {
val userUuid = Recipient.self().requireAci().rawUuid
val userAci = Recipient.self().requireAci()
val requestContext = CreateCallLinkCredentialRequestContext.forRoom(roomId)
val request = requestContext.request
@@ -60,7 +60,7 @@ class SignalCallLinkManager(
val createCallLinkCredential: CreateCallLinkCredential = requestContext.receiveResponse(
serviceResponse.result.get(),
userUuid,
userAci.libSignalAci,
genericServerPublicParams
)
@@ -68,7 +68,7 @@ class SignalCallLinkManager(
return createCallLinkCredential.present(
roomId,
userUuid,
userAci.libSignalAci,
genericServerPublicParams,
CallLinkSecretParams.deriveFromRootKey(linkRootKey)
)

View File

@@ -295,7 +295,7 @@ public final class ProfileUtil {
Log.i(TAG, String.format("Updating profile key credential on recipient %s, fetching", recipient.getId()));
Optional<ExpiringProfileKeyCredential> profileKeyCredentialOptional = ApplicationDependencies.getSignalServiceAccountManager()
.resolveProfileKeyCredential(recipient.requireServiceId(), profileKey, Locale.getDefault());
.resolveProfileKeyCredential(recipient.requireAci(), profileKey, Locale.getDefault());
if (profileKeyCredentialOptional.isPresent()) {
boolean updatedProfileKey = SignalDatabase.recipients().setProfileKeyCredential(recipient.getId(), profileKey, profileKeyCredentialOptional.get());