Create contacts API routes

Change-Id: I35a51776c794d23fed3661db9ace6d54842bf83a
diff --git a/server/src/jamid/jami-swig.ts b/server/src/jamid/jami-swig.ts
index b072328..1ada8e9 100644
--- a/server/src/jamid/jami-swig.ts
+++ b/server/src/jamid/jami-swig.ts
@@ -16,7 +16,7 @@
  * <https://www.gnu.org/licenses/>.
  */
 import { Constructable } from '../interfaces.js';
-import { itMap, itRange, itToArr, itToMap, itToRecord } from './utils.js';
+import { itMap, itRange, itToArr, itToRecord } from './utils.js';
 
 enum Bool {
   False = 'false',
@@ -47,11 +47,9 @@
 export type VectMap = SwigVec<StringMap>;
 // export type Blob = SwigVec<number>;
 
-// TODO: Consider always converting to Record rather than Map as conversion to interfaces is easier
 export const stringVectToArray = (sv: StringVect) => itToArr(swigVecToIt(sv));
 export const stringMapToRecord = (sm: StringMap) => itToRecord(swigMapToIt(sm));
-export const stringMapToMap = (sm: StringMap) => itToMap(swigMapToIt(sm));
-// export const vectMapToArrayMap = (vm: VectMap) => itToArr(itMap(swigVecToIt(vm), stringMapToMap));
+export const vectMapToRecordArray = (vm: VectMap) => itToArr(itMap(swigVecToIt(vm), stringMapToRecord));
 
 /**
  * Non-exhaustive list of properties for JamiSwig.
diff --git a/server/src/jamid/jamid.ts b/server/src/jamid/jamid.ts
index 8676875..27ff0e3 100644
--- a/server/src/jamid/jamid.ts
+++ b/server/src/jamid/jamid.ts
@@ -34,10 +34,11 @@
   RegistrationStateChanged,
   VolatileDetailsChanged,
 } from './jami-signal-interfaces.js';
-import { JamiSwig, StringMap, stringMapToRecord, stringVectToArray } from './jami-swig.js';
+import { JamiSwig, StringMap, stringMapToRecord, stringVectToArray, vectMapToRecordArray } from './jami-swig.js';
 import { require } from './utils.js';
 
 // TODO: Mechanism to map account IDs to a list of WebSockets
+// TODO: Convert Records to interfaces and replace them in common/ (e.g. Contact)
 
 @Service()
 export class Jamid {
@@ -230,6 +231,26 @@
     return stringMapToRecord(this.jamiSwig.getKnownRingDevices(accountId));
   }
 
+  addContact(accountId: string, contactId: string) {
+    this.jamiSwig.addContact(accountId, contactId);
+  }
+
+  removeContact(accountId: string, contactId: string) {
+    this.jamiSwig.removeContact(accountId, contactId, false);
+  }
+
+  blockContact(accountId: string, contactId: string) {
+    this.jamiSwig.removeContact(accountId, contactId, true);
+  }
+
+  getContacts(accountId: string): Record<string, string>[] {
+    return vectMapToRecordArray(this.jamiSwig.getContacts(accountId));
+  }
+
+  getContactDetails(accountId: string, contactId: string): Record<string, string> {
+    return stringMapToRecord(this.jamiSwig.getContactDetails(accountId, contactId));
+  }
+
   getDefaultModerators(accountId: string): string[] {
     return stringVectToArray(this.jamiSwig.getDefaultModerators(accountId));
   }
diff --git a/server/src/jamid/utils.ts b/server/src/jamid/utils.ts
index 0952fec..f692578 100644
--- a/server/src/jamid/utils.ts
+++ b/server/src/jamid/utils.ts
@@ -43,14 +43,6 @@
 
 export const itToArr = <T>(it: Iterable<T>) => Array.from(it);
 
-export const itToMap = <T, U>(it: Iterable<[T, U]>) => {
-  const m = new Map<T, U>();
-  for (const [k, v] of it) {
-    m.set(k, v);
-  }
-  return m;
-};
-
 export const itToRecord = <T>(it: Iterable<[string, T]>) => {
   const r: Record<string, T> = {};
   for (const [k, v] of it) {