Misha Krieger-Raynauld | addd6fe | 2022-10-22 12:46:04 -0400 | [diff] [blame] | 1 | /* |
| 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 | */ |
simon | 43da57b | 2022-10-26 18:22:22 -0400 | [diff] [blame] | 18 | import { Constructable } from '../interfaces.js'; |
Misha Krieger-Raynauld | bfed173 | 2022-11-01 20:49:35 -0400 | [diff] [blame^] | 19 | import { itMap, itRange, itToArr, itToRecord } from './utils.js'; |
Misha Krieger-Raynauld | addd6fe | 2022-10-22 12:46:04 -0400 | [diff] [blame] | 20 | |
| 21 | enum Bool { |
| 22 | False = 'false', |
| 23 | True = 'true', |
| 24 | } |
| 25 | |
| 26 | interface SwigVec<T> { |
| 27 | size(): number; |
| 28 | get(i: number): T; // TODO: | undefined; |
| 29 | } |
| 30 | |
| 31 | interface 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-Raynauld | b6f1c32 | 2022-10-23 20:42:57 -0400 | [diff] [blame] | 37 | // TODO: Review these conversion functions |
Misha Krieger-Raynauld | addd6fe | 2022-10-22 12:46:04 -0400 | [diff] [blame] | 38 | const swigVecToIt = <T>(v: SwigVec<T>) => itMap(itRange(0, v.size()), (i) => v.get(i)); |
| 39 | const swigMapToIt = <T, U>(m: SwigMap<T, U>) => itMap(swigVecToIt(m.keys()), (k): [T, U] => [k, m.get(k)]); |
| 40 | |
Misha Krieger-Raynauld | b6f1c32 | 2022-10-23 20:42:57 -0400 | [diff] [blame] | 41 | // export type IntVect = SwigVec<number>; |
| 42 | // export type UintVect = SwigVec<number>; |
| 43 | // export type FloatVect = SwigVec<number>; |
Misha Krieger-Raynauld | addd6fe | 2022-10-22 12:46:04 -0400 | [diff] [blame] | 44 | export type StringVect = SwigVec<string>; |
Misha Krieger-Raynauld | b6f1c32 | 2022-10-23 20:42:57 -0400 | [diff] [blame] | 45 | // export type IntegerMap = SwigMap<string, number>; |
Misha Krieger-Raynauld | addd6fe | 2022-10-22 12:46:04 -0400 | [diff] [blame] | 46 | export type StringMap = SwigMap<string, string>; |
Misha Krieger-Raynauld | b6f1c32 | 2022-10-23 20:42:57 -0400 | [diff] [blame] | 47 | export type VectMap = SwigVec<StringMap>; |
| 48 | // export type Blob = SwigVec<number>; |
Misha Krieger-Raynauld | addd6fe | 2022-10-22 12:46:04 -0400 | [diff] [blame] | 49 | |
Misha Krieger-Raynauld | b6f1c32 | 2022-10-23 20:42:57 -0400 | [diff] [blame] | 50 | export const stringVectToArray = (sv: StringVect) => itToArr(swigVecToIt(sv)); |
| 51 | export const stringMapToRecord = (sm: StringMap) => itToRecord(swigMapToIt(sm)); |
Misha Krieger-Raynauld | bfed173 | 2022-11-01 20:49:35 -0400 | [diff] [blame^] | 52 | export const vectMapToRecordArray = (vm: VectMap) => itToArr(itMap(swigVecToIt(vm), stringMapToRecord)); |
Misha Krieger-Raynauld | addd6fe | 2022-10-22 12:46:04 -0400 | [diff] [blame] | 53 | |
Misha Krieger-Raynauld | 68a9b56 | 2022-10-28 19:47:46 -0400 | [diff] [blame] | 54 | /** |
| 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-Raynauld | addd6fe | 2022-10-22 12:46:04 -0400 | [diff] [blame] | 59 | export interface JamiSwig { |
| 60 | init(args: Record<string, unknown>): void; |
Misha Krieger-Raynauld | 62a0da9 | 2022-10-22 13:46:59 -0400 | [diff] [blame] | 61 | fini(): void; |
Misha Krieger-Raynauld | addd6fe | 2022-10-22 12:46:04 -0400 | [diff] [blame] | 62 | |
Misha Krieger-Raynauld | b6f1c32 | 2022-10-23 20:42:57 -0400 | [diff] [blame] | 63 | 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 | |
Charlie | b62c678 | 2022-10-30 15:14:56 -0400 | [diff] [blame] | 73 | sendAccountTextMessage(accountId: string, contactId: string, message: StringMap): void; |
| 74 | |
Misha Krieger-Raynauld | b6f1c32 | 2022-10-23 20:42:57 -0400 | [diff] [blame] | 75 | 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-Raynauld | b6f1c32 | 2022-10-23 20:42:57 -0400 | [diff] [blame] | 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 | |
simon | 43da57b | 2022-10-26 18:22:22 -0400 | [diff] [blame] | 97 | // 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-Raynauld | addd6fe | 2022-10-22 12:46:04 -0400 | [diff] [blame] | 105 | } |