If two recipient ids get canonicalized to the same thing, drop one

There's not a great way for me to know which of them is the "real"
entry, which means that I could be deleting the wrong one. In the
case of recipient "preferences," it's hopefully not a huge loss,
and there aren't any other great options.

Fixes #6838

// FREEBIE
This commit is contained in:
Moxie Marlinspike 2017-08-01 14:49:16 -07:00
parent 8a5c89244a
commit 6ed549cfb2

View File

@ -19,6 +19,7 @@ package org.thoughtcrime.securesms.database;
import android.content.ContentValues; import android.content.ContentValues;
import android.content.Context; import android.content.Context;
import android.database.Cursor; import android.database.Cursor;
import android.database.sqlite.SQLiteConstraintException;
import android.database.sqlite.SQLiteDatabase; import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteDatabase.CursorFactory; import android.database.sqlite.SQLiteDatabase.CursorFactory;
import android.database.sqlite.SQLiteOpenHelper; import android.database.sqlite.SQLiteOpenHelper;
@ -997,7 +998,13 @@ public class DatabaseFactory {
ContentValues values = new ContentValues(1); ContentValues values = new ContentValues(1);
values.put("recipient_ids", Util.join(addresses, " ")); values.put("recipient_ids", Util.join(addresses, " "));
db.update("recipient_preferences", values, "_id = ?", new String[] {String.valueOf(id)});
try {
db.update("recipient_preferences", values, "_id = ?", new String[] {String.valueOf(id)});
} catch (SQLiteConstraintException e) {
Log.w(TAG, e);
db.delete("recipient_preference", "_id = ?", new String[] {String.valueOf(id)});
}
} }
if (cursor != null) cursor.close(); if (cursor != null) cursor.close();