From ea1a96299282278a90900c34102f4e2d8c1e6ced Mon Sep 17 00:00:00 2001 From: Simon Laux Date: Tue, 25 Oct 2022 23:54:05 +0200 Subject: [PATCH] jsonrpc: add `Context` class you can get via `getContext` or `getContextEvents`, it is a convenience wrapper that has all account specific functions with the accountId pre-set. --- CHANGELOG.md | 1 + deltachat-jsonrpc/src/api/mod.rs | 86 ++ .../typescript/example/example.ts | 1 + .../typescript/generated/context_methods.ts | 855 ++++++++++++++++++ .../typescript/generated/types.ts | 126 +-- deltachat-jsonrpc/typescript/src/client.ts | 11 +- 6 files changed, 1014 insertions(+), 66 deletions(-) create mode 100644 deltachat-jsonrpc/typescript/generated/context_methods.ts diff --git a/CHANGELOG.md b/CHANGELOG.md index a2125aaf1..cf66a25b1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,7 @@ ## Unreleased ### API-Changes +- jsonrpc: add `Context` class you can get via `getContext` or `getContextEvents`, it is a convinience wrapper that has all account specific functions with the accountId pre-set. ### Changes diff --git a/deltachat-jsonrpc/src/api/mod.rs b/deltachat-jsonrpc/src/api/mod.rs index 31f09e43f..954c39d1a 100644 --- a/deltachat-jsonrpc/src/api/mod.rs +++ b/deltachat-jsonrpc/src/api/mod.rs @@ -1710,3 +1710,89 @@ async fn get_config( .await } } + +#[cfg(test)] +#[test] +fn stuff() { + let root_namespace = Some("T"); + let methods: Vec = raw_ts_binding_methods(); + let account_methods: Vec = methods + .into_iter() + .filter_map(|m| { + // No idea how to check the type, to lazy to find out + // if let Some((name, _)) = m.args.get(0) { + // println!("{}", name); + // } + + //println!("-> {}", m.to_string(root_namespace)); + if m.to_string(root_namespace).contains("accountId: T.U32") { + //println!("old: {}", m.to_string(root_namespace)); + + let args2 = Vec::from_iter(m.args[1..].iter().map(|m| m.to_owned())); + + let m2 = yerpc::typescript::Method::new( + &m.ts_name, + &m.rpc_name, + args2, + m.output, + m.is_notification, + m.is_positional, + m.docs.as_deref(), + ); + + let args_string = if m2.args.is_empty() { + "".to_string() + } else { + format!( + ", {}", + m2.args + .iter() + .map(|(name, _)| name.as_ref()) + .collect::>() + .join(", ") + ) + }; + + let replacement_line = format!( + " return this.controller.rpc.{}(this.accountId{})", + m.ts_name, args_string + ); + + // println!("{}", m2.to_string(root_namespace)); + let m_string = m2.to_string(root_namespace); + let new_string: String = m_string + .split('\n') + .map(|line| { + if line.contains("this._transport") { + &replacement_line + } else { + line + } + }) + .collect::>() + .join("\n"); + + // println!("new: {}", new_string); + + Some(new_string) + } else { + None + } + }) + .collect(); + + let head = r#"import * as T from "./types.js" +import { RawClient } from "./client.js" +import { TinyEmitter } from "tiny-emitter"; +export class Context extends TinyEmitter { + constructor( + private controller: {rpc: RawClient}, + readonly accountId: T.U32 + ){ + super() + }"#; + + let context_methods = format!("{}\n{}\n}}\n", head, account_methods.join("")); + + std::fs::write("typescript/generated/context_methods.ts", context_methods).unwrap(); +} diff --git a/deltachat-jsonrpc/typescript/example/example.ts b/deltachat-jsonrpc/typescript/example/example.ts index 14dfc9881..2918c0866 100644 --- a/deltachat-jsonrpc/typescript/example/example.ts +++ b/deltachat-jsonrpc/typescript/example/example.ts @@ -18,6 +18,7 @@ async function run() { const client = new DeltaChat("ws://localhost:20808/ws"); + (window as any).dc = client; (window as any).client = client.rpc; client.on("ALL", (accountId, event) => { diff --git a/deltachat-jsonrpc/typescript/generated/context_methods.ts b/deltachat-jsonrpc/typescript/generated/context_methods.ts new file mode 100644 index 000000000..aec75d783 --- /dev/null +++ b/deltachat-jsonrpc/typescript/generated/context_methods.ts @@ -0,0 +1,855 @@ +import * as T from "./types.js" +import { RawClient } from "./client.js" +import { TinyEmitter } from "tiny-emitter"; +export class Context extends TinyEmitter { + constructor( + private controller: {rpc: RawClient}, + readonly accountId: T.U32 + ){ + super() + } + + public removeAccount(): Promise { + return this.controller.rpc.removeAccount(this.accountId) + } + + /** + * Get top-level info for an account. + */ + public getAccountInfo(): Promise { + return this.controller.rpc.getAccountInfo(this.accountId) + } + + /** + * Get the combined filesize of an account in bytes + */ + public getAccountFileSize(): Promise { + return this.controller.rpc.getAccountFileSize(this.accountId) + } + + /** + * Returns provider for the given domain. + * + * This function looks up domain in offline database. + * + * For compatibility, email address can be passed to this function + * instead of the domain. + */ + public getProviderInfo(email: string): Promise<(T.ProviderInfo|null)> { + return this.controller.rpc.getProviderInfo(this.accountId, email) + } + + /** + * Checks if the context is already configured. + */ + public isConfigured(): Promise { + return this.controller.rpc.isConfigured(this.accountId) + } + + /** + * Get system info for an account. + */ + public getInfo(): Promise> { + return this.controller.rpc.getInfo(this.accountId) + } + + + public setConfig(key: string, value: (string|null)): Promise { + return this.controller.rpc.setConfig(this.accountId, key, value) + } + + + public batchSetConfig(config: Record): Promise { + return this.controller.rpc.batchSetConfig(this.accountId, config) + } + + /** + * Set configuration values from a QR code. (technically from the URI that is stored in the qrcode) + * Before this function is called, `checkQr()` should confirm the type of the + * QR code is `account` or `webrtcInstance`. + * + * Internally, the function will call dc_set_config() with the appropriate keys, + */ + public setConfigFromQr(qrContent: string): Promise { + return this.controller.rpc.setConfigFromQr(this.accountId, qrContent) + } + + + public checkQr(qrContent: string): Promise { + return this.controller.rpc.checkQr(this.accountId, qrContent) + } + + + public getConfig(key: string): Promise<(string|null)> { + return this.controller.rpc.getConfig(this.accountId, key) + } + + + public batchGetConfig(keys: (string)[]): Promise> { + return this.controller.rpc.batchGetConfig(this.accountId, keys) + } + + /** + * Configures this account with the currently set parameters. + * Setup the credential config before calling this. + */ + public configure(): Promise { + return this.controller.rpc.configure(this.accountId) + } + + /** + * Signal an ongoing process to stop. + */ + public stopOngoingProcess(): Promise { + return this.controller.rpc.stopOngoingProcess(this.accountId) + } + + + public exportSelfKeys(path: string, passphrase: (string|null)): Promise { + return this.controller.rpc.exportSelfKeys(this.accountId, path, passphrase) + } + + + public importSelfKeys(path: string, passphrase: (string|null)): Promise { + return this.controller.rpc.importSelfKeys(this.accountId, path, passphrase) + } + + /** + * Returns the message IDs of all _fresh_ messages of any chat. + * Typically used for implementing notification summaries + * or badge counters e.g. on the app icon. + * The list is already sorted and starts with the most recent fresh message. + * + * Messages belonging to muted chats or to the contact requests are not returned; + * these messages should not be notified + * and also badge counters should not include these messages. + * + * To get the number of fresh messages for a single chat, muted or not, + * use `get_fresh_msg_cnt()`. + */ + public getFreshMsgs(): Promise<(T.U32)[]> { + return this.controller.rpc.getFreshMsgs(this.accountId) + } + + /** + * Get the number of _fresh_ messages in a chat. + * Typically used to implement a badge with a number in the chatlist. + * + * If the specified chat is muted, + * the UI should show the badge counter "less obtrusive", + * e.g. using "gray" instead of "red" color. + */ + public getFreshMsgCnt(chatId: T.U32): Promise { + return this.controller.rpc.getFreshMsgCnt(this.accountId, chatId) + } + + /** + * Estimate the number of messages that will be deleted + * by the set_config()-options `delete_device_after` or `delete_server_after`. + * This is typically used to show the estimated impact to the user + * before actually enabling deletion of old messages. + */ + public estimateAutoDeletionCount(fromServer: boolean, seconds: T.I64): Promise { + return this.controller.rpc.estimateAutoDeletionCount(this.accountId, fromServer, seconds) + } + + + public autocryptInitiateKeyTransfer(): Promise { + return this.controller.rpc.autocryptInitiateKeyTransfer(this.accountId) + } + + + public autocryptContinueKeyTransfer(messageId: T.U32, setupCode: string): Promise { + return this.controller.rpc.autocryptContinueKeyTransfer(this.accountId, messageId, setupCode) + } + + + public getChatlistEntries(listFlags: (T.U32|null), queryString: (string|null), queryContactId: (T.U32|null)): Promise<(T.ChatListEntry)[]> { + return this.controller.rpc.getChatlistEntries(this.accountId, listFlags, queryString, queryContactId) + } + + + public getChatlistItemsByEntries(entries: (T.ChatListEntry)[]): Promise> { + return this.controller.rpc.getChatlistItemsByEntries(this.accountId, entries) + } + + + public chatlistGetFullChatById(chatId: T.U32): Promise { + return this.controller.rpc.chatlistGetFullChatById(this.accountId, chatId) + } + + /** + * get basic info about a chat, + * use chatlist_get_full_chat_by_id() instead if you need more information + */ + public getBasicChatInfo(chatId: T.U32): Promise { + return this.controller.rpc.getBasicChatInfo(this.accountId, chatId) + } + + + public acceptChat(chatId: T.U32): Promise { + return this.controller.rpc.acceptChat(this.accountId, chatId) + } + + + public blockChat(chatId: T.U32): Promise { + return this.controller.rpc.blockChat(this.accountId, chatId) + } + + /** + * Delete a chat. + * + * Messages are deleted from the device and the chat database entry is deleted. + * After that, the event #DC_EVENT_MSGS_CHANGED is posted. + * + * Things that are _not done_ implicitly: + * + * - Messages are **not deleted from the server**. + * - The chat or the contact is **not blocked**, so new messages from the user/the group may appear as a contact request + * and the user may create the chat again. + * - **Groups are not left** - this would + * be unexpected as (1) deleting a normal chat also does not prevent new mails + * from arriving, (2) leaving a group requires sending a message to + * all group members - especially for groups not used for a longer time, this is + * really unexpected when deletion results in contacting all members again, + * (3) only leaving groups is also a valid usecase. + * + * To leave a chat explicitly, use leave_group() + */ + public deleteChat(chatId: T.U32): Promise { + return this.controller.rpc.deleteChat(this.accountId, chatId) + } + + /** + * Get encryption info for a chat. + * Get a multi-line encryption info, containing encryption preferences of all members. + * Can be used to find out why messages sent to group are not encrypted. + * + * returns Multi-line text + */ + public getChatEncryptionInfo(chatId: T.U32): Promise { + return this.controller.rpc.getChatEncryptionInfo(this.accountId, chatId) + } + + /** + * Get QR code (text and SVG) that will offer an Setup-Contact or Verified-Group invitation. + * The QR code is compatible to the OPENPGP4FPR format + * so that a basic fingerprint comparison also works e.g. with OpenKeychain. + * + * The scanning device will pass the scanned content to `checkQr()` then; + * if `checkQr()` returns `askVerifyContact` or `askVerifyGroup` + * an out-of-band-verification can be joined using `secure_join()` + * + * chat_id: If set to a group-chat-id, + * the Verified-Group-Invite protocol is offered in the QR code; + * works for protected groups as well as for normal groups. + * If not set, the Setup-Contact protocol is offered in the QR code. + * See https://countermitm.readthedocs.io/en/latest/new.html + * for details about both protocols. + * + * return format: `[code, svg]` + */ + public getChatSecurejoinQrCodeSvg(chatId: (T.U32|null)): Promise<[string,string]> { + return this.controller.rpc.getChatSecurejoinQrCodeSvg(this.accountId, chatId) + } + + /** + * Continue a Setup-Contact or Verified-Group-Invite protocol + * started on another device with `get_chat_securejoin_qr_code_svg()`. + * This function is typically called when `check_qr()` returns + * type=AskVerifyContact or type=AskVerifyGroup. + * + * The function returns immediately and the handshake runs in background, + * sending and receiving several messages. + * During the handshake, info messages are added to the chat, + * showing progress, success or errors. + * + * Subsequent calls of `secure_join()` will abort previous, unfinished handshakes. + * + * See https://countermitm.readthedocs.io/en/latest/new.html + * for details about both protocols. + * + * **qr**: The text of the scanned QR code. Typically, the same string as given + * to `check_qr()`. + * + * **returns**: The chat ID of the joined chat, the UI may redirect to the this chat. + * A returned chat ID does not guarantee that the chat is protected or the belonging contact is verified. + * + */ + public secureJoin(qr: string): Promise { + return this.controller.rpc.secureJoin(this.accountId, qr) + } + + + public leaveGroup(chatId: T.U32): Promise { + return this.controller.rpc.leaveGroup(this.accountId, chatId) + } + + /** + * Remove a member from a group. + * + * If the group is already _promoted_ (any message was sent to the group), + * all group members are informed by a special status message that is sent automatically by this function. + * + * Sends out #DC_EVENT_CHAT_MODIFIED and #DC_EVENT_MSGS_CHANGED if a status message was sent. + */ + public removeContactFromChat(chatId: T.U32, contactId: T.U32): Promise { + return this.controller.rpc.removeContactFromChat(this.accountId, chatId, contactId) + } + + /** + * Add a member to a group. + * + * If the group is already _promoted_ (any message was sent to the group), + * all group members are informed by a special status message that is sent automatically by this function. + * + * If the group has group protection enabled, only verified contacts can be added to the group. + * + * Sends out #DC_EVENT_CHAT_MODIFIED and #DC_EVENT_MSGS_CHANGED if a status message was sent. + */ + public addContactToChat(chatId: T.U32, contactId: T.U32): Promise { + return this.controller.rpc.addContactToChat(this.accountId, chatId, contactId) + } + + /** + * Get the contact IDs belonging to a chat. + * + * - for normal chats, the function always returns exactly one contact, + * DC_CONTACT_ID_SELF is returned only for SELF-chats. + * + * - for group chats all members are returned, DC_CONTACT_ID_SELF is returned + * explicitly as it may happen that oneself gets removed from a still existing + * group + * + * - for broadcasts, all recipients are returned, DC_CONTACT_ID_SELF is not included + * + * - for mailing lists, the behavior is not documented currently, we will decide on that later. + * for now, the UI should not show the list for mailing lists. + * (we do not know all members and there is not always a global mailing list address, + * so we could return only SELF or the known members; this is not decided yet) + */ + public getChatContacts(chatId: T.U32): Promise<(T.U32)[]> { + return this.controller.rpc.getChatContacts(this.accountId, chatId) + } + + /** + * Create a new group chat. + * + * After creation, + * the group has one member with the ID DC_CONTACT_ID_SELF + * and is in _unpromoted_ state. + * This means, you can add or remove members, change the name, + * the group image and so on without messages being sent to all group members. + * + * This changes as soon as the first message is sent to the group members + * and the group becomes _promoted_. + * After that, all changes are synced with all group members + * by sending status message. + * + * To check, if a chat is still unpromoted, you can look at the `is_unpromoted` property of `BasicChat` or `FullChat`. + * This may be useful if you want to show some help for just created groups. + * + * @param protect If set to 1 the function creates group with protection initially enabled. + * Only verified members are allowed in these groups + * and end-to-end-encryption is always enabled. + */ + public createGroupChat(name: string, protect: boolean): Promise { + return this.controller.rpc.createGroupChat(this.accountId, name, protect) + } + + /** + * Create a new broadcast list. + * + * Broadcast lists are similar to groups on the sending device, + * however, recipients get the messages in normal one-to-one chats + * and will not be aware of other members. + * + * Replies to broadcasts go only to the sender + * and not to all broadcast recipients. + * Moreover, replies will not appear in the broadcast list + * but in the one-to-one chat with the person answering. + * + * The name and the image of the broadcast list is set automatically + * and is visible to the sender only. + * Not asking for these data allows more focused creation + * and we bypass the question who will get which data. + * Also, many users will have at most one broadcast list + * so, a generic name and image is sufficient at the first place. + * + * Later on, however, the name can be changed using dc_set_chat_name(). + * The image cannot be changed to have a unique, recognizable icon in the chat lists. + * All in all, this is also what other messengers are doing here. + */ + public createBroadcastList(): Promise { + return this.controller.rpc.createBroadcastList(this.accountId) + } + + /** + * Set group name. + * + * If the group is already _promoted_ (any message was sent to the group), + * all group members are informed by a special status message that is sent automatically by this function. + * + * Sends out #DC_EVENT_CHAT_MODIFIED and #DC_EVENT_MSGS_CHANGED if a status message was sent. + */ + public setChatName(chatId: T.U32, newName: string): Promise { + return this.controller.rpc.setChatName(this.accountId, chatId, newName) + } + + /** + * Set group profile image. + * + * If the group is already _promoted_ (any message was sent to the group), + * all group members are informed by a special status message that is sent automatically by this function. + * + * Sends out #DC_EVENT_CHAT_MODIFIED and #DC_EVENT_MSGS_CHANGED if a status message was sent. + * + * To find out the profile image of a chat, use dc_chat_get_profile_image() + * + * @param image_path Full path of the image to use as the group image. The image will immediately be copied to the + * `blobdir`; the original image will not be needed anymore. + * If you pass null here, the group image is deleted (for promoted groups, all members are informed about + * this change anyway). + */ + public setChatProfileImage(chatId: T.U32, imagePath: (string|null)): Promise { + return this.controller.rpc.setChatProfileImage(this.accountId, chatId, imagePath) + } + + + public setChatVisibility(chatId: T.U32, visibility: T.ChatVisibility): Promise { + return this.controller.rpc.setChatVisibility(this.accountId, chatId, visibility) + } + + + public setChatEphemeralTimer(chatId: T.U32, timer: T.U32): Promise { + return this.controller.rpc.setChatEphemeralTimer(this.accountId, chatId, timer) + } + + + public getChatEphemeralTimer(chatId: T.U32): Promise { + return this.controller.rpc.getChatEphemeralTimer(this.accountId, chatId) + } + + + public addDeviceMessage(label: string, text: string): Promise { + return this.controller.rpc.addDeviceMessage(this.accountId, label, text) + } + + /** + * Mark all messages in a chat as _noticed_. + * _Noticed_ messages are no longer _fresh_ and do not count as being unseen + * but are still waiting for being marked as "seen" using markseen_msgs() + * (IMAP/MDNs is not done for noticed messages). + * + * Calling this function usually results in the event #DC_EVENT_MSGS_NOTICED. + * See also markseen_msgs(). + */ + public marknoticedChat(chatId: T.U32): Promise { + return this.controller.rpc.marknoticedChat(this.accountId, chatId) + } + + + public getFirstUnreadMessageOfChat(chatId: T.U32): Promise<(T.U32|null)> { + return this.controller.rpc.getFirstUnreadMessageOfChat(this.accountId, chatId) + } + + /** + * Set mute duration of a chat. + * + * The UI can then call is_chat_muted() when receiving a new message + * to decide whether it should trigger an notification. + * + * Muted chats should not sound or vibrate + * and should not show a visual notification in the system area. + * Moreover, muted chats should be excluded from global badge counter + * (get_fresh_msgs() skips muted chats therefore) + * and the in-app, per-chat badge counter should use a less obtrusive color. + * + * Sends out #DC_EVENT_CHAT_MODIFIED. + */ + public setChatMuteDuration(chatId: T.U32, duration: T.MuteDuration): Promise { + return this.controller.rpc.setChatMuteDuration(this.accountId, chatId, duration) + } + + /** + * Check whether the chat is currently muted (can be changed by set_chat_mute_duration()). + * + * This is available as a standalone function outside of fullchat, because it might be only needed for notification + */ + public isChatMuted(chatId: T.U32): Promise { + return this.controller.rpc.isChatMuted(this.accountId, chatId) + } + + /** + * Mark messages as presented to the user. + * Typically, UIs call this function on scrolling through the message list, + * when the messages are presented at least for a little moment. + * The concrete action depends on the type of the chat and on the users settings + * (dc_msgs_presented() may be a better name therefore, but well. :) + * + * - For normal chats, the IMAP state is updated, MDN is sent + * (if set_config()-options `mdns_enabled` is set) + * and the internal state is changed to @ref DC_STATE_IN_SEEN to reflect these actions. + * + * - For contact requests, no IMAP or MDNs is done + * and the internal state is not changed therefore. + * See also marknoticed_chat(). + * + * Moreover, timer is started for incoming ephemeral messages. + * This also happens for contact requests chats. + * + * One #DC_EVENT_MSGS_NOTICED event is emitted per modified chat. + */ + public markseenMsgs(msgIds: (T.U32)[]): Promise { + return this.controller.rpc.markseenMsgs(this.accountId, msgIds) + } + + + public getMessageIds(chatId: T.U32, flags: T.U32): Promise<(T.U32)[]> { + return this.controller.rpc.getMessageIds(this.accountId, chatId, flags) + } + + + public getMessageListItems(chatId: T.U32, flags: T.U32): Promise<(T.MessageListItem)[]> { + return this.controller.rpc.getMessageListItems(this.accountId, chatId, flags) + } + + + public messageGetMessage(messageId: T.U32): Promise { + return this.controller.rpc.messageGetMessage(this.accountId, messageId) + } + + + public getMessageHtml(messageId: T.U32): Promise<(string|null)> { + return this.controller.rpc.getMessageHtml(this.accountId, messageId) + } + + + public messageGetMessages(messageIds: (T.U32)[]): Promise> { + return this.controller.rpc.messageGetMessages(this.accountId, messageIds) + } + + /** + * Fetch info desktop needs for creating a notification for a message + */ + public messageGetNotificationInfo(messageId: T.U32): Promise { + return this.controller.rpc.messageGetNotificationInfo(this.accountId, messageId) + } + + /** + * Delete messages. The messages are deleted on the current device and + * on the IMAP server. + */ + public deleteMessages(messageIds: (T.U32)[]): Promise { + return this.controller.rpc.deleteMessages(this.accountId, messageIds) + } + + /** + * Get an informational text for a single message. The text is multiline and may + * contain e.g. the raw text of the message. + * + * The max. text returned is typically longer (about 100000 characters) than the + * max. text returned by dc_msg_get_text() (about 30000 characters). + */ + public getMessageInfo(messageId: T.U32): Promise { + return this.controller.rpc.getMessageInfo(this.accountId, messageId) + } + + /** + * Asks the core to start downloading a message fully. + * This function is typically called when the user hits the "Download" button + * that is shown by the UI in case `download_state` is `'Available'` or `'Failure'` + * + * On success, the @ref DC_MSG "view type of the message" may change + * or the message may be replaced completely by one or more messages with other message IDs. + * That may happen e.g. in cases where the message was encrypted + * and the type could not be determined without fully downloading. + * Downloaded content can be accessed as usual after download. + * + * To reflect these changes a @ref DC_EVENT_MSGS_CHANGED event will be emitted. + */ + public downloadFullMessage(messageId: T.U32): Promise { + return this.controller.rpc.downloadFullMessage(this.accountId, messageId) + } + + /** + * Search messages containing the given query string. + * Searching can be done globally (chat_id=0) or in a specified chat only (chat_id set). + * + * Global chat results are typically displayed using dc_msg_get_summary(), chat + * search results may just hilite the corresponding messages and present a + * prev/next button. + * + * For global search, result is limited to 1000 messages, + * this allows incremental search done fast. + * So, when getting exactly 1000 results, the result may be truncated; + * the UIs may display sth. as "1000+ messages found" in this case. + * Chat search (if a chat_id is set) is not limited. + */ + public searchMessages(query: string, chatId: (T.U32|null)): Promise<(T.U32)[]> { + return this.controller.rpc.searchMessages(this.accountId, query, chatId) + } + + + public messageIdsToSearchResults(messageIds: (T.U32)[]): Promise> { + return this.controller.rpc.messageIdsToSearchResults(this.accountId, messageIds) + } + + /** + * Get a single contact options by ID. + */ + public contactsGetContact(contactId: T.U32): Promise { + return this.controller.rpc.contactsGetContact(this.accountId, contactId) + } + + /** + * Add a single contact as a result of an explicit user action. + * + * Returns contact id of the created or existing contact + */ + public contactsCreateContact(email: string, name: (string|null)): Promise { + return this.controller.rpc.contactsCreateContact(this.accountId, email, name) + } + + /** + * Returns contact id of the created or existing DM chat with that contact + */ + public contactsCreateChatByContactId(contactId: T.U32): Promise { + return this.controller.rpc.contactsCreateChatByContactId(this.accountId, contactId) + } + + + public contactsBlock(contactId: T.U32): Promise { + return this.controller.rpc.contactsBlock(this.accountId, contactId) + } + + + public contactsUnblock(contactId: T.U32): Promise { + return this.controller.rpc.contactsUnblock(this.accountId, contactId) + } + + + public contactsGetBlocked(): Promise<(T.Contact)[]> { + return this.controller.rpc.contactsGetBlocked(this.accountId) + } + + + public contactsGetContactIds(listFlags: T.U32, query: (string|null)): Promise<(T.U32)[]> { + return this.controller.rpc.contactsGetContactIds(this.accountId, listFlags, query) + } + + /** + * Get a list of contacts. + * (formerly called getContacts2 in desktop) + */ + public contactsGetContacts(listFlags: T.U32, query: (string|null)): Promise<(T.Contact)[]> { + return this.controller.rpc.contactsGetContacts(this.accountId, listFlags, query) + } + + + public contactsGetContactsByIds(ids: (T.U32)[]): Promise> { + return this.controller.rpc.contactsGetContactsByIds(this.accountId, ids) + } + + + public deleteContact(contactId: T.U32): Promise { + return this.controller.rpc.deleteContact(this.accountId, contactId) + } + + + public changeContactName(contactId: T.U32, name: string): Promise { + return this.controller.rpc.changeContactName(this.accountId, contactId, name) + } + + /** + * Get encryption info for a contact. + * Get a multi-line encryption info, containing your fingerprint and the + * fingerprint of the contact, used e.g. to compare the fingerprints for a simple out-of-band verification. + */ + public getContactEncryptionInfo(contactId: T.U32): Promise { + return this.controller.rpc.getContactEncryptionInfo(this.accountId, contactId) + } + + /** + * Check if an e-mail address belongs to a known and unblocked contact. + * To get a list of all known and unblocked contacts, use contacts_get_contacts(). + * + * To validate an e-mail address independently of the contact database + * use check_email_validity(). + */ + public lookupContactIdByAddr(addr: string): Promise<(T.U32|null)> { + return this.controller.rpc.lookupContactIdByAddr(this.accountId, addr) + } + + /** + * Returns all message IDs of the given types in a chat. + * Typically used to show a gallery. + * + * The list is already sorted and starts with the oldest message. + * Clients should not try to re-sort the list as this would be an expensive action + * and would result in inconsistencies between clients. + * + * Setting `chat_id` to `None` (`null` in typescript) means get messages with media + * from any chat of the currently used account. + */ + public chatGetMedia(chatId: (T.U32|null), messageType: T.Viewtype, orMessageType2: (T.Viewtype|null), orMessageType3: (T.Viewtype|null)): Promise<(T.U32)[]> { + return this.controller.rpc.chatGetMedia(this.accountId, chatId, messageType, orMessageType2, orMessageType3) + } + + /** + * Search next/previous message based on a given message and a list of types. + * Typically used to implement the "next" and "previous" buttons + * in a gallery or in a media player. + * + * one combined call for getting chat::get_next_media for both directions + * the manual chat::get_next_media in only one direction is not exposed by the jsonrpc yet + */ + public chatGetNeighboringMedia(msgId: T.U32, messageType: T.Viewtype, orMessageType2: (T.Viewtype|null), orMessageType3: (T.Viewtype|null)): Promise<[(T.U32|null),(T.U32|null)]> { + return this.controller.rpc.chatGetNeighboringMedia(this.accountId, msgId, messageType, orMessageType2, orMessageType3) + } + + + public exportBackup(destination: string, passphrase: (string|null)): Promise { + return this.controller.rpc.exportBackup(this.accountId, destination, passphrase) + } + + + public importBackup(path: string, passphrase: (string|null)): Promise { + return this.controller.rpc.importBackup(this.accountId, path, passphrase) + } + + /** + * Get the current connectivity, i.e. whether the device is connected to the IMAP server. + * One of: + * - DC_CONNECTIVITY_NOT_CONNECTED (1000-1999): Show e.g. the string "Not connected" or a red dot + * - DC_CONNECTIVITY_CONNECTING (2000-2999): Show e.g. the string "Connecting…" or a yellow dot + * - DC_CONNECTIVITY_WORKING (3000-3999): Show e.g. the string "Getting new messages" or a spinning wheel + * - DC_CONNECTIVITY_CONNECTED (>=4000): Show e.g. the string "Connected" or a green dot + * + * We don't use exact values but ranges here so that we can split up + * states into multiple states in the future. + * + * Meant as a rough overview that can be shown + * e.g. in the title of the main screen. + * + * If the connectivity changes, a #DC_EVENT_CONNECTIVITY_CHANGED will be emitted. + */ + public getConnectivity(): Promise { + return this.controller.rpc.getConnectivity(this.accountId) + } + + /** + * Get an overview of the current connectivity, and possibly more statistics. + * Meant to give the user more insight about the current status than + * the basic connectivity info returned by get_connectivity(); show this + * e.g., if the user taps on said basic connectivity info. + * + * If this page changes, a #DC_EVENT_CONNECTIVITY_CHANGED will be emitted. + * + * This comes as an HTML from the core so that we can easily improve it + * and the improvement instantly reaches all UIs. + */ + public getConnectivityHtml(): Promise { + return this.controller.rpc.getConnectivityHtml(this.accountId) + } + + + public getLocations(chatId: (T.U32|null), contactId: (T.U32|null), timestampBegin: T.I64, timestampEnd: T.I64): Promise<(T.Location)[]> { + return this.controller.rpc.getLocations(this.accountId, chatId, contactId, timestampBegin, timestampEnd) + } + + + public webxdcSendStatusUpdate(instanceMsgId: T.U32, updateStr: string, description: string): Promise { + return this.controller.rpc.webxdcSendStatusUpdate(this.accountId, instanceMsgId, updateStr, description) + } + + + public webxdcGetStatusUpdates(instanceMsgId: T.U32, lastKnownSerial: T.U32): Promise { + return this.controller.rpc.webxdcGetStatusUpdates(this.accountId, instanceMsgId, lastKnownSerial) + } + + /** + * Get info from a webxdc message + */ + public messageGetWebxdcInfo(instanceMsgId: T.U32): Promise { + return this.controller.rpc.messageGetWebxdcInfo(this.accountId, instanceMsgId) + } + + /** + * Forward messages to another chat. + * + * All types of messages can be forwarded, + * however, they will be flagged as such (dc_msg_is_forwarded() is set). + * + * Original sender, info-state and webxdc updates are not forwarded on purpose. + */ + public forwardMessages(messageIds: (T.U32)[], chatId: T.U32): Promise { + return this.controller.rpc.forwardMessages(this.accountId, messageIds, chatId) + } + + + public sendSticker(chatId: T.U32, stickerPath: string): Promise { + return this.controller.rpc.sendSticker(this.accountId, chatId, stickerPath) + } + + /** + * Send a reaction to message. + * + * Reaction is a string of emojis separated by spaces. Reaction to a + * single message can be sent multiple times. The last reaction + * received overrides all previously received reactions. It is + * possible to remove all reactions by sending an empty string. + */ + public sendReaction(messageId: T.U32, reaction: (string)[]): Promise { + return this.controller.rpc.sendReaction(this.accountId, messageId, reaction) + } + + + public removeDraft(chatId: T.U32): Promise { + return this.controller.rpc.removeDraft(this.accountId, chatId) + } + + /** + * Get draft for a chat, if any. + */ + public getDraft(chatId: T.U32): Promise<(T.Message|null)> { + return this.controller.rpc.getDraft(this.accountId, chatId) + } + + + public sendVideochatInvitation(chatId: T.U32): Promise { + return this.controller.rpc.sendVideochatInvitation(this.accountId, chatId) + } + + + public miscGetStickerFolder(): Promise { + return this.controller.rpc.miscGetStickerFolder(this.accountId) + } + + /** + * for desktop, get stickers from stickers folder, + * grouped by the folder they are in. + */ + public miscGetStickers(): Promise> { + return this.controller.rpc.miscGetStickers(this.accountId) + } + + /** + * Returns the messageid of the sent message + */ + public miscSendTextMessage(text: string, chatId: T.U32): Promise { + return this.controller.rpc.miscSendTextMessage(this.accountId, text, chatId) + } + + + public miscSendMsg(chatId: T.U32, text: (string|null), file: (string|null), location: ([T.F64,T.F64]|null), quotedMessageId: (T.U32|null)): Promise<[T.U32,T.Message]> { + return this.controller.rpc.miscSendMsg(this.accountId, chatId, text, file, location, quotedMessageId) + } + + + public miscSetDraft(chatId: T.U32, text: (string|null), file: (string|null), quotedMessageId: (T.U32|null)): Promise { + return this.controller.rpc.miscSetDraft(this.accountId, chatId, text, file, quotedMessageId) + } + + +} diff --git a/deltachat-jsonrpc/typescript/generated/types.ts b/deltachat-jsonrpc/typescript/generated/types.ts index d776ccd7e..d08fa25c0 100644 --- a/deltachat-jsonrpc/typescript/generated/types.ts +++ b/deltachat-jsonrpc/typescript/generated/types.ts @@ -1,67 +1,6 @@ // AUTO-GENERATED by typescript-type-def export type U32=number; -export type Account=(({"type":"Configured";}&{"id":U32;"displayName":(string|null);"addr":(string|null);"profileImage":(string|null);"color":string;})|({"type":"Unconfigured";}&{"id":U32;})); -export type U64=number; -export type ProviderInfo={"beforeLoginHint":string;"overviewPage":string;"status":U32;}; -export type Qr=(({"type":"askVerifyContact";}&{"contact_id":U32;"fingerprint":string;"invitenumber":string;"authcode":string;})|({"type":"askVerifyGroup";}&{"grpname":string;"grpid":string;"contact_id":U32;"fingerprint":string;"invitenumber":string;"authcode":string;})|({"type":"fprOk";}&{"contact_id":U32;})|({"type":"fprMismatch";}&{"contact_id":(U32|null);})|({"type":"fprWithoutAddr";}&{"fingerprint":string;})|({"type":"account";}&{"domain":string;})|({"type":"webrtcInstance";}&{"domain":string;"instance_pattern":string;})|({"type":"addr";}&{"contact_id":U32;"draft":(string|null);})|({"type":"url";}&{"url":string;})|({"type":"text";}&{"text":string;})|({"type":"withdrawVerifyContact";}&{"contact_id":U32;"fingerprint":string;"invitenumber":string;"authcode":string;})|({"type":"withdrawVerifyGroup";}&{"grpname":string;"grpid":string;"contact_id":U32;"fingerprint":string;"invitenumber":string;"authcode":string;})|({"type":"reviveVerifyContact";}&{"contact_id":U32;"fingerprint":string;"invitenumber":string;"authcode":string;})|({"type":"reviveVerifyGroup";}&{"grpname":string;"grpid":string;"contact_id":U32;"fingerprint":string;"invitenumber":string;"authcode":string;})|({"type":"login";}&{"address":string;})); -export type Usize=number; -export type I64=number; -export type ChatListEntry=[U32,U32]; -export type ChatListItemFetchResult=(({"type":"ChatListItem";}&{"id":U32;"name":string;"avatarPath":(string|null);"color":string;"lastUpdated":(I64|null);"summaryText1":string;"summaryText2":string;"summaryStatus":U32;"isProtected":boolean;"isGroup":boolean;"freshMessageCounter":Usize;"isSelfTalk":boolean;"isDeviceTalk":boolean;"isSendingLocation":boolean;"isSelfInGroup":boolean;"isArchived":boolean;"isPinned":boolean;"isMuted":boolean;"isContactRequest":boolean; -/** - * true when chat is a broadcastlist - */ -"isBroadcast":boolean; -/** - * contact id if this is a dm chat (for view profile entry in context menu) - */ -"dmChatContact":(U32|null);"wasSeenRecently":boolean;})|{"type":"ArchiveLink";}|({"type":"Error";}&{"id":U32;"error":string;})); -export type Contact={"address":string;"color":string;"authName":string;"status":string;"displayName":string;"id":U32;"name":string;"profileImage":(string|null);"nameAndAddr":string;"isBlocked":boolean;"isVerified":boolean; -/** - * the contact's last seen timestamp - */ -"lastSeen":I64;"wasSeenRecently":boolean;}; -export type FullChat={"id":U32;"name":string;"isProtected":boolean;"profileImage":(string|null);"archived":boolean;"chatType":U32;"isUnpromoted":boolean;"isSelfTalk":boolean;"contacts":(Contact)[];"contactIds":(U32)[];"color":string;"freshMessageCounter":Usize;"isContactRequest":boolean;"isDeviceChat":boolean;"selfInGroup":boolean;"isMuted":boolean;"ephemeralTimer":U32;"canSend":boolean;"wasSeenRecently":boolean;"mailingListAddress":string;}; - -/** - * cheaper version of fullchat, omits: - * - contacts - * - contact_ids - * - fresh_message_counter - * - ephemeral_timer - * - self_in_group - * - was_seen_recently - * - can_send - * - * used when you only need the basic metadata of a chat like type, name, profile picture - */ -export type BasicChat= -/** - * cheaper version of fullchat, omits: - * - contacts - * - contact_ids - * - fresh_message_counter - * - ephemeral_timer - * - self_in_group - * - was_seen_recently - * - can_send - * - * used when you only need the basic metadata of a chat like type, name, profile picture - */ -{"id":U32;"name":string;"isProtected":boolean;"profileImage":(string|null);"archived":boolean;"chatType":U32;"isUnpromoted":boolean;"isSelfTalk":boolean;"color":string;"isContactRequest":boolean;"isDeviceChat":boolean;"isMuted":boolean;}; -export type ChatVisibility=("Normal"|"Archived"|"Pinned"); -export type MuteDuration=("NotMuted"|"Forever"|{"Until":I64;}); -export type MessageListItem=(({"kind":"message";}&{"msg_id":U32;})|({ -/** - * Day marker, separating messages that correspond to different - * days according to local time. - */ -"kind":"dayMarker";}&{ -/** - * Marker timestamp, for day markers, in unix milliseconds - */ -"timestamp":I64;})); export type Viewtype=("Unknown"| /** * Text message. @@ -108,7 +47,14 @@ export type Viewtype=("Unknown"| */ "Webxdc"); export type MessageQuote=(({"kind":"JustText";}&{"text":string;})|({"kind":"WithMessage";}&{"text":string;"messageId":U32;"authorDisplayName":string;"authorDisplayColor":string;"overrideSenderName":(string|null);"image":(string|null);"isForwarded":boolean;"viewType":Viewtype;})); +export type I64=number; export type I32=number; +export type Contact={"address":string;"color":string;"authName":string;"status":string;"displayName":string;"id":U32;"name":string;"profileImage":(string|null);"nameAndAddr":string;"isBlocked":boolean;"isVerified":boolean; +/** + * the contact's last seen timestamp + */ +"lastSeen":I64;"wasSeenRecently":boolean;}; +export type U64=number; export type WebxdcMessageInfo={ /** * The name of the app. @@ -165,6 +111,47 @@ export type Reactions= */ "reactions":Record;}; export type Message={"id":U32;"chatId":U32;"fromId":U32;"quote":(MessageQuote|null);"parentId":(U32|null);"text":(string|null);"hasLocation":boolean;"hasHtml":boolean;"viewType":Viewtype;"state":U32;"timestamp":I64;"sortTimestamp":I64;"receivedTimestamp":I64;"hasDeviatingTimestamp":boolean;"subject":string;"showPadlock":boolean;"isSetupmessage":boolean;"isInfo":boolean;"isForwarded":boolean;"duration":I32;"dimensionsHeight":I32;"dimensionsWidth":I32;"videochatType":(U32|null);"videochatUrl":(string|null);"overrideSenderName":(string|null);"sender":Contact;"setupCodeBegin":(string|null);"file":(string|null);"fileMime":(string|null);"fileBytes":U64;"fileName":(string|null);"webxdcInfo":(WebxdcMessageInfo|null);"downloadState":DownloadState;"reactions":(Reactions|null);}; +export type Account=(({"type":"Configured";}&{"id":U32;"displayName":(string|null);"addr":(string|null);"profileImage":(string|null);"color":string;})|({"type":"Unconfigured";}&{"id":U32;})); + +/** + * cheaper version of fullchat, omits: + * - contacts + * - contact_ids + * - fresh_message_counter + * - ephemeral_timer + * - self_in_group + * - was_seen_recently + * - can_send + * + * used when you only need the basic metadata of a chat like type, name, profile picture + */ +export type BasicChat= +/** + * cheaper version of fullchat, omits: + * - contacts + * - contact_ids + * - fresh_message_counter + * - ephemeral_timer + * - self_in_group + * - was_seen_recently + * - can_send + * + * used when you only need the basic metadata of a chat like type, name, profile picture + */ +{"id":U32;"name":string;"isProtected":boolean;"profileImage":(string|null);"archived":boolean;"chatType":U32;"isUnpromoted":boolean;"isSelfTalk":boolean;"color":string;"isContactRequest":boolean;"isDeviceChat":boolean;"isMuted":boolean;}; +export type Usize=number; +export type FullChat={"id":U32;"name":string;"isProtected":boolean;"profileImage":(string|null);"archived":boolean;"chatType":U32;"isUnpromoted":boolean;"isSelfTalk":boolean;"contacts":(Contact)[];"contactIds":(U32)[];"color":string;"freshMessageCounter":Usize;"isContactRequest":boolean;"isDeviceChat":boolean;"selfInGroup":boolean;"isMuted":boolean;"ephemeralTimer":U32;"canSend":boolean;"wasSeenRecently":boolean;"mailingListAddress":string;}; +export type ChatListItemFetchResult=(({"type":"ChatListItem";}&{"id":U32;"name":string;"avatarPath":(string|null);"color":string;"lastUpdated":(I64|null);"summaryText1":string;"summaryText2":string;"summaryStatus":U32;"isProtected":boolean;"isGroup":boolean;"freshMessageCounter":Usize;"isSelfTalk":boolean;"isDeviceTalk":boolean;"isSendingLocation":boolean;"isSelfInGroup":boolean;"isArchived":boolean;"isPinned":boolean;"isMuted":boolean;"isContactRequest":boolean; +/** + * true when chat is a broadcastlist + */ +"isBroadcast":boolean; +/** + * contact id if this is a dm chat (for view profile entry in context menu) + */ +"dmChatContact":(U32|null);"wasSeenRecently":boolean;})|{"type":"ArchiveLink";}|({"type":"Error";}&{"id":U32;"error":string;})); +export type MessageSearchResult={"id":U32;"authorProfileImage":(string|null);"authorName":string;"authorColor":string;"chatName":(string|null);"message":string;"timestamp":I64;}; +export type ChatVisibility=("Normal"|"Archived"|"Pinned"); export type MessageNotificationInfo={"id":U32;"chatId":U32;"accountId":U32;"image":(string|null);"imageMimeType":(string|null);"chatName":string;"chatProfileImage":(string|null); /** * also known as summary_text1 @@ -174,7 +161,20 @@ export type MessageNotificationInfo={"id":U32;"chatId":U32;"accountId":U32;"imag * also known as summary_text2 */ "summaryText":string;}; -export type MessageSearchResult={"id":U32;"authorProfileImage":(string|null);"authorName":string;"authorColor":string;"chatName":(string|null);"message":string;"timestamp":I64;}; +export type MuteDuration=("NotMuted"|"Forever"|{"Until":I64;}); export type F64=number; +export type ProviderInfo={"beforeLoginHint":string;"overviewPage":string;"status":U32;}; +export type Qr=(({"type":"askVerifyContact";}&{"contact_id":U32;"fingerprint":string;"invitenumber":string;"authcode":string;})|({"type":"askVerifyGroup";}&{"grpname":string;"grpid":string;"contact_id":U32;"fingerprint":string;"invitenumber":string;"authcode":string;})|({"type":"fprOk";}&{"contact_id":U32;})|({"type":"fprMismatch";}&{"contact_id":(U32|null);})|({"type":"fprWithoutAddr";}&{"fingerprint":string;})|({"type":"account";}&{"domain":string;})|({"type":"webrtcInstance";}&{"domain":string;"instance_pattern":string;})|({"type":"addr";}&{"contact_id":U32;"draft":(string|null);})|({"type":"url";}&{"url":string;})|({"type":"text";}&{"text":string;})|({"type":"withdrawVerifyContact";}&{"contact_id":U32;"fingerprint":string;"invitenumber":string;"authcode":string;})|({"type":"withdrawVerifyGroup";}&{"grpname":string;"grpid":string;"contact_id":U32;"fingerprint":string;"invitenumber":string;"authcode":string;})|({"type":"reviveVerifyContact";}&{"contact_id":U32;"fingerprint":string;"invitenumber":string;"authcode":string;})|({"type":"reviveVerifyGroup";}&{"grpname":string;"grpid":string;"contact_id":U32;"fingerprint":string;"invitenumber":string;"authcode":string;})|({"type":"login";}&{"address":string;})); +export type ChatListEntry=[U32,U32]; +export type MessageListItem=(({"kind":"message";}&{"msg_id":U32;})|({ +/** + * Day marker, separating messages that correspond to different + * days according to local time. + */ +"kind":"dayMarker";}&{ +/** + * Marker timestamp, for day markers, in unix milliseconds + */ +"timestamp":I64;})); export type Location={"locationId":U32;"isIndependent":boolean;"latitude":F64;"longitude":F64;"accuracy":F64;"timestamp":I64;"contactId":U32;"msgId":U32;"chatId":U32;"marker":(string|null);}; -export type __AllTyps=[string,boolean,Record,U32,U32,null,(U32)[],U32,null,(U32|null),(Account)[],null,null,U32,null,U32,null,U32,Account,U32,U64,U32,string,(ProviderInfo|null),U32,boolean,U32,Record,U32,string,(string|null),null,U32,Record,null,U32,string,null,U32,string,Qr,U32,string,(string|null),U32,(string)[],Record,Record,null,U32,null,U32,null,U32,string,(string|null),null,U32,string,(string|null),null,U32,(U32)[],U32,U32,Usize,U32,boolean,I64,Usize,U32,string,U32,U32,string,null,U32,(U32|null),(string|null),(U32|null),(ChatListEntry)[],U32,(ChatListEntry)[],Record,U32,U32,FullChat,U32,U32,BasicChat,U32,U32,null,U32,U32,null,U32,U32,null,U32,U32,string,U32,(U32|null),[string,string],U32,string,U32,U32,U32,null,U32,U32,U32,null,U32,U32,U32,null,U32,U32,(U32)[],U32,string,boolean,U32,U32,U32,U32,U32,string,null,U32,U32,(string|null),null,U32,U32,ChatVisibility,null,U32,U32,U32,null,U32,U32,U32,U32,string,string,U32,U32,U32,null,U32,U32,(U32|null),U32,U32,MuteDuration,null,U32,U32,boolean,U32,(U32)[],null,U32,U32,U32,(U32)[],U32,U32,U32,(MessageListItem)[],U32,U32,Message,U32,U32,(string|null),U32,(U32)[],Record,U32,U32,MessageNotificationInfo,U32,(U32)[],null,U32,U32,string,U32,U32,null,U32,string,(U32|null),(U32)[],U32,(U32)[],Record,U32,U32,Contact,U32,string,(string|null),U32,U32,U32,U32,U32,U32,null,U32,U32,null,U32,(Contact)[],U32,U32,(string|null),(U32)[],U32,U32,(string|null),(Contact)[],U32,(U32)[],Record,U32,U32,boolean,U32,U32,string,null,U32,U32,string,U32,string,(U32|null),U32,(U32|null),Viewtype,(Viewtype|null),(Viewtype|null),(U32)[],U32,U32,Viewtype,(Viewtype|null),(Viewtype|null),[(U32|null),(U32|null)],U32,string,(string|null),null,U32,string,(string|null),null,null,U32,U32,U32,string,U32,(U32|null),(U32|null),I64,I64,(Location)[],U32,U32,string,string,null,U32,U32,U32,string,U32,U32,WebxdcMessageInfo,U32,(U32)[],U32,null,U32,U32,string,U32,U32,U32,(string)[],U32,U32,U32,null,U32,U32,(Message|null),U32,U32,U32,U32,string,U32,Record,U32,string,U32,U32,U32,U32,(string|null),(string|null),([F64,F64]|null),(U32|null),[U32,Message],U32,U32,(string|null),(string|null),(U32|null),null]; +export type __AllTyps=[null,[(U32|null),(U32|null)],[string,string],[U32,Message],Account,Record,BasicChat,Contact,FullChat,Record,Record,Record,Record,Record,Record,Record,ChatVisibility,MessageNotificationInfo,Message,Viewtype,MuteDuration,([F64,F64]|null),(Message|null),(Viewtype|null),(ProviderInfo|null),(string|null),(U32|null),Qr,string,(Account)[],(ChatListEntry)[],(Contact)[],(MessageListItem)[],(Location)[],(string)[],(U32)[],WebxdcMessageInfo,boolean,I64,U32,U64,Usize]; diff --git a/deltachat-jsonrpc/typescript/src/client.ts b/deltachat-jsonrpc/typescript/src/client.ts index 8da65c055..3d33c78e1 100644 --- a/deltachat-jsonrpc/typescript/src/client.ts +++ b/deltachat-jsonrpc/typescript/src/client.ts @@ -2,6 +2,7 @@ import * as T from "../generated/types.js"; import * as RPC from "../generated/jsonrpc.js"; import { RawClient } from "../generated/client.js"; import { Event } from "../generated/events.js"; +import { Context } from "../generated/context_methods.js"; import { WebsocketTransport, BaseTransport, Request } from "yerpc"; import { TinyEmitter } from "tiny-emitter"; @@ -28,14 +29,14 @@ type ContextEvents = { ALL: (event: Event) => void } & { }; export type DcEvent = Event; -export type DcEventType = Extract +export type DcEventType = Extract; export class BaseDeltaChat< Transport extends BaseTransport > extends TinyEmitter { rpc: RawClient; account?: T.Account; - private contextEmitters: TinyEmitter[] = []; + private contextEmitters: Context[] = []; constructor(public transport: Transport) { super(); this.rpc = new RawClient(this.transport); @@ -62,10 +63,14 @@ export class BaseDeltaChat< } getContextEvents(account_id: number) { + return this.getContext(account_id); + } + + getContext(account_id: number) { if (this.contextEmitters[account_id]) { return this.contextEmitters[account_id]; } else { - this.contextEmitters[account_id] = new TinyEmitter(); + this.contextEmitters[account_id] = new Context(this, account_id); return this.contextEmitters[account_id]; } }