|
|
@ -217,7 +217,7 @@ public class EntityRule {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static int run(Context context, List<EntityRule> rules,
|
|
|
|
static int run(Context context, List<EntityRule> rules,
|
|
|
|
EntityMessage message, List<Header> headers, String html)
|
|
|
|
EntityMessage message, boolean browsed, List<Header> headers, String html)
|
|
|
|
throws JSONException, MessagingException, IOException {
|
|
|
|
throws JSONException, MessagingException, IOException {
|
|
|
|
int applied = 0;
|
|
|
|
int applied = 0;
|
|
|
|
|
|
|
|
|
|
|
@ -226,7 +226,7 @@ public class EntityRule {
|
|
|
|
if (rule.group != null && stopped.contains(rule.group))
|
|
|
|
if (rule.group != null && stopped.contains(rule.group))
|
|
|
|
continue;
|
|
|
|
continue;
|
|
|
|
if (rule.matches(context, message, headers, html)) {
|
|
|
|
if (rule.matches(context, message, headers, html)) {
|
|
|
|
if (rule.execute(context, message, html))
|
|
|
|
if (rule.execute(context, message, browsed, html))
|
|
|
|
applied++;
|
|
|
|
applied++;
|
|
|
|
if (rule.stop)
|
|
|
|
if (rule.stop)
|
|
|
|
if (rule.group == null)
|
|
|
|
if (rule.group == null)
|
|
|
@ -635,8 +635,8 @@ public class EntityRule {
|
|
|
|
return matched;
|
|
|
|
return matched;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
boolean execute(Context context, EntityMessage message, String html) throws JSONException, IOException {
|
|
|
|
boolean execute(Context context, EntityMessage message, boolean browsed, String html) throws JSONException, IOException {
|
|
|
|
boolean executed = _execute(context, message, html);
|
|
|
|
boolean executed = _execute(context, message, browsed, html);
|
|
|
|
if (this.id != null && executed) {
|
|
|
|
if (this.id != null && executed) {
|
|
|
|
DB db = DB.getInstance(context);
|
|
|
|
DB db = DB.getInstance(context);
|
|
|
|
db.rule().applyRule(id, new Date().getTime());
|
|
|
|
db.rule().applyRule(id, new Date().getTime());
|
|
|
@ -644,7 +644,7 @@ public class EntityRule {
|
|
|
|
return executed;
|
|
|
|
return executed;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private boolean _execute(Context context, EntityMessage message, String html) throws JSONException, IllegalArgumentException, IOException {
|
|
|
|
private boolean _execute(Context context, EntityMessage message, boolean browsed, String html) throws JSONException, IllegalArgumentException, IOException {
|
|
|
|
JSONObject jaction = new JSONObject(action);
|
|
|
|
JSONObject jaction = new JSONObject(action);
|
|
|
|
int type = jaction.getInt("type");
|
|
|
|
int type = jaction.getInt("type");
|
|
|
|
EntityLog.log(context, EntityLog.Type.Rules, message,
|
|
|
|
EntityLog.log(context, EntityLog.Type.Rules, message,
|
|
|
@ -674,15 +674,15 @@ public class EntityRule {
|
|
|
|
case TYPE_COPY:
|
|
|
|
case TYPE_COPY:
|
|
|
|
return onActionCopy(context, message, jaction);
|
|
|
|
return onActionCopy(context, message, jaction);
|
|
|
|
case TYPE_ANSWER:
|
|
|
|
case TYPE_ANSWER:
|
|
|
|
return onActionAnswer(context, message, jaction);
|
|
|
|
return onActionAnswer(context, message, browsed, jaction);
|
|
|
|
case TYPE_TTS:
|
|
|
|
case TYPE_TTS:
|
|
|
|
return onActionTts(context, message, jaction);
|
|
|
|
return onActionTts(context, message, browsed, jaction);
|
|
|
|
case TYPE_AUTOMATION:
|
|
|
|
case TYPE_AUTOMATION:
|
|
|
|
return onActionAutomation(context, message, jaction);
|
|
|
|
return onActionAutomation(context, message, jaction);
|
|
|
|
case TYPE_DELETE:
|
|
|
|
case TYPE_DELETE:
|
|
|
|
return onActionDelete(context, message, jaction);
|
|
|
|
return onActionDelete(context, message, jaction);
|
|
|
|
case TYPE_SOUND:
|
|
|
|
case TYPE_SOUND:
|
|
|
|
return onActionSound(context, message, jaction);
|
|
|
|
return onActionSound(context, message, browsed, jaction);
|
|
|
|
case TYPE_LOCAL_ONLY:
|
|
|
|
case TYPE_LOCAL_ONLY:
|
|
|
|
return onActionLocalOnly(context, message, jaction);
|
|
|
|
return onActionLocalOnly(context, message, jaction);
|
|
|
|
case TYPE_NOTES:
|
|
|
|
case TYPE_NOTES:
|
|
|
@ -692,7 +692,7 @@ public class EntityRule {
|
|
|
|
case TYPE_SILENT:
|
|
|
|
case TYPE_SILENT:
|
|
|
|
return onActionSilent(context, message, jaction);
|
|
|
|
return onActionSilent(context, message, jaction);
|
|
|
|
case TYPE_SUMMARIZE:
|
|
|
|
case TYPE_SUMMARIZE:
|
|
|
|
return onActionSummarize(context, message, jaction);
|
|
|
|
return onActionSummarize(context, message, browsed, jaction);
|
|
|
|
default:
|
|
|
|
default:
|
|
|
|
throw new IllegalArgumentException("Unknown rule type=" + type + " name=" + name);
|
|
|
|
throw new IllegalArgumentException("Unknown rule type=" + type + " name=" + name);
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -1017,7 +1017,7 @@ public class EntityRule {
|
|
|
|
return true;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private boolean onActionAnswer(Context context, EntityMessage message, JSONObject jargs) {
|
|
|
|
private boolean onActionAnswer(Context context, EntityMessage message, boolean browsed, JSONObject jargs) {
|
|
|
|
DB db = DB.getInstance(context);
|
|
|
|
DB db = DB.getInstance(context);
|
|
|
|
String to = jargs.optString("to");
|
|
|
|
String to = jargs.optString("to");
|
|
|
|
boolean resend = jargs.optBoolean("resend");
|
|
|
|
boolean resend = jargs.optBoolean("resend");
|
|
|
@ -1068,7 +1068,7 @@ public class EntityRule {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (!complete && this.id != null) {
|
|
|
|
if (!complete && this.id != null) {
|
|
|
|
EntityOperation.queue(context, message, EntityOperation.RULE, this.id);
|
|
|
|
EntityOperation.queue(context, message, EntityOperation.RULE, this.id, browsed);
|
|
|
|
return true;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -1286,15 +1286,15 @@ public class EntityRule {
|
|
|
|
return true;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private boolean onActionTts(Context context, EntityMessage message, JSONObject jargs) {
|
|
|
|
private boolean onActionTts(Context context, EntityMessage message, boolean browsed, JSONObject jargs) {
|
|
|
|
DB db = DB.getInstance(context);
|
|
|
|
DB db = DB.getInstance(context);
|
|
|
|
|
|
|
|
|
|
|
|
if (message.ui_seen)
|
|
|
|
if (message.ui_seen || browsed)
|
|
|
|
return false;
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
|
|
if (!message.content && this.id != null) {
|
|
|
|
if (!message.content && this.id != null) {
|
|
|
|
EntityOperation.queue(context, message, EntityOperation.BODY);
|
|
|
|
EntityOperation.queue(context, message, EntityOperation.BODY);
|
|
|
|
EntityOperation.queue(context, message, EntityOperation.RULE, this.id);
|
|
|
|
EntityOperation.queue(context, message, EntityOperation.RULE, this.id, browsed);
|
|
|
|
return true;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -1439,13 +1439,16 @@ public class EntityRule {
|
|
|
|
return true;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private boolean onActionSound(Context context, EntityMessage message, JSONObject jargs) throws JSONException {
|
|
|
|
private boolean onActionSound(Context context, EntityMessage message, boolean browsed, JSONObject jargs) throws JSONException {
|
|
|
|
Uri uri = (jargs.has("uri") ? Uri.parse(jargs.getString("uri")) : null);
|
|
|
|
Uri uri = (jargs.has("uri") ? Uri.parse(jargs.getString("uri")) : null);
|
|
|
|
boolean loop = jargs.optBoolean("loop");
|
|
|
|
boolean loop = jargs.optBoolean("loop");
|
|
|
|
boolean alarm = jargs.optBoolean("alarm");
|
|
|
|
boolean alarm = jargs.optBoolean("alarm");
|
|
|
|
int duration = jargs.optInt("duration", MediaPlayerHelper.DEFAULT_ALARM_DURATION);
|
|
|
|
int duration = jargs.optInt("duration", MediaPlayerHelper.DEFAULT_ALARM_DURATION);
|
|
|
|
Log.i("Sound uri=" + uri + " loop=" + loop + " alarm=" + alarm + " duration=" + duration);
|
|
|
|
Log.i("Sound uri=" + uri + " loop=" + loop + " alarm=" + alarm + " duration=" + duration);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (browsed)
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
|
|
DB db = DB.getInstance(context);
|
|
|
|
DB db = DB.getInstance(context);
|
|
|
|
|
|
|
|
|
|
|
|
message.ui_silent = true;
|
|
|
|
message.ui_silent = true;
|
|
|
@ -1600,14 +1603,14 @@ public class EntityRule {
|
|
|
|
return true;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private boolean onActionSummarize(Context context, EntityMessage message, JSONObject jargs) throws JSONException, IOException {
|
|
|
|
private boolean onActionSummarize(Context context, EntityMessage message, boolean browsed, JSONObject jargs) throws JSONException, IOException {
|
|
|
|
DB db = DB.getInstance(context);
|
|
|
|
DB db = DB.getInstance(context);
|
|
|
|
|
|
|
|
|
|
|
|
if (message.ui_hide)
|
|
|
|
if (message.ui_hide)
|
|
|
|
return false;
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
|
|
if (!this.async && this.id != null) {
|
|
|
|
if (!this.async && this.id != null) {
|
|
|
|
EntityOperation.queue(context, message, EntityOperation.RULE, this.id);
|
|
|
|
EntityOperation.queue(context, message, EntityOperation.RULE, this.id, browsed);
|
|
|
|
return true;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|