mirror of
https://github.com/signalapp/Signal-Android.git
synced 2026-04-21 09:20:19 +01:00
Fix issue with group creation on linked devices.
This commit is contained in:
@@ -22,6 +22,9 @@ import org.signal.zkgroup.InvalidInputException;
|
||||
import org.signal.zkgroup.groups.GroupMasterKey;
|
||||
import org.thoughtcrime.securesms.crypto.SenderKeyUtil;
|
||||
import org.thoughtcrime.securesms.database.helpers.SQLCipherOpenHelper;
|
||||
import org.thoughtcrime.securesms.dependencies.ApplicationDependencies;
|
||||
import org.thoughtcrime.securesms.groups.v2.processing.GroupsV2StateProcessor;
|
||||
import org.thoughtcrime.securesms.jobs.RequestGroupV2InfoJob;
|
||||
import org.whispersystems.signalservice.api.push.DistributionId;
|
||||
import org.thoughtcrime.securesms.groups.GroupAccessControl;
|
||||
import org.thoughtcrime.securesms.groups.GroupId;
|
||||
@@ -441,6 +444,47 @@ private static final String[] GROUP_PROJECTION = {
|
||||
return groupId;
|
||||
}
|
||||
|
||||
/**
|
||||
* There was a point in time where we weren't properly responding to group creates on linked devices. This would result in us having a Recipient entry for the
|
||||
* group, but we'd either be missing the group entry, or that entry would be missing a master key. This method fixes this scenario.
|
||||
*/
|
||||
public void fixMissingMasterKey(@NonNull GroupMasterKey groupMasterKey) {
|
||||
GroupId.V2 groupId = GroupId.v2(groupMasterKey);
|
||||
|
||||
if (getGroupV1ByExpectedV2(groupId).isPresent()) {
|
||||
throw new MissedGroupMigrationInsertException(groupId);
|
||||
}
|
||||
|
||||
SQLiteDatabase db = databaseHelper.getWritableDatabase();
|
||||
|
||||
db.beginTransaction();
|
||||
try {
|
||||
String query = GROUP_ID + " = ?";
|
||||
String[] args = SqlUtil.buildArgs(groupId);
|
||||
ContentValues values = new ContentValues();
|
||||
|
||||
values.put(V2_MASTER_KEY, groupMasterKey.serialize());
|
||||
|
||||
int updated = db.update(TABLE_NAME, values, query, args);
|
||||
|
||||
if (updated < 1) {
|
||||
Log.w(TAG, "No group entry. Creating restore placeholder for " + groupId);
|
||||
create(groupMasterKey, DecryptedGroup.newBuilder()
|
||||
.setRevision(GroupsV2StateProcessor.RESTORE_PLACEHOLDER_REVISION)
|
||||
.build());
|
||||
} else {
|
||||
Log.w(TAG, "Had a group entry, but it was missing a master key. Updated.");
|
||||
}
|
||||
|
||||
db.setTransactionSuccessful();
|
||||
} finally {
|
||||
db.endTransaction();
|
||||
}
|
||||
|
||||
Log.w(TAG, "Scheduling request for latest group info for " + groupId);
|
||||
ApplicationDependencies.getJobManager().add(new RequestGroupV2InfoJob(groupId));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param groupMasterKey null for V1, must be non-null for V2 (presence dictates group version).
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user