mirror of
https://github.com/chatmail/core.git
synced 2026-04-26 01:46:34 +03:00
Make _rpc private
This commit is contained in:
@@ -7,7 +7,7 @@ from .message import Message
|
||||
|
||||
class Account:
|
||||
def __init__(self, rpc, account_id) -> None:
|
||||
self.rpc = rpc
|
||||
self._rpc = rpc
|
||||
self.account_id = account_id
|
||||
|
||||
def __repr__(self) -> str:
|
||||
@@ -15,53 +15,53 @@ class Account:
|
||||
|
||||
async def wait_for_event(self) -> dict:
|
||||
"""Wait until the next event and return it."""
|
||||
return await self.rpc.wait_for_event(self.account_id)
|
||||
return await self._rpc.wait_for_event(self.account_id)
|
||||
|
||||
async def remove(self) -> None:
|
||||
"""Remove the account."""
|
||||
await self.rpc.remove_account(self.account_id)
|
||||
await self._rpc.remove_account(self.account_id)
|
||||
|
||||
async def start_io(self) -> None:
|
||||
"""Start the account I/O."""
|
||||
await self.rpc.start_io(self.account_id)
|
||||
await self._rpc.start_io(self.account_id)
|
||||
|
||||
async def stop_io(self) -> None:
|
||||
"""Stop the account I/O."""
|
||||
await self.rpc.stop_io(self.account_id)
|
||||
await self._rpc.stop_io(self.account_id)
|
||||
|
||||
async def get_info(self) -> dict:
|
||||
return await self.rpc.get_info(self.account_id)
|
||||
return await self._rpc.get_info(self.account_id)
|
||||
|
||||
async def get_file_size(self) -> int:
|
||||
return await self.rpc.get_account_file_size(self.account_id)
|
||||
return await self._rpc.get_account_file_size(self.account_id)
|
||||
|
||||
async def is_configured(self) -> bool:
|
||||
"""Return True for configured accounts."""
|
||||
return await self.rpc.is_configured(self.account_id)
|
||||
return await self._rpc.is_configured(self.account_id)
|
||||
|
||||
async def set_config(self, key: str, value: Optional[str] = None) -> None:
|
||||
"""Set the configuration value key pair."""
|
||||
await self.rpc.set_config(self.account_id, key, value)
|
||||
await self._rpc.set_config(self.account_id, key, value)
|
||||
|
||||
async def get_config(self, key: str) -> Optional[str]:
|
||||
"""Get the configuration value."""
|
||||
return await self.rpc.get_config(self.account_id, key)
|
||||
return await self._rpc.get_config(self.account_id, key)
|
||||
|
||||
async def configure(self) -> None:
|
||||
"""Configure an account."""
|
||||
await self.rpc.configure(self.account_id)
|
||||
await self._rpc.configure(self.account_id)
|
||||
|
||||
async def create_contact(self, address: str, name: Optional[str] = None) -> Contact:
|
||||
"""Create a contact with the given address and, optionally, a name."""
|
||||
return Contact(
|
||||
self.rpc,
|
||||
self._rpc,
|
||||
self.account_id,
|
||||
await self.rpc.create_contact(self.account_id, address, name),
|
||||
await self._rpc.create_contact(self.account_id, address, name),
|
||||
)
|
||||
|
||||
async def secure_join(self, qrdata: str) -> Chat:
|
||||
chat_id = await self.rpc.secure_join(self.account_id, qrdata)
|
||||
return Chat(self.rpc, self.account_id, chat_id)
|
||||
chat_id = await self._rpc.secure_join(self.account_id, qrdata)
|
||||
return Chat(self._rpc, self.account_id, chat_id)
|
||||
|
||||
async def get_fresh_messages(self) -> List[Message]:
|
||||
"""Return the list of fresh messages, newest messages first.
|
||||
@@ -70,10 +70,10 @@ class Account:
|
||||
If you are writing a bot, use get_fresh_messages_in_arrival_order instead,
|
||||
to process oldest messages first.
|
||||
"""
|
||||
fresh_msg_ids = await self.rpc.get_fresh_msgs(self.account_id)
|
||||
return [Message(self.rpc, self.account_id, msg_id) for msg_id in fresh_msg_ids]
|
||||
fresh_msg_ids = await self._rpc.get_fresh_msgs(self.account_id)
|
||||
return [Message(self._rpc, self.account_id, msg_id) for msg_id in fresh_msg_ids]
|
||||
|
||||
async def get_fresh_messages_in_arrival_order(self) -> List[Message]:
|
||||
"""Return fresh messages list sorted in the order of their arrival, with ascending IDs."""
|
||||
fresh_msg_ids = sorted(await self.rpc.get_fresh_msgs(self.account_id))
|
||||
return [Message(self.rpc, self.account_id, msg_id) for msg_id in fresh_msg_ids]
|
||||
fresh_msg_ids = sorted(await self._rpc.get_fresh_msgs(self.account_id))
|
||||
return [Message(self._rpc, self.account_id, msg_id) for msg_id in fresh_msg_ids]
|
||||
|
||||
@@ -8,34 +8,34 @@ if TYPE_CHECKING:
|
||||
|
||||
class Chat:
|
||||
def __init__(self, rpc: Rpc, account_id: int, chat_id: int) -> None:
|
||||
self.rpc = rpc
|
||||
self._rpc = rpc
|
||||
self.account_id = account_id
|
||||
self.chat_id = chat_id
|
||||
|
||||
async def block(self) -> None:
|
||||
"""Block the chat."""
|
||||
await self.rpc.block_chat(self.account_id, self.chat_id)
|
||||
await self._rpc.block_chat(self.account_id, self.chat_id)
|
||||
|
||||
async def accept(self) -> None:
|
||||
"""Accept the contact request."""
|
||||
await self.rpc.accept_chat(self.account_id, self.chat_id)
|
||||
await self._rpc.accept_chat(self.account_id, self.chat_id)
|
||||
|
||||
async def delete(self) -> None:
|
||||
await self.rpc.delete_chat(self.account_id, self.chat_id)
|
||||
await self._rpc.delete_chat(self.account_id, self.chat_id)
|
||||
|
||||
async def get_encryption_info(self) -> str:
|
||||
return await self.rpc.get_chat_encryption_info(self.account_id, self.chat_id)
|
||||
return await self._rpc.get_chat_encryption_info(self.account_id, self.chat_id)
|
||||
|
||||
async def send_text(self, text: str) -> "Message":
|
||||
from .message import Message
|
||||
|
||||
msg_id = await self.rpc.misc_send_text_message(
|
||||
msg_id = await self._rpc.misc_send_text_message(
|
||||
self.account_id, self.chat_id, text
|
||||
)
|
||||
return Message(self.rpc, self.account_id, msg_id)
|
||||
return Message(self._rpc, self.account_id, msg_id)
|
||||
|
||||
async def leave(self) -> None:
|
||||
await self.rpc.leave_group(self.account_id, self.chat_id)
|
||||
await self._rpc.leave_group(self.account_id, self.chat_id)
|
||||
|
||||
async def get_fresh_message_count(self) -> int:
|
||||
return await self.rpc.get_fresh_msg_cnt(self.account_id, self.chat_id)
|
||||
return await self._rpc.get_fresh_msg_cnt(self.account_id, self.chat_id)
|
||||
|
||||
@@ -14,39 +14,39 @@ class Contact:
|
||||
"""
|
||||
|
||||
def __init__(self, rpc: Rpc, account_id: int, contact_id: int) -> None:
|
||||
self.rpc = rpc
|
||||
self._rpc = rpc
|
||||
self.account_id = account_id
|
||||
self.contact_id = contact_id
|
||||
|
||||
async def block(self) -> None:
|
||||
"""Block contact."""
|
||||
await self.rpc.block_contact(self.account_id, self.contact_id)
|
||||
await self._rpc.block_contact(self.account_id, self.contact_id)
|
||||
|
||||
async def unblock(self) -> None:
|
||||
"""Unblock contact."""
|
||||
await self.rpc.unblock_contact(self.account_id, self.contact_id)
|
||||
await self._rpc.unblock_contact(self.account_id, self.contact_id)
|
||||
|
||||
async def delete(self) -> None:
|
||||
"""Delete contact."""
|
||||
await self.rpc.delete_contact(self.account_id, self.contact_id)
|
||||
await self._rpc.delete_contact(self.account_id, self.contact_id)
|
||||
|
||||
async def change_name(self, name: str) -> None:
|
||||
await self.rpc.change_contact_name(self.account_id, self.contact_id, name)
|
||||
await self._rpc.change_contact_name(self.account_id, self.contact_id, name)
|
||||
|
||||
async def get_encryption_info(self) -> str:
|
||||
return await self.rpc.get_contact_encryption_info(
|
||||
return await self._rpc.get_contact_encryption_info(
|
||||
self.account_id, self.contact_id
|
||||
)
|
||||
|
||||
async def get_dictionary(self) -> dict:
|
||||
"""Return a dictionary with a snapshot of all contact properties."""
|
||||
return await self.rpc.get_contact(self.account_id, self.contact_id)
|
||||
return await self._rpc.get_contact(self.account_id, self.contact_id)
|
||||
|
||||
async def create_chat(self) -> "Chat":
|
||||
from .chat import Chat
|
||||
|
||||
return Chat(
|
||||
self.rpc,
|
||||
self._rpc,
|
||||
self.account_id,
|
||||
await self.rpc.create_chat_by_contact_id(self.account_id, self.contact_id),
|
||||
await self._rpc.create_chat_by_contact_id(self.account_id, self.contact_id),
|
||||
)
|
||||
|
||||
@@ -8,20 +8,20 @@ from .rpc import Rpc
|
||||
|
||||
class Message:
|
||||
def __init__(self, rpc: Rpc, account_id: int, msg_id: int) -> None:
|
||||
self.rpc = rpc
|
||||
self._rpc = rpc
|
||||
self.account_id = account_id
|
||||
self.msg_id = msg_id
|
||||
|
||||
async def send_reaction(self, reactions: str) -> "Message":
|
||||
msg_id = await self.rpc.send_reaction(self.account_id, self.msg_id, reactions)
|
||||
return Message(self.rpc, self.account_id, msg_id)
|
||||
msg_id = await self._rpc.send_reaction(self.account_id, self.msg_id, reactions)
|
||||
return Message(self._rpc, self.account_id, msg_id)
|
||||
|
||||
async def get_snapshot(self) -> "MessageSnapshot":
|
||||
message_object = await self.rpc.get_message(self.account_id, self.msg_id)
|
||||
message_object = await self._rpc.get_message(self.account_id, self.msg_id)
|
||||
return MessageSnapshot(
|
||||
message=self,
|
||||
chat=Chat(self.rpc, self.account_id, message_object["chatId"]),
|
||||
sender=Contact(self.rpc, self.account_id, message_object["fromId"]),
|
||||
chat=Chat(self._rpc, self.account_id, message_object["chatId"]),
|
||||
sender=Contact(self._rpc, self.account_id, message_object["fromId"]),
|
||||
text=message_object["text"],
|
||||
error=message_object.get("error"),
|
||||
is_info=message_object["isInfo"],
|
||||
@@ -29,7 +29,7 @@ class Message:
|
||||
|
||||
async def mark_seen(self) -> None:
|
||||
"""Mark the message as seen."""
|
||||
await self.rpc.markseen_msgs(self.account_id, [self.msg_id])
|
||||
await self._rpc.markseen_msgs(self.account_id, [self.msg_id])
|
||||
|
||||
|
||||
@dataclass
|
||||
|
||||
Reference in New Issue
Block a user