aboutsummaryrefslogtreecommitdiff
path: root/libdino
diff options
context:
space:
mode:
authorbobufa <bobufa@users.noreply.github.com>2018-07-25 20:41:51 +0200
committerbobufa <bobufa@users.noreply.github.com>2018-08-13 22:39:18 +0200
commite376a577b6bfcdd9bdc0cc6ca283d99199a0197a (patch)
tree741cab1ce822fcfc89655e762abfe2ceb3892357 /libdino
parent4901b096708ff5ca54c3e5393de74f2a8be55894 (diff)
downloaddino-e376a577b6bfcdd9bdc0cc6ca283d99199a0197a.tar.gz
dino-e376a577b6bfcdd9bdc0cc6ca283d99199a0197a.zip
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)
Diffstat (limited to 'libdino')
-rw-r--r--libdino/src/service/database.vala5
-rw-r--r--libdino/src/service/message_storage.vala18
-rw-r--r--libdino/src/service/search_processor.vala21
3 files changed, 30 insertions, 14 deletions
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<int> 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<Message>? get_messages_before_message(Conversation? conversation, DateTime before, int id, int count = 20) {
+ public Gee.List<MessageItem> get_messages_before_message(Conversation? conversation, DateTime before, int id, int count = 20) {
// SortedSet<Message>? before = messages[conversation].head_set(message);
// if (before != null && before.size >= count) {
// Gee.List<Message> ret = new ArrayList<Message>(Message.equals_func);
@@ -66,14 +66,22 @@ public class MessageStorage : StreamInteractionModule, Object {
// }
// return ret;
// } else {
- Gee.List<Message> 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<Message> db_messages = db.get_messages(conversation.counterpart, conversation.account, Util.get_message_type_for_conversation(conversation), count, before, null, id);
+ Gee.List<MessageItem> ret = new ArrayList<MessageItem>();
+ foreach (Message message in db_messages) {
+ ret.add(new MessageItem(message, conversation, -1));
+ }
+ return ret;
// }
}
- public Gee.List<Message>? get_messages_after_message(Conversation? conversation, DateTime after, int id, int count = 20) {
+ public Gee.List<MessageItem> get_messages_after_message(Conversation? conversation, DateTime after, int id, int count = 20) {
Gee.List<Message> 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<MessageItem> ret = new ArrayList<MessageItem>();
+ 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<Message> match_messages(string query, int offset = -1) {
- Gee.List<Message> ret = new ArrayList<Message>(Message.equals_func);
- var rows = prepare_search(query).limit(10);
+ public Gee.List<MessageItem> match_messages(string query, int offset = -1) {
+ Gee.List<MessageItem> ret = new ArrayList<MessageItem>();
+ 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();
}
}