Store and check uid validity

pull/159/head
M66B 5 years ago
parent ab50d9db77
commit 861c6da4b9

File diff suppressed because it is too large Load Diff

@ -985,6 +985,19 @@ class Core {
db.folder().setFolderSyncState(folder.id, "syncing"); db.folder().setFolderSyncState(folder.id, "syncing");
// Check uid validity
try {
long uidv = ifolder.getUIDValidity();
if (folder.uidv != null && folder.uidv.equals(uidv)) {
Log.w(folder.name + " uid validity changed from " + folder.uidv + " to " + uidv);
db.message().deleteLocalMessages(folder.id);
}
folder.uidv = uidv;
db.folder().setFolderUidValidity(folder.id, uidv);
} catch (MessagingException ex) {
Log.w(ex);
}
// Get reference times // Get reference times
Calendar cal_sync = Calendar.getInstance(); Calendar cal_sync = Calendar.getInstance();
cal_sync.add(Calendar.DAY_OF_MONTH, -sync_days); cal_sync.add(Calendar.DAY_OF_MONTH, -sync_days);

@ -57,7 +57,7 @@ import io.requery.android.database.sqlite.RequerySQLiteOpenHelperFactory;
// https://developer.android.com/topic/libraries/architecture/room.html // https://developer.android.com/topic/libraries/architecture/room.html
@Database( @Database(
version = 96, version = 97,
entities = { entities = {
EntityIdentity.class, EntityIdentity.class,
EntityAccount.class, EntityAccount.class,
@ -977,6 +977,13 @@ public abstract class DB extends RoomDatabase {
" (SELECT COUNT(attachment.id) FROM attachment WHERE attachment.message = message.id)"); " (SELECT COUNT(attachment.id) FROM attachment WHERE attachment.message = message.id)");
} }
}) })
.addMigrations(new Migration(96, 97) {
@Override
public void migrate(@NonNull SupportSQLiteDatabase db) {
Log.i("DB migration from version " + startVersion + " to " + endVersion);
db.execSQL("ALTER TABLE `folder` ADD COLUMN `uidv` INTEGER");
}
})
.build(); .build();
} }

@ -278,6 +278,9 @@ public interface DaoFolder {
@Query("UPDATE folder SET keep_days = :days WHERE id = :id") @Query("UPDATE folder SET keep_days = :days WHERE id = :id")
int setFolderKeep(long id, int days); int setFolderKeep(long id, int days);
@Query("UPDATE folder SET uidv = :uidv WHERE id = :id")
int setFolderUidValidity(long id, Long uidv);
@Query("UPDATE folder SET last_sync = :last_sync WHERE id = :id") @Query("UPDATE folder SET last_sync = :last_sync WHERE id = :id")
int setFolderSync(long id, long last_sync); int setFolderSync(long id, long last_sync);

@ -64,6 +64,7 @@ public class EntityFolder extends EntityOrder implements Serializable {
public Long id; public Long id;
public Long account; // Outbox = null public Long account; // Outbox = null
public Long parent; public Long parent;
public Long uidv; // UIDValidity
@NonNull @NonNull
public String name; public String name;
@NonNull @NonNull
@ -287,6 +288,7 @@ public class EntityFolder extends EntityOrder implements Serializable {
EntityFolder other = (EntityFolder) obj; EntityFolder other = (EntityFolder) obj;
return (this.id.equals(other.id) && return (this.id.equals(other.id) &&
Objects.equals(this.account, other.account) && Objects.equals(this.account, other.account) &&
Objects.equals(this.uidv, other.uidv) &&
this.name.equals(other.name) && this.name.equals(other.name) &&
this.type.equals(other.type) && this.type.equals(other.type) &&
this.synchronize.equals(other.synchronize) && this.synchronize.equals(other.synchronize) &&

Loading…
Cancel
Save