Fix some bugs that would mis-label threads in migration

// FREEBIE
This commit is contained in:
Moxie Marlinspike 2017-07-31 14:04:47 -07:00
parent 737810475e
commit 0ae60da68b

View File

@ -911,14 +911,14 @@ public class DatabaseFactory {
long threadId = cursor.getLong(0);
String recipientIdsList = cursor.getString(1);
String[] recipientIds = recipientIdsList.split(" ");
String[] numbers = new String[recipientIds.length];
String[] addresses = new String[recipientIds.length];
for (int i=0;i<recipientIds.length;i++) {
Cursor resolved = canonicalAddressDatabase.query("canonical_addresses", new String[] {"address"}, "_id = ?", new String[] {recipientIds[i]}, null, null, null);
if (resolved != null && resolved.moveToFirst()) {
String address = resolved.getString(0);
numbers[i] = numberMigrator.migrate(address);
addresses[i] = numberMigrator.migrate(address);
} else {
throw new AssertionError("Unable to resolve: " + recipientIds[i]);
}
@ -927,7 +927,7 @@ public class DatabaseFactory {
}
ContentValues values = new ContentValues(1);
values.put("recipient_ids", Util.join(numbers, " "));
values.put("recipient_ids", Util.join(addresses, " "));
db.update("thread", values, "_id = ?", new String[] {String.valueOf(threadId)});
}
@ -997,7 +997,7 @@ public class DatabaseFactory {
ContentValues values = new ContentValues(1);
values.put("recipient_ids", Util.join(addresses, " "));
db.update("thread", values, "_id = ?", new String[] {String.valueOf(id)});
db.update("recipient_preferences", values, "_id = ?", new String[] {String.valueOf(id)});
}
if (cursor != null) cursor.close();
@ -1337,12 +1337,12 @@ public class DatabaseFactory {
if (localNumberImprecise.charAt(0) == '+')
localNumberImprecise = localNumberImprecise.substring(1);
if (localNumberImprecise.length() == number.length() || number.length() > localNumberImprecise.length())
if (localNumberImprecise.length() == bareNumber.length() || bareNumber.length() > localNumberImprecise.length())
return "+" + number;
int difference = localNumberImprecise.length() - number.length();
int difference = localNumberImprecise.length() - bareNumber.length();
return "+" + localNumberImprecise.substring(0, difference) + number;
return "+" + localNumberImprecise.substring(0, difference) + bareNumber;
}
}