|
|
@ -211,91 +211,96 @@ public class ActivityCompose extends ActivityBase implements FragmentManager.OnB
|
|
|
|
Intent.ACTION_SEND_MULTIPLE.equals(action));
|
|
|
|
Intent.ACTION_SEND_MULTIPLE.equals(action));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void undoSend(long id, final Context context, final LifecycleOwner owner, final FragmentManager manager) {
|
|
|
|
static void undoSend(final long id, final Context context, final LifecycleOwner owner, final FragmentManager manager) {
|
|
|
|
Bundle args = new Bundle();
|
|
|
|
Bundle args = new Bundle();
|
|
|
|
args.putLong("id", id);
|
|
|
|
args.putLong("id", id);
|
|
|
|
|
|
|
|
|
|
|
|
new SimpleTask<EntityMessage>() {
|
|
|
|
new SimpleTask<Long>() {
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
protected EntityMessage onExecute(Context context, Bundle args) {
|
|
|
|
protected Long onExecute(Context context, Bundle args) {
|
|
|
|
long id = args.getLong("id");
|
|
|
|
long id = args.getLong("id");
|
|
|
|
|
|
|
|
return undoSend(id, context);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
DB db = DB.getInstance(context);
|
|
|
|
@Override
|
|
|
|
|
|
|
|
protected void onExecuted(Bundle args, Long id) {
|
|
|
|
|
|
|
|
if (id == null)
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
context.startActivity(
|
|
|
|
|
|
|
|
new Intent(context, ActivityCompose.class)
|
|
|
|
|
|
|
|
.putExtra("action", "edit")
|
|
|
|
|
|
|
|
.putExtra("id", id));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
EntityOperation operation = db.operation().getOperation(id, EntityOperation.SEND);
|
|
|
|
@Override
|
|
|
|
if (operation != null)
|
|
|
|
protected void onException(Bundle args, Throwable ex) {
|
|
|
|
if ("executing".equals(operation.state)) {
|
|
|
|
Log.unexpectedError(manager, ex, !(ex instanceof IllegalArgumentException));
|
|
|
|
// Trigger update
|
|
|
|
}
|
|
|
|
db.message().setMessageUiBusy(id, new Date().getTime());
|
|
|
|
}.execute(context, owner, args, "undo:sent");
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
} else
|
|
|
|
|
|
|
|
db.operation().deleteOperation(operation.id);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
EntityMessage message;
|
|
|
|
static Long undoSend(long id, Context context) {
|
|
|
|
|
|
|
|
DB db = DB.getInstance(context);
|
|
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
EntityOperation operation = db.operation().getOperation(id, EntityOperation.SEND);
|
|
|
|
db.beginTransaction();
|
|
|
|
if (operation != null)
|
|
|
|
|
|
|
|
if ("executing".equals(operation.state)) {
|
|
|
|
|
|
|
|
// Trigger update
|
|
|
|
|
|
|
|
db.message().setMessageUiBusy(id, new Date().getTime());
|
|
|
|
|
|
|
|
return null;
|
|
|
|
|
|
|
|
} else
|
|
|
|
|
|
|
|
db.operation().deleteOperation(operation.id);
|
|
|
|
|
|
|
|
|
|
|
|
message = db.message().getMessage(id);
|
|
|
|
EntityMessage message;
|
|
|
|
if (message == null)
|
|
|
|
|
|
|
|
return null;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
db.folder().setFolderError(message.folder, null);
|
|
|
|
try {
|
|
|
|
if (message.identity != null)
|
|
|
|
db.beginTransaction();
|
|
|
|
db.identity().setIdentityError(message.identity, null);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
File source = message.getFile(context);
|
|
|
|
message = db.message().getMessage(id);
|
|
|
|
|
|
|
|
if (message == null)
|
|
|
|
|
|
|
|
return null;
|
|
|
|
|
|
|
|
|
|
|
|
// Insert into drafts
|
|
|
|
db.folder().setFolderError(message.folder, null);
|
|
|
|
EntityFolder drafts = db.folder().getFolderByType(message.account, EntityFolder.DRAFTS);
|
|
|
|
if (message.identity != null)
|
|
|
|
if (drafts == null)
|
|
|
|
db.identity().setIdentityError(message.identity, null);
|
|
|
|
throw new IllegalArgumentException(context.getString(R.string.title_no_drafts));
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
message.id = null;
|
|
|
|
File source = message.getFile(context);
|
|
|
|
message.folder = drafts.id;
|
|
|
|
|
|
|
|
message.fts = false;
|
|
|
|
|
|
|
|
message.ui_snoozed = null;
|
|
|
|
|
|
|
|
message.error = null;
|
|
|
|
|
|
|
|
message.id = db.message().insertMessage(message);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
File target = message.getFile(context);
|
|
|
|
// Insert into drafts
|
|
|
|
source.renameTo(target);
|
|
|
|
EntityFolder drafts = db.folder().getFolderByType(message.account, EntityFolder.DRAFTS);
|
|
|
|
|
|
|
|
if (drafts == null)
|
|
|
|
|
|
|
|
throw new IllegalArgumentException(context.getString(R.string.title_no_drafts));
|
|
|
|
|
|
|
|
|
|
|
|
List<EntityAttachment> attachments = db.attachment().getAttachments(id);
|
|
|
|
message.id = null;
|
|
|
|
for (EntityAttachment attachment : attachments)
|
|
|
|
message.folder = drafts.id;
|
|
|
|
db.attachment().setMessage(attachment.id, message.id);
|
|
|
|
message.fts = false;
|
|
|
|
|
|
|
|
message.ui_snoozed = null;
|
|
|
|
|
|
|
|
message.error = null;
|
|
|
|
|
|
|
|
message.id = db.message().insertMessage(message);
|
|
|
|
|
|
|
|
|
|
|
|
EntityOperation.queue(context, message, EntityOperation.ADD);
|
|
|
|
File target = message.getFile(context);
|
|
|
|
|
|
|
|
source.renameTo(target);
|
|
|
|
|
|
|
|
|
|
|
|
// Delete from outbox
|
|
|
|
List<EntityAttachment> attachments = db.attachment().getAttachments(id);
|
|
|
|
db.message().deleteMessage(id); // will delete operation too
|
|
|
|
for (EntityAttachment attachment : attachments)
|
|
|
|
|
|
|
|
db.attachment().setMessage(attachment.id, message.id);
|
|
|
|
|
|
|
|
|
|
|
|
db.setTransactionSuccessful();
|
|
|
|
EntityOperation.queue(context, message, EntityOperation.ADD);
|
|
|
|
} finally {
|
|
|
|
|
|
|
|
db.endTransaction();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ServiceSynchronize.eval(context, "outbox/drafts");
|
|
|
|
// Delete from outbox
|
|
|
|
|
|
|
|
db.message().deleteMessage(id); // will delete operation too
|
|
|
|
|
|
|
|
|
|
|
|
NotificationManager nm = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
|
|
|
|
db.setTransactionSuccessful();
|
|
|
|
nm.cancel("send:" + id, 1);
|
|
|
|
} finally {
|
|
|
|
|
|
|
|
db.endTransaction();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return message;
|
|
|
|
ServiceSynchronize.eval(context, "outbox/drafts");
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
NotificationManager nm = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
|
|
|
|
protected void onExecuted(Bundle args, EntityMessage draft) {
|
|
|
|
nm.cancel("send:" + id, 1);
|
|
|
|
if (draft != null)
|
|
|
|
|
|
|
|
context.startActivity(
|
|
|
|
|
|
|
|
new Intent(context, ActivityCompose.class)
|
|
|
|
|
|
|
|
.putExtra("action", "edit")
|
|
|
|
|
|
|
|
.putExtra("id", draft.id));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
return message.id;
|
|
|
|
protected void onException(Bundle args, Throwable ex) {
|
|
|
|
|
|
|
|
Log.unexpectedError(manager, ex, !(ex instanceof IllegalArgumentException));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}.execute(context, owner, args, "undo:sent");
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|