This commit is contained in:
Classic298 2026-11-05 06:44:53 +09:00 • committed by GitHub
commit 62410d7e2d
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 30 additions and 2 deletions

View file

@ -3,7 +3,7 @@ import time
import uuid
from typing import Optional
from open_webui.models.notifications import emit_changes
from open_webui.models.notifications import emit_changes, mark_resource_notifications_read
from open_webui.internal.db import Base, JSONField, get_async_db_context
from open_webui.models.access_grants import (
AccessGrantModel,
@ -705,7 +705,12 @@ class ChannelTable:
membership.last_read_at = int(time.time_ns())
membership.updated_at = int(time.time_ns())
changed = await mark_resource_notifications_read(
user_id=user_id, resource_type='channel', resource_id=channel_id, db=db
)
await db.commit()
if changed:
await emit_changes({user_id})
return True
async def update_member_active_status(

View file

@ -6,7 +6,7 @@ from uuid import uuid4
from open_webui.internal.db import Base
from pydantic import BaseModel, ConfigDict, Field
from sqlalchemy import JSON, BigInteger, CheckConstraint, Column, Index, Text, UniqueConstraint, delete, update
from sqlalchemy import JSON, BigInteger, CheckConstraint, Column, Index, Text, UniqueConstraint, delete, func, update
log = logging.getLogger(__name__)
@ -157,6 +157,25 @@ async def delete_notifications(*, resource_type=None, resource_ids=None, object_
return set(recipients)
async def mark_resource_notifications_read(*, user_id: str, resource_type: str, resource_id: str, db) -> bool:
now = time.time_ns()
result = await db.execute(
update(Notification)
.where(
Notification.user_id == user_id,
Notification.resource_type == resource_type,
Notification.resource_id == resource_id,
Notification.read_at.is_(None),
)
.values(
seen_at=func.coalesce(Notification.seen_at, now),
read_at=now,
updated_at=now,
)
)
return result.rowcount > 0
async def delete_user_notifications(user_id, db):
await db.execute(delete(Notification).where(Notification.user_id == user_id))
await db.execute(update(Notification).where(Notification.actor_id == user_id).values(actor_id=None))

View file

@ -212,6 +212,10 @@
const data = event?.data?.data ?? null;
if (type === 'message') {
if (document.visibilityState === 'visible') {
updateLastReadAt(id);
}
if ((data?.parent_id ?? null) === null) {
const idx = (messages ?? []).findIndex(
(message) =>