Remove ContentFilters

fixes #1129 #573
This commit is contained in:
fiaxh 2021-12-09 15:46:16 +01:00
parent 905f93bccc
commit fa1ba2f83d
8 changed files with 18 additions and 79 deletions

View file

@ -14,7 +14,6 @@ public class ContentItemStore : StreamInteractionModule, Object {
private StreamInteractor stream_interactor;
private Database db;
private Gee.List<ContentFilter> filters = new ArrayList<ContentFilter>();
private HashMap<Conversation, ContentItemCollection> collection_conversations = new HashMap<Conversation, ContentItemCollection>(Conversation.hash_func, Conversation.equals_func);
public static void start(StreamInteractor stream_interactor, Database db) {
@ -149,10 +148,6 @@ public class ContentItemStore : StreamInteractionModule, Object {
return get_items_from_query(select, conversation);
}
public void add_filter(ContentFilter content_filter) {
filters.add(content_filter);
}
public void insert_message(Message message, Conversation conversation, bool hide = false) {
MessageItem item = new MessageItem(message, conversation, -1);
item.id = db.add_content_item(conversation, message.time, message.local_time, 1, message.id, hide);
@ -165,12 +160,10 @@ public class ContentItemStore : StreamInteractionModule, Object {
select.with(db.content_item.hide, "=", false);
foreach (Row row in select) {
MessageItem item = new MessageItem(message, conversation, row[db.content_item.id]);
if (!discard(item)) {
if (collection_conversations.has_key(conversation)) {
collection_conversations.get(conversation).insert_item(item);
}
new_item(item, conversation);
if (collection_conversations.has_key(conversation)) {
collection_conversations.get(conversation).insert_item(item);
}
new_item(item, conversation);
break;
}
}
@ -178,12 +171,10 @@ public class ContentItemStore : StreamInteractionModule, Object {
private void insert_file_transfer(FileTransfer file_transfer, Conversation conversation) {
FileItem item = new FileItem(file_transfer, conversation, -1);
item.id = db.add_content_item(conversation, file_transfer.time, file_transfer.local_time, 2, file_transfer.id, false);
if (!discard(item)) {
if (collection_conversations.has_key(conversation)) {
collection_conversations.get(conversation).insert_item(item);
}
new_item(item, conversation);
if (collection_conversations.has_key(conversation)) {
collection_conversations.get(conversation).insert_item(item);
}
new_item(item, conversation);
}
private void insert_call(Call call, Conversation conversation) {
@ -205,15 +196,6 @@ public class ContentItemStore : StreamInteractionModule, Object {
.set(db.content_item.hide, hide)
.perform();
}
private bool discard(ContentItem content_item) {
foreach (ContentFilter filter in filters) {
if (filter.discard(content_item)) {
return true;
}
}
return false;
}
}
public interface ContentItemCollection : Object {
@ -221,10 +203,6 @@ public interface ContentItemCollection : Object {
public abstract void remove_item(ContentItem item);
}
public interface ContentFilter : Object {
public abstract bool discard(ContentItem content_item);
}
public abstract class ContentItem : Object {
public int id { get; set; }
public string type_ { get; set; }

View file

@ -45,7 +45,6 @@ public class MessageCorrection : StreamInteractionModule, MessageListener {
Message out_message = stream_interactor.get_module(MessageProcessor.IDENTITY).create_out_message(correction_text, conversation);
out_message.edit_to = stanza_id;
outstanding_correction_nodes[out_message.stanza_id] = stanza_id;
stream_interactor.get_module(MessageStorage.IDENTITY).add_message(out_message, conversation);
stream_interactor.get_module(MessageProcessor.IDENTITY).send_xmpp_message(out_message, conversation);
db.message_correction.insert()

View file

@ -60,7 +60,6 @@ public class MessageProcessor : StreamInteractionModule, Object {
}
public Entities.Message send_message(Entities.Message message, Conversation conversation) {
stream_interactor.get_module(MessageStorage.IDENTITY).add_message(message, conversation);
stream_interactor.get_module(ContentItemStore.IDENTITY).insert_message(message, conversation);
send_xmpp_message(message, conversation);
message_sent(message, conversation);
@ -575,7 +574,7 @@ public class MessageProcessor : StreamInteractionModule, Object {
private class StoreContentItemListener : MessageListener {
public string[] after_actions_const = new string[]{ "DEDUPLICATE", "DECRYPT", "FILTER_EMPTY", "STORE", "CORRECTION" };
public string[] after_actions_const = new string[]{ "DEDUPLICATE", "DECRYPT", "FILTER_EMPTY", "STORE", "CORRECTION", "MESSAGE_REINTERPRETING" };
public override string action_group { get { return "STORE_CONTENT_ITEM"; } }
public override string[] after_actions { get { return after_actions_const; } }
@ -634,6 +633,9 @@ public class MessageProcessor : StreamInteractionModule, Object {
}
message.marked = Entities.Message.Marked.UNSENT;
message.encryption = conversation.encryption;
stream_interactor.get_module(MessageStorage.IDENTITY).add_message(message, conversation);
return message;
}

View file

@ -11,7 +11,6 @@ vala_precompile(HTTP_FILES_VALA_C
SOURCES
src/file_provider.vala
src/file_sender.vala
src/message_filter.vala
src/plugin.vala
src/register_plugin.vala
CUSTOM_VAPIS

View file

@ -23,7 +23,7 @@ public class FileProvider : Dino.FileProvider, Object {
private class ReceivedMessageListener : MessageListener {
public string[] after_actions_const = new string[]{ "STORE" };
public override string action_group { get { return ""; } }
public override string action_group { get { return "MESSAGE_REINTERPRETING"; } }
public override string[] after_actions { get { return after_actions_const; } }
private FileProvider outer;
@ -39,19 +39,14 @@ public class FileProvider : Dino.FileProvider, Object {
bool normal_file = oob_url != null && oob_url == message.body && FileProvider.http_url_regex.match(message.body);
bool omemo_file = FileProvider.omemo_url_regex.match(message.body);
if (normal_file || omemo_file) {
yield outer.on_file_message(message, conversation);
outer.on_file_message(message, conversation);
return true;
}
return false;
}
}
private async void on_file_message(Entities.Message message, Conversation conversation) {
// Hide message
ContentItem? content_item = stream_interactor.get_module(ContentItemStore.IDENTITY).get_item(conversation, 1, message.id);
if (content_item != null) {
stream_interactor.get_module(ContentItemStore.IDENTITY).set_item_hide(content_item, true);
}
private void on_file_message(Entities.Message message, Conversation conversation) {
var additional_info = message.id.to_string();
var receive_data = new HttpFileReceiveData();

View file

@ -42,19 +42,11 @@ public class HttpFileSender : FileSender, Object {
yield upload(file_transfer, send_data, file_meta);
file_transfer.info = send_data.url_down; // store the message content temporarily so the message gets filtered out
Entities.Message message = stream_interactor.get_module(MessageProcessor.IDENTITY).create_out_message(send_data.url_down, conversation);
message.encryption = send_data.encrypt_message ? conversation.encryption : Encryption.NONE;
stream_interactor.get_module(MessageProcessor.IDENTITY).send_message(message, conversation);
file_transfer.info = message.id.to_string();
ContentItem? content_item = stream_interactor.get_module(ContentItemStore.IDENTITY).get_item(conversation, 1, message.id);
if (content_item != null) {
stream_interactor.get_module(ContentItemStore.IDENTITY).set_item_hide(content_item, true);
}
message.encryption = send_data.encrypt_message ? conversation.encryption : Encryption.NONE;
stream_interactor.get_module(MessageProcessor.IDENTITY).send_xmpp_message(message, conversation);
}
public async bool can_send(Conversation conversation, FileTransfer file_transfer) {
@ -126,7 +118,7 @@ public class HttpFileSender : FileSender, Object {
}
private void check_add_oob(Entities.Message message, Xmpp.MessageStanza message_stanza, Conversation conversation) {
if (message.encryption == Encryption.NONE && message_is_file(db, message) && message.body.has_prefix("http")) {
if (message.encryption == Encryption.NONE && message.body.has_prefix("http") && message_is_file(db, message)) {
Xep.OutOfBandData.add_url_to_message(message_stanza, message_stanza.body);
}
}

View file

@ -1,23 +0,0 @@
using Dino.Entities;
using Xmpp;
using Gee;
namespace Dino.Plugins.HttpFiles {
public class FileMessageFilter : ContentFilter, Object {
public Database db;
public FileMessageFilter(Dino.Database db) {
this.db = db;
}
public bool discard(ContentItem content_item) {
if (content_item.type_ == MessageItem.TYPE) {
MessageItem message_item = content_item as MessageItem;
return message_is_file(db, message_item.message);
}
return false;
}
}
}

View file

@ -17,8 +17,6 @@ public class Plugin : RootInterface, Object {
app.stream_interactor.get_module(FileManager.IDENTITY).add_provider(file_provider);
app.stream_interactor.get_module(FileManager.IDENTITY).add_sender(file_sender);
app.stream_interactor.get_module(ContentItemStore.IDENTITY).add_filter(new FileMessageFilter(app.db));
}
public void shutdown() {
@ -28,8 +26,7 @@ public class Plugin : RootInterface, Object {
private bool message_is_file(Database db, Entities.Message message) {
Qlite.QueryBuilder builder = db.file_transfer.select({db.file_transfer.id}).with(db.file_transfer.info, "=", message.id.to_string());
Qlite.QueryBuilder builder2 = db.file_transfer.select({db.file_transfer.id}).with(db.file_transfer.info, "=", message.body);
return builder.count() > 0 || builder2.count() > 0;
return builder.count() > 0;
}
}