aboutsummaryrefslogtreecommitdiff
path: root/libdino/src/service/content_item_accumulator.vala
diff options
context:
space:
mode:
authorbobufa <bobufa@users.noreply.github.com>2018-06-23 11:59:21 +0200
committerbobufa <bobufa@users.noreply.github.com>2018-08-13 22:05:04 +0200
commit760fd4cb26340165fb85c2e3aee8390e46dc8b63 (patch)
treee68f93a234680b4d84fd79b02cd27c6f1b058077 /libdino/src/service/content_item_accumulator.vala
parent443e7ee49da305a9ae8052c5b7a73412d03ce75f (diff)
downloaddino-760fd4cb26340165fb85c2e3aee8390e46dc8b63.tar.gz
dino-760fd4cb26340165fb85c2e3aee8390e46dc8b63.zip
load+display later messages when scrolling down
Diffstat (limited to 'libdino/src/service/content_item_accumulator.vala')
-rw-r--r--libdino/src/service/content_item_accumulator.vala43
1 files changed, 33 insertions, 10 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;