aboutsummaryrefslogtreecommitdiff
path: root/libdino
diff options
context:
space:
mode:
Diffstat (limited to 'libdino')
-rw-r--r--libdino/src/service/content_item_accumulator.vala43
-rw-r--r--libdino/src/service/database.vala14
-rw-r--r--libdino/src/service/file_manager.vala24
-rw-r--r--libdino/src/service/message_storage.vala11
4 files changed, 60 insertions, 32 deletions
diff --git a/libdino/src/service/content_item_accumulator.vala b/libdino/src/service/content_item_accumulator.vala
index 9fc852b2..9f9e672c 100644
--- a/libdino/src/service/content_item_accumulator.vala
+++ b/libdino/src/service/content_item_accumulator.vala
@@ -46,50 +46,73 @@ public class ContentItemAccumulator : StreamInteractionModule, Object {
items.add(new FileItem(transfer));
}
+ Gee.List<ContentItem> ret = new ArrayList<ContentItem>();
+ if (items.size == 0) return ret;
+
BidirIterator<ContentItem> iter = items.bidir_iterator();
iter.last();
int i = 0;
- while (i < n && iter.has_previous()) {
+ while (i < n - 1 && iter.has_previous()) {
iter.previous();
i++;
}
- Gee.List<ContentItem> ret = new ArrayList<ContentItem>();
do {
ret.add(iter.get());
- } while(iter.next());
+ } while (iter.next());
return ret;
}
public Gee.List<ContentItem> populate_before(ContentItemCollection item_collection, Conversation conversation, ContentItem item, int n) {
Gee.TreeSet<ContentItem> items = new Gee.TreeSet<ContentItem>(ContentItem.compare);
- Gee.List<Entities.Message>? messages = stream_interactor.get_module(MessageStorage.IDENTITY).get_messages_before_message(conversation, item.display_time, n);
+ int before_id = item as MessageItem != null ? (int)Math.floor(item.seccondary_sort_indicator) : -1;
+ Gee.List<Entities.Message>? messages = stream_interactor.get_module(MessageStorage.IDENTITY).get_messages_before_message(conversation, item.display_time, before_id, n);
if (messages != null) {
foreach (Entities.Message message in messages) {
items.add(new MessageItem(message, conversation));
}
}
- Gee.List<FileTransfer> transfers = stream_interactor.get_module(FileManager.IDENTITY).get_transfers_before(conversation.account, conversation.counterpart, item.display_time, n);
+ Gee.List<FileTransfer> transfers = stream_interactor.get_module(FileManager.IDENTITY).get_transfers_before(conversation.account, conversation.counterpart, item.sort_time, n);
foreach (FileTransfer transfer in transfers) {
items.add(new FileItem(transfer));
}
+ Gee.List<ContentItem> ret = new ArrayList<ContentItem>();
+ if (items.size == 0) return ret;
+
BidirIterator<ContentItem> iter = items.bidir_iterator();
iter.last();
int i = 0;
- while (i < n && iter.has_previous()) {
+ while (i < n - 1 && iter.has_previous()) {
iter.previous();
i++;
}
- Gee.List<ContentItem> ret = new ArrayList<ContentItem>();
do {
ret.add(iter.get());
- } while(iter.next());
+ } while (iter.next());
return ret;
}
- public void populate_after(Conversation conversation, ContentItem item, int n) {
+ public Gee.List<ContentItem> populate_after(ContentItemCollection item_collection, Conversation conversation, ContentItem item, int n) {
+ Gee.TreeSet<ContentItem> items = new Gee.TreeSet<ContentItem>(ContentItem.compare);
+ int after_id = item as MessageItem != null ? (int)Math.floor(item.seccondary_sort_indicator) : -1;
+ Gee.List<Entities.Message>? messages = stream_interactor.get_module(MessageStorage.IDENTITY).get_messages_after_message(conversation, item.sort_time, after_id, n);
+ if (messages != null) {
+ foreach (Entities.Message message in messages) {
+ items.add(new MessageItem(message, conversation));
+ }
+ }
+ Gee.List<FileTransfer> transfers = stream_interactor.get_module(FileManager.IDENTITY).get_transfers_after(conversation.account, conversation.counterpart, item.sort_time, n);
+ foreach (FileTransfer transfer in transfers) {
+ items.add(new FileItem(transfer));
+ }
+
+ Gee.List<ContentItem> ret = new ArrayList<ContentItem>();
+ foreach (ContentItem content_item in items) {
+ ret.add(content_item);
+ }
+ return ret;
}
public void add_filter(ContentFilter content_filter) {
@@ -196,7 +219,7 @@ public class FileItem : ContentItem {
this.file_transfer = file_transfer;
this.jid = file_transfer.direction == FileTransfer.DIRECTION_SENT ? file_transfer.account.bare_jid.with_resource(file_transfer.account.resourcepart) : file_transfer.counterpart;
- this.sort_time = file_transfer.time;
+ this.sort_time = file_transfer.local_time;
this.seccondary_sort_indicator = file_transfer.id + 0.2903;
this.display_time = file_transfer.time;
this.encryption = file_transfer.encryption;
diff --git a/libdino/src/service/database.vala b/libdino/src/service/database.vala
index 2dca686f..d02e4c71 100644
--- a/libdino/src/service/database.vala
+++ b/libdino/src/service/database.vala
@@ -236,11 +236,10 @@ public class Database : Qlite.Database {
}
}
- public Gee.List<Message> get_messages(Xmpp.Jid jid, Account account, Message.Type? type, int count, DateTime? before) {
+ public Gee.List<Message> get_messages(Xmpp.Jid jid, Account account, Message.Type? type, int count, DateTime? before, DateTime? after, int id) {
QueryBuilder select = message.select()
.with(message.counterpart_id, "=", get_jid_id(jid))
.with(message.account_id, "=", account.id)
- .order_by(message.id, "DESC")
.limit(count);
if (jid.resourcepart != null) {
select.with(message.counterpart_resource, "=", jid.resourcepart);
@@ -250,6 +249,17 @@ public class Database : Qlite.Database {
}
if (before != null) {
select.with(message.local_time, "<", (long) before.to_unix());
+ if (id > 0) {
+ select.with(message.id, "<", id);
+ }
+ }
+ if (after != null) {
+ select.with(message.local_time, ">", (long) after.to_unix());
+ if (id > 0) {
+ select.with(message.id, ">", id);
+ }
+ } else {
+ select.order_by(message.id, "DESC");
}
LinkedList<Message> ret = new LinkedList<Message>();
diff --git a/libdino/src/service/file_manager.vala b/libdino/src/service/file_manager.vala
index 667076dd..18f1735d 100644
--- a/libdino/src/service/file_manager.vala
+++ b/libdino/src/service/file_manager.vala
@@ -84,13 +84,7 @@ public class FileManager : StreamInteractionModule, Object {
.with(db.file_transfer.account_id, "=", account.id)
.order_by(db.file_transfer.local_time, "DESC")
.limit(n);
-
- Gee.List<FileTransfer> ret = new ArrayList<FileTransfer>();
- foreach (Qlite.Row row in select) {
- FileTransfer file_transfer = new FileTransfer.from_row(db, row, get_storage_dir());
- ret.insert(0, file_transfer);
- }
- return ret;
+ return get_transfers_from_qry(select);
}
public Gee.List<FileTransfer> get_transfers_before(Account account, Jid counterpart, DateTime before, int n) {
@@ -100,23 +94,19 @@ public class FileManager : StreamInteractionModule, Object {
.with(db.file_transfer.local_time, "<", (long)before.to_unix())
.order_by(db.file_transfer.local_time, "DESC")
.limit(n);
-
- Gee.List<FileTransfer> ret = new ArrayList<FileTransfer>();
- foreach (Qlite.Row row in select) {
- FileTransfer file_transfer = new FileTransfer.from_row(db, row, get_storage_dir());
- ret.insert(0, file_transfer);
- }
- return ret;
+ return get_transfers_from_qry(select);
}
- public Gee.List<FileTransfer> get_file_transfers(Account account, Jid counterpart, DateTime after, DateTime before) {
+ public Gee.List<FileTransfer> get_transfers_after(Account account, Jid counterpart, DateTime after, int n) {
Qlite.QueryBuilder select = db.file_transfer.select()
.with(db.file_transfer.counterpart_id, "=", db.get_jid_id(counterpart))
.with(db.file_transfer.account_id, "=", account.id)
.with(db.file_transfer.local_time, ">", (long)after.to_unix())
- .with(db.file_transfer.local_time, "<", (long)before.to_unix())
- .order_by(db.file_transfer.id, "DESC");
+ .limit(n);
+ return get_transfers_from_qry(select);
+ }
+ private Gee.List<FileTransfer> get_transfers_from_qry(Qlite.QueryBuilder select) {
Gee.List<FileTransfer> ret = new ArrayList<FileTransfer>();
foreach (Qlite.Row row in select) {
FileTransfer file_transfer = new FileTransfer.from_row(db, row, get_storage_dir());
diff --git a/libdino/src/service/message_storage.vala b/libdino/src/service/message_storage.vala
index 906693a3..e3869e41 100644
--- a/libdino/src/service/message_storage.vala
+++ b/libdino/src/service/message_storage.vala
@@ -51,7 +51,7 @@ public class MessageStorage : StreamInteractionModule, Object {
return null;
}
- public Gee.List<Message>? get_messages_before_message(Conversation? conversation, DateTime before, int count = 20) {
+ public Gee.List<Message>? 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);
@@ -65,11 +65,16 @@ 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);
+ 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;
// }
}
+ public Gee.List<Message>? 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;
+ }
+
public Message? get_message_by_id(string stanza_id, Conversation conversation) {
init_conversation(conversation);
foreach (Message message in messages[conversation]) {
@@ -100,7 +105,7 @@ public class MessageStorage : StreamInteractionModule, Object {
}
return res;
});
- Gee.List<Message> db_messages = db.get_messages(conversation.counterpart, conversation.account, Util.get_message_type_for_conversation(conversation), 50, null);
+ Gee.List<Message> db_messages = db.get_messages(conversation.counterpart, conversation.account, Util.get_message_type_for_conversation(conversation), 50, null, null, -1);
messages[conversation].add_all(db_messages);
}
}