From e376a577b6bfcdd9bdc0cc6ca283d99199a0197a Mon Sep 17 00:00:00 2001 From: bobufa Date: Wed, 25 Jul 2018 20:41:51 +0200 Subject: improve sidebar UI - only display messages that are content items - only display messages for active accounts - "fix" textview issue - add empty states (no search, no results) --- libdino/src/service/database.vala | 5 +++-- libdino/src/service/message_storage.vala | 18 +++++++++++++----- libdino/src/service/search_processor.vala | 21 ++++++++++++++------- 3 files changed, 30 insertions(+), 14 deletions(-) (limited to 'libdino/src/service') diff --git a/libdino/src/service/database.vala b/libdino/src/service/database.vala index 01cc2f52..bea07dda 100644 --- a/libdino/src/service/database.vala +++ b/libdino/src/service/database.vala @@ -43,8 +43,9 @@ public class Database : Qlite.Database { public Column foreign_id = new Column.Integer("foreign_id") { not_null = true }; internal ContentTable(Database db) { - base(db, "content"); + base(db, "contentx"); init({id, conversation_id, time, local_time, content_type, foreign_id}); + unique({content_type, foreign_id}, "IGNORE"); } } @@ -227,7 +228,7 @@ public class Database : Qlite.Database { message.fts_rebuild(); } else if (oldVersion < 8) { exec(""" - insert into content (conversation_id, time, local_time, content_type, foreign_id) + insert into contentx (conversation_id, time, local_time, content_type, foreign_id) select conversation.id, message.time, message.local_time, 1, message.id from message join conversation on message.account_id=conversation.account_id and diff --git a/libdino/src/service/message_storage.vala b/libdino/src/service/message_storage.vala index 9fb6ab19..50fc94b3 100644 --- a/libdino/src/service/message_storage.vala +++ b/libdino/src/service/message_storage.vala @@ -52,7 +52,7 @@ public class MessageStorage : StreamInteractionModule, Object { return null; } - public Gee.List? get_messages_before_message(Conversation? conversation, DateTime before, int id, int count = 20) { + public Gee.List get_messages_before_message(Conversation? conversation, DateTime before, int id, int count = 20) { // SortedSet? before = messages[conversation].head_set(message); // if (before != null && before.size >= count) { // Gee.List ret = new ArrayList(Message.equals_func); @@ -66,14 +66,22 @@ public class MessageStorage : StreamInteractionModule, Object { // } // return ret; // } else { - Gee.List db_messages = db.get_messages(conversation.counterpart, conversation.account, Util.get_message_type_for_conversation(conversation), count, before, null, id); - return db_messages; + Gee.List db_messages = db.get_messages(conversation.counterpart, conversation.account, Util.get_message_type_for_conversation(conversation), count, before, null, id); + Gee.List ret = new ArrayList(); + foreach (Message message in db_messages) { + ret.add(new MessageItem(message, conversation, -1)); + } + return ret; // } } - public Gee.List? get_messages_after_message(Conversation? conversation, DateTime after, int id, int count = 20) { + public Gee.List get_messages_after_message(Conversation? conversation, DateTime after, int id, int count = 20) { Gee.List db_messages = db.get_messages(conversation.counterpart, conversation.account, Util.get_message_type_for_conversation(conversation), count, null, after, id); - return db_messages; + Gee.List ret = new ArrayList(); + foreach (Message message in db_messages) { + ret.add(new MessageItem(message, conversation, -1)); + } + return ret; } public Message? get_message_by_id(int id, Conversation conversation) { diff --git a/libdino/src/service/search_processor.vala b/libdino/src/service/search_processor.vala index 6962a7c1..e56efa41 100644 --- a/libdino/src/service/search_processor.vala +++ b/libdino/src/service/search_processor.vala @@ -23,7 +23,7 @@ public class SearchProcessor : StreamInteractionModule, Object { this.db = db; } - private QueryBuilder prepare_search(string query) { + private QueryBuilder prepare_search(string query, bool join_content) { string words = ""; string? with = null; string? in_ = null; @@ -60,7 +60,12 @@ public class SearchProcessor : StreamInteractionModule, Object { .order_by(db.message.id, "DESC") .join_with(db.jid, db.jid.id, db.message.counterpart_id) .join_with(db.account, db.account.id, db.message.account_id) - .outer_join_with(db.real_jid, db.real_jid.message_id, db.message.id); + .outer_join_with(db.real_jid, db.real_jid.message_id, db.message.id) + .with(db.account.enabled, "=", true); + if (join_content) { + rows.join_on(db.content, "message.id=contentx.foreign_id AND contentx.content_type=1") + .with(db.content.content_type, "=", 1); + } if (with != null) { if (with.index_of("/") > 0) { rows.with(db.message.type_, "=", Message.Type.GROUPCHAT_PM) @@ -85,20 +90,22 @@ public class SearchProcessor : StreamInteractionModule, Object { return rows; } - public Gee.List match_messages(string query, int offset = -1) { - Gee.List ret = new ArrayList(Message.equals_func); - var rows = prepare_search(query).limit(10); + public Gee.List match_messages(string query, int offset = -1) { + Gee.List ret = new ArrayList(); + var rows = prepare_search(query, true).limit(10); if (offset > 0) { rows.offset(offset); } foreach (Row row in rows) { - ret.add(new Message.from_row(db, row)); + Message message = new Message.from_row(db, row); + Conversation? conversation = stream_interactor.get_module(ConversationManager.IDENTITY).get_conversation_for_message(message); + ret.add(new MessageItem(message, conversation, row[db.content.id])); } return ret; } public int count_match_messages(string query) { - return (int)prepare_search(query).select({db.message.id}).count(); + return (int)prepare_search(query, false).select({db.message.id}).count(); } } -- cgit v1.2.3-70-g09d2