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 | b6f1c32 | 2022-10-23 20:42:57 -0400 | [diff] [blame] | 19 | import { itMap, itRange, itToArr, itToMap, 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 | // TODO: Consider always converting to Record rather than Map as conversion to interfaces is easier |
| 51 | export const stringVectToArray = (sv: StringVect) => itToArr(swigVecToIt(sv)); |
| 52 | export const stringMapToRecord = (sm: StringMap) => itToRecord(swigMapToIt(sm)); |
Misha Krieger-Raynauld | addd6fe | 2022-10-22 12:46:04 -0400 | [diff] [blame] | 53 | export const stringMapToMap = (sm: StringMap) => itToMap(swigMapToIt(sm)); |
Misha Krieger-Raynauld | b6f1c32 | 2022-10-23 20:42:57 -0400 | [diff] [blame] | 54 | // export const vectMapToArrayMap = (vm: VectMap) => itToArr(itMap(swigVecToIt(vm), stringMapToMap)); |
Misha Krieger-Raynauld | addd6fe | 2022-10-22 12:46:04 -0400 | [diff] [blame] | 55 | |
| 56 | export interface JamiSwig { |
| 57 | init(args: Record<string, unknown>): void; |
Misha Krieger-Raynauld | 62a0da9 | 2022-10-22 13:46:59 -0400 | [diff] [blame] | 58 | fini(): void; |
Misha Krieger-Raynauld | addd6fe | 2022-10-22 12:46:04 -0400 | [diff] [blame] | 59 | |
Misha Krieger-Raynauld | b6f1c32 | 2022-10-23 20:42:57 -0400 | [diff] [blame] | 60 | 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 | |
Charlie | b62c678 | 2022-10-30 15:14:56 -0400 | [diff] [blame] | 70 | sendAccountTextMessage(accountId: string, contactId: string, message: StringMap): void; |
| 71 | |
Misha Krieger-Raynauld | b6f1c32 | 2022-10-23 20:42:57 -0400 | [diff] [blame] | 72 | lookupName(accountId: string, nameserver: string, username: string): boolean; |
| 73 | lookupAddress(accountId: string, nameserver: string, address: string): boolean; |
| 74 | registerName(accountId: string, password: string, username: string): boolean; |
| 75 | |
| 76 | getKnownRingDevices(accountId: string): StringMap; |
| 77 | |
| 78 | getAudioOutputDeviceList(): StringVect; |
| 79 | |
| 80 | getVolume(device: string): number; |
| 81 | setVolume(device: string, value: number): void; |
| 82 | |
| 83 | addContact(accountId: string, contactId: string): void; |
| 84 | removeContact(accountId: string, contactId: string, ban: boolean): void; |
| 85 | getContacts(accountId: string): VectMap; |
| 86 | getContactDetails(accountId: string, contactId: string): StringMap; |
| 87 | |
| 88 | getDefaultModerators(accountId: string): StringVect; |
| 89 | setDefaultModerators(accountId: string, uri: string, state: boolean): void; |
| 90 | |
| 91 | getConversations(accountId: string): StringVect; |
| 92 | conversationInfos(accountId: string, conversationId: string): StringMap; |
| 93 | |
| 94 | getConversationMembers(accountId: string, conversationId: string): VectMap; |
| 95 | |
| 96 | sendMessage(accountId: string, conversationId: string, message: string, replyTo: string): void; |
| 97 | loadConversationMessages(accountId: string, conversationId: string, fromMessage: string, n: number): number; |
| 98 | |
simon | 43da57b | 2022-10-26 18:22:22 -0400 | [diff] [blame] | 99 | // IntVect: Constructable<IntVect>; |
| 100 | // UintVect: Constructable<UintVect>; |
| 101 | // FloatVect: Constructable<FloatVect>; |
| 102 | // StringVect: Constructable<StringVect>; |
| 103 | // IntegerMap: Constructable<IntegerMap> |
| 104 | StringMap: Constructable<StringMap>; |
| 105 | // VectMap: Constructable<VectMap>; |
| 106 | // IntegerMap: Constructable<IntegerMap>; |
Misha Krieger-Raynauld | addd6fe | 2022-10-22 12:46:04 -0400 | [diff] [blame] | 107 | } |