Skip to content

Commit

Permalink
Fix some logs and only tag rooms when creating
Browse files Browse the repository at this point in the history
  • Loading branch information
tulir committed Jun 1, 2023
1 parent 73b75fd commit 5241efb
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 29 deletions.
8 changes: 5 additions & 3 deletions mautrix_twitter/backfill.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ class NoFirstMessageException(BaseException):
pass


log = logging.getLogger("mau.backfill_loop")


class BackfillStatus(DBBackfillStatus):
recheck_queues: set[asyncio.Queue] = set()

Expand Down Expand Up @@ -70,12 +73,11 @@ async def backfill_loop(cls) -> None:
elif state.state == 0:
state.state = 1
except NoFirstMessageException:
logging.error("No first message found to do backfill!")
log.error(f"No first message found to do backfill for {state.twid}")
state.state = 0
except Exception:
# TODO: handle and log error, and be smarter about backfill loops
log.exception(f"Error handling backfill task for {state.twid}")
state.state = 3
logging.error(traceback.format_exc())
finally:
state.dispatched = False
await state.update()
14 changes: 7 additions & 7 deletions mautrix_twitter/portal.py
Original file line number Diff line number Diff line change
Expand Up @@ -928,7 +928,7 @@ async def _backfill(self, source: u.User, limit: int, is_initial: bool = False)
if first_message is not None:
max_id = first_message.twid
else:
self.log.warn("Can't backfill without a first bridged message!")
self.log.warning("Can't backfill without a first bridged message")
raise b.NoFirstMessageException()

mark_read, entries = await self._fetch_backfill_entries(source, limit, max_id)
Expand Down Expand Up @@ -1112,10 +1112,10 @@ async def _batch_handle_backfill(
if not self.bridge.homeserver_software.is_hungry:
before_first_message_timestamp = events[0].timestamp - 1
self.log.debug("Adding member state events to batch")
for u in users_in_batch:
puppet = await self.bridge.get_puppet(u)
for mxid in users_in_batch:
puppet = await p.Puppet.get_by_mxid(mxid)
if puppet is None:
self.log.warn("No puppet found for user %s while backfilling!", u)
self.log.warning(f"No puppet found for user {mxid} while backfilling")
continue
state_events_at_start.append(
BatchSendStateEvent(
Expand All @@ -1125,7 +1125,7 @@ async def _batch_handle_backfill(
),
sender=intent.mxid,
timestamp=before_first_message_timestamp,
state_key=u,
state_key=mxid,
)
)
state_events_at_start.append(
Expand All @@ -1134,9 +1134,9 @@ async def _batch_handle_backfill(
content=MemberStateEventContent(
Membership.JOIN, avatar_url=puppet.photo_mxc, displayname=puppet.name
),
sender=u,
sender=mxid,
timestamp=before_first_message_timestamp,
state_key=u,
state_key=mxid,
)
)

Expand Down
25 changes: 6 additions & 19 deletions mautrix_twitter/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -405,7 +405,7 @@ async def sync(self) -> None:
await self.handle_conversation_update(conversation, create_portal=create_portal)
except Exception:
self.log.exception(
"Error while syncing conversation %s!", conversation.conversation_id
"Error while syncing conversation %s", conversation.conversation_id
)
await self.update_direct_chats()

Expand Down Expand Up @@ -487,27 +487,14 @@ async def handle_conversation_update(
portal = await po.Portal.get_by_twid(
evt.conversation_id, receiver=self.twid, conv_type=evt.type
)
if not portal.mxid:
self.log.debug("Conversation %s doesn't have MXID!", evt.conversation_id)
if create_portal:
self.log.debug("Creating Matrix room...")
await portal.create_matrix_room(self, evt)
else:
if portal.mxid:
# We don't want to do the invite_user and such things each time conversation info
# comes down polling, so if the room already exists, only call .update_info()
await portal.update_info(evt)
puppet = await pu.Puppet.get_by_custom_mxid(self.mxid)
if puppet:
if self.config["bridge.low_quality_tag"]:
self.log.debug("Tagging room if low-quality")
await self.tag_room(
puppet,
portal,
self.config["bridge.low_quality_tag"],
evt.low_quality == True,
)
if self.config["bridge.low_quality_mute"] and evt.low_quality:
await self.set_muted(puppet, portal, True)
elif create_portal:
await portal.create_matrix_room(self, evt)
else:
self.log.debug(f"Ignoring conversation update for {evt.conversation_id}")

@async_time(METRIC_USER_UPDATE)
async def handle_user_update(self, user: TwitterUser) -> None:
Expand Down

0 comments on commit 5241efb

Please sign in to comment.