From 6260a3517fae23b0e95278326e7d849cf45fb6a8 Mon Sep 17 00:00:00 2001 From: M66B Date: Thu, 24 Oct 2024 19:10:05 +0200 Subject: [PATCH] Seen delay: ensure body is loaded --- .../eu/faircode/email/FragmentMessages.java | 60 +++++++++++++++++-- 1 file changed, 55 insertions(+), 5 deletions(-) diff --git a/app/src/main/java/eu/faircode/email/FragmentMessages.java b/app/src/main/java/eu/faircode/email/FragmentMessages.java index 9445f9b533..0fecea4457 100644 --- a/app/src/main/java/eu/faircode/email/FragmentMessages.java +++ b/app/src/main/java/eu/faircode/email/FragmentMessages.java @@ -8192,17 +8192,67 @@ public class FragmentMessages extends FragmentBase if (seen_delay == 0) return; + Bundle dargs = new Bundle(); + dargs.putLong("id", id); + dargs.putBoolean("seen", true); + view.postDelayed(new RunnableEx("seen_delay") { @Override public void delegate() { - if (values.containsKey("expanded") && values.get("expanded").contains(id)) { - Bundle dargs = new Bundle(); - dargs.putLong("id", id); - dargs.putBoolean("seen", true); + if (values.containsKey("expanded") && values.get("expanded").contains(id)) taskExpand.execute(FragmentMessages.this, dargs, "messages:seen_delay"); - } } }, seen_delay); + + new SimpleTask() { + @Override + protected Void onExecute(Context context, Bundle args) { + long id = args.getLong("id"); + + Long reload = null; + + DB db = DB.getInstance(context); + try { + db.beginTransaction(); + + EntityMessage message = db.message().getMessageEx(id); + if (message == null) + return null; + + EntityFolder folder = db.folder().getFolder(message.folder); + if (folder == null || folder.account == null) + return null; + + EntityAccount account = db.account().getAccount(folder.account); + if (account == null) + return null; + + if (!"connected".equals(account.state) && !account.isTransient(context)) + reload = account.id; + + if (account.protocol != EntityAccount.TYPE_IMAP || message.uid != null) { + if (!message.content) + EntityOperation.queue(context, message, EntityOperation.BODY); + } + + db.setTransactionSuccessful(); + } finally { + db.endTransaction(); + } + + if (reload == null) + ServiceSynchronize.eval(context, "expand"); + else + ServiceSynchronize.reload(context, reload, false, "expand"); + + return null; + } + + @Override + protected void onException(Bundle args, Throwable ex) { + Log.unexpectedError(getParentFragmentManager(), ex); + } + }.setLog(false).execute(this, dargs, "messages:expand"); } private void handleAutoClose() {