blob: 8797b96a85130000f60c48a5874345a32d272a48 [file] [log] [blame]
Misha Krieger-Raynauldaddd6fe2022-10-22 12:46:04 -04001/*
2 * Copyright (C) 2022 Savoir-faire Linux Inc.
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU Affero General Public License as
6 * published by the Free Software Foundation; either version 3 of the
7 * License, or (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU Affero General Public License for more details.
13 *
14 * You should have received a copy of the GNU Affero General Public
15 * License along with this program. If not, see
16 * <https://www.gnu.org/licenses/>.
17 */
simon43da57b2022-10-26 18:22:22 -040018import { Constructable } from '../interfaces.js';
Misha Krieger-Raynauldb6f1c322022-10-23 20:42:57 -040019import { itMap, itRange, itToArr, itToMap, itToRecord } from './utils.js';
Misha Krieger-Raynauldaddd6fe2022-10-22 12:46:04 -040020
21enum Bool {
22 False = 'false',
23 True = 'true',
24}
25
26interface SwigVec<T> {
27 size(): number;
28 get(i: number): T; // TODO: | undefined;
29}
30
31interface SwigMap<T, U> {
32 keys(): SwigVec<T>;
33 get(k: T): U; // TODO: | undefined;
34 set(k: T, v: U): void;
35}
36
Misha Krieger-Raynauldb6f1c322022-10-23 20:42:57 -040037// TODO: Review these conversion functions
Misha Krieger-Raynauldaddd6fe2022-10-22 12:46:04 -040038const swigVecToIt = <T>(v: SwigVec<T>) => itMap(itRange(0, v.size()), (i) => v.get(i));
39const swigMapToIt = <T, U>(m: SwigMap<T, U>) => itMap(swigVecToIt(m.keys()), (k): [T, U] => [k, m.get(k)]);
40
Misha Krieger-Raynauldb6f1c322022-10-23 20:42:57 -040041// export type IntVect = SwigVec<number>;
42// export type UintVect = SwigVec<number>;
43// export type FloatVect = SwigVec<number>;
Misha Krieger-Raynauldaddd6fe2022-10-22 12:46:04 -040044export type StringVect = SwigVec<string>;
Misha Krieger-Raynauldb6f1c322022-10-23 20:42:57 -040045// export type IntegerMap = SwigMap<string, number>;
Misha Krieger-Raynauldaddd6fe2022-10-22 12:46:04 -040046export type StringMap = SwigMap<string, string>;
Misha Krieger-Raynauldb6f1c322022-10-23 20:42:57 -040047export type VectMap = SwigVec<StringMap>;
48// export type Blob = SwigVec<number>;
Misha Krieger-Raynauldaddd6fe2022-10-22 12:46:04 -040049
Misha Krieger-Raynauldb6f1c322022-10-23 20:42:57 -040050// TODO: Consider always converting to Record rather than Map as conversion to interfaces is easier
51export const stringVectToArray = (sv: StringVect) => itToArr(swigVecToIt(sv));
52export const stringMapToRecord = (sm: StringMap) => itToRecord(swigMapToIt(sm));
Misha Krieger-Raynauldaddd6fe2022-10-22 12:46:04 -040053export const stringMapToMap = (sm: StringMap) => itToMap(swigMapToIt(sm));
Misha Krieger-Raynauldb6f1c322022-10-23 20:42:57 -040054// export const vectMapToArrayMap = (vm: VectMap) => itToArr(itMap(swigVecToIt(vm), stringMapToMap));
Misha Krieger-Raynauldaddd6fe2022-10-22 12:46:04 -040055
56export interface JamiSwig {
57 init(args: Record<string, unknown>): void;
Misha Krieger-Raynauld62a0da92022-10-22 13:46:59 -040058 fini(): void;
Misha Krieger-Raynauldaddd6fe2022-10-22 12:46:04 -040059
Misha Krieger-Raynauldb6f1c322022-10-23 20:42:57 -040060 getAccountDetails(accountId: string): StringMap;
61 getVolatileAccountDetails(accountId: string): StringMap;
62 setAccountDetails(accountId: string, details: StringMap): void;
63 setAccountActive(accountId: string, active: Bool): void;
64
65 addAccount(details: StringMap): string;
66 removeAccount(accountId: string): void;
67
68 getAccountList(): StringVect;
69
70 lookupName(accountId: string, nameserver: string, username: string): boolean;
71 lookupAddress(accountId: string, nameserver: string, address: string): boolean;
72 registerName(accountId: string, password: string, username: string): boolean;
73
74 getKnownRingDevices(accountId: string): StringMap;
75
76 getAudioOutputDeviceList(): StringVect;
77
78 getVolume(device: string): number;
79 setVolume(device: string, value: number): void;
80
81 addContact(accountId: string, contactId: string): void;
82 removeContact(accountId: string, contactId: string, ban: boolean): void;
83 getContacts(accountId: string): VectMap;
84 getContactDetails(accountId: string, contactId: string): StringMap;
85
86 getDefaultModerators(accountId: string): StringVect;
87 setDefaultModerators(accountId: string, uri: string, state: boolean): void;
88
89 getConversations(accountId: string): StringVect;
90 conversationInfos(accountId: string, conversationId: string): StringMap;
91
92 getConversationMembers(accountId: string, conversationId: string): VectMap;
93
94 sendMessage(accountId: string, conversationId: string, message: string, replyTo: string): void;
95 loadConversationMessages(accountId: string, conversationId: string, fromMessage: string, n: number): number;
96
simon43da57b2022-10-26 18:22:22 -040097 // IntVect: Constructable<IntVect>;
98 // UintVect: Constructable<UintVect>;
99 // FloatVect: Constructable<FloatVect>;
100 // StringVect: Constructable<StringVect>;
101 // IntegerMap: Constructable<IntegerMap>
102 StringMap: Constructable<StringMap>;
103 // VectMap: Constructable<VectMap>;
104 // IntegerMap: Constructable<IntegerMap>;
Misha Krieger-Raynauldaddd6fe2022-10-22 12:46:04 -0400105}