diff options
author | bobufa <bobufa@users.noreply.github.com> | 2018-06-19 18:07:00 +0200 |
---|---|---|
committer | bobufa <bobufa@users.noreply.github.com> | 2018-08-13 22:04:47 +0200 |
commit | 3ea00446fb5893804243f5b1a1aa89817b7bc19a (patch) | |
tree | 3be25cfd7b807cd6db4846e6fe1b6e404a58a1f4 /libdino/src/service/file_manager.vala | |
parent | ab0bc7f04d156db9e398c3f8c4f8bdfc11dd7458 (diff) | |
download | dino-3ea00446fb5893804243f5b1a1aa89817b7bc19a.tar.gz dino-3ea00446fb5893804243f5b1a1aa89817b7bc19a.zip |
refactor conversation item management (accumulate them in libdino)
Diffstat (limited to 'libdino/src/service/file_manager.vala')
-rw-r--r-- | libdino/src/service/file_manager.vala | 37 |
1 files changed, 32 insertions, 5 deletions
diff --git a/libdino/src/service/file_manager.vala b/libdino/src/service/file_manager.vala index 3def24af..667076dd 100644 --- a/libdino/src/service/file_manager.vala +++ b/libdino/src/service/file_manager.vala @@ -78,6 +78,37 @@ public class FileManager : StreamInteractionModule, Object { return false; } + public Gee.List<FileTransfer> get_latest_transfers(Account account, Jid counterpart, 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) + .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; + } + + public Gee.List<FileTransfer> get_transfers_before(Account account, Jid counterpart, DateTime before, 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)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; + } + public Gee.List<FileTransfer> get_file_transfers(Account account, Jid counterpart, DateTime after, DateTime before) { Qlite.QueryBuilder select = db.file_transfer.select() .with(db.file_transfer.counterpart_id, "=", db.get_jid_id(counterpart)) @@ -88,11 +119,7 @@ public class FileManager : StreamInteractionModule, Object { Gee.List<FileTransfer> ret = new ArrayList<FileTransfer>(); foreach (Qlite.Row row in select) { - FileTransfer file_transfer = new FileTransfer.from_row(db, row); - File file = File.new_for_path(Path.build_filename(get_storage_dir(), file_transfer.path ?? file_transfer.file_name)); - try { - file_transfer.input_stream = file.read(); - } catch (Error e) { } + FileTransfer file_transfer = new FileTransfer.from_row(db, row, get_storage_dir()); ret.insert(0, file_transfer); } return ret; |