blob: 1ada8e9af4c59321a888a8e3eecc1799f352a6db [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-Raynauldbfed1732022-11-01 20:49:35 -040019import { itMap, itRange, itToArr, 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 -040050export const stringVectToArray = (sv: StringVect) => itToArr(swigVecToIt(sv));
51export const stringMapToRecord = (sm: StringMap) => itToRecord(swigMapToIt(sm));
Misha Krieger-Raynauldbfed1732022-11-01 20:49:35 -040052export const vectMapToRecordArray = (vm: VectMap) => itToArr(itMap(swigVecToIt(vm), stringMapToRecord));
Misha Krieger-Raynauldaddd6fe2022-10-22 12:46:04 -040053
Misha Krieger-Raynauld68a9b562022-10-28 19:47:46 -040054/**
55 * Non-exhaustive list of properties for JamiSwig.
56 *
57 * The full list of methods can be found in SWIG interface files (`.i`) in `daemon/bin/nodejs`.
58 */
Misha Krieger-Raynauldaddd6fe2022-10-22 12:46:04 -040059export interface JamiSwig {
60 init(args: Record<string, unknown>): void;
Misha Krieger-Raynauld62a0da92022-10-22 13:46:59 -040061 fini(): void;
Misha Krieger-Raynauldaddd6fe2022-10-22 12:46:04 -040062
Misha Krieger-Raynauldb6f1c322022-10-23 20:42:57 -040063 getAccountDetails(accountId: string): StringMap;
64 getVolatileAccountDetails(accountId: string): StringMap;
65 setAccountDetails(accountId: string, details: StringMap): void;
66 setAccountActive(accountId: string, active: Bool): void;
67
68 addAccount(details: StringMap): string;
69 removeAccount(accountId: string): void;
70
71 getAccountList(): StringVect;
72
Charlieb62c6782022-10-30 15:14:56 -040073 sendAccountTextMessage(accountId: string, contactId: string, message: StringMap): void;
74
Misha Krieger-Raynauldb6f1c322022-10-23 20:42:57 -040075 lookupName(accountId: string, nameserver: string, username: string): boolean;
76 lookupAddress(accountId: string, nameserver: string, address: string): boolean;
77 registerName(accountId: string, password: string, username: string): boolean;
78
79 getKnownRingDevices(accountId: string): StringMap;
80
Misha Krieger-Raynauldb6f1c322022-10-23 20:42:57 -040081 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}