Browse Source

Implement get_bridge_states

Tulir Asokan 3 years ago
parent
commit
4ea831536f
2 changed files with 12 additions and 2 deletions
  1. 11 1
      mautrix_signal/user.py
  2. 1 1
      requirements.txt

+ 11 - 1
mautrix_signal/user.py

@@ -13,7 +13,7 @@
 #
 # You should have received a copy of the GNU Affero General Public License
 # along with this program.  If not, see <https://www.gnu.org/licenses/>.
-from typing import Union, Dict, Optional, AsyncGenerator, TYPE_CHECKING, cast
+from typing import Union, Dict, Optional, AsyncGenerator, List, TYPE_CHECKING, cast
 from uuid import UUID
 import asyncio
 
@@ -109,6 +109,16 @@ class User(DBUser, BaseUser):
             puppet = await self.get_puppet()
             state.remote_name = puppet.name or self.username
 
+    async def get_bridge_states(self) -> List[BridgeState]:
+        if not self.username:
+            return []
+        state = BridgeState(state_event=BridgeStateEvent.UNKNOWN_ERROR)
+        if self.bridge.signal.is_connected and self._connected:
+            state.state_event = BridgeStateEvent.CONNECTED
+        else:
+            state.state_event = BridgeStateEvent.TRANSIENT_DISCONNECT
+        return [state]
+
     async def get_puppet(self) -> Optional['pu.Puppet']:
         if not self.address:
             return None

+ 1 - 1
requirements.txt

@@ -4,5 +4,5 @@ commonmark>=0.8,<0.10
 aiohttp>=3,<4
 yarl>=1,<2
 attrs>=19.1
-mautrix>=0.10.4,<0.11
+mautrix>=0.10.5,<0.11
 asyncpg>=0.20,<0.25