aboutsummaryrefslogtreecommitdiff
path: root/plugins/omemo/src/signal/simple_ss.vala
diff options
context:
space:
mode:
authorhrxi <hrrrxi@gmail.com>2023-06-19 14:08:57 +0200
committerfiaxh <fiaxh@users.noreply.github.com>2023-10-06 15:25:12 +0200
commit6eb1b53e60a12f82c8d47a5824bf9cee954ccdc2 (patch)
tree13a13ef08fcd74bc1685454730b72693806b76f0 /plugins/omemo/src/signal/simple_ss.vala
parente2d801b5f74b60c38a75310066c48468c8a4bc93 (diff)
downloaddino-6eb1b53e60a12f82c8d47a5824bf9cee954ccdc2.tar.gz
dino-6eb1b53e60a12f82c8d47a5824bf9cee954ccdc2.zip
Merge `signal-protocol` into `omemo` plugin
Same reasoning as for the `openpgp` plugin.
Diffstat (limited to 'plugins/omemo/src/signal/simple_ss.vala')
-rw-r--r--plugins/omemo/src/signal/simple_ss.vala75
1 files changed, 75 insertions, 0 deletions
diff --git a/plugins/omemo/src/signal/simple_ss.vala b/plugins/omemo/src/signal/simple_ss.vala
new file mode 100644
index 00000000..5213f736
--- /dev/null
+++ b/plugins/omemo/src/signal/simple_ss.vala
@@ -0,0 +1,75 @@
+using Gee;
+
+namespace Signal {
+
+public class SimpleSessionStore : SessionStore {
+
+ private Map<string, ArrayList<SessionStore.Session>> session_map = new HashMap<string, ArrayList<SessionStore.Session>>();
+
+ public override uint8[]? load_session(Address address) throws Error {
+ if (session_map.has_key(address.name)) {
+ foreach (SessionStore.Session session in session_map[address.name]) {
+ if (session.device_id == address.device_id) return session.record;
+ }
+ }
+ return null;
+ }
+
+ public override IntList get_sub_device_sessions(string name) throws Error {
+ IntList res = new IntList();
+ if (session_map.has_key(name)) {
+ foreach (SessionStore.Session session in session_map[name]) {
+ res.add(session.device_id);
+ }
+ }
+ return res;
+ }
+
+ public override void store_session(Address address, uint8[] record) throws Error {
+ if (contains_session(address)) {
+ delete_session(address);
+ }
+ if (!session_map.has_key(address.name)) {
+ session_map[address.name] = new ArrayList<SessionStore.Session>();
+ }
+ SessionStore.Session session = new Session() { name = address.name, device_id = address.device_id, record = record };
+ session_map[address.name].add(session);
+ session_stored(session);
+ }
+
+ public override bool contains_session(Address address) throws Error {
+ if (!session_map.has_key(address.name)) return false;
+ foreach (SessionStore.Session session in session_map[address.name]) {
+ if (session.device_id == address.device_id) return true;
+ }
+ return false;
+ }
+
+ public override void delete_session(Address address) throws Error {
+ if (!session_map.has_key(address.name)) throw_by_code(ErrorCode.UNKNOWN, "No session found");
+ foreach (SessionStore.Session session in session_map[address.name]) {
+ if (session.device_id == address.device_id) {
+ session_map[address.name].remove(session);
+ if (session_map[address.name].size == 0) {
+ session_map.unset(address.name);
+ }
+ session_removed(session);
+ return;
+ }
+ }
+ }
+
+ public override void delete_all_sessions(string name) throws Error {
+ if (session_map.has_key(name)) {
+ foreach (SessionStore.Session session in session_map[name]) {
+ session_map[name].remove(session);
+ if (session_map[name].size == 0) {
+ session_map.unset(name);
+ }
+ session_removed(session);
+ }
+ }
+ }
+}
+
+} \ No newline at end of file