Allow no template when forwarding

pull/197/head
M66B 4 years ago
parent 7e41786536
commit c2de70e91d

@ -405,11 +405,15 @@ public class EntityRule {
throw new IllegalArgumentException("Identity not found"); throw new IllegalArgumentException("Identity not found");
long aid = jargs.optLong("answer", -1); long aid = jargs.optLong("answer", -1);
if (aid < 0) if (aid < 0) {
String to = jargs.optString("to");
if (TextUtils.isEmpty(to))
throw new IllegalArgumentException(context.getString(R.string.title_rule_answer_missing)); throw new IllegalArgumentException(context.getString(R.string.title_rule_answer_missing));
} else {
EntityAnswer answer = db.answer().getAnswer(aid); EntityAnswer answer = db.answer().getAnswer(aid);
if (answer == null) if (answer == null)
throw new IllegalArgumentException("Answer not found"); throw new IllegalArgumentException("Template not found");
}
return; return;
case TYPE_TTS: case TYPE_TTS:
return; return;
@ -541,9 +545,18 @@ public class EntityRule {
if (identity == null) if (identity == null)
throw new IllegalArgumentException("Rule identity not found name=" + rule.name); throw new IllegalArgumentException("Rule identity not found name=" + rule.name);
EntityAnswer answer = db.answer().getAnswer(aid); EntityAnswer answer;
if (aid < 0) {
if (TextUtils.isEmpty(to))
throw new IllegalArgumentException("Rule template missing name=" + rule.name);
answer = new EntityAnswer();
answer.text = "";
} else {
answer = db.answer().getAnswer(aid);
if (answer == null) if (answer == null)
throw new IllegalArgumentException("Rule answer not found name=" + rule.name); throw new IllegalArgumentException("Rule template not found name=" + rule.name);
}
EntityFolder outbox = db.folder().getOutbox(); EntityFolder outbox = db.folder().getOutbox();
if (outbox == null) { if (outbox == null) {

@ -632,6 +632,11 @@ public class FragmentRule extends FragmentBase {
adapterIdentity.clear(); adapterIdentity.clear();
adapterIdentity.addAll(data.identities); adapterIdentity.addAll(data.identities);
EntityAnswer none = new EntityAnswer();
none.name = "-";
none.favorite = false;
data.answers.add(0, none);
adapterAnswer.clear(); adapterAnswer.clear();
adapterAnswer.addAll(data.answers); adapterAnswer.addAll(data.answers);
@ -970,7 +975,7 @@ public class FragmentRule extends FragmentBase {
} }
long answer = jaction.optLong("answer", -1); long answer = jaction.optLong("answer", -1);
for (int pos = 0; pos < adapterAnswer.getCount(); pos++) for (int pos = 1; pos < adapterAnswer.getCount(); pos++)
if (adapterAnswer.getItem(pos).id.equals(answer)) { if (adapterAnswer.getItem(pos).id.equals(answer)) {
spAnswer.setSelection(pos); spAnswer.setSelection(pos);
break; break;
@ -1117,6 +1122,7 @@ public class FragmentRule extends FragmentBase {
JSONObject jrecipient = jcondition.optJSONObject("recipient"); JSONObject jrecipient = jcondition.optJSONObject("recipient");
JSONObject jsubject = jcondition.optJSONObject("subject"); JSONObject jsubject = jcondition.optJSONObject("subject");
JSONObject jheader = jcondition.optJSONObject("header"); JSONObject jheader = jcondition.optJSONObject("header");
JSONObject jdate = jcondition.optJSONObject("date");
JSONObject jschedule = jcondition.optJSONObject("schedule"); JSONObject jschedule = jcondition.optJSONObject("schedule");
if (jsender == null && if (jsender == null &&
@ -1124,6 +1130,7 @@ public class FragmentRule extends FragmentBase {
jsubject == null && jsubject == null &&
!jcondition.optBoolean("attachments") && !jcondition.optBoolean("attachments") &&
jheader == null && jheader == null &&
jdate == null &&
jschedule == null) jschedule == null)
throw new IllegalArgumentException(context.getString(R.string.title_rule_condition_missing)); throw new IllegalArgumentException(context.getString(R.string.title_rule_condition_missing));
@ -1295,7 +1302,7 @@ public class FragmentRule extends FragmentBase {
EntityIdentity identity = (EntityIdentity) spIdent.getSelectedItem(); EntityIdentity identity = (EntityIdentity) spIdent.getSelectedItem();
EntityAnswer answer = (EntityAnswer) spAnswer.getSelectedItem(); EntityAnswer answer = (EntityAnswer) spAnswer.getSelectedItem();
jaction.put("identity", identity == null ? -1 : identity.id); jaction.put("identity", identity == null ? -1 : identity.id);
jaction.put("answer", answer == null ? -1 : answer.id); jaction.put("answer", answer == null || answer.id == null ? -1 : answer.id);
jaction.put("to", etTo.getText().toString().trim()); jaction.put("to", etTo.getText().toString().trim());
jaction.put("cc", cbCc.isChecked()); jaction.put("cc", cbCc.isChecked());
jaction.put("attachments", cbWithAttachments.isChecked()); jaction.put("attachments", cbWithAttachments.isChecked());

Loading…
Cancel
Save