Maybe actually fix time comparison

This commit is contained in:
Tulir Asokan
2022-10-12 22:09:23 +03:00
parent f2d0489488
commit fef03ddec0
+3 -3
View File
@@ -695,12 +695,12 @@ class User(DBUser, AbstractUser, BaseUser):
self.log.exception(f"Error while creating {portal.tgid_log}")
if portal.mxid and puppet and puppet.is_real_user:
tg_space = portal.tgid if portal.peer_type == "channel" else self.tgid
last_message_date: datetime = cast(datetime, dialog.date)
last_message_date: float = cast(datetime, dialog.date).timestamp()
unread_threshold_hours = self.config["bridge.backfill.unread_hours_threshold"]
force_read = (
was_created
and unread_threshold_hours >= 0
and last_message_date + timedelta(hours=unread_threshold_hours) < datetime.utcnow()
and last_message_date + (unread_threshold_hours * 60 * 60) < time.time()
)
if dialog.unread_count == 0 or force_read:
# This is usually more reliable than finding a specific message
@@ -709,7 +709,7 @@ class User(DBUser, AbstractUser, BaseUser):
if force_read:
self.log.debug(
f"Marking {portal.tgid_log} as read because the last message is from "
f"{last_message_date} (unread threshold is {unread_threshold_hours} hours)"
f"{dialog.date} (unread threshold is {unread_threshold_hours} hours)"
)
else:
last_read = await DBMessage.get_one_by_tgid(