aboutsummaryrefslogtreecommitdiff
path: root/libdino/src/service
diff options
context:
space:
mode:
Diffstat (limited to 'libdino/src/service')
-rw-r--r--libdino/src/service/calls.vala2
-rw-r--r--libdino/src/service/chat_interaction.vala22
-rw-r--r--libdino/src/service/content_item_store.vala34
-rw-r--r--libdino/src/service/file_manager.vala8
-rw-r--r--libdino/src/service/message_correction.vala1
-rw-r--r--libdino/src/service/message_processor.vala6
6 files changed, 31 insertions, 42 deletions
diff --git a/libdino/src/service/calls.vala b/libdino/src/service/calls.vala
index 3e2181a5..76cd0c68 100644
--- a/libdino/src/service/calls.vala
+++ b/libdino/src/service/calls.vala
@@ -389,7 +389,7 @@ namespace Dino {
Call call = current_jmi_request_peer[account].call;
bool outgoing_retract = call.direction == Call.DIRECTION_OUTGOING && from.equals_bare(account.bare_jid);
- bool incoming_retract = call.direction == Call.DIRECTION_INCOMING && from.equals_bare(call.counterparts[0]);
+ bool incoming_retract = call.direction == Call.DIRECTION_INCOMING && from.equals_bare(call.counterpart);
if (!(outgoing_retract || incoming_retract)) return;
call.state = Call.State.MISSED;
diff --git a/libdino/src/service/chat_interaction.vala b/libdino/src/service/chat_interaction.vala
index 240d22af..00c611db 100644
--- a/libdino/src/service/chat_interaction.vala
+++ b/libdino/src/service/chat_interaction.vala
@@ -33,17 +33,21 @@ public class ChatInteraction : StreamInteractionModule, Object {
}
public int get_num_unread(Conversation conversation) {
- ContentItem? read_up_to_item = stream_interactor.get_module(ContentItemStore.IDENTITY).get_item_by_id(conversation, conversation.read_up_to_item);
- if (read_up_to_item == null) return 0;
-
Database db = Dino.Application.get_default().db;
- string time = read_up_to_item.time.to_unix().to_string();
- string id = read_up_to_item.id.to_string();
- return (int)db.content_item.select()
- .where(@"time > ? OR (time = ? AND id > ?)", { time, time, id })
+
+ Qlite.QueryBuilder query = db.content_item.select()
.with(db.content_item.conversation_id, "=", conversation.id)
- .with(db.content_item.hide, "=", false)
- .count();
+ .with(db.content_item.hide, "=", false);
+
+ ContentItem? read_up_to_item = stream_interactor.get_module(ContentItemStore.IDENTITY).get_item_by_id(conversation, conversation.read_up_to_item);
+ if (read_up_to_item != null) {
+ string time = read_up_to_item.time.to_unix().to_string();
+ string id = read_up_to_item.id.to_string();
+ query.where(@"time > ? OR (time = ? AND id > ?)", { time, time, id });
+ }
+ // If it's a new conversation with read_up_to_item == null, all items are new.
+
+ return (int) query.count();
}
public bool is_active_focus(Conversation? conversation = null) {
diff --git a/libdino/src/service/content_item_store.vala b/libdino/src/service/content_item_store.vala
index 7a8e38b8..c6c47af4 100644
--- a/libdino/src/service/content_item_store.vala
+++ b/libdino/src/service/content_item_store.vala
@@ -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, CallState call_state, 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; }
diff --git a/libdino/src/service/file_manager.vala b/libdino/src/service/file_manager.vala
index 19d51b44..a478695c 100644
--- a/libdino/src/service/file_manager.vala
+++ b/libdino/src/service/file_manager.vala
@@ -176,7 +176,13 @@ public class FileManager : StreamInteractionModule, Object {
public bool is_sender_trustworthy(FileTransfer file_transfer, Conversation conversation) {
if (file_transfer.direction == FileTransfer.DIRECTION_SENT) return true;
- Jid relevant_jid = stream_interactor.get_module(MucManager.IDENTITY).get_real_jid(file_transfer.from, conversation.account) ?? conversation.counterpart;
+
+ Jid relevant_jid = conversation.counterpart;
+ if (conversation.type_ == Conversation.Type.GROUPCHAT) {
+ relevant_jid = stream_interactor.get_module(MucManager.IDENTITY).get_real_jid(file_transfer.from, conversation.account);
+ }
+ if (relevant_jid == null) return false;
+
bool in_roster = stream_interactor.get_module(RosterManager.IDENTITY).get_roster_item(conversation.account, relevant_jid) != null;
return in_roster;
}
diff --git a/libdino/src/service/message_correction.vala b/libdino/src/service/message_correction.vala
index 1374621a..322fa1c1 100644
--- a/libdino/src/service/message_correction.vala
+++ b/libdino/src/service/message_correction.vala
@@ -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()
diff --git a/libdino/src/service/message_processor.vala b/libdino/src/service/message_processor.vala
index fcabeba6..4fe1f6c3 100644
--- a/libdino/src/service/message_processor.vala
+++ b/libdino/src/service/message_processor.vala
@@ -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;
}