Added summarize rule action

master
M66B 2 months ago
parent 4f22f269c8
commit 2b6423c01d

@ -616,6 +616,8 @@ public class AdapterRule extends RecyclerView.Adapter<AdapterRule.ViewHolder> {
return R.string.title_rule_url; return R.string.title_rule_url;
case EntityRule.TYPE_SILENT: case EntityRule.TYPE_SILENT:
return R.string.title_rule_silent; return R.string.title_rule_silent;
case EntityRule.TYPE_SUMMARIZE:
return R.string.title_rule_summarize;
default: default:
throw new IllegalArgumentException("Unknown action type=" + type); throw new IllegalArgumentException("Unknown action type=" + type);
} }

@ -64,6 +64,7 @@ import com.sun.mail.pop3.POP3Store;
import org.json.JSONArray; import org.json.JSONArray;
import org.json.JSONException; import org.json.JSONException;
import org.json.JSONObject;
import java.io.BufferedInputStream; import java.io.BufferedInputStream;
import java.io.BufferedOutputStream; import java.io.BufferedOutputStream;
@ -3136,6 +3137,7 @@ class Core {
if (!message.content) if (!message.content)
throw new IllegalArgumentException("Message without content id=" + rule.id + ":" + rule.name); throw new IllegalArgumentException("Message without content id=" + rule.id + ":" + rule.name);
rule.async = true;
rule.execute(context, message, null); rule.execute(context, message, null);
} }

@ -38,6 +38,7 @@ import androidx.annotation.NonNull;
import androidx.preference.PreferenceManager; import androidx.preference.PreferenceManager;
import androidx.room.Entity; import androidx.room.Entity;
import androidx.room.ForeignKey; import androidx.room.ForeignKey;
import androidx.room.Ignore;
import androidx.room.Index; import androidx.room.Index;
import androidx.room.PrimaryKey; import androidx.room.PrimaryKey;
@ -118,6 +119,9 @@ public class EntityRule {
public Integer applied = 0; public Integer applied = 0;
public Long last_applied; public Long last_applied;
@Ignore
public boolean async;
static final int TYPE_SEEN = 1; static final int TYPE_SEEN = 1;
static final int TYPE_UNSEEN = 2; static final int TYPE_UNSEEN = 2;
static final int TYPE_MOVE = 3; static final int TYPE_MOVE = 3;
@ -138,6 +142,7 @@ public class EntityRule {
static final int TYPE_NOTES = 18; static final int TYPE_NOTES = 18;
static final int TYPE_URL = 19; static final int TYPE_URL = 19;
static final int TYPE_SILENT = 20; static final int TYPE_SILENT = 20;
static final int TYPE_SUMMARIZE = 21;
static final String ACTION_AUTOMATION = BuildConfig.APPLICATION_ID + ".AUTOMATION"; static final String ACTION_AUTOMATION = BuildConfig.APPLICATION_ID + ".AUTOMATION";
static final String EXTRA_RULE = "rule"; static final String EXTRA_RULE = "rule";
@ -679,6 +684,8 @@ public class EntityRule {
return onActionUrl(context, message, jaction, html); return onActionUrl(context, message, jaction, html);
case TYPE_SILENT: case TYPE_SILENT:
return onActionSilent(context, message, jaction); return onActionSilent(context, message, jaction);
case TYPE_SUMMARIZE:
return onActionSummarize(context, message, jaction);
default: default:
throw new IllegalArgumentException("Unknown rule type=" + type + " name=" + name); throw new IllegalArgumentException("Unknown rule type=" + type + " name=" + name);
} }
@ -781,6 +788,8 @@ public class EntityRule {
return; return;
case TYPE_SILENT: case TYPE_SILENT:
return; return;
case TYPE_SUMMARIZE:
return;
default: default:
throw new IllegalArgumentException("Unknown rule type=" + type); throw new IllegalArgumentException("Unknown rule type=" + type);
} }
@ -1554,6 +1563,22 @@ public class EntityRule {
return true; return true;
} }
private boolean onActionSummarize(Context context, EntityMessage message, JSONObject jargs) throws JSONException, IOException {
DB db = DB.getInstance(context);
if (!this.async && this.id != null) {
EntityOperation.queue(context, message, EntityOperation.RULE, this.id);
return true;
}
message.preview = AI.getSummaryText(context, message);
db.message().setMessageContent(message.id, message.content, message.language, message.plain_only, message.preview, message.warning);
db.message().setMessageNotifying(message.id, 0);
return true;
}
private static Calendar getRelativeCalendar(boolean all, int minutes, long reference) { private static Calendar getRelativeCalendar(boolean all, int minutes, long reference) {
int d = minutes / (24 * 60); int d = minutes / (24 * 60);
int h = minutes / 60 % 24; int h = minutes / 60 % 24;

@ -670,6 +670,8 @@ public class FragmentRule extends FragmentBase {
actions.add(new Action(EntityRule.TYPE_COPY, getString(R.string.title_rule_copy))); actions.add(new Action(EntityRule.TYPE_COPY, getString(R.string.title_rule_copy)));
actions.add(new Action(EntityRule.TYPE_DELETE, getString(R.string.title_rule_delete))); actions.add(new Action(EntityRule.TYPE_DELETE, getString(R.string.title_rule_delete)));
actions.add(new Action(EntityRule.TYPE_ANSWER, getString(R.string.title_rule_answer))); actions.add(new Action(EntityRule.TYPE_ANSWER, getString(R.string.title_rule_answer)));
if (AI.isAvailable(getContext()))
actions.add(new Action(EntityRule.TYPE_SUMMARIZE, getString(R.string.title_rule_summarize)));
actions.add(new Action(EntityRule.TYPE_TTS, getString(R.string.title_rule_tts))); actions.add(new Action(EntityRule.TYPE_TTS, getString(R.string.title_rule_tts)));
actions.add(new Action(EntityRule.TYPE_SOUND, getString(R.string.title_rule_sound))); actions.add(new Action(EntityRule.TYPE_SOUND, getString(R.string.title_rule_sound)));
actions.add(new Action(EntityRule.TYPE_AUTOMATION, getString(R.string.title_rule_automation))); actions.add(new Action(EntityRule.TYPE_AUTOMATION, getString(R.string.title_rule_automation)));

@ -2035,6 +2035,7 @@
<string name="title_rule_delete">Delete permanently</string> <string name="title_rule_delete">Delete permanently</string>
<string name="title_rule_sound">Play sound</string> <string name="title_rule_sound">Play sound</string>
<string name="title_rule_silent">Silent notification</string> <string name="title_rule_silent">Silent notification</string>
<string name="title_rule_summarize">Summarize</string>
<string name="title_rule_caption">Edit rule</string> <string name="title_rule_caption">Edit rule</string>
<string name="title_rule_title">Rule applies to</string> <string name="title_rule_title">Rule applies to</string>

Loading…
Cancel
Save