|
| 1 | +from typing import Optional |
| 2 | + |
| 3 | +from .chat import Chat |
| 4 | +from .contact import Contact |
| 5 | +from .message import Message |
| 6 | + |
| 7 | + |
| 8 | +class Account: |
| 9 | + def __init__(self, rpc, account_id): |
| 10 | + self.rpc = rpc |
| 11 | + self.account_id = account_id |
| 12 | + |
| 13 | + def __repr__(self): |
| 14 | + return "<Account id={}>".format(self.account_id) |
| 15 | + |
| 16 | + async def wait_for_event(self): |
| 17 | + """Wait until the next event and return it.""" |
| 18 | + return await self.rpc.wait_for_event(self.account_id) |
| 19 | + |
| 20 | + async def remove(self) -> None: |
| 21 | + """Remove the account.""" |
| 22 | + await self.rpc.remove_account(self.account_id) |
| 23 | + |
| 24 | + async def start_io(self) -> None: |
| 25 | + """Start the account I/O.""" |
| 26 | + await self.rpc.start_io(self.account_id) |
| 27 | + |
| 28 | + async def stop_io(self) -> None: |
| 29 | + """Stop the account I/O.""" |
| 30 | + await self.rpc.stop_io(self.account_id) |
| 31 | + |
| 32 | + async def get_info(self): |
| 33 | + return await self.rpc.get_info(self.account_id) |
| 34 | + |
| 35 | + async def get_file_size(self): |
| 36 | + return await self.rpc.get_account_file_size(self.account_id) |
| 37 | + |
| 38 | + async def is_configured(self) -> bool: |
| 39 | + """Return True for configured accounts.""" |
| 40 | + return await self.rpc.is_configured(self.account_id) |
| 41 | + |
| 42 | + async def set_config(self, key: str, value: Optional[str]): |
| 43 | + """Set the configuration value key pair.""" |
| 44 | + await self.rpc.set_config(self.account_id, key, value) |
| 45 | + |
| 46 | + async def get_config(self, key: str) -> Optional[str]: |
| 47 | + """Get the configuration value.""" |
| 48 | + return await self.rpc.get_config(self.account_id, key) |
| 49 | + |
| 50 | + async def configure(self): |
| 51 | + """Configure an account.""" |
| 52 | + await self.rpc.configure(self.account_id) |
| 53 | + |
| 54 | + async def create_contact(self, address: str, name: Optional[str]) -> Contact: |
| 55 | + """Create a contact with the given address and, optionally, a name.""" |
| 56 | + return Contact( |
| 57 | + self.rpc, |
| 58 | + self.account_id, |
| 59 | + await self.rpc.create_contact(self.account_id, address, name), |
| 60 | + ) |
| 61 | + |
| 62 | + async def secure_join(self, qr: str) -> Chat: |
| 63 | + chat_id = await self.rpc.secure_join(self.account_id, qr) |
| 64 | + return Chat(self.rpc, self.account_id, self.chat_id) |
| 65 | + |
| 66 | + async def get_fresh_messages(self): |
| 67 | + fresh_msg_ids = await self.rpc.get_fresh_msgs(self.account_id) |
| 68 | + return [Message(self.rpc, self.account_id, msg_id) for msg_id in fresh_msg_ids] |
0 commit comments