mirror of
https://github.com/simplex-chat/simplex-chat.git
synced 2026-11-21 20:57:15 +00:00
Merge branch 'master' into names
This commit is contained in:
commit
0465fd649a
654 files changed
+24588
-119924
No files matched your search
@@ -277,17 +277,30 @@ def lib() -> ctypes.CDLL:
|
||||
return _lib
|
||||
|
||||
|
||||
QUEUE_SIZE_UNSUPPORTED = (
|
||||
"loaded libsimplex does not export chat_migrate_init_queue; queue size needs a newer libsimplex"
|
||||
)
|
||||
def _optional_export(name: str, feature: str, argtypes: list[Any]) -> Any:
|
||||
try:
|
||||
fn = getattr(lib(), name)
|
||||
except AttributeError as e:
|
||||
raise RuntimeError(
|
||||
f"loaded libsimplex does not export {name}; {feature} needs a newer libsimplex"
|
||||
) from e
|
||||
fn.argtypes = argtypes
|
||||
fn.restype = c_void_p
|
||||
return fn
|
||||
|
||||
|
||||
def migrate_init_queue() -> Any:
|
||||
"""`chat_migrate_init_queue`, which older libsimplex releases do not export."""
|
||||
try:
|
||||
fn = lib().chat_migrate_init_queue
|
||||
except AttributeError as e:
|
||||
raise RuntimeError(QUEUE_SIZE_UNSUPPORTED) from e
|
||||
fn.argtypes = [c_char_p, c_char_p, c_char_p, c_int, POINTER(c_void_p)]
|
||||
fn.restype = c_void_p
|
||||
return fn
|
||||
return _optional_export(
|
||||
"chat_migrate_init_queue",
|
||||
"queue size",
|
||||
[c_char_p, c_char_p, c_char_p, c_int, POINTER(c_void_p)],
|
||||
)
|
||||
|
||||
|
||||
def resize_image() -> Any:
|
||||
return _optional_export("chat_resize_image", "image resizing", [c_char_p, c_int, c_int, c_int])
|
||||
|
||||
|
||||
def resize_image_uri() -> Any:
|
||||
return _optional_export("chat_resize_image_uri", "image resizing", [c_char_p, c_int, c_int])
|
||||
@@ -1,17 +1,19 @@
|
||||
"""Internal typed async wrapper around libsimplex's 8 C ABI functions.
|
||||
"""Typed async wrapper around libsimplex's C ABI functions.
|
||||
|
||||
Users interact with `Bot` / `ChatApi`. This module is exposed as
|
||||
`simplex_chat.core` for tests and the api.ChatApi class only.
|
||||
`simplex_chat.core` for tests, the api.ChatApi class and image resizing
|
||||
(`resize_image`, `chat_resize_image`, `chat_resize_image_uri`).
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import asyncio
|
||||
import base64
|
||||
import ctypes
|
||||
import json
|
||||
from concurrent.futures import Executor
|
||||
from enum import StrEnum
|
||||
from typing import Any, TypedDict
|
||||
from typing import Any, Literal, TypedDict, overload
|
||||
|
||||
from . import _native
|
||||
from .types import CR, CEvt, T
|
||||
@@ -70,6 +72,12 @@ class MigrationConfirmation(StrEnum):
|
||||
ERROR = "error"
|
||||
|
||||
|
||||
class ImageSize(StrEnum):
|
||||
IMAGE = "image"
|
||||
PROFILE_PREVIEW = "profilePreview"
|
||||
MESSAGE_PREVIEW = "messagePreview"
|
||||
|
||||
|
||||
class CryptoArgs(TypedDict): # wire-format JSON; camelCase fields
|
||||
fileKey: str
|
||||
fileNonce: str
|
||||
@@ -88,6 +96,12 @@ def _read_and_free(ptr: int | None) -> str:
|
||||
_native.libc().free(ctypes.c_void_p(ptr))
|
||||
|
||||
|
||||
def _check_c_int(name: str, value: int) -> None:
|
||||
# ctypes silently wraps ints that do not fit C int.
|
||||
if ctypes.c_int(value).value != value:
|
||||
raise ValueError(f"{name} {value} does not fit C int")
|
||||
|
||||
|
||||
async def chat_send_cmd(ctrl: int, cmd: str) -> CR.ChatResponse:
|
||||
def _call() -> str:
|
||||
ptr = _native.lib().chat_send_cmd(ctrl, cmd.encode("utf-8"))
|
||||
@@ -138,9 +152,8 @@ async def chat_migrate_init(
|
||||
|
||||
`queue_size` is the size of internal queues; the core default is used when None.
|
||||
"""
|
||||
# ctypes silently wraps ints that do not fit C int.
|
||||
if queue_size is not None and ctypes.c_int(queue_size).value != queue_size:
|
||||
raise ValueError(f"queue_size {queue_size} does not fit C int")
|
||||
if queue_size is not None:
|
||||
_check_c_int("queue_size", queue_size)
|
||||
|
||||
init_queue = _native.migrate_init_queue() if queue_size is not None else None
|
||||
|
||||
@@ -246,3 +259,62 @@ def _crypto_args_result(raw: str) -> CryptoArgs:
|
||||
if parsed.get("type") == "error":
|
||||
raise RuntimeError(parsed.get("writeError", "unknown write error"))
|
||||
raise RuntimeError(f"unexpected result: {raw[:200]}")
|
||||
|
||||
|
||||
async def chat_resize_image_uri(data: bytes, max_size: int) -> str:
|
||||
_check_c_int("len(data)", len(data))
|
||||
_check_c_int("max_size", max_size)
|
||||
resize = _native.resize_image_uri()
|
||||
|
||||
def _call() -> str:
|
||||
return _read_and_free(resize(data, len(data), max_size))
|
||||
|
||||
return _resized_image(await asyncio.to_thread(_call))
|
||||
|
||||
|
||||
async def chat_resize_image(
|
||||
data: bytes, max_size: int, image_format: Literal["jpeg", "png"]
|
||||
) -> bytes:
|
||||
return await _resize_image_data(data, max_size, 1 if image_format == "png" else 0)
|
||||
|
||||
|
||||
@overload
|
||||
async def resize_image(data: bytes, size: Literal[ImageSize.IMAGE]) -> bytes: ...
|
||||
|
||||
|
||||
@overload
|
||||
async def resize_image(
|
||||
data: bytes, size: Literal[ImageSize.PROFILE_PREVIEW, ImageSize.MESSAGE_PREVIEW]
|
||||
) -> str: ...
|
||||
|
||||
|
||||
@overload
|
||||
async def resize_image(data: bytes, size: ImageSize) -> bytes | str: ...
|
||||
|
||||
|
||||
async def resize_image(data: bytes, size: ImageSize) -> bytes | str:
|
||||
"""Resize image to the app size limit: JPEG or PNG for an image, a data URI for a preview."""
|
||||
match size:
|
||||
case ImageSize.IMAGE:
|
||||
return await _resize_image_data(data, 261120, -1)
|
||||
case ImageSize.PROFILE_PREVIEW:
|
||||
return await chat_resize_image_uri(data, 12500)
|
||||
case ImageSize.MESSAGE_PREVIEW:
|
||||
return await chat_resize_image_uri(data, 14000)
|
||||
|
||||
|
||||
async def _resize_image_data(data: bytes, max_size: int, png: int) -> bytes:
|
||||
_check_c_int("len(data)", len(data))
|
||||
_check_c_int("max_size", max_size)
|
||||
resize = _native.resize_image()
|
||||
|
||||
def _call() -> str:
|
||||
return _read_and_free(resize(data, len(data), max_size, png))
|
||||
|
||||
return base64.b64decode(_resized_image(await asyncio.to_thread(_call)))
|
||||
|
||||
|
||||
def _resized_image(res: str) -> str:
|
||||
if not res:
|
||||
raise RuntimeError("image cannot be decoded or does not fit max_size")
|
||||
return res
|
||||
@@ -342,6 +342,32 @@ def APIListMembers_cmd_string(self: APIListMembers) -> str:
|
||||
APIListMembers_Response = CR.GroupMembers | CR.ChatCmdError
|
||||
|
||||
|
||||
# Create a direct message contact with a group member.
|
||||
# Network usage: interactive.
|
||||
class APICreateMemberContact(TypedDict):
|
||||
groupId: int # int64
|
||||
groupMemberId: int # int64
|
||||
|
||||
|
||||
def APICreateMemberContact_cmd_string(self: APICreateMemberContact) -> str:
|
||||
return '/_create member contact #' + str(self['groupId']) + ' ' + str(self['groupMemberId'])
|
||||
|
||||
APICreateMemberContact_Response = CR.NewMemberContact | CR.ChatCmdError
|
||||
|
||||
|
||||
# Send a direct message invitation to a group member contact.
|
||||
# Network usage: background.
|
||||
class APISendMemberContactInvitation(TypedDict):
|
||||
contactId: int # int64
|
||||
msgContent_: NotRequired["T.MsgContent"]
|
||||
|
||||
|
||||
def APISendMemberContactInvitation_cmd_string(self: APISendMemberContactInvitation) -> str:
|
||||
return '/_invite member contact @' + str(self['contactId']) + ((' json ' + json.dumps(self.get('msgContent_'))) if self.get('msgContent_') is not None else '')
|
||||
|
||||
APISendMemberContactInvitation_Response = CR.NewMemberContactSentInv | CR.ChatCmdError
|
||||
|
||||
|
||||
# Create group.
|
||||
# Network usage: no.
|
||||
class APINewGroup(TypedDict):
|
||||
@@ -512,7 +538,7 @@ class APIConnectPlan(TypedDict):
|
||||
|
||||
|
||||
def APIConnectPlan_cmd_string(self: APIConnectPlan) -> str:
|
||||
return '/_connect plan ' + str(self['userId']) + ' ' + self.get('connectTarget')
|
||||
return '/_connect plan ' + str(self['userId']) + ' ' + self.get('connectTarget') + T.PlanResolveMode_cmd_string(self['resolveMode']) + ((' sig=' + json.dumps(self.get('linkOwnerSig'))) if self.get('linkOwnerSig') is not None else '')
|
||||
|
||||
APIConnectPlan_Response = CR.ConnectionPlan | CR.ChatCmdError
|
||||
|
||||
@@ -553,6 +579,80 @@ Connect_Response = (
|
||||
)
|
||||
|
||||
|
||||
# Prepare contact chat from link data before connecting.
|
||||
# Network usage: no.
|
||||
class APIPrepareContact(TypedDict):
|
||||
userId: int # int64
|
||||
connLink: "T.CreatedConnLink"
|
||||
verifiedDomain: NotRequired[str]
|
||||
contactSLinkData: "T.ContactShortLinkData"
|
||||
|
||||
|
||||
def APIPrepareContact_cmd_string(self: APIPrepareContact) -> str:
|
||||
return '/_prepare contact ' + str(self['userId']) + ' ' + T.CreatedConnLink_cmd_string(self['connLink']) + ((' domain=' + self.get('verifiedDomain')) if self.get('verifiedDomain') is not None else '') + ' ' + json.dumps(self['contactSLinkData'])
|
||||
|
||||
APIPrepareContact_Response = CR.NewPreparedChat | CR.ChatCmdError
|
||||
|
||||
|
||||
# Prepare group chat from link data before connecting.
|
||||
# Network usage: no.
|
||||
class APIPrepareGroup(TypedDict):
|
||||
userId: int # int64
|
||||
connLinkContact: "T.CreatedConnLink"
|
||||
direct: bool
|
||||
verifiedDomain: NotRequired[str]
|
||||
groupSLinkData: "T.GroupShortLinkData"
|
||||
|
||||
|
||||
def APIPrepareGroup_cmd_string(self: APIPrepareGroup) -> str:
|
||||
return '/_prepare group ' + str(self['userId']) + ' ' + T.CreatedConnLink_cmd_string(self['connLinkContact']) + (' direct=off' if not self['direct'] else '') + ((' domain=' + self.get('verifiedDomain')) if self.get('verifiedDomain') is not None else '') + ' ' + json.dumps(self['groupSLinkData'])
|
||||
|
||||
APIPrepareGroup_Response = CR.NewPreparedChat | CR.ChatCmdError
|
||||
|
||||
|
||||
# Connect to prepared contact.
|
||||
# Network usage: interactive.
|
||||
class APIConnectPreparedContact(TypedDict):
|
||||
contactId: int # int64
|
||||
incognito: bool
|
||||
msgContent_: NotRequired["T.MsgContent"]
|
||||
|
||||
|
||||
def APIConnectPreparedContact_cmd_string(self: APIConnectPreparedContact) -> str:
|
||||
return '/_connect contact @' + str(self['contactId']) + (' incognito=on' if self['incognito'] else '') + ((' json ' + json.dumps(self.get('msgContent_'))) if self.get('msgContent_') is not None else '')
|
||||
|
||||
APIConnectPreparedContact_Response = CR.StartedConnectionToContact | CR.ContactAlreadyExists | CR.ChatCmdError
|
||||
|
||||
|
||||
# Connect to prepared group.
|
||||
# Network usage: interactive.
|
||||
class APIConnectPreparedGroup(TypedDict):
|
||||
groupId: int # int64
|
||||
incognito: bool
|
||||
ownerContact: NotRequired["T.GroupOwnerContact"]
|
||||
msgContent_: NotRequired["T.MsgContent"]
|
||||
|
||||
|
||||
def APIConnectPreparedGroup_cmd_string(self: APIConnectPreparedGroup) -> str:
|
||||
return '/_connect group #' + str(self['groupId']) + (' incognito=on' if self['incognito'] else '') + ((' ' + T.GroupOwnerContact_cmd_string(self.get('ownerContact'))) if self.get('ownerContact') is not None else '') + ((' json ' + json.dumps(self.get('msgContent_'))) if self.get('msgContent_') is not None else '')
|
||||
|
||||
APIConnectPreparedGroup_Response = CR.StartedConnectionToGroup | CR.ChatCmdError
|
||||
|
||||
|
||||
# Connect to existing contact via address in its profile.
|
||||
# Network usage: interactive.
|
||||
class APIConnectContactViaAddress(TypedDict):
|
||||
userId: int # int64
|
||||
incognito: bool
|
||||
contactId: int # int64
|
||||
|
||||
|
||||
def APIConnectContactViaAddress_cmd_string(self: APIConnectContactViaAddress) -> str:
|
||||
return '/_connect contact ' + str(self['userId']) + (' incognito=on' if self['incognito'] else '') + ' ' + str(self['contactId'])
|
||||
|
||||
APIConnectContactViaAddress_Response = CR.SentInvitationToContact | CR.ChatCmdError
|
||||
|
||||
|
||||
# Accept contact request.
|
||||
# Network usage: interactive.
|
||||
class APIAcceptContact(TypedDict):
|
||||
@@ -622,6 +722,59 @@ def APIGetChats_cmd_string(self: APIGetChats) -> str:
|
||||
APIGetChats_Response = CR.ApiChats | CR.ChatCmdError
|
||||
|
||||
|
||||
# Get chat messages.
|
||||
# Network usage: no.
|
||||
class APIGetChat(TypedDict):
|
||||
chatRef: "T.ChatRef"
|
||||
contentTag: NotRequired["T.MsgContentTag"]
|
||||
chatPagination: "T.ChatPagination"
|
||||
search: NotRequired[str]
|
||||
|
||||
|
||||
def APIGetChat_cmd_string(self: APIGetChat) -> str:
|
||||
return '/_get chat ' + T.ChatRef_cmd_string(self['chatRef']) + ((' content=' + str(self.get('contentTag'))) if self.get('contentTag') is not None else '') + ' ' + T.ChatPagination_cmd_string(self['chatPagination']) + ((' search=' + self.get('search')) if self.get('search') is not None else '')
|
||||
|
||||
APIGetChat_Response = CR.ApiChat | CR.ChatCmdError
|
||||
|
||||
|
||||
# Mark messages as read.
|
||||
# Network usage: no.
|
||||
class APIChatItemsRead(TypedDict):
|
||||
chatRef: "T.ChatRef"
|
||||
chatItemIds: list[int] # int64, non-empty
|
||||
|
||||
|
||||
def APIChatItemsRead_cmd_string(self: APIChatItemsRead) -> str:
|
||||
return '/_read chat items ' + T.ChatRef_cmd_string(self['chatRef']) + ' ' + ','.join(map(str, self['chatItemIds']))
|
||||
|
||||
APIChatItemsRead_Response = CR.ItemsReadForChat | CR.ChatCmdError
|
||||
|
||||
|
||||
# Get contact information.
|
||||
# Network usage: no.
|
||||
class APIContactInfo(TypedDict):
|
||||
contactId: int # int64
|
||||
|
||||
|
||||
def APIContactInfo_cmd_string(self: APIContactInfo) -> str:
|
||||
return '/_info @' + str(self['contactId'])
|
||||
|
||||
APIContactInfo_Response = CR.ContactInfo | CR.ChatCmdError
|
||||
|
||||
|
||||
# Get message information.
|
||||
# Network usage: no.
|
||||
class APIGetChatItemInfo(TypedDict):
|
||||
chatRef: "T.ChatRef"
|
||||
chatItemId: int # int64
|
||||
|
||||
|
||||
def APIGetChatItemInfo_cmd_string(self: APIGetChatItemInfo) -> str:
|
||||
return '/_get item info ' + T.ChatRef_cmd_string(self['chatRef']) + ' ' + str(self['chatItemId'])
|
||||
|
||||
APIGetChatItemInfo_Response = CR.ChatItemInfo | CR.ChatCmdError
|
||||
|
||||
|
||||
# Delete chat.
|
||||
# Network usage: background.
|
||||
class APIDeleteChat(TypedDict):
|
||||
@@ -825,6 +978,42 @@ def APIStopChat_cmd_string(self: APIStopChat) -> str:
|
||||
APIStopChat_Response = CR.ChatStopped
|
||||
|
||||
|
||||
# Get network configuration.
|
||||
# Network usage: no.
|
||||
class APIGetNetworkConfig(TypedDict):
|
||||
pass
|
||||
|
||||
|
||||
def APIGetNetworkConfig_cmd_string(self: APIGetNetworkConfig) -> str:
|
||||
return '/network'
|
||||
|
||||
APIGetNetworkConfig_Response = CR.NetworkConfig | CR.ChatCmdError
|
||||
|
||||
|
||||
# Set network configuration.
|
||||
# Network usage: background.
|
||||
class APISetNetworkConfig(TypedDict):
|
||||
networkConfig: "T.NetworkConfig"
|
||||
|
||||
|
||||
def APISetNetworkConfig_cmd_string(self: APISetNetworkConfig) -> str:
|
||||
return '/_network ' + json.dumps(self['networkConfig'])
|
||||
|
||||
APISetNetworkConfig_Response = CR.CmdOk | CR.ChatCmdError
|
||||
|
||||
|
||||
# Get user servers and chat relays, grouped by operator.
|
||||
# Network usage: no.
|
||||
class APIGetUserServers(TypedDict):
|
||||
userId: int # int64
|
||||
|
||||
|
||||
def APIGetUserServers_cmd_string(self: APIGetUserServers) -> str:
|
||||
return '/_servers ' + str(self['userId'])
|
||||
|
||||
APIGetUserServers_Response = CR.UserServers | CR.ChatCmdError
|
||||
|
||||
|
||||
# Remote control commands
|
||||
# Allows a bot to accept an incoming remote control session from a SimpleX Desktop client, giving the desktop live access to the bot's SimpleX instance.
|
||||
|
||||
|
||||
@@ -13,6 +13,18 @@ class ActiveUser(TypedDict):
|
||||
type: Literal["activeUser"]
|
||||
user: "T.User"
|
||||
|
||||
class ApiChat(TypedDict):
|
||||
type: Literal["apiChat"]
|
||||
user: "T.User"
|
||||
chat: "T.AChat"
|
||||
navInfo: NotRequired["T.NavigationInfo"]
|
||||
|
||||
class ChatItemInfo(TypedDict):
|
||||
type: Literal["chatItemInfo"]
|
||||
user: "T.User"
|
||||
chatItem: "T.AChatItem"
|
||||
chatItemInfo: "T.ChatItemInfo"
|
||||
|
||||
class ChatItemNotChanged(TypedDict):
|
||||
type: Literal["chatItemNotChanged"]
|
||||
user: "T.User"
|
||||
@@ -81,6 +93,13 @@ class ContactDeleted(TypedDict):
|
||||
user: "T.User"
|
||||
contact: "T.Contact"
|
||||
|
||||
class ContactInfo(TypedDict):
|
||||
type: Literal["contactInfo"]
|
||||
user: "T.User"
|
||||
contact: "T.Contact"
|
||||
connectionStats_: NotRequired["T.ConnectionStats"]
|
||||
customUserProfile: NotRequired["T.Profile"]
|
||||
|
||||
class ContactPrefsUpdated(TypedDict):
|
||||
type: Literal["contactPrefsUpdated"]
|
||||
user: "T.User"
|
||||
@@ -192,6 +211,11 @@ class Invitation(TypedDict):
|
||||
connLinkInvitation: "T.CreatedConnLink"
|
||||
connection: "T.PendingContactConnection"
|
||||
|
||||
class ItemsReadForChat(TypedDict):
|
||||
type: Literal["itemsReadForChat"]
|
||||
user: "T.User"
|
||||
chatInfo: "T.ChatInfo"
|
||||
|
||||
class LeftMemberUser(TypedDict):
|
||||
type: Literal["leftMemberUser"]
|
||||
user: "T.User"
|
||||
@@ -219,11 +243,34 @@ class MembersRoleUser(TypedDict):
|
||||
toRole: "T.GroupMemberRole"
|
||||
msgSigned: bool
|
||||
|
||||
class NetworkConfig(TypedDict):
|
||||
type: Literal["networkConfig"]
|
||||
networkConfig: "T.NetworkConfig"
|
||||
|
||||
class NewChatItems(TypedDict):
|
||||
type: Literal["newChatItems"]
|
||||
user: "T.User"
|
||||
chatItems: list["T.AChatItem"]
|
||||
|
||||
class NewMemberContact(TypedDict):
|
||||
type: Literal["newMemberContact"]
|
||||
user: "T.User"
|
||||
contact: "T.Contact"
|
||||
groupInfo: "T.GroupInfo"
|
||||
member: "T.GroupMember"
|
||||
|
||||
class NewMemberContactSentInv(TypedDict):
|
||||
type: Literal["newMemberContactSentInv"]
|
||||
user: "T.User"
|
||||
contact: "T.Contact"
|
||||
groupInfo: "T.GroupInfo"
|
||||
member: "T.GroupMember"
|
||||
|
||||
class NewPreparedChat(TypedDict):
|
||||
type: Literal["newPreparedChat"]
|
||||
user: "T.User"
|
||||
chat: "T.AChat"
|
||||
|
||||
class RcvFileAccepted(TypedDict):
|
||||
type: Literal["rcvFileAccepted"]
|
||||
user: "T.User"
|
||||
@@ -353,6 +400,11 @@ class UserProfileNoChange(TypedDict):
|
||||
type: Literal["userProfileNoChange"]
|
||||
user: "T.User"
|
||||
|
||||
class UserServers(TypedDict):
|
||||
type: Literal["userServers"]
|
||||
user: "T.User"
|
||||
userServers: list["T.UserOperatorServers"]
|
||||
|
||||
class UsersList(TypedDict):
|
||||
type: Literal["usersList"]
|
||||
users: list["T.UserInfo"]
|
||||
@@ -365,6 +417,8 @@ class ApiChats(TypedDict):
|
||||
ChatResponse = (
|
||||
AcceptingContactRequest
|
||||
| ActiveUser
|
||||
| ApiChat
|
||||
| ChatItemInfo
|
||||
| ChatItemNotChanged
|
||||
| ChatItemReaction
|
||||
| ChatItemUpdated
|
||||
@@ -379,6 +433,7 @@ ChatResponse = (
|
||||
| ContactAlreadyExists
|
||||
| ContactConnectionDeleted
|
||||
| ContactDeleted
|
||||
| ContactInfo
|
||||
| ContactPrefsUpdated
|
||||
| ContactRequestRejected
|
||||
| ContactsList
|
||||
@@ -398,11 +453,16 @@ ChatResponse = (
|
||||
| GroupsList
|
||||
| GroupDomainVerified
|
||||
| Invitation
|
||||
| ItemsReadForChat
|
||||
| LeftMemberUser
|
||||
| MemberAccepted
|
||||
| MembersBlockedForAllUser
|
||||
| MembersRoleUser
|
||||
| NetworkConfig
|
||||
| NewChatItems
|
||||
| NewMemberContact
|
||||
| NewMemberContactSentInv
|
||||
| NewPreparedChat
|
||||
| RcvFileAccepted
|
||||
| RcvFileAcceptedSndCancelled
|
||||
| RcvFileCancelled
|
||||
@@ -425,8 +485,9 @@ ChatResponse = (
|
||||
| UserDeletedMembers
|
||||
| UserProfileUpdated
|
||||
| UserProfileNoChange
|
||||
| UserServers
|
||||
| UsersList
|
||||
| ApiChats
|
||||
)
|
||||
|
||||
ChatResponse_Tag = Literal["acceptingContactRequest", "activeUser", "chatItemNotChanged", "chatItemReaction", "chatItemUpdated", "chatItemsDeleted", "chatMsgContent", "chatRunning", "chatStarted", "chatStopped", "cmdOk", "chatCmdError", "connectionPlan", "contactAlreadyExists", "contactConnectionDeleted", "contactDeleted", "contactPrefsUpdated", "contactRequestRejected", "contactsList", "groupDeletedUser", "groupLink", "groupLinkCreated", "groupLinkDeleted", "groupCreated", "publicGroupCreated", "publicGroupCreationFailed", "groupRelays", "groupRelaysAdded", "groupRelaysAddFailed", "relayGroupAllowed", "groupMembers", "groupUpdated", "groupsList", "groupDomainVerified", "invitation", "leftMemberUser", "memberAccepted", "membersBlockedForAllUser", "membersRoleUser", "newChatItems", "rcvFileAccepted", "rcvFileAcceptedSndCancelled", "rcvFileCancelled", "remoteCtrlConnected", "remoteCtrlConnecting", "sentConfirmation", "sentGroupInvitation", "sentGroupInvitationViaGroup", "sentInvitation", "sentInvitationToContact", "serviceReplyAccepted", "sndFileCancelled", "startedConnectionToContact", "startedConnectionToGroup", "userAcceptedGroupSent", "userContactLink", "userContactLinkCreated", "userContactLinkDeleted", "userContactLinkUpdated", "userDeletedMembers", "userProfileUpdated", "userProfileNoChange", "usersList", "apiChats"]
|
||||
ChatResponse_Tag = Literal["acceptingContactRequest", "activeUser", "apiChat", "chatItemInfo", "chatItemNotChanged", "chatItemReaction", "chatItemUpdated", "chatItemsDeleted", "chatMsgContent", "chatRunning", "chatStarted", "chatStopped", "cmdOk", "chatCmdError", "connectionPlan", "contactAlreadyExists", "contactConnectionDeleted", "contactDeleted", "contactInfo", "contactPrefsUpdated", "contactRequestRejected", "contactsList", "groupDeletedUser", "groupLink", "groupLinkCreated", "groupLinkDeleted", "groupCreated", "publicGroupCreated", "publicGroupCreationFailed", "groupRelays", "groupRelaysAdded", "groupRelaysAddFailed", "relayGroupAllowed", "groupMembers", "groupUpdated", "groupsList", "groupDomainVerified", "invitation", "itemsReadForChat", "leftMemberUser", "memberAccepted", "membersBlockedForAllUser", "membersRoleUser", "networkConfig", "newChatItems", "newMemberContact", "newMemberContactSentInv", "newPreparedChat", "rcvFileAccepted", "rcvFileAcceptedSndCancelled", "rcvFileCancelled", "remoteCtrlConnected", "remoteCtrlConnecting", "sentConfirmation", "sentGroupInvitation", "sentGroupInvitationViaGroup", "sentInvitation", "sentInvitationToContact", "serviceReplyAccepted", "sndFileCancelled", "startedConnectionToContact", "startedConnectionToGroup", "userAcceptedGroupSent", "userContactLink", "userContactLinkCreated", "userContactLinkDeleted", "userContactLinkUpdated", "userDeletedMembers", "userProfileUpdated", "userProfileNoChange", "userServers", "usersList", "apiChats"]
|
||||
@@ -1312,6 +1312,20 @@ class ChatItemDeletion(TypedDict):
|
||||
deletedChatItem: "AChatItem"
|
||||
toChatItem: NotRequired["AChatItem"]
|
||||
|
||||
class ChatItemInfo(TypedDict):
|
||||
itemVersions: list["ChatItemVersion"]
|
||||
memberDeliveryStatuses: NotRequired[list["MemberDeliveryStatus"]] # non-empty
|
||||
forwardedFromChatItem: NotRequired["AChatItem"]
|
||||
fileXftpServers: list[str]
|
||||
|
||||
class ChatItemVersion(TypedDict):
|
||||
chatItemVersionId: int # int64
|
||||
msgContent: "MsgContent"
|
||||
formattedText: NotRequired[list["FormattedText"]]
|
||||
markdownBlocks: NotRequired[list["MarkdownBlock"]] # non-empty
|
||||
itemVersionTs: str # ISO-8601 timestamp
|
||||
createdAt: str # ISO-8601 timestamp
|
||||
|
||||
ChatLayout = Literal["classic", "terminal"]
|
||||
|
||||
class ChatListQuery_filters(TypedDict):
|
||||
@@ -1327,6 +1341,43 @@ ChatListQuery = ChatListQuery_filters | ChatListQuery_search
|
||||
|
||||
ChatListQuery_Tag = Literal["filters", "search"]
|
||||
|
||||
class ChatPagination_last(TypedDict):
|
||||
type: Literal["last"]
|
||||
count: int # int
|
||||
|
||||
class ChatPagination_after(TypedDict):
|
||||
type: Literal["after"]
|
||||
chatItemId: int # int64
|
||||
count: int # int
|
||||
|
||||
class ChatPagination_before(TypedDict):
|
||||
type: Literal["before"]
|
||||
chatItemId: int # int64
|
||||
count: int # int
|
||||
|
||||
class ChatPagination_around(TypedDict):
|
||||
type: Literal["around"]
|
||||
chatItemId: int # int64
|
||||
count: int # int
|
||||
|
||||
class ChatPagination_initial(TypedDict):
|
||||
type: Literal["initial"]
|
||||
count: int # int
|
||||
|
||||
ChatPagination = (
|
||||
ChatPagination_last
|
||||
| ChatPagination_after
|
||||
| ChatPagination_before
|
||||
| ChatPagination_around
|
||||
| ChatPagination_initial
|
||||
)
|
||||
|
||||
ChatPagination_Tag = Literal["last", "after", "before", "around", "initial"]
|
||||
|
||||
|
||||
def ChatPagination_cmd_string(self: ChatPagination) -> str:
|
||||
return 'count=' + str(self['count']) if str(self['type']) == 'last' else 'after=' + str(self['chatItemId']) + ' count=' + str(self['count']) if str(self['type']) == 'after' else 'before=' + str(self['chatItemId']) + ' count=' + str(self['count']) if str(self['type']) == 'before' else 'around=' + str(self['chatItemId']) + ' count=' + str(self['count']) if str(self['type']) == 'around' else 'initial=' + str(self['count']) # type: ignore[typeddict-item]
|
||||
|
||||
ChatPeerType = Literal["human", "bot", "business", "agent"]
|
||||
|
||||
# Used in API commands. Chat scope can only be passed with groups.
|
||||
@@ -1437,6 +1488,19 @@ class ComposedMessage(TypedDict):
|
||||
msgContent: "MsgContent"
|
||||
mentions: dict[str, int] # str : int64
|
||||
|
||||
class ConditionsAcceptance_accepted(TypedDict):
|
||||
type: Literal["accepted"]
|
||||
acceptedAt: NotRequired[str] # ISO-8601 timestamp
|
||||
autoAccepted: bool
|
||||
|
||||
class ConditionsAcceptance_required(TypedDict):
|
||||
type: Literal["required"]
|
||||
deadline: NotRequired[str] # ISO-8601 timestamp
|
||||
|
||||
ConditionsAcceptance = ConditionsAcceptance_accepted | ConditionsAcceptance_required
|
||||
|
||||
ConditionsAcceptance_Tag = Literal["accepted", "required"]
|
||||
|
||||
class ConnStatus_new(TypedDict):
|
||||
type: Literal["new"]
|
||||
|
||||
@@ -1585,6 +1649,14 @@ ConnectionPlan = (
|
||||
|
||||
ConnectionPlan_Tag = Literal["invitationLink", "contactAddress", "groupLink", "error"]
|
||||
|
||||
class ConnectionStats(TypedDict):
|
||||
connAgentVersion: int # int
|
||||
rcvQueuesInfo: list["RcvQueueInfo"]
|
||||
sndQueuesInfo: list["SndQueueInfo"]
|
||||
ratchetSyncState: "RatchetSyncState"
|
||||
ratchetSyncSupported: bool
|
||||
subStatus: NotRequired["SubscriptionStatus"]
|
||||
|
||||
class Contact(TypedDict):
|
||||
contactId: int # int64
|
||||
localDisplayName: str
|
||||
@@ -2156,6 +2228,14 @@ class GroupMemberSettings(TypedDict):
|
||||
|
||||
GroupMemberStatus = Literal["rejected", "removed", "left", "deleted", "unknown", "invited", "pending_approval", "pending_review", "introduced", "intro-inv", "accepted", "announced", "connected", "complete", "creator"]
|
||||
|
||||
class GroupOwnerContact(TypedDict):
|
||||
contactId: int # int64
|
||||
memberId: str
|
||||
|
||||
|
||||
def GroupOwnerContact_cmd_string(self: GroupOwnerContact) -> str:
|
||||
return 'contact=' + str(self['contactId']) + ' owner=' + self['memberId']
|
||||
|
||||
class GroupPreference(TypedDict):
|
||||
enable: "GroupFeatureEnabled"
|
||||
|
||||
@@ -2203,6 +2283,47 @@ class GroupShortLinkInfo(TypedDict):
|
||||
groupRelays: list[str]
|
||||
publicGroupId: NotRequired[str]
|
||||
|
||||
class GroupSndStatus_new(TypedDict):
|
||||
type: Literal["new"]
|
||||
|
||||
class GroupSndStatus_forwarded(TypedDict):
|
||||
type: Literal["forwarded"]
|
||||
|
||||
class GroupSndStatus_inactive(TypedDict):
|
||||
type: Literal["inactive"]
|
||||
|
||||
class GroupSndStatus_sent(TypedDict):
|
||||
type: Literal["sent"]
|
||||
|
||||
class GroupSndStatus_rcvd(TypedDict):
|
||||
type: Literal["rcvd"]
|
||||
msgRcptStatus: "MsgReceiptStatus"
|
||||
|
||||
class GroupSndStatus_error(TypedDict):
|
||||
type: Literal["error"]
|
||||
agentError: "SndError"
|
||||
|
||||
class GroupSndStatus_warning(TypedDict):
|
||||
type: Literal["warning"]
|
||||
agentError: "SndError"
|
||||
|
||||
class GroupSndStatus_invalid(TypedDict):
|
||||
type: Literal["invalid"]
|
||||
text: str
|
||||
|
||||
GroupSndStatus = (
|
||||
GroupSndStatus_new
|
||||
| GroupSndStatus_forwarded
|
||||
| GroupSndStatus_inactive
|
||||
| GroupSndStatus_sent
|
||||
| GroupSndStatus_rcvd
|
||||
| GroupSndStatus_error
|
||||
| GroupSndStatus_warning
|
||||
| GroupSndStatus_invalid
|
||||
)
|
||||
|
||||
GroupSndStatus_Tag = Literal["new", "forwarded", "inactive", "sent", "rcvd", "error", "warning", "invalid"]
|
||||
|
||||
class GroupSummary(TypedDict):
|
||||
currentMembers: int # int64
|
||||
publicMemberCount: NotRequired[int] # int64
|
||||
@@ -2218,6 +2339,8 @@ GroupType = Literal["channel", "group"]
|
||||
|
||||
HandshakeError = Literal["PARSE", "IDENTITY", "BAD_AUTH", "BAD_SERVICE"]
|
||||
|
||||
HostMode = Literal["onionViaSocks", "onion", "public"]
|
||||
|
||||
InlineFileMode = Literal["offer", "sent"]
|
||||
|
||||
class InvitationLinkPlan_ok(TypedDict):
|
||||
@@ -2259,6 +2382,11 @@ InvitedBy = InvitedBy_contact | InvitedBy_user | InvitedBy_unknown
|
||||
|
||||
InvitedBy_Tag = Literal["contact", "user", "unknown"]
|
||||
|
||||
class KeepAliveOpts(TypedDict):
|
||||
keepIdle: int # int
|
||||
keepIntvl: int # int
|
||||
keepCnt: int # int
|
||||
|
||||
class LinkContent_page(TypedDict):
|
||||
type: Literal["page"]
|
||||
|
||||
@@ -2360,6 +2488,11 @@ MarkdownBlock_Tag = Literal["paragraph", "heading", "codeBlock", "quote", "list"
|
||||
|
||||
MemberCriteria = Literal["all"]
|
||||
|
||||
class MemberDeliveryStatus(TypedDict):
|
||||
groupMemberId: int # int64
|
||||
memberDeliveryStatus: "GroupSndStatus"
|
||||
sentViaProxy: NotRequired[bool]
|
||||
|
||||
# Connection link sent in a message - only short links are allowed.
|
||||
|
||||
class MsgChatLink_contact(TypedDict):
|
||||
@@ -2442,6 +2575,8 @@ MsgContent = (
|
||||
|
||||
MsgContent_Tag = Literal["text", "link", "image", "video", "voice", "file", "report", "chat", "unknown"]
|
||||
|
||||
MsgContentTag = Literal["text", "link", "image", "video", "voice", "file", "report", "chat"]
|
||||
|
||||
MsgDecryptError = Literal["ratchetHeader", "tooManySkipped", "ratchetEarlier", "other", "ratchetSync"]
|
||||
|
||||
MsgDirection = Literal["rcv", "snd"]
|
||||
@@ -2554,6 +2689,28 @@ NameWarning = (
|
||||
|
||||
NameWarning_Tag = Literal["expired", "available", "reservedForCommunity", "notRegistered"]
|
||||
|
||||
class NavigationInfo(TypedDict):
|
||||
afterUnread: int # int
|
||||
afterTotal: int # int
|
||||
|
||||
class NetworkConfig(TypedDict):
|
||||
socksProxy: NotRequired[str]
|
||||
socksMode: "SocksMode"
|
||||
hostMode: "HostMode"
|
||||
requiredHostMode: bool
|
||||
sessionMode: "TransportSessionMode"
|
||||
smpProxyMode: "SMPProxyMode"
|
||||
smpProxyFallback: "SMPProxyFallback"
|
||||
smpWebPortServers: "SMPWebPortServers"
|
||||
tcpConnectTimeout: "NetworkTimeout"
|
||||
tcpTimeout: "NetworkTimeout"
|
||||
tcpTimeoutPerKb: int # int64
|
||||
rcvConcurrency: int # int
|
||||
tcpKeepAlive: NotRequired["KeepAliveOpts"]
|
||||
smpPingInterval: int # int64
|
||||
smpPingCount: int # int
|
||||
logTLSErrors: bool
|
||||
|
||||
class NetworkError_connectError(TypedDict):
|
||||
type: Literal["connectError"]
|
||||
connectError: str
|
||||
@@ -2586,6 +2743,10 @@ NetworkError = (
|
||||
|
||||
NetworkError_Tag = Literal["connectError", "tLSError", "unknownCAError", "failedError", "timeoutError", "subscribeError"]
|
||||
|
||||
class NetworkTimeout(TypedDict):
|
||||
backgroundTimeout: int # int
|
||||
interactiveTimeout: int # int
|
||||
|
||||
class NewUser(TypedDict):
|
||||
profile: NotRequired["Profile"]
|
||||
pastTimestamp: bool
|
||||
@@ -2601,6 +2762,8 @@ class NoteFolder(TypedDict):
|
||||
favorite: bool
|
||||
unread: bool
|
||||
|
||||
OperatorTag = Literal["simplex", "flux"]
|
||||
|
||||
class OwnerVerification_verified(TypedDict):
|
||||
type: Literal["verified"]
|
||||
|
||||
@@ -2639,6 +2802,10 @@ class PendingContactConnection(TypedDict):
|
||||
|
||||
PlanResolveMode = Literal["allGroups", "unknown", "never"]
|
||||
|
||||
|
||||
def PlanResolveMode_cmd_string(self: PlanResolveMode) -> str:
|
||||
return ' resolve=allGroups' if str(self) == 'allGroups' else ' resolve=never' if str(self) == 'never' else ''
|
||||
|
||||
class PrefEnabled(TypedDict):
|
||||
forUser: bool
|
||||
forContact: bool
|
||||
@@ -2731,6 +2898,8 @@ class PublicGroupProfile(TypedDict):
|
||||
publicGroupId: str
|
||||
publicGroupAccess: NotRequired["PublicGroupAccess"]
|
||||
|
||||
QueueStatus = Literal["new", "confirmed", "secured", "active", "disabled"]
|
||||
|
||||
class RCErrorType_internal(TypedDict):
|
||||
type: Literal["internal"]
|
||||
internalErr: str
|
||||
@@ -3000,6 +3169,15 @@ RcvMsgError = RcvMsgError_dropped | RcvMsgError_parseError
|
||||
|
||||
RcvMsgError_Tag = Literal["dropped", "parseError"]
|
||||
|
||||
class RcvQueueInfo(TypedDict):
|
||||
rcvServer: str
|
||||
status: "QueueStatus"
|
||||
rcvSwitchStatus: NotRequired["RcvSwitchStatus"]
|
||||
canAbortSwitch: bool
|
||||
subStatus: "SubscriptionStatus"
|
||||
|
||||
RcvSwitchStatus = Literal["switch_started", "sending_qadd", "sending_quse", "received_message", "received_qend"]
|
||||
|
||||
class RelayCapabilities(TypedDict):
|
||||
webDomain: NotRequired[str]
|
||||
|
||||
@@ -3121,6 +3299,12 @@ SMPAgentError = (
|
||||
|
||||
SMPAgentError_Tag = Literal["A_MESSAGE", "A_PROHIBITED", "A_VERSION", "A_LINK", "A_CRYPTO", "A_DUPLICATE", "A_QUEUE", "A_SERVICE"]
|
||||
|
||||
SMPProxyFallback = Literal["allow", "allowProtected", "prohibit"]
|
||||
|
||||
SMPProxyMode = Literal["always", "unknown", "unprotected", "never"]
|
||||
|
||||
SMPWebPortServers = Literal["all", "preset", "off"]
|
||||
|
||||
class SecurityCode(TypedDict):
|
||||
securityCode: str
|
||||
verifiedAt: str # ISO-8601 timestamp
|
||||
@@ -3130,6 +3314,27 @@ SegmentRange = TypedDict("SegmentRange", {
|
||||
"to": int, # int
|
||||
})
|
||||
|
||||
class ServerOperator(TypedDict):
|
||||
operatorId: int # int64
|
||||
operatorTag: NotRequired["OperatorTag"]
|
||||
tradeName: str
|
||||
legalName: NotRequired[str]
|
||||
serverDomains: list[str]
|
||||
conditionsAcceptance: "ConditionsAcceptance"
|
||||
enabled: bool
|
||||
smpRoles: "ServerRoles"
|
||||
xftpRoles: "ServerRoles"
|
||||
|
||||
class ServerRoles(TypedDict):
|
||||
storage: bool
|
||||
proxy: bool
|
||||
names: bool
|
||||
|
||||
class ServerRolesOverride(TypedDict):
|
||||
storage: NotRequired[bool]
|
||||
proxy: NotRequired[bool]
|
||||
names: NotRequired[bool]
|
||||
|
||||
class SimplePreference(TypedDict):
|
||||
allow: "FeatureAllowed"
|
||||
|
||||
@@ -3297,6 +3502,15 @@ SndGroupEvent = (
|
||||
|
||||
SndGroupEvent_Tag = Literal["memberRole", "memberBlocked", "userRole", "memberDeleted", "userLeft", "groupUpdated", "memberAccepted", "userPendingReview"]
|
||||
|
||||
class SndQueueInfo(TypedDict):
|
||||
sndServer: str
|
||||
status: "QueueStatus"
|
||||
sndSwitchStatus: NotRequired["SndSwitchStatus"]
|
||||
|
||||
SndSwitchStatus = Literal["sending_qkey", "sending_qtest", "securing_queue", "sending_qend"]
|
||||
|
||||
SocksMode = Literal["always", "onion"]
|
||||
|
||||
class SrvError_host(TypedDict):
|
||||
type: Literal["host"]
|
||||
|
||||
@@ -3822,6 +4036,8 @@ TransportError = (
|
||||
|
||||
TransportError_Tag = Literal["badBlock", "version", "largeMsg", "badSession", "noServerAuth", "handshake"]
|
||||
|
||||
TransportSessionMode = Literal["user", "session", "server", "entity"]
|
||||
|
||||
UIColorMode = Literal["light", "dark"]
|
||||
|
||||
class UIColors(TypedDict):
|
||||
@@ -3920,6 +4136,12 @@ class UserInfo(TypedDict):
|
||||
user: "User"
|
||||
unreadCount: int # int
|
||||
|
||||
class UserOperatorServers(TypedDict):
|
||||
operator: NotRequired["ServerOperator"]
|
||||
smpServers: list["UserServer"]
|
||||
xftpServers: list["UserServer"]
|
||||
chatRelays: list["UserChatRelay"]
|
||||
|
||||
class UserProfileUpdateSummary(TypedDict):
|
||||
updateSuccesses: int # int
|
||||
updateFailures: int # int
|
||||
@@ -3929,6 +4151,15 @@ class UserPwdHash(TypedDict):
|
||||
hash: str
|
||||
salt: str
|
||||
|
||||
class UserServer(TypedDict):
|
||||
serverId: int # int64
|
||||
server: str
|
||||
preset: bool
|
||||
tested: NotRequired[bool]
|
||||
enabled: bool
|
||||
roles: "ServerRolesOverride"
|
||||
deleted: bool
|
||||
|
||||
class VersionRange(TypedDict):
|
||||
minVersion: int # int
|
||||
maxVersion: int # int
|
||||
|
||||
Reference in new issue
Block a user