aboutsummaryrefslogtreecommitdiff
path: root/libdino/src/service/file_manager.vala
diff options
context:
space:
mode:
Diffstat (limited to 'libdino/src/service/file_manager.vala')
-rw-r--r--libdino/src/service/file_manager.vala43
1 files changed, 30 insertions, 13 deletions
diff --git a/libdino/src/service/file_manager.vala b/libdino/src/service/file_manager.vala
index 3def24af..340205af 100644
--- a/libdino/src/service/file_manager.vala
+++ b/libdino/src/service/file_manager.vala
@@ -11,7 +11,7 @@ public class FileManager : StreamInteractionModule, Object {
public string id { get { return IDENTITY.id; } }
public signal void upload_available(Account account);
- public signal void received_file(FileTransfer file_transfer);
+ public signal void received_file(FileTransfer file_transfer, Conversation conversation);
private StreamInteractor stream_interactor;
private Database db;
@@ -68,7 +68,7 @@ public class FileManager : StreamInteractionModule, Object {
file_sender.send_file(conversation, file_transfer);
}
}
- received_file(file_transfer);
+ received_file(file_transfer, conversation);
}
public bool is_upload_available(Conversation conversation) {
@@ -78,21 +78,38 @@ public class FileManager : StreamInteractionModule, Object {
return false;
}
- public Gee.List<FileTransfer> get_file_transfers(Account account, Jid counterpart, DateTime after, DateTime before) {
+ 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);
+ return get_transfers_from_qry(select);
+ }
+
+ 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)after.to_unix())
.with(db.file_transfer.local_time, "<", (long)before.to_unix())
- .order_by(db.file_transfer.id, "DESC");
+ .order_by(db.file_transfer.local_time, "DESC")
+ .limit(n);
+ return get_transfers_from_qry(select);
+ }
+
+ 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())
+ .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);
- 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;
@@ -117,7 +134,7 @@ public class FileManager : StreamInteractionModule, Object {
outgoing_processors.add(processor);
}
- private void handle_incomming_file(FileTransfer file_transfer) {
+ private void handle_incomming_file(FileTransfer file_transfer, Conversation conversation) {
foreach (IncommingFileProcessor processor in incomming_processors) {
if (processor.can_process(file_transfer)) {
processor.process(file_transfer);
@@ -131,7 +148,7 @@ public class FileManager : StreamInteractionModule, Object {
} catch (Error e) { }
file_transfer.persist(db);
- received_file(file_transfer);
+ received_file(file_transfer, conversation);
}
private void save_file(FileTransfer file_transfer) {
@@ -152,7 +169,7 @@ public class FileManager : StreamInteractionModule, Object {
}
public interface FileProvider : Object {
- public signal void file_incoming(FileTransfer file_transfer);
+ public signal void file_incoming(FileTransfer file_transfer, Conversation conversation);
}
public interface FileSender : Object {