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 | */ |
Misha Krieger-Raynauld | b933fbb | 2022-11-15 15:11:09 -0500 | [diff] [blame] | 18 | import { Constructable } from '../interfaces/constructable.js'; |
Misha Krieger-Raynauld | addd6fe | 2022-10-22 12:46:04 -0400 | [diff] [blame] | 19 | |
Misha Krieger-Raynauld | b933fbb | 2022-11-15 15:11:09 -0500 | [diff] [blame] | 20 | interface SwigVect<T> { |
Misha Krieger-Raynauld | addd6fe | 2022-10-22 12:46:04 -0400 | [diff] [blame] | 21 | size(): number; |
Misha Krieger-Raynauld | b933fbb | 2022-11-15 15:11:09 -0500 | [diff] [blame] | 22 | get(index: number): T | undefined; |
Misha Krieger-Raynauld | addd6fe | 2022-10-22 12:46:04 -0400 | [diff] [blame] | 23 | } |
| 24 | |
| 25 | interface SwigMap<T, U> { |
Misha Krieger-Raynauld | b933fbb | 2022-11-15 15:11:09 -0500 | [diff] [blame] | 26 | keys(): SwigVect<T>; |
| 27 | get(key: T): U | undefined; |
| 28 | set(key: T, value: U): void; |
Misha Krieger-Raynauld | addd6fe | 2022-10-22 12:46:04 -0400 | [diff] [blame] | 29 | } |
| 30 | |
Michelle Sepkap Sime | dd82cbf | 2022-11-17 23:31:49 -0500 | [diff] [blame] | 31 | // export type IntVect = SwigVect<number>; |
| 32 | // export type UintVect = SwigVect<number>; |
| 33 | // export type FloatVect = SwigVect<number>; |
Misha Krieger-Raynauld | b933fbb | 2022-11-15 15:11:09 -0500 | [diff] [blame] | 34 | export type StringVect = SwigVect<string>; |
Misha Krieger-Raynauld | b6f1c32 | 2022-10-23 20:42:57 -0400 | [diff] [blame] | 35 | // export type IntegerMap = SwigMap<string, number>; |
Misha Krieger-Raynauld | addd6fe | 2022-10-22 12:46:04 -0400 | [diff] [blame] | 36 | export type StringMap = SwigMap<string, string>; |
Misha Krieger-Raynauld | b933fbb | 2022-11-15 15:11:09 -0500 | [diff] [blame] | 37 | export type VectMap = SwigVect<StringMap>; |
Michelle Sepkap Sime | dd82cbf | 2022-11-17 23:31:49 -0500 | [diff] [blame] | 38 | export type Blob = SwigVect<number>; |
Misha Krieger-Raynauld | addd6fe | 2022-10-22 12:46:04 -0400 | [diff] [blame] | 39 | |
Misha Krieger-Raynauld | b933fbb | 2022-11-15 15:11:09 -0500 | [diff] [blame] | 40 | function* swigVectToIt<T>(swigVect: SwigVect<T>) { |
| 41 | const size = swigVect.size(); |
| 42 | for (let i = 0; i < size; i++) { |
| 43 | yield swigVect.get(i)!; |
| 44 | } |
| 45 | } |
| 46 | |
| 47 | function* swigMapToIt<T, U>(swigMap: SwigMap<T, U>) { |
| 48 | const keys = swigVectToIt(swigMap.keys()); |
| 49 | for (const key of keys) { |
| 50 | const value = swigMap.get(key)!; |
| 51 | yield [key, value]; |
| 52 | } |
| 53 | } |
| 54 | |
| 55 | export function stringVectToArray(stringVect: StringVect): string[] { |
| 56 | const elements = swigVectToIt(stringVect); |
| 57 | return Array.from(elements); |
| 58 | } |
| 59 | |
| 60 | export function stringMapToRecord(stringMap: StringMap): Record<string, string> { |
| 61 | const keyValuePairs = swigMapToIt(stringMap); |
| 62 | const record: Record<string, string> = {}; |
| 63 | for (const [key, value] of keyValuePairs) { |
| 64 | record[key] = value; |
| 65 | } |
| 66 | return record; |
| 67 | } |
| 68 | |
| 69 | export function vectMapToRecordArray(vectMap: VectMap): Record<string, string>[] { |
| 70 | const stringMaps = swigVectToIt(vectMap); |
| 71 | const records = []; |
| 72 | for (const stringMap of stringMaps) { |
| 73 | const record = stringMapToRecord(stringMap); |
| 74 | records.push(record); |
| 75 | } |
| 76 | return records; |
| 77 | } |
Misha Krieger-Raynauld | addd6fe | 2022-10-22 12:46:04 -0400 | [diff] [blame] | 78 | |
Misha Krieger-Raynauld | 68a9b56 | 2022-10-28 19:47:46 -0400 | [diff] [blame] | 79 | /** |
| 80 | * Non-exhaustive list of properties for JamiSwig. |
| 81 | * |
| 82 | * The full list of methods can be found in SWIG interface files (`.i`) in `daemon/bin/nodejs`. |
| 83 | */ |
Misha Krieger-Raynauld | addd6fe | 2022-10-22 12:46:04 -0400 | [diff] [blame] | 84 | export interface JamiSwig { |
| 85 | init(args: Record<string, unknown>): void; |
Misha Krieger-Raynauld | 62a0da9 | 2022-10-22 13:46:59 -0400 | [diff] [blame] | 86 | fini(): void; |
Misha Krieger-Raynauld | addd6fe | 2022-10-22 12:46:04 -0400 | [diff] [blame] | 87 | |
idillon | 559ce28 | 2022-12-22 15:18:32 -0500 | [diff] [blame] | 88 | monitor(continuous: boolean): void; |
| 89 | |
Misha Krieger-Raynauld | b6f1c32 | 2022-10-23 20:42:57 -0400 | [diff] [blame] | 90 | getAccountDetails(accountId: string): StringMap; |
| 91 | getVolatileAccountDetails(accountId: string): StringMap; |
| 92 | setAccountDetails(accountId: string, details: StringMap): void; |
Misha Krieger-Raynauld | b6f1c32 | 2022-10-23 20:42:57 -0400 | [diff] [blame] | 93 | |
| 94 | addAccount(details: StringMap): string; |
| 95 | removeAccount(accountId: string): void; |
| 96 | |
| 97 | getAccountList(): StringVect; |
| 98 | |
Charlie | b62c678 | 2022-10-30 15:14:56 -0400 | [diff] [blame] | 99 | sendAccountTextMessage(accountId: string, contactId: string, message: StringMap): void; |
| 100 | |
Misha Krieger-Raynauld | b6f1c32 | 2022-10-23 20:42:57 -0400 | [diff] [blame] | 101 | lookupName(accountId: string, nameserver: string, username: string): boolean; |
| 102 | lookupAddress(accountId: string, nameserver: string, address: string): boolean; |
| 103 | registerName(accountId: string, password: string, username: string): boolean; |
| 104 | |
| 105 | getKnownRingDevices(accountId: string): StringMap; |
| 106 | |
Misha Krieger-Raynauld | b6f1c32 | 2022-10-23 20:42:57 -0400 | [diff] [blame] | 107 | addContact(accountId: string, contactId: string): void; |
| 108 | removeContact(accountId: string, contactId: string, ban: boolean): void; |
| 109 | getContacts(accountId: string): VectMap; |
| 110 | getContactDetails(accountId: string, contactId: string): StringMap; |
Michelle Sepkap Sime | dd82cbf | 2022-11-17 23:31:49 -0500 | [diff] [blame] | 111 | sendTrustRequest(accountId: string, to: string, payload: Blob): void; |
| 112 | acceptTrustRequest(accountId: string, from: string): boolean; |
| 113 | discardTrustRequest(accountId: string, from: string): boolean; |
Misha Krieger-Raynauld | b6f1c32 | 2022-10-23 20:42:57 -0400 | [diff] [blame] | 114 | |
| 115 | getDefaultModerators(accountId: string): StringVect; |
Misha Krieger-Raynauld | 153a148 | 2022-11-05 12:00:41 -0400 | [diff] [blame] | 116 | setDefaultModerator(accountId: string, uri: string, state: boolean): void; |
Misha Krieger-Raynauld | b6f1c32 | 2022-10-23 20:42:57 -0400 | [diff] [blame] | 117 | |
| 118 | getConversations(accountId: string): StringVect; |
| 119 | conversationInfos(accountId: string, conversationId: string): StringMap; |
Misha Krieger-Raynauld | b6f1c32 | 2022-10-23 20:42:57 -0400 | [diff] [blame] | 120 | getConversationMembers(accountId: string, conversationId: string): VectMap; |
Michelle Sepkap Sime | dd82cbf | 2022-11-17 23:31:49 -0500 | [diff] [blame] | 121 | acceptConversationRequest(accountId: string, conversationId: string): void; |
idillon | 07d31cc | 2022-12-06 22:40:14 -0500 | [diff] [blame] | 122 | removeConversation(accountId: string, conversationId: string): void; |
Misha Krieger-Raynauld | b6f1c32 | 2022-10-23 20:42:57 -0400 | [diff] [blame] | 123 | |
Issam E. Maghni | 2cb239b | 2022-11-18 22:39:32 +0000 | [diff] [blame] | 124 | sendMessage(accountId: string, conversationId: string, message: string, replyTo: string, flag: number): void; |
Misha Krieger-Raynauld | b6f1c32 | 2022-10-23 20:42:57 -0400 | [diff] [blame] | 125 | loadConversationMessages(accountId: string, conversationId: string, fromMessage: string, n: number): number; |
idillon | 3e378fd | 2022-12-23 11:48:12 -0500 | [diff] [blame] | 126 | setIsComposing(accountId: string, conversationId: string, isWriting: boolean): void; |
Misha Krieger-Raynauld | b6f1c32 | 2022-10-23 20:42:57 -0400 | [diff] [blame] | 127 | |
Misha Krieger-Raynauld | 7f95933 | 2022-11-04 15:12:53 -0400 | [diff] [blame] | 128 | getCallList(accountId: string): StringVect; |
| 129 | getCallDetails(accountId: string, callId: string): StringMap; |
| 130 | |
simon | 43da57b | 2022-10-26 18:22:22 -0400 | [diff] [blame] | 131 | // IntVect: Constructable<IntVect>; |
| 132 | // UintVect: Constructable<UintVect>; |
| 133 | // FloatVect: Constructable<FloatVect>; |
| 134 | // StringVect: Constructable<StringVect>; |
| 135 | // IntegerMap: Constructable<IntegerMap> |
| 136 | StringMap: Constructable<StringMap>; |
| 137 | // VectMap: Constructable<VectMap>; |
| 138 | // IntegerMap: Constructable<IntegerMap>; |
Michelle Sepkap Sime | dd82cbf | 2022-11-17 23:31:49 -0500 | [diff] [blame] | 139 | Blob: Constructable<Blob>; |
Misha Krieger-Raynauld | addd6fe | 2022-10-22 12:46:04 -0400 | [diff] [blame] | 140 | } |