mirror of
https://github.com/M66B/FairEmail.git
synced 2026-03-27 19:35:10 +01:00
Added uuid to answers
This commit is contained in:
2771
app/schemas/eu.faircode.email.DB/238.json
Normal file
2771
app/schemas/eu.faircode.email.DB/238.json
Normal file
File diff suppressed because it is too large
Load Diff
@@ -984,6 +984,10 @@ public class ActivitySetup extends ActivityBase implements FragmentManager.OnBac
|
||||
long id = answer.id;
|
||||
answer.id = null;
|
||||
|
||||
EntityAnswer existing = db.answer().getAnswerByUUID(answer.uuid);
|
||||
if (existing != null)
|
||||
db.answer().deleteAnswer(existing.id);
|
||||
|
||||
answer.id = db.answer().insertAnswer(answer);
|
||||
xAnswer.put(id, answer.id);
|
||||
|
||||
|
||||
@@ -71,7 +71,7 @@ import io.requery.android.database.sqlite.SQLiteDatabase;
|
||||
// https://developer.android.com/topic/libraries/architecture/room.html
|
||||
|
||||
@Database(
|
||||
version = 237,
|
||||
version = 238,
|
||||
entities = {
|
||||
EntityIdentity.class,
|
||||
EntityAccount.class,
|
||||
@@ -2361,6 +2361,19 @@ public abstract class DB extends RoomDatabase {
|
||||
}
|
||||
}
|
||||
}
|
||||
}).addMigrations(new Migration(237, 238) {
|
||||
@Override
|
||||
public void migrate(@NonNull SupportSQLiteDatabase db) {
|
||||
logMigration(startVersion, endVersion);
|
||||
db.execSQL("ALTER TABLE `answer` ADD COLUMN `uuid` TEXT NOT NULL DEFAULT ''");
|
||||
try (Cursor cursor = db.query("SELECT id FROM answer")) {
|
||||
while (cursor != null && cursor.moveToNext()) {
|
||||
long id = cursor.getLong(0);
|
||||
String uuid = UUID.randomUUID().toString();
|
||||
db.execSQL("UPDATE answer SET uuid = ? WHERE id = ?", new Object[]{uuid, id});
|
||||
}
|
||||
}
|
||||
}
|
||||
}).addMigrations(new Migration(998, 999) {
|
||||
@Override
|
||||
public void migrate(@NonNull SupportSQLiteDatabase db) {
|
||||
|
||||
@@ -55,6 +55,9 @@ public interface DaoAnswer {
|
||||
@Query("SELECT * FROM answer WHERE id = :id")
|
||||
EntityAnswer getAnswer(long id);
|
||||
|
||||
@Query("SELECT * FROM answer WHERE uuid = :uuid")
|
||||
EntityAnswer getAnswerByUUID(String uuid);
|
||||
|
||||
@Query("SELECT * FROM answer" +
|
||||
" WHERE standard AND NOT hide")
|
||||
EntityAnswer getStandardAnswer();
|
||||
|
||||
@@ -56,6 +56,7 @@ import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.UUID;
|
||||
|
||||
import javax.mail.Address;
|
||||
import javax.mail.internet.InternetAddress;
|
||||
@@ -75,6 +76,8 @@ public class EntityAnswer implements Serializable {
|
||||
@PrimaryKey(autoGenerate = true)
|
||||
public Long id;
|
||||
@NonNull
|
||||
public String uuid = UUID.randomUUID().toString();
|
||||
@NonNull
|
||||
public String name;
|
||||
public String group;
|
||||
@NonNull
|
||||
@@ -336,7 +339,7 @@ public class EntityAnswer implements Serializable {
|
||||
ssb.append(p.link).append("\n\n");
|
||||
|
||||
profiles.add(999, profiles.size(), profiles.size() + 1, p.name +
|
||||
(p.appPassword ? "+" : ""))
|
||||
(p.appPassword ? "+" : ""))
|
||||
.setIntent(new Intent().putExtra("config", ssb));
|
||||
}
|
||||
}
|
||||
@@ -374,6 +377,7 @@ public class EntityAnswer implements Serializable {
|
||||
public JSONObject toJSON() throws JSONException {
|
||||
JSONObject json = new JSONObject();
|
||||
json.put("id", id);
|
||||
json.put("uuid", uuid);
|
||||
json.put("name", name);
|
||||
json.put("group", group);
|
||||
json.put("standard", standard);
|
||||
@@ -392,6 +396,8 @@ public class EntityAnswer implements Serializable {
|
||||
public static EntityAnswer fromJSON(JSONObject json) throws JSONException {
|
||||
EntityAnswer answer = new EntityAnswer();
|
||||
answer.id = json.getLong("id");
|
||||
if (json.has("uuid"))
|
||||
answer.uuid = json.getString("uuid");
|
||||
answer.name = json.getString("name");
|
||||
answer.group = json.optString("group");
|
||||
if (TextUtils.isEmpty(answer.group))
|
||||
@@ -415,7 +421,8 @@ public class EntityAnswer implements Serializable {
|
||||
public boolean equals(Object obj) {
|
||||
if (obj instanceof EntityAnswer) {
|
||||
EntityAnswer other = (EntityAnswer) obj;
|
||||
return (this.name.equals(other.name) &&
|
||||
return (Objects.equals(this.uuid, other.uuid) &&
|
||||
this.name.equals(other.name) &&
|
||||
Objects.equals(this.group, other.group) &&
|
||||
this.standard.equals(other.standard) &&
|
||||
this.receipt.equals(other.receipt) &&
|
||||
|
||||
Reference in New Issue
Block a user