aboutsummaryrefslogtreecommitdiff
path: root/libdino/src/service/call_store.vala
diff options
context:
space:
mode:
authorfiaxh <git@lightrise.org>2021-05-11 12:57:02 +0200
committerfiaxh <git@lightrise.org>2021-05-11 12:57:02 +0200
commitd71604913dd5b3372a823320db83c37c845fac5c (patch)
tree2ffbff97a02c81d48d8aef4a4b7ee870507236e9 /libdino/src/service/call_store.vala
parente92ed27317ae398c867c946cf7206b1f0b32f3b4 (diff)
parent90f9ecf62b2ebfef14de2874e7942552409632bf (diff)
downloaddino-d71604913dd5b3372a823320db83c37c845fac5c.tar.gz
dino-d71604913dd5b3372a823320db83c37c845fac5c.zip
Merge remote-tracking branch 'origin/feature/calls'
Diffstat (limited to 'libdino/src/service/call_store.vala')
-rw-r--r--libdino/src/service/call_store.vala61
1 files changed, 61 insertions, 0 deletions
diff --git a/libdino/src/service/call_store.vala b/libdino/src/service/call_store.vala
new file mode 100644
index 00000000..fa6e63ee
--- /dev/null
+++ b/libdino/src/service/call_store.vala
@@ -0,0 +1,61 @@
+using Xmpp;
+using Gee;
+using Qlite;
+
+using Dino.Entities;
+
+namespace Dino {
+
+ public class CallStore : StreamInteractionModule, Object {
+ public static ModuleIdentity<CallStore> IDENTITY = new ModuleIdentity<CallStore>("call_store");
+ public string id { get { return IDENTITY.id; } }
+
+ private StreamInteractor stream_interactor;
+ private Database db;
+
+ private WeakMap<int, Call> calls_by_db_id = new WeakMap<int, Call>();
+
+ public static void start(StreamInteractor stream_interactor, Database db) {
+ CallStore m = new CallStore(stream_interactor, db);
+ stream_interactor.add_module(m);
+ }
+
+ private CallStore(StreamInteractor stream_interactor, Database db) {
+ this.stream_interactor = stream_interactor;
+ this.db = db;
+ }
+
+ public void add_call(Call call, Conversation conversation) {
+ call.persist(db);
+ cache_call(call);
+ }
+
+ public Call? get_call_by_id(int id) {
+ Call? call = calls_by_db_id[id];
+ if (call != null) {
+ return call;
+ }
+
+ RowOption row_option = db.call.select().with(db.call.id, "=", id).row();
+
+ return create_call_from_row_opt(row_option);
+ }
+
+ private Call? create_call_from_row_opt(RowOption row_opt) {
+ if (!row_opt.is_present()) return null;
+
+ try {
+ Call call = new Call.from_row(db, row_opt.inner);
+ cache_call(call);
+ return call;
+ } catch (InvalidJidError e) {
+ warning("Got message with invalid Jid: %s", e.message);
+ }
+ return null;
+ }
+
+ private void cache_call(Call call) {
+ calls_by_db_id[call.id] = call;
+ }
+ }
+} \ No newline at end of file