This commit is contained in:
Classic298 2026-11-05 06:49:45 +09:00 • committed by GitHub
commit e805243a39
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -942,14 +942,17 @@ class ChatTable:
) -> tuple[int, bool] | None:
try:
async with get_async_db_context(db) as session:
chat = await session.get(Chat, id)
if chat and chat.user_id == user_id:
last_read_at = int(time.time())
was_unread = chat.last_read_at is None or chat.updated_at > chat.last_read_at
chat.last_read_at = last_read_at
await session.commit()
return last_read_at, was_unread
return None
row = (
await session.execute(select(Chat.updated_at, Chat.last_read_at).filter_by(id=id, user_id=user_id))
).one_or_none()
if row is None:
return None
last_read_at = int(time.time())
was_unread = row.last_read_at is None or row.updated_at > row.last_read_at
await session.execute(update(Chat).filter_by(id=id).values(last_read_at=last_read_at))
await session.commit()
return last_read_at, was_unread
except Exception:
return None
@ -958,18 +961,23 @@ class ChatTable:
) -> ChatTitleIdResponse | None:
try:
async with get_async_db_context(db) as session:
chat = await session.get(Chat, id)
if chat and chat.user_id == user_id:
chat.last_read_at = 0
await session.commit()
return ChatTitleIdResponse(
id=chat.id,
title=chat.title,
updated_at=chat.updated_at,
created_at=chat.created_at,
last_read_at=chat.last_read_at,
row = (
await session.execute(
select(Chat.title, Chat.updated_at, Chat.created_at).filter_by(id=id, user_id=user_id)
)
return None
).one_or_none()
if row is None:
return None
await session.execute(update(Chat).filter_by(id=id).values(last_read_at=0))
await session.commit()
return ChatTitleIdResponse(
id=id,
title=row.title,
updated_at=row.updated_at,
created_at=row.created_at,
last_read_at=0,
)
except Exception:
return None
@ -2815,15 +2823,16 @@ class ChatTable:
) -> bool:
try:
async with get_async_db_context(db) as session:
chat = await session.get(Chat, id)
tags = chat.meta.get('tags', [])
row = (await session.execute(select(Chat.meta).filter_by(id=id))).one_or_none()
if row is None:
return False
meta = row[0]
tags = meta.get('tags', [])
tag_id = tag_name.replace(' ', '_').lower()
tags = [tag for tag in tags if tag != tag_id]
chat.meta = {
**chat.meta,
'tags': list(set(tags)),
}
await session.execute(update(Chat).filter_by(id=id).values(meta={**meta, 'tags': list(set(tags))}))
await session.commit()
return True
except Exception: