Store encryption status

pull/172/head
M66B 5 years ago
parent 2fddb29006
commit 0a8a412238

File diff suppressed because it is too large Load Diff

@ -4293,6 +4293,10 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
same = false; same = false;
Log.i("plain_only changed id=" + next.id); Log.i("plain_only changed id=" + next.id);
} }
if (!Objects.equals(prev.encrypt, next.encrypt)) {
same = false;
Log.i("encrypt changed id=" + next.id);
}
if (!Objects.equals(prev.preview, next.preview)) { if (!Objects.equals(prev.preview, next.preview)) {
same = false; same = false;
Log.i("preview changed id=" + next.id); Log.i("preview changed id=" + next.id);

@ -1516,6 +1516,7 @@ class Core {
message.total = helper.getSize(); message.total = helper.getSize();
message.content = false; message.content = false;
message.encrypt = parts.getEncryption(); message.encrypt = parts.getEncryption();
message.ui_encrypt = message.encrypt;
message.received = sent; message.received = sent;
message.sent = sent; message.sent = sent;
message.seen = false; message.seen = false;
@ -2101,6 +2102,7 @@ class Core {
message.total = helper.getSize(); message.total = helper.getSize();
message.content = false; message.content = false;
message.encrypt = parts.getEncryption(); message.encrypt = parts.getEncryption();
message.ui_encrypt = message.encrypt;
message.received = (account.use_date ? (sent == null ? 0 : sent) : helper.getReceived()); message.received = (account.use_date ? (sent == null ? 0 : sent) : helper.getReceived());
message.sent = sent; message.sent = sent;
message.seen = seen; message.seen = seen;

@ -56,7 +56,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 = 131, version = 132,
entities = { entities = {
EntityIdentity.class, EntityIdentity.class,
EntityAccount.class, EntityAccount.class,
@ -1261,6 +1261,14 @@ public abstract class DB extends RoomDatabase {
db.execSQL("ALTER TABLE `answer` ADD COLUMN `favorite` INTEGER NOT NULL DEFAULT 0"); db.execSQL("ALTER TABLE `answer` ADD COLUMN `favorite` INTEGER NOT NULL DEFAULT 0");
} }
}) })
.addMigrations(new Migration(131, 132) {
@Override
public void migrate(@NonNull SupportSQLiteDatabase db) {
Log.i("DB migration from version " + startVersion + " to " + endVersion);
db.execSQL("ALTER TABLE `message` ADD COLUMN `ui_encrypt` INTEGER");
db.execSQL("UPDATE `message` SET `ui_encrypt` = `encrypt`");
}
})
.build(); .build();
} }

@ -52,8 +52,8 @@ public interface DaoMessage {
", SUM(1 - message.ui_seen) AS unseen" + ", SUM(1 - message.ui_seen) AS unseen" +
", SUM(1 - message.ui_flagged) AS unflagged" + ", SUM(1 - message.ui_flagged) AS unflagged" +
", SUM(folder.type = '" + EntityFolder.DRAFTS + "') AS drafts" + ", SUM(folder.type = '" + EntityFolder.DRAFTS + "') AS drafts" +
", (message.encrypt IN (2, 4)) AS signed" + ", (message.ui_encrypt IN (2, 4)) AS signed" +
", (message.encrypt IN (1, 3)) AS encrypted" + ", (message.ui_encrypt IN (1, 3)) AS encrypted" +
", COUNT(DISTINCT CASE WHEN message.msgid IS NULL THEN message.id ELSE message.msgid END) AS visible" + ", COUNT(DISTINCT CASE WHEN message.msgid IS NULL THEN message.id ELSE message.msgid END) AS visible" +
", SUM(message.total) AS totalSize" + ", SUM(message.total) AS totalSize" +
", MAX(CASE WHEN" + ", MAX(CASE WHEN" +
@ -104,8 +104,8 @@ public interface DaoMessage {
", SUM(1 - message.ui_seen) AS unseen" + ", SUM(1 - message.ui_seen) AS unseen" +
", SUM(1 - message.ui_flagged) AS unflagged" + ", SUM(1 - message.ui_flagged) AS unflagged" +
", SUM(folder.type = '" + EntityFolder.DRAFTS + "') AS drafts" + ", SUM(folder.type = '" + EntityFolder.DRAFTS + "') AS drafts" +
", (message.encrypt IN (2, 4)) AS signed" + ", (message.ui_encrypt IN (2, 4)) AS signed" +
", (message.encrypt IN (1, 3)) AS encrypted" + ", (message.ui_encrypt IN (1, 3)) AS encrypted" +
", COUNT(DISTINCT CASE WHEN message.msgid IS NULL THEN message.id ELSE message.msgid END) AS visible" + ", COUNT(DISTINCT CASE WHEN message.msgid IS NULL THEN message.id ELSE message.msgid END) AS visible" +
", SUM(message.total) AS totalSize" + ", SUM(message.total) AS totalSize" +
", MAX(CASE WHEN folder.id = :folder THEN message.received ELSE 0 END) AS dummy" + ", MAX(CASE WHEN folder.id = :folder THEN message.received ELSE 0 END) AS dummy" +
@ -150,8 +150,8 @@ public interface DaoMessage {
", CASE WHEN message.ui_seen THEN 0 ELSE 1 END AS unseen" + ", CASE WHEN message.ui_seen THEN 0 ELSE 1 END AS unseen" +
", CASE WHEN message.ui_flagged THEN 0 ELSE 1 END AS unflagged" + ", CASE WHEN message.ui_flagged THEN 0 ELSE 1 END AS unflagged" +
", (folder.type = '" + EntityFolder.DRAFTS + "') AS drafts" + ", (folder.type = '" + EntityFolder.DRAFTS + "') AS drafts" +
", (message.encrypt IN (2, 4)) AS signed" + ", (message.ui_encrypt IN (2, 4)) AS signed" +
", (message.encrypt IN (1, 3)) AS encrypted" + ", (message.ui_encrypt IN (1, 3)) AS encrypted" +
", 1 AS visible" + ", 1 AS visible" +
", message.total AS totalSize" + ", message.total AS totalSize" +
" FROM message" + " FROM message" +
@ -254,7 +254,7 @@ public interface DaoMessage {
" AND (:seen IS NULL OR ui_seen = :seen)" + " AND (:seen IS NULL OR ui_seen = :seen)" +
" AND (:flagged IS NULL OR ui_flagged = :flagged)" + " AND (:flagged IS NULL OR ui_flagged = :flagged)" +
" AND (:hidden IS NULL OR (CASE WHEN ui_snoozed IS NULL THEN 0 ELSE 1 END) = :hidden)" + " AND (:hidden IS NULL OR (CASE WHEN ui_snoozed IS NULL THEN 0 ELSE 1 END) = :hidden)" +
" AND (:encrypted IS NULL OR encrypt > 0)" + " AND (:encrypted IS NULL OR ui_encrypt > 0)" +
" ORDER BY received DESC" + " ORDER BY received DESC" +
" LIMIT :limit OFFSET :offset") " LIMIT :limit OFFSET :offset")
List<TupleMatch> matchMessages( List<TupleMatch> matchMessages(
@ -304,8 +304,8 @@ public interface DaoMessage {
", CASE WHEN message.ui_seen THEN 0 ELSE 1 END AS unseen" + ", CASE WHEN message.ui_seen THEN 0 ELSE 1 END AS unseen" +
", CASE WHEN message.ui_flagged THEN 0 ELSE 1 END AS unflagged" + ", CASE WHEN message.ui_flagged THEN 0 ELSE 1 END AS unflagged" +
", (folder.type = '" + EntityFolder.DRAFTS + "') AS drafts" + ", (folder.type = '" + EntityFolder.DRAFTS + "') AS drafts" +
", (message.encrypt IN (2, 4)) AS signed" + ", (message.ui_encrypt IN (2, 4)) AS signed" +
", (message.encrypt IN (1, 3)) AS encrypted" + ", (message.ui_encrypt IN (1, 3)) AS encrypted" +
", 1 AS visible" + ", 1 AS visible" +
", message.total AS totalSize" + ", message.total AS totalSize" +
" FROM message" + " FROM message" +
@ -349,8 +349,8 @@ public interface DaoMessage {
", 1 AS unseen" + ", 1 AS unseen" +
", 0 AS unflagged" + ", 0 AS unflagged" +
", 0 AS drafts" + ", 0 AS drafts" +
", (message.encrypt IN (2, 4)) AS signed" + ", (message.ui_encrypt IN (2, 4)) AS signed" +
", (message.encrypt IN (1, 3)) AS encrypted" + ", (message.ui_encrypt IN (1, 3)) AS encrypted" +
", 1 AS visible" + ", 1 AS visible" +
", message.total AS totalSize" + ", message.total AS totalSize" +
" FROM message" + " FROM message" +
@ -527,6 +527,9 @@ public interface DaoMessage {
@Query("UPDATE message SET encrypt = :encrypt WHERE id = :id") @Query("UPDATE message SET encrypt = :encrypt WHERE id = :id")
int setMessageEncrypt(long id, Integer encrypt); int setMessageEncrypt(long id, Integer encrypt);
@Query("UPDATE message SET encrypt = :encrypt, ui_encrypt = :encrypt WHERE id = :id")
int setMessageUiEncrypt(long id, Integer encrypt);
@Query("UPDATE message SET last_attempt = :last_attempt WHERE id = :id") @Query("UPDATE message SET last_attempt = :last_attempt WHERE id = :id")
int setMessageLastAttempt(long id, long last_attempt); int setMessageLastAttempt(long id, long last_attempt);

@ -135,6 +135,7 @@ public class EntityMessage implements Serializable {
public Boolean content = false; public Boolean content = false;
public Boolean plain_only = null; public Boolean plain_only = null;
public Integer encrypt = null; public Integer encrypt = null;
public Integer ui_encrypt = null;
public String preview; public String preview;
@NonNull @NonNull
public Boolean signature = true; public Boolean signature = true;
@ -276,6 +277,7 @@ public class EntityMessage implements Serializable {
return (Objects.equals(this.account, other.account) && return (Objects.equals(this.account, other.account) &&
this.folder.equals(other.folder) && this.folder.equals(other.folder) &&
Objects.equals(this.identity, other.identity) && Objects.equals(this.identity, other.identity) &&
// extra
Objects.equals(this.uid, other.uid) && Objects.equals(this.uid, other.uid) &&
Objects.equals(this.msgid, other.msgid) && Objects.equals(this.msgid, other.msgid) &&
Objects.equals(this.references, other.references) && Objects.equals(this.references, other.references) &&
@ -298,6 +300,8 @@ public class EntityMessage implements Serializable {
MessageHelper.equal(this.bcc, other.bcc) && MessageHelper.equal(this.bcc, other.bcc) &&
MessageHelper.equal(this.reply, other.reply) && MessageHelper.equal(this.reply, other.reply) &&
MessageHelper.equal(this.list_post, other.list_post) && MessageHelper.equal(this.list_post, other.list_post) &&
Objects.equals(this.unsubscribe, other.unsubscribe) &&
Objects.equals(this.autocrypt, other.autocrypt) &&
Objects.equals(this.headers, other.headers) && Objects.equals(this.headers, other.headers) &&
Objects.equals(this.raw, other.raw) && Objects.equals(this.raw, other.raw) &&
Objects.equals(this.subject, other.subject) && Objects.equals(this.subject, other.subject) &&
@ -306,7 +310,10 @@ public class EntityMessage implements Serializable {
Objects.equals(this.attachments, other.attachments) && Objects.equals(this.attachments, other.attachments) &&
this.content == other.content && this.content == other.content &&
Objects.equals(this.plain_only, other.plain_only) && Objects.equals(this.plain_only, other.plain_only) &&
Objects.equals(this.encrypt, other.encrypt) &&
Objects.equals(this.ui_encrypt, other.ui_encrypt) &&
Objects.equals(this.preview, other.preview) && Objects.equals(this.preview, other.preview) &&
this.signature.equals(other.signature) &&
Objects.equals(this.sent, other.sent) && Objects.equals(this.sent, other.sent) &&
this.received.equals(other.received) && this.received.equals(other.received) &&
this.stored.equals(other.stored) && this.stored.equals(other.stored) &&

@ -1095,9 +1095,9 @@ public class FragmentCompose extends FragmentBase {
DB db = DB.getInstance(context); DB db = DB.getInstance(context);
if (EntityMessage.ENCRYPT_NONE.equals(encrypt)) if (EntityMessage.ENCRYPT_NONE.equals(encrypt))
db.message().setMessageEncrypt(id, null); db.message().setMessageUiEncrypt(id, null);
else else
db.message().setMessageEncrypt(id, encrypt); db.message().setMessageUiEncrypt(id, encrypt);
return null; return null;
} }
@ -2649,6 +2649,7 @@ public class FragmentCompose extends FragmentBase {
data.draft.encrypt = EntityMessage.SMIME_SIGNONLY; data.draft.encrypt = EntityMessage.SMIME_SIGNONLY;
else else
data.draft.encrypt = EntityMessage.PGP_SIGNONLY; data.draft.encrypt = EntityMessage.PGP_SIGNONLY;
data.draft.ui_encrypt = data.draft.encrypt;
if (receipt_default) if (receipt_default)
data.draft.receipt_request = true; data.draft.receipt_request = true;
@ -2895,8 +2896,10 @@ public class FragmentCompose extends FragmentBase {
if (ref.plain_only != null && ref.plain_only) if (ref.plain_only != null && ref.plain_only)
data.draft.plain_only = true; data.draft.plain_only = true;
if (ref.encrypt != null && ref.encrypt != 0) if (ref.ui_encrypt != null && ref.ui_encrypt != EntityMessage.ENCRYPT_NONE) {
data.draft.encrypt = ref.encrypt; data.draft.encrypt = ref.ui_encrypt;
data.draft.ui_encrypt = ref.ui_encrypt;
}
if (answer > 0) { if (answer > 0) {
EntityAnswer a = db.answer().getAnswer(answer); EntityAnswer a = db.answer().getAnswer(answer);
@ -4277,7 +4280,7 @@ public class FragmentCompose extends FragmentBase {
int encrypt = args.getInt("encrypt"); int encrypt = args.getInt("encrypt");
DB db = DB.getInstance(context); DB db = DB.getInstance(context);
db.message().setMessageEncrypt(id, encrypt); db.message().setMessageUiEncrypt(id, encrypt);
return null; return null;
} }

@ -76,6 +76,7 @@ public class TupleMessageEx extends EntityMessage {
Objects.equals(this.identityName, other.identityName) && Objects.equals(this.identityName, other.identityName) &&
Objects.equals(this.identityEmail, other.identityEmail) && Objects.equals(this.identityEmail, other.identityEmail) &&
Objects.equals(this.identitySynchronize, other.identitySynchronize) && Objects.equals(this.identitySynchronize, other.identitySynchronize) &&
MessageHelper.equal(this.senders, other.senders) &&
this.count == other.count && this.count == other.count &&
this.unseen == other.unseen && this.unseen == other.unseen &&
this.unflagged == other.unflagged && this.unflagged == other.unflagged &&

Loading…
Cancel
Save