|
1 | 1 | import abc |
2 | 2 | import asyncio |
3 | 3 | import logging |
4 | | -import functools |
5 | 4 | from typing import Union, Optional |
6 | 5 | from ..client import Client |
7 | 6 | from ..client.protocol import Proto |
| 7 | +from ..util.is_name import is_name |
8 | 8 |
|
9 | 9 |
|
10 | 10 | class RoomBase(abc.ABC): |
@@ -61,13 +61,19 @@ async def no_join(self, client: Client): |
61 | 61 | self._client = client |
62 | 62 |
|
63 | 63 | if isinstance(self._id, str): |
64 | | - code = self._id |
65 | | - id = await client.query(code, scope=self._scope) |
66 | | - if not isinstance(id, int): |
67 | | - raise TypeError( |
68 | | - f'expecting ThingsDB code `{code}` to return with a ' |
69 | | - f'room Id (integer value), ' |
70 | | - f'but got type `{type(id).__name__}`') |
| 64 | + if is_name(self._id): |
| 65 | + id = await client.query( |
| 66 | + "room(name).id();", |
| 67 | + name=self._id, |
| 68 | + scope=self._scope) |
| 69 | + else: |
| 70 | + code = self._id |
| 71 | + id = await client.query(code, scope=self._scope) |
| 72 | + if not isinstance(id, int): |
| 73 | + raise TypeError( |
| 74 | + f'expecting ThingsDB code `{code}` to return with ' |
| 75 | + f'a room Id (integer value), ' |
| 76 | + f'but got type `{type(id).__name__}`') |
71 | 77 | else: |
72 | 78 | id = self._id |
73 | 79 | is_room = \ |
@@ -99,13 +105,19 @@ async def join(self, client: Client, wait: Optional[float] = 60.0): |
99 | 105 | self._client = client |
100 | 106 |
|
101 | 107 | if isinstance(self._id, str): |
102 | | - code = self._id |
103 | | - id = await client.query(code, scope=self._scope) |
104 | | - if not isinstance(id, int): |
105 | | - raise TypeError( |
106 | | - f'expecting ThingsDB code `{code}` to return with a ' |
107 | | - f'room Id (integer value), ' |
108 | | - f'but got type `{type(id).__name__}`') |
| 108 | + if is_name(self._id): |
| 109 | + id = await client.query( |
| 110 | + "room(name).id();", |
| 111 | + name=self._id, |
| 112 | + scope=self._scope) |
| 113 | + else: |
| 114 | + code = self._id |
| 115 | + id = await client.query(code, scope=self._scope) |
| 116 | + if not isinstance(id, int): |
| 117 | + raise TypeError( |
| 118 | + f'expecting ThingsDB code `{code}` to return with ' |
| 119 | + f'a room Id (integer value), ' |
| 120 | + f'but got type `{type(id).__name__}`') |
109 | 121 | res = await client._join(id, scope=self._scope) |
110 | 122 | if res[0] is None: |
111 | 123 | raise LookupError( |
|
0 commit comments