Refactoring

pull/162/head
M66B 5 years ago
parent 77496ae970
commit cd4cb88192

@ -1307,15 +1307,16 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences.
db.beginTransaction(); db.beginTransaction();
EntityMessage message = db.message().getMessage(id); EntityMessage message = db.message().getMessage(id);
if (message == null)
return result;
EntityFolder target = null; EntityFolder target = db.folder().getFolderByType(message.account, type);
if (message != null)
target = db.folder().getFolderByType(message.account, type); if (target == null)
return result;
if (target != null) {
EntityAccount account = db.account().getAccount(target.account); EntityAccount account = db.account().getAccount(target.account);
result.add(new MessageTarget(message, account, target)); result.add(new MessageTarget(message, account, target));
}
db.setTransactionSuccessful(); db.setTransactionSuccessful();
} finally { } finally {
@ -1628,12 +1629,13 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences.
db.beginTransaction(); db.beginTransaction();
EntityMessage message = db.message().getMessage(id); EntityMessage message = db.message().getMessage(id);
if (message == null)
return result;
EntityFolder target = null; EntityFolder target = db.folder().getFolder(tid);
if (message != null) if (target == null)
target = db.folder().getFolder(tid); return result;
if (target != null) {
EntityAccount account = db.account().getAccount(target.account); EntityAccount account = db.account().getAccount(target.account);
List<EntityMessage> messages = db.message().getMessagesByThread( List<EntityMessage> messages = db.message().getMessagesByThread(
message.account, message.thread, threading && thread ? null : id, message.folder); message.account, message.thread, threading && thread ? null : id, message.folder);
@ -1643,7 +1645,6 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences.
// Prevent new message notification on undo // Prevent new message notification on undo
db.message().setMessageUiIgnored(threaded.id, true); db.message().setMessageUiIgnored(threaded.id, true);
} }
}
db.setTransactionSuccessful(); db.setTransactionSuccessful();
} finally { } finally {
@ -1878,14 +1879,15 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences.
for (long id : ids) { for (long id : ids) {
EntityMessage message = db.message().getMessage(id); EntityMessage message = db.message().getMessage(id);
if (message != null) { if (message == null)
continue;
List<EntityMessage> messages = db.message().getMessagesByThread( List<EntityMessage> messages = db.message().getMessagesByThread(
message.account, message.thread, threading ? null : id, seen ? null : message.folder); message.account, message.thread, threading ? null : id, seen ? null : message.folder);
for (EntityMessage threaded : messages) for (EntityMessage threaded : messages)
if (threaded.ui_seen != seen) if (threaded.ui_seen != seen)
EntityOperation.queue(context, threaded, EntityOperation.SEEN, seen); EntityOperation.queue(context, threaded, EntityOperation.SEEN, seen);
} }
}
db.setTransactionSuccessful(); db.setTransactionSuccessful();
} finally { } finally {
@ -1934,14 +1936,15 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences.
for (long id : ids) { for (long id : ids) {
EntityMessage message = db.message().getMessage(id); EntityMessage message = db.message().getMessage(id);
if (message != null) { if (message == null)
continue;
List<EntityMessage> messages = db.message().getMessagesByThread( List<EntityMessage> messages = db.message().getMessagesByThread(
message.account, message.thread, threading ? null : id, null); message.account, message.thread, threading ? null : id, null);
for (EntityMessage threaded : messages) for (EntityMessage threaded : messages)
if (threaded.ui_flagged != flagged || !Objects.equals(threaded.color, color)) if (threaded.ui_flagged != flagged || !Objects.equals(threaded.color, color))
EntityOperation.queue(context, threaded, EntityOperation.FLAG, flagged, color); EntityOperation.queue(context, threaded, EntityOperation.FLAG, flagged, color);
} }
}
db.setTransactionSuccessful(); db.setTransactionSuccessful();
} finally { } finally {
@ -1981,14 +1984,15 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences.
for (long id : selected) { for (long id : selected) {
EntityMessage message = db.message().getMessage(id); EntityMessage message = db.message().getMessage(id);
if (message != null) { if (message == null)
continue;
List<EntityMessage> messages = db.message().getMessagesByThread( List<EntityMessage> messages = db.message().getMessagesByThread(
message.account, message.thread, threading ? null : id, message.folder); message.account, message.thread, threading ? null : id, message.folder);
for (EntityMessage threaded : messages) for (EntityMessage threaded : messages)
if (message.uid != null) if (message.uid != null)
ids.add(threaded.id); ids.add(threaded.id);
} }
}
db.setTransactionSuccessful(); db.setTransactionSuccessful();
} finally { } finally {
@ -2050,7 +2054,9 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences.
for (long id : ids) { for (long id : ids) {
EntityMessage message = db.message().getMessage(id); EntityMessage message = db.message().getMessage(id);
if (message != null) { if (message == null)
continue;
List<EntityMessage> messages = db.message().getMessagesByThread( List<EntityMessage> messages = db.message().getMessagesByThread(
message.account, message.thread, threading ? null : id, message.folder); message.account, message.thread, threading ? null : id, message.folder);
for (EntityMessage threaded : messages) { for (EntityMessage threaded : messages) {
@ -2061,7 +2067,6 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences.
} }
} }
} }
}
db.setTransactionSuccessful(); db.setTransactionSuccessful();
} finally { } finally {
@ -2120,14 +2125,15 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences.
EntityAccount account = db.account().getAccount(target.account); EntityAccount account = db.account().getAccount(target.account);
for (long id : ids) { for (long id : ids) {
EntityMessage message = db.message().getMessage(id); EntityMessage message = db.message().getMessage(id);
if (message != null) { if (message == null)
continue;
List<EntityMessage> messages = db.message().getMessagesByThread( List<EntityMessage> messages = db.message().getMessagesByThread(
message.account, message.thread, threading ? null : id, message.folder); message.account, message.thread, threading ? null : id, message.folder);
for (EntityMessage threaded : messages) for (EntityMessage threaded : messages)
result.add(new MessageTarget(threaded, account, target)); result.add(new MessageTarget(threaded, account, target));
} }
} }
}
db.setTransactionSuccessful(); db.setTransactionSuccessful();
} finally { } finally {
@ -3369,11 +3375,12 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences.
for (MessageTarget target : result) { for (MessageTarget target : result) {
EntityMessage message = db.message().getMessage(target.id); EntityMessage message = db.message().getMessage(target.id);
if (message != null) { if (message == null)
continue;
Log.i("Move id=" + target.id + " target=" + target.folder.name); Log.i("Move id=" + target.id + " target=" + target.folder.name);
EntityOperation.queue(context, message, EntityOperation.MOVE, target.folder.id); EntityOperation.queue(context, message, EntityOperation.MOVE, target.folder.id);
} }
}
db.setTransactionSuccessful(); db.setTransactionSuccessful();
} finally { } finally {
@ -3463,11 +3470,12 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences.
for (MessageTarget target : result) { for (MessageTarget target : result) {
EntityMessage message = db.message().getMessage(target.id); EntityMessage message = db.message().getMessage(target.id);
if (message != null && message.ui_hide != 0) { if (message == null || message.ui_hide == 0)
continue;
Log.i("Move id=" + id + " target=" + target.folder.name); Log.i("Move id=" + id + " target=" + target.folder.name);
EntityOperation.queue(context, message, EntityOperation.MOVE, target.folder.id); EntityOperation.queue(context, message, EntityOperation.MOVE, target.folder.id);
} }
}
db.setTransactionSuccessful(); db.setTransactionSuccessful();
} catch (Throwable ex) { } catch (Throwable ex) {
@ -4016,7 +4024,9 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences.
for (long id : ids) { for (long id : ids) {
EntityMessage message = db.message().getMessage(id); EntityMessage message = db.message().getMessage(id);
if (message != null) if (message == null)
continue;
EntityOperation.queue(context, message, EntityOperation.DELETE); EntityOperation.queue(context, message, EntityOperation.DELETE);
} }
@ -4203,7 +4213,9 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences.
for (long id : ids) { for (long id : ids) {
EntityMessage message = db.message().getMessage(id); EntityMessage message = db.message().getMessage(id);
if (message != null) { if (message == null)
continue;
List<EntityMessage> messages = db.message().getMessagesByThread( List<EntityMessage> messages = db.message().getMessagesByThread(
message.account, message.thread, threading ? null : id, message.folder); message.account, message.thread, threading ? null : id, message.folder);
for (EntityMessage threaded : messages) { for (EntityMessage threaded : messages) {
@ -4212,7 +4224,6 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences.
EntityOperation.queue(context, threaded, EntityOperation.SEEN, true); EntityOperation.queue(context, threaded, EntityOperation.SEEN, true);
} }
} }
}
db.setTransactionSuccessful(); db.setTransactionSuccessful();
} finally { } finally {
@ -4245,12 +4256,13 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences.
db.beginTransaction(); db.beginTransaction();
EntityMessage message = db.message().getMessage(id); EntityMessage message = db.message().getMessage(id);
if (message == null)
return result;
EntityFolder target = null; EntityFolder target = db.folder().getFolder(tid);
if (message != null) if (target == null)
target = db.folder().getFolder(tid); return result;
if (target != null) {
EntityAccount account = db.account().getAccount(target.account); EntityAccount account = db.account().getAccount(target.account);
if (account != null) { if (account != null) {
List<EntityMessage> messages = db.message().getMessagesByThread( List<EntityMessage> messages = db.message().getMessagesByThread(
@ -4261,7 +4273,6 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences.
else else
result.add(new MessageTarget(threaded, account, target)); result.add(new MessageTarget(threaded, account, target));
} }
}
db.setTransactionSuccessful(); db.setTransactionSuccessful();
} finally { } finally {

@ -356,7 +356,9 @@ public class ServiceUI extends IntentService {
db.beginTransaction(); db.beginTransaction();
EntityMessage message = db.message().getMessage(id); EntityMessage message = db.message().getMessage(id);
if (message != null) { if (message == null)
return;
db.message().setMessageSnoozed(message.id, null); db.message().setMessageSnoozed(message.id, null);
EntityFolder folder = db.folder().getFolder(message.folder); EntityFolder folder = db.folder().getFolder(message.folder);
@ -367,7 +369,6 @@ public class ServiceUI extends IntentService {
if (folder.notify) if (folder.notify)
EntityOperation.queue(this, message, EntityOperation.SEEN, false, false); EntityOperation.queue(this, message, EntityOperation.SEEN, false, false);
} }
}
db.setTransactionSuccessful(); db.setTransactionSuccessful();
} finally { } finally {

Loading…
Cancel
Save