Fixed indentation (w). Probably fixed redactions sometimes displaying viewing user's name in place of actor's name. Fixed room history never loading sometimes (but not missing chunks in the middle yet).

This commit is contained in:
Zergling_man 2023-10-27 20:25:20 +11:00
parent bc20e47fb1
commit b6543b09cc
29 changed files with 7158 additions and 7155 deletions

View File

@ -1107,26 +1107,24 @@ class MatrixClient(nio.AsyncClient):
Returns whether there are any messages left to load. Returns whether there are any messages left to load.
""" """
log.info("loading events for %s",room_id)
if room_id in self.fully_loaded_rooms or \ if room_id in self.fully_loaded_rooms or \
room_id in self.invited_rooms or \ room_id in self.invited_rooms or \
room_id in self.cleared_events_rooms or \ room_id in self.cleared_events_rooms or \
self.models[self.user_id, "rooms"][room_id].left: self.models[self.user_id, "rooms"][room_id].left:
return False return False
log.info("waiting for first sync %s",room_id)
await self.first_sync_done.wait() await self.first_sync_done.wait()
log.info("waiting for past token %s",room_id)
while not self.past_tokens.get(room_id): i=0
while i<100 and not self.past_tokens.get(room_id):
# If a new room was added, wait for onSyncResponse to set the token # If a new room was added, wait for onSyncResponse to set the token
await asyncio.sleep(0.1) await asyncio.sleep(0.1)
i+=1 # Give up waiting after 10 seconds and just fetch from newest instead. This fixes a bug where initial sync occasionally inserts None into the batch for some reason - I'm blaming nio currently. Also fixes a bug where the room just straight up doesn't seem to exist in initial sync, but somehow still ends up in room list.
response = await self.room_messages( log.info("performing actual fetch %s",room_id)
room_id = room_id, args={"room_id":room_id,"limit":100 if room_id in self.loaded_once_rooms else 10,"message_filter":self.lazy_load_filter,"start":self.past_tokens.get(room_id)}
start = self.past_tokens[room_id], response = await self.room_messages(**args)
limit = 100 if room_id in self.loaded_once_rooms else 10, log.info("data returned %s",room_id)
message_filter = self.lazy_load_filter,
)
self.loaded_once_rooms.add(room_id) self.loaded_once_rooms.add(room_id)
more_to_load = True more_to_load = True
@ -1575,6 +1573,9 @@ class MatrixClient(nio.AsyncClient):
resp = await self.get_presence(user_id) resp = await self.get_presence(user_id)
except (MatrixForbidden, MatrixUnrecognized): except (MatrixForbidden, MatrixUnrecognized):
return return
except MatrixError as e:
if e.http_code==500: return # Probably conduit which hasn't implemented it yet
else: raise
await self.nio_callbacks.onPresenceEvent(nio.PresenceEvent( await self.nio_callbacks.onPresenceEvent(nio.PresenceEvent(
user_id = resp.user_id, user_id = resp.user_id,
@ -1843,7 +1844,7 @@ class MatrixClient(nio.AsyncClient):
auth = { auth = {
"type": "m.login.password", "type": "m.login.password",
"user": self.user_id, "identifier": {"type":"m.id.user", "user":self.user_id},
"password": password, "password": password,
} }
@ -2317,7 +2318,7 @@ class MatrixClient(nio.AsyncClient):
ev.set_fields(target_name=target_name, target_avatar=target_avatar) ev.set_fields(target_name=target_name, target_avatar=target_avatar)
if ev.redacter_id and not ev.redacter_name: if ev.redacter_id and not ev.redacter_name:
redacter_name, _, _ = await get_profile(ev.target_id) redacter_name, _, _ = await get_profile(ev.redacter_id)
ev.redacter_name = redacter_name ev.redacter_name = redacter_name
ev.fetch_profile = False ev.fetch_profile = False

View File

@ -82,9 +82,11 @@ class NioCallbacks:
await self.client.register_nio_room(self.client.all_rooms[room_id]) await self.client.register_nio_room(self.client.all_rooms[room_id])
for room_id, info in resp.rooms.join.items(): for room_id, info in resp.rooms.join.items():
log.info("%s %a",room_id,room_id in self.client.past_tokens)
await self.client.register_nio_room(self.client.rooms[room_id]) await self.client.register_nio_room(self.client.rooms[room_id])
if room_id not in self.client.past_tokens: if room_id not in self.client.past_tokens:
log.info("adding %s to %s's past_tokens", info.timeline.prev_batch,room_id)
self.client.past_tokens[room_id] = info.timeline.prev_batch self.client.past_tokens[room_id] = info.timeline.prev_batch
for ev in info.state: for ev in info.state: