Skip to content

docs: add missing documentation to deltachat-rpc-client #6846

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 12, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion deltachat-rpc-client/src/deltachat_rpc_client/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
"""Delta Chat JSON-RPC high-level API"""
"""Delta Chat JSON-RPC high-level API."""

from ._utils import AttrDict, run_bot_cli, run_client_cli
from .account import Account
Expand Down
6 changes: 3 additions & 3 deletions deltachat-rpc-client/src/deltachat_rpc_client/_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ def _run_cli(


def extract_addr(text: str) -> str:
"""extract email address from the given text."""
"""Extract email address from the given text."""
match = re.match(r".*\((.+@.+)\)", text)
if match:
text = match.group(1)
Expand All @@ -124,7 +124,7 @@ def extract_addr(text: str) -> str:


def parse_system_image_changed(text: str) -> Optional[Tuple[str, bool]]:
"""return image changed/deleted info from parsing the given system message text."""
"""Return image changed/deleted info from parsing the given system message text."""
text = text.lower()
match = re.match(r"group image (changed|deleted) by (.+).", text)
if match:
Expand All @@ -143,7 +143,7 @@ def parse_system_title_changed(text: str) -> Optional[Tuple[str, str]]:


def parse_system_add_remove(text: str) -> Optional[Tuple[str, str, str]]:
"""return add/remove info from parsing the given system message text.
"""Return add/remove info from parsing the given system message text.

returns a (action, affected, actor) tuple.
"""
Expand Down
35 changes: 24 additions & 11 deletions deltachat-rpc-client/src/deltachat_rpc_client/account.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
"""Account module."""

from __future__ import annotations

from dataclasses import dataclass
Expand Down Expand Up @@ -34,7 +36,10 @@ def wait_for_event(self, event_type=None) -> AttrDict:
return next_event

def clear_all_events(self):
"""Removes all queued-up events for a given account. Useful for tests."""
"""Remove all queued-up events for a given account.

Useful for tests.
"""
self._rpc.clear_all_events(self.id)

def remove(self) -> None:
Expand All @@ -43,7 +48,9 @@ def remove(self) -> None:

def clone(self) -> "Account":
"""Clone given account.
This uses backup-transfer via iroh, i.e. the 'Add second device' feature."""

This uses backup-transfer via iroh, i.e. the 'Add second device' feature.
"""
future = self._rpc.provide_backup.future(self.id)
qr = self._rpc.get_backup_qr(self.id)
new_account = self.manager.add_account()
Expand Down Expand Up @@ -80,7 +87,7 @@ def get_config(self, key: str) -> Optional[str]:
return self._rpc.get_config(self.id, key)

def update_config(self, **kwargs) -> None:
"""update config values."""
"""Update config values."""
for key, value in kwargs.items():
self.set_config(key, value)

Expand All @@ -99,10 +106,12 @@ def check_qr(self, qr):
"""Parse QR code contents.

This function takes the raw text scanned
and checks what can be done with it."""
and checks what can be done with it.
"""
return self._rpc.check_qr(self.id, qr)

def set_config_from_qr(self, qr: str):
"""Set configuration values from a QR code."""
self._rpc.set_config_from_qr(self.id, qr)

@futuremethod
Expand All @@ -117,7 +126,7 @@ def add_or_update_transport(self, params):

@futuremethod
def list_transports(self):
"""Returns the list of all email accounts that are used as a transport in the current profile."""
"""Return the list of all email accounts that are used as a transport in the current profile."""
transports = yield self._rpc.list_transports.future(self.id)
return transports

Expand Down Expand Up @@ -158,7 +167,8 @@ def make_vcard(self, contacts: list[Contact]) -> str:
def import_vcard(self, vcard: str) -> list[Contact]:
"""Import vCard.

Return created or modified contacts in the order they appear in vCard."""
Return created or modified contacts in the order they appear in vCard.
"""
contact_ids = self._rpc.import_vcard_contents(self.id, vcard)
return [Contact(self, contact_id) for contact_id in contact_ids]

Expand Down Expand Up @@ -227,12 +237,12 @@ def get_contacts(

@property
def self_contact(self) -> Contact:
"""This account's identity as a Contact."""
"""Account's identity as a Contact."""
return Contact(self, SpecialContactId.SELF)

@property
def device_contact(self) -> Chat:
"""This account's device contact."""
"""Account's device contact."""
return Contact(self, SpecialContactId.DEVICE)

def get_chatlist(
Expand Down Expand Up @@ -290,8 +300,7 @@ def get_chat_by_id(self, chat_id: int) -> Chat:
return Chat(self, chat_id)

def secure_join(self, qrdata: str) -> Chat:
"""Continue a Setup-Contact or Verified-Group-Invite protocol started on
another device.
"""Continue a Setup-Contact or Verified-Group-Invite protocol started on another device.

The function returns immediately and the handshake runs in background, sending
and receiving several messages.
Expand Down Expand Up @@ -361,22 +370,26 @@ def wait_for_msgs_noticed_event(self):
def wait_for_incoming_msg(self):
"""Wait for incoming message and return it.

Consumes all events before the next incoming message event."""
Consumes all events before the next incoming message event.
"""
return self.get_message_by_id(self.wait_for_incoming_msg_event().msg_id)

def wait_for_securejoin_inviter_success(self):
"""Wait until SecureJoin process finishes successfully on the inviter side."""
while True:
event = self.wait_for_event()
if event["kind"] == "SecurejoinInviterProgress" and event["progress"] == 1000:
break

def wait_for_securejoin_joiner_success(self):
"""Wait until SecureJoin process finishes successfully on the joiner side."""
while True:
event = self.wait_for_event()
if event["kind"] == "SecurejoinJoinerProgress" and event["progress"] == 1000:
break

def wait_for_reactions_changed(self):
"""Wait for reaction change event."""
return self.wait_for_event(EventType.REACTIONS_CHANGED)

def get_fresh_messages_in_arrival_order(self) -> list[Message]:
Expand Down
9 changes: 6 additions & 3 deletions deltachat-rpc-client/src/deltachat_rpc_client/chat.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
"""Chat module."""

from __future__ import annotations

import calendar
Expand Down Expand Up @@ -89,7 +91,8 @@ def set_name(self, name: str) -> None:
def set_ephemeral_timer(self, timer: int) -> None:
"""Set ephemeral timer of this chat in seconds.

0 means the timer is disabled, use 1 for immediate deletion."""
0 means the timer is disabled, use 1 for immediate deletion.
"""
self._rpc.set_chat_ephemeral_timer(self.account.id, self.id, timer)

def get_encryption_info(self) -> str:
Expand Down Expand Up @@ -199,12 +202,12 @@ def get_draft(self) -> Optional[AttrDict]:
return snapshot

def get_messages(self, info_only: bool = False, add_daymarker: bool = False) -> list[Message]:
"""get the list of messages in this chat."""
"""Get the list of messages in this chat."""
msgs = self._rpc.get_message_ids(self.account.id, self.id, info_only, add_daymarker)
return [Message(self.account, msg_id) for msg_id in msgs]

def get_fresh_message_count(self) -> int:
"""Get number of fresh messages in this chat"""
"""Get number of fresh messages in this chat."""
return self._rpc.get_fresh_msg_cnt(self.account.id, self.id)

def mark_noticed(self) -> None:
Expand Down
4 changes: 4 additions & 0 deletions deltachat-rpc-client/src/deltachat_rpc_client/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ def __init__(
self.add_hooks(hooks or [])

def add_hooks(self, hooks: Iterable[tuple[Callable, Union[type, EventFilter]]]) -> None:
"""Register multiple hooks."""
for hook, event in hooks:
self.add_hook(hook, event)

Expand Down Expand Up @@ -77,9 +78,11 @@ def remove_hook(self, hook: Callable, event: Union[type, EventFilter]) -> None:
self._hooks.get(type(event), set()).remove((hook, event))

def is_configured(self) -> bool:
"""Return True if the client is configured."""
return self.account.is_configured()

def configure(self, email: str, password: str, **kwargs) -> None:
"""Configure the client."""
self.account.set_config("addr", email)
self.account.set_config("mail_pw", password)
for key, value in kwargs.items():
Expand Down Expand Up @@ -198,5 +201,6 @@ class Bot(Client):
"""Simple bot implementation that listens to events of a single account."""

def configure(self, email: str, password: str, **kwargs) -> None:
"""Configure the bot."""
kwargs.setdefault("bot", "1")
super().configure(email, password, **kwargs)
40 changes: 24 additions & 16 deletions deltachat-rpc-client/src/deltachat_rpc_client/const.py
Original file line number Diff line number Diff line change
@@ -1,29 +1,37 @@
"""Constants module."""

from enum import Enum, IntEnum

COMMAND_PREFIX = "/"


class ContactFlag(IntEnum):
"""Bit flags for get_contacts() method."""

VERIFIED_ONLY = 0x01
ADD_SELF = 0x02


class ChatlistFlag(IntEnum):
"""Bit flags for get_chatlist() method."""

ARCHIVED_ONLY = 0x01
NO_SPECIALS = 0x02
ADD_ALLDONE_HINT = 0x04
FOR_FORWARDING = 0x08


class SpecialContactId(IntEnum):
"""Special contact IDs."""

SELF = 1
INFO = 2 # centered messages as "member added", used in all chats
DEVICE = 5 # messages "update info" in the device-chat
LAST_SPECIAL = 9


class EventType(str, Enum):
"""Core event types"""
"""Core event types."""

INFO = "Info"
SMTP_CONNECTED = "SmtpConnected"
Expand Down Expand Up @@ -71,7 +79,7 @@ class EventType(str, Enum):


class ChatId(IntEnum):
"""Special chat ids"""
"""Special chat IDs."""

TRASH = 3
ARCHIVED_LINK = 6
Expand All @@ -80,7 +88,7 @@ class ChatId(IntEnum):


class ChatType(IntEnum):
"""Chat types"""
"""Chat type."""

UNDEFINED = 0
SINGLE = 100
Expand All @@ -90,15 +98,15 @@ class ChatType(IntEnum):


class ChatVisibility(str, Enum):
"""Chat visibility types"""
"""Chat visibility types."""

NORMAL = "Normal"
ARCHIVED = "Archived"
PINNED = "Pinned"


class DownloadState(str, Enum):
"""Message download state"""
"""Message download state."""

DONE = "Done"
AVAILABLE = "Available"
Expand Down Expand Up @@ -159,22 +167,22 @@ class MessageState(IntEnum):


class MessageId(IntEnum):
"""Special message ids"""
"""Special message IDs."""

DAYMARKER = 9
LAST_SPECIAL = 9


class CertificateChecks(IntEnum):
"""Certificate checks mode"""
"""Certificate checks mode."""

AUTOMATIC = 0
STRICT = 1
ACCEPT_INVALID_CERTIFICATES = 3


class Connectivity(IntEnum):
"""Connectivity states"""
"""Connectivity states."""

NOT_CONNECTED = 1000
CONNECTING = 2000
Expand All @@ -183,7 +191,7 @@ class Connectivity(IntEnum):


class KeyGenType(IntEnum):
"""Type of the key to generate"""
"""Type of the key to generate."""

DEFAULT = 0
RSA2048 = 1
Expand All @@ -193,45 +201,45 @@ class KeyGenType(IntEnum):

# "Lp" means "login parameters"
class LpAuthFlag(IntEnum):
"""Authorization flags"""
"""Authorization flags."""

OAUTH2 = 0x2
NORMAL = 0x4


class MediaQuality(IntEnum):
"""Media quality setting"""
"""Media quality setting."""

BALANCED = 0
WORSE = 1


class ProviderStatus(IntEnum):
"""Provider status according to manual testing"""
"""Provider status according to manual testing."""

OK = 1
PREPARATION = 2
BROKEN = 3


class PushNotifyState(IntEnum):
"""Push notifications state"""
"""Push notifications state."""

NOT_CONNECTED = 0
HEARTBEAT = 1
CONNECTED = 2


class ShowEmails(IntEnum):
"""Show emails mode"""
"""Show emails mode."""

OFF = 0
ACCEPTED_CONTACTS = 1
ALL = 2


class SocketSecurity(IntEnum):
"""Socket security"""
"""Socket security."""

AUTOMATIC = 0
SSL = 1
Expand All @@ -240,7 +248,7 @@ class SocketSecurity(IntEnum):


class VideochatType(IntEnum):
"""Video chat URL type"""
"""Video chat URL type."""

UNKNOWN = 0
BASICWEBRTC = 1
Expand Down
Loading
Loading