diff options
author | fiaxh <git@lightrise.org> | 2021-12-23 00:44:51 +0100 |
---|---|---|
committer | fiaxh <git@lightrise.org> | 2021-12-23 00:46:58 +0100 |
commit | d02c5bc55d4325de308a592e8980139aa0634215 (patch) | |
tree | 9cb91f86056dd29f863bd8e54580cccc625af60e /libdino/src/entity | |
parent | 1378224444b1862ac95783ac2bae7d25a0a8862d (diff) | |
parent | f0c7dd0682fec8d72c644d8e54896de7bdc40ddb (diff) | |
download | dino-d02c5bc55d4325de308a592e8980139aa0634215.tar.gz dino-d02c5bc55d4325de308a592e8980139aa0634215.zip |
Merge branch groupcalls
Diffstat (limited to 'libdino/src/entity')
-rw-r--r-- | libdino/src/entity/call.vala | 54 |
1 files changed, 43 insertions, 11 deletions
diff --git a/libdino/src/entity/call.vala b/libdino/src/entity/call.vala index 577b3ab8..8e5bc246 100644 --- a/libdino/src/entity/call.vala +++ b/libdino/src/entity/call.vala @@ -11,7 +11,7 @@ namespace Dino.Entities { RINGING, ESTABLISHING, IN_PROGRESS, - OTHER_DEVICE_ACCEPTED, + OTHER_DEVICE, ENDED, DECLINED, MISSED, @@ -21,13 +21,11 @@ namespace Dino.Entities { public int id { get; set; default=-1; } public Account account { get; set; } public Jid counterpart { get; set; } + public Gee.List<Jid> counterparts = new Gee.ArrayList<Jid>(Jid.equals_bare_func); public Jid ourpart { get; set; } - public Jid? from { + public Jid proposer { get { return direction == DIRECTION_OUTGOING ? ourpart : counterpart; } } - public Jid? to { - get { return direction == DIRECTION_OUTGOING ? counterpart : ourpart; } - } public bool direction { get; set; } public DateTime time { get; set; } public DateTime local_time { get; set; } @@ -44,10 +42,6 @@ namespace Dino.Entities { id = row[db.call.id]; account = db.get_account_by_id(row[db.call.account_id]); - counterpart = db.get_jid_by_id(row[db.call.counterpart_id]); - string counterpart_resource = row[db.call.counterpart_resource]; - if (counterpart_resource != null) counterpart = counterpart.with_resource(counterpart_resource); - string our_resource = row[db.call.our_resource]; if (our_resource != null) { ourpart = account.bare_jid.with_resource(our_resource); @@ -61,6 +55,21 @@ namespace Dino.Entities { encryption = (Encryption) row[db.call.encryption]; state = (State) row[db.call.state]; + Qlite.QueryBuilder counterparts_select = db.call_counterpart.select().with(db.call_counterpart.call_id, "=", id); + foreach (Qlite.Row counterparts_row in counterparts_select) { + Jid peer = db.get_jid_by_id(counterparts_row[db.call_counterpart.jid_id]); + if (!counterparts.contains(peer)) { // Legacy: The first peer is also in the `call` table. Don't add twice. + counterparts.add(peer); + } + } + + counterpart = db.get_jid_by_id(row[db.call.counterpart_id]); + string counterpart_resource = row[db.call.counterpart_resource]; + if (counterpart_resource != null) counterpart = counterpart.with_resource(counterpart_resource); + if (counterparts.is_empty) { + counterparts.add(counterpart); + } + notify.connect(on_update); } @@ -70,8 +79,6 @@ namespace Dino.Entities { this.db = db; Qlite.InsertBuilder builder = db.call.insert() .value(db.call.account_id, account.id) - .value(db.call.counterpart_id, db.get_jid_id(counterpart)) - .value(db.call.counterpart_resource, counterpart.resourcepart) .value(db.call.our_resource, ourpart.resourcepart) .value(db.call.direction, direction) .value(db.call.time, (long) time.to_unix()) @@ -83,11 +90,36 @@ namespace Dino.Entities { } else { builder.value(db.call.end_time, (long) local_time.to_unix()); } + if (counterpart != null) { + builder.value(db.call.counterpart_id, db.get_jid_id(counterpart)) + .value(db.call.counterpart_resource, counterpart.resourcepart); + } id = (int) builder.perform(); + foreach (Jid peer in counterparts) { + db.call_counterpart.insert() + .value(db.call_counterpart.call_id, id) + .value(db.call_counterpart.jid_id, db.get_jid_id(peer)) + .value(db.call_counterpart.resource, peer.resourcepart) + .perform(); + } + notify.connect(on_update); } + public void add_peer(Jid peer) { + if (counterparts.contains(peer)) return; + + counterparts.add(peer); + if (db != null) { + db.call_counterpart.insert() + .value(db.call_counterpart.call_id, id) + .value(db.call_counterpart.jid_id, db.get_jid_id(peer)) + .value(db.call_counterpart.resource, peer.resourcepart) + .perform(); + } + } + public bool equals(Call c) { return equals_func(this, c); } |