Fix olm instnciation ordering
This commit is contained in:
parent
7ece0b2222
commit
e393b0b084
1 changed files with 6 additions and 3 deletions
|
|
@ -49,6 +49,7 @@ class PickleCryptoStore(MemoryCryptoStore):
|
||||||
def __init__(self, filepath: str, account_id: str = "bot", pickle_key: str = ""):
|
def __init__(self, filepath: str, account_id: str = "bot", pickle_key: str = ""):
|
||||||
super().__init__(account_id=account_id, pickle_key=pickle_key)
|
super().__init__(account_id=account_id, pickle_key=pickle_key)
|
||||||
self.filepath = filepath
|
self.filepath = filepath
|
||||||
|
self.account = None # Ensure attribute always exists
|
||||||
self.load()
|
self.load()
|
||||||
|
|
||||||
def load(self):
|
def load(self):
|
||||||
|
|
@ -410,7 +411,6 @@ async def main():
|
||||||
crypto_store = PickleCryptoStore(CRYPTO_STORE_FILE, account_id=client.mxid)
|
crypto_store = PickleCryptoStore(CRYPTO_STORE_FILE, account_id=client.mxid)
|
||||||
|
|
||||||
client.state_store = state_store
|
client.state_store = state_store
|
||||||
client.crypto = OlmMachine(client, crypto_store, state_store)
|
|
||||||
|
|
||||||
# Authenticate if access token is missing
|
# Authenticate if access token is missing
|
||||||
if not client.api.token:
|
if not client.api.token:
|
||||||
|
|
@ -430,13 +430,16 @@ async def main():
|
||||||
"device_id": client.device_id
|
"device_id": client.device_id
|
||||||
}, f)
|
}, f)
|
||||||
|
|
||||||
# Ensure an Olm crypto account exists in the store
|
# Ensure an Olm crypto account exists in the store BEFORE initializing OlmMachine
|
||||||
account = await crypto_store.get_account()
|
account = await crypto_store.get_account()
|
||||||
if not account:
|
if not account:
|
||||||
log.info("Creating new Olm account...")
|
log.info("Creating new Olm account...")
|
||||||
account = OlmAccount()
|
account = OlmAccount()
|
||||||
await crypto_store.put_account(account)
|
await crypto_store.put_account(account)
|
||||||
|
|
||||||
|
# Initialize OlmMachine after the account is guaranteed to exist
|
||||||
|
client.crypto = OlmMachine(client, crypto_store, state_store)
|
||||||
|
|
||||||
# Register Event Handlers
|
# Register Event Handlers
|
||||||
client.add_event_handler(EventType.ROOM_MEMBER, on_invite)
|
client.add_event_handler(EventType.ROOM_MEMBER, on_invite)
|
||||||
client.add_event_handler(EventType.ROOM_MESSAGE, on_message)
|
client.add_event_handler(EventType.ROOM_MESSAGE, on_message)
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue