use of org.thoughtcrime.securesms.groups.GroupMigrationMembershipChange in project Signal-Android by WhisperSystems.
the class GroupDatabase method migrateToV2.
/**
* Migrates a V1 group to a V2 group.
*
* @param decryptedGroup The state that represents the group on the server. This will be used to
* determine if we need to save our old membership list and stuff.
*/
@NonNull
public GroupId.V2 migrateToV2(long threadId, @NonNull GroupId.V1 groupIdV1, @NonNull DecryptedGroup decryptedGroup) {
SQLiteDatabase db = databaseHelper.getSignalWritableDatabase();
GroupId.V2 groupIdV2 = groupIdV1.deriveV2MigrationGroupId();
GroupMasterKey groupMasterKey = groupIdV1.deriveV2MigrationMasterKey();
db.beginTransaction();
try {
GroupRecord record = getGroup(groupIdV1).get();
ContentValues contentValues = new ContentValues();
contentValues.put(GROUP_ID, groupIdV2.toString());
contentValues.put(V2_MASTER_KEY, groupMasterKey.serialize());
contentValues.put(DISTRIBUTION_ID, DistributionId.create().toString());
contentValues.putNull(EXPECTED_V2_ID);
List<RecipientId> newMembers = uuidsToRecipientIds(DecryptedGroupUtil.membersToUuidList(decryptedGroup.getMembersList()));
List<RecipientId> pendingMembers = uuidsToRecipientIds(DecryptedGroupUtil.pendingToUuidList(decryptedGroup.getPendingMembersList()));
newMembers.addAll(pendingMembers);
List<RecipientId> droppedMembers = new ArrayList<>(SetUtil.difference(record.getMembers(), newMembers));
List<RecipientId> unmigratedMembers = Util.concatenatedList(pendingMembers, droppedMembers);
contentValues.put(UNMIGRATED_V1_MEMBERS, unmigratedMembers.isEmpty() ? null : RecipientId.toSerializedList(unmigratedMembers));
int updated = db.update(TABLE_NAME, contentValues, GROUP_ID + " = ?", SqlUtil.buildArgs(groupIdV1.toString()));
if (updated != 1) {
throw new AssertionError();
}
SignalDatabase.recipients().updateGroupId(groupIdV1, groupIdV2);
update(groupMasterKey, decryptedGroup);
SignalDatabase.sms().insertGroupV1MigrationEvents(record.getRecipientId(), threadId, new GroupMigrationMembershipChange(pendingMembers, droppedMembers));
db.setTransactionSuccessful();
} finally {
db.endTransaction();
}
return groupIdV2;
}
use of org.thoughtcrime.securesms.groups.GroupMigrationMembershipChange in project Signal-Android by WhisperSystems.
the class MessageRecord method getGroupMigrationEventDescription.
private UpdateDescription getGroupMigrationEventDescription(@NonNull Context context) {
if (Util.isEmpty(getBody())) {
return staticUpdateDescription(context.getString(R.string.MessageRecord_this_group_was_updated_to_a_new_group), R.drawable.ic_update_group_role_16);
} else {
GroupMigrationMembershipChange change = getGroupV1MigrationMembershipChanges();
List<UpdateDescription> updates = new ArrayList<>(2);
if (change.getPending().size() == 1 && change.getPending().get(0).equals(Recipient.self().getId())) {
updates.add(staticUpdateDescription(context.getString(R.string.MessageRecord_you_couldnt_be_added_to_the_new_group_and_have_been_invited_to_join), R.drawable.ic_update_group_add_16));
} else if (change.getPending().size() > 0) {
int count = change.getPending().size();
updates.add(staticUpdateDescription(context.getResources().getQuantityString(R.plurals.MessageRecord_members_couldnt_be_added_to_the_new_group_and_have_been_invited, count, count), R.drawable.ic_update_group_add_16));
}
if (change.getDropped().size() > 0) {
int count = change.getDropped().size();
updates.add(staticUpdateDescription(context.getResources().getQuantityString(R.plurals.MessageRecord_members_couldnt_be_added_to_the_new_group_and_have_been_removed, count, count), R.drawable.ic_update_group_remove_16));
}
return UpdateDescription.concatWithNewLines(updates);
}
}
use of org.thoughtcrime.securesms.groups.GroupMigrationMembershipChange in project Signal-Android by signalapp.
the class GroupDatabase method migrateToV2.
/**
* Migrates a V1 group to a V2 group.
*
* @param decryptedGroup The state that represents the group on the server. This will be used to
* determine if we need to save our old membership list and stuff.
*/
@NonNull
public GroupId.V2 migrateToV2(long threadId, @NonNull GroupId.V1 groupIdV1, @NonNull DecryptedGroup decryptedGroup) {
SQLiteDatabase db = databaseHelper.getSignalWritableDatabase();
GroupId.V2 groupIdV2 = groupIdV1.deriveV2MigrationGroupId();
GroupMasterKey groupMasterKey = groupIdV1.deriveV2MigrationMasterKey();
db.beginTransaction();
try {
GroupRecord record = getGroup(groupIdV1).get();
ContentValues contentValues = new ContentValues();
contentValues.put(GROUP_ID, groupIdV2.toString());
contentValues.put(V2_MASTER_KEY, groupMasterKey.serialize());
contentValues.put(DISTRIBUTION_ID, DistributionId.create().toString());
contentValues.putNull(EXPECTED_V2_ID);
List<RecipientId> newMembers = uuidsToRecipientIds(DecryptedGroupUtil.membersToUuidList(decryptedGroup.getMembersList()));
List<RecipientId> pendingMembers = uuidsToRecipientIds(DecryptedGroupUtil.pendingToUuidList(decryptedGroup.getPendingMembersList()));
newMembers.addAll(pendingMembers);
List<RecipientId> droppedMembers = new ArrayList<>(SetUtil.difference(record.getMembers(), newMembers));
List<RecipientId> unmigratedMembers = Util.concatenatedList(pendingMembers, droppedMembers);
contentValues.put(UNMIGRATED_V1_MEMBERS, unmigratedMembers.isEmpty() ? null : RecipientId.toSerializedList(unmigratedMembers));
int updated = db.update(TABLE_NAME, contentValues, GROUP_ID + " = ?", SqlUtil.buildArgs(groupIdV1.toString()));
if (updated != 1) {
throw new AssertionError();
}
SignalDatabase.recipients().updateGroupId(groupIdV1, groupIdV2);
update(groupMasterKey, decryptedGroup);
SignalDatabase.sms().insertGroupV1MigrationEvents(record.getRecipientId(), threadId, new GroupMigrationMembershipChange(pendingMembers, droppedMembers));
db.setTransactionSuccessful();
} finally {
db.endTransaction();
}
return groupIdV2;
}
use of org.thoughtcrime.securesms.groups.GroupMigrationMembershipChange in project Signal-Android by signalapp.
the class MessageRecord method getGroupMigrationEventDescription.
private UpdateDescription getGroupMigrationEventDescription(@NonNull Context context) {
if (Util.isEmpty(getBody())) {
return staticUpdateDescription(context.getString(R.string.MessageRecord_this_group_was_updated_to_a_new_group), R.drawable.ic_update_group_role_16);
} else {
GroupMigrationMembershipChange change = getGroupV1MigrationMembershipChanges();
List<UpdateDescription> updates = new ArrayList<>(2);
if (change.getPending().size() == 1 && change.getPending().get(0).equals(Recipient.self().getId())) {
updates.add(staticUpdateDescription(context.getString(R.string.MessageRecord_you_couldnt_be_added_to_the_new_group_and_have_been_invited_to_join), R.drawable.ic_update_group_add_16));
} else if (change.getPending().size() > 0) {
int count = change.getPending().size();
updates.add(staticUpdateDescription(context.getResources().getQuantityString(R.plurals.MessageRecord_members_couldnt_be_added_to_the_new_group_and_have_been_invited, count, count), R.drawable.ic_update_group_add_16));
}
if (change.getDropped().size() > 0) {
int count = change.getDropped().size();
updates.add(staticUpdateDescription(context.getResources().getQuantityString(R.plurals.MessageRecord_members_couldnt_be_added_to_the_new_group_and_have_been_removed, count, count), R.drawable.ic_update_group_remove_16));
}
return UpdateDescription.concatWithNewLines(updates);
}
}
use of org.thoughtcrime.securesms.groups.GroupMigrationMembershipChange in project Signal-Android by WhisperSystems.
the class GroupsV1MigrationInfoBottomSheetDialogFragment method onViewCreated.
@Override
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
this.pendingContainer = view.findViewById(R.id.gv1_learn_more_pending_container);
this.pendingTitle = view.findViewById(R.id.gv1_learn_more_pending_title);
this.pendingList = view.findViewById(R.id.gv1_learn_more_pending_list);
this.droppedContainer = view.findViewById(R.id.gv1_learn_more_dropped_container);
this.droppedTitle = view.findViewById(R.id.gv1_learn_more_dropped_title);
this.droppedList = view.findViewById(R.id.gv1_learn_more_dropped_list);
pendingList.initializeAdapter(getViewLifecycleOwner());
droppedList.initializeAdapter(getViewLifecycleOwner());
// noinspection ConstantConditions
GroupMigrationMembershipChange membershipChange = GroupMigrationMembershipChange.deserialize(getArguments().getString(KEY_MEMBERSHIP_CHANGE));
this.viewModel = ViewModelProviders.of(this, new GroupsV1MigrationInfoViewModel.Factory(membershipChange)).get(GroupsV1MigrationInfoViewModel.class);
viewModel.getPendingMembers().observe(getViewLifecycleOwner(), this::onPendingMembersChanged);
viewModel.getDroppedMembers().observe(getViewLifecycleOwner(), this::onDroppedMembersChanged);
view.findViewById(R.id.gv1_learn_more_ok_button).setOnClickListener(v -> dismiss());
}
Aggregations