shout-following-upgrade
All checks were successful
Deploy on push / deploy (push) Successful in 5m59s
All checks were successful
Deploy on push / deploy (push) Successful in 5m59s
This commit is contained in:
@@ -16,7 +16,7 @@ from orm.notification import (
|
||||
NotificationEntity,
|
||||
NotificationSeen,
|
||||
)
|
||||
from orm.shout import Shout
|
||||
from orm.shout import Shout, ShoutReactionsFollower
|
||||
from services.auth import login_required
|
||||
from storage.db import local_session
|
||||
from storage.schema import mutation, query
|
||||
@@ -57,6 +57,37 @@ def query_notifications(author_id: int, after: int = 0) -> tuple[int, int, list[
|
||||
return total, unread, notifications
|
||||
|
||||
|
||||
def check_subscription(shout_id: int, current_author_id: int) -> bool:
|
||||
"""
|
||||
Проверяет подписку пользователя на уведомления о шауте.
|
||||
|
||||
Проверяет наличие записи в ShoutReactionsFollower:
|
||||
- Запись есть → подписан
|
||||
- Записи нет → не подписан (отписался или никогда не подписывался)
|
||||
|
||||
Автоматическая подписка (auto=True) создается при:
|
||||
- Создании поста
|
||||
- Первом комментарии/реакции
|
||||
|
||||
Отписка = удаление записи из таблицы
|
||||
|
||||
Returns:
|
||||
bool: True если подписан на уведомления
|
||||
"""
|
||||
with local_session() as session:
|
||||
# Проверяем наличие записи в ShoutReactionsFollower
|
||||
follow = (
|
||||
session.query(ShoutReactionsFollower)
|
||||
.filter(
|
||||
ShoutReactionsFollower.follower == current_author_id,
|
||||
ShoutReactionsFollower.shout == shout_id,
|
||||
)
|
||||
.first()
|
||||
)
|
||||
|
||||
return follow is not None
|
||||
|
||||
|
||||
def group_notification(
|
||||
thread: str,
|
||||
authors: list[Any] | None = None,
|
||||
@@ -118,15 +149,20 @@ def get_notifications_grouped(author_id: int, after: int = 0, limit: int = 10, o
|
||||
if str(notification.entity) == NotificationEntity.SHOUT.value:
|
||||
shout = payload
|
||||
shout_id = shout.get("id")
|
||||
author_id = shout.get("created_by")
|
||||
shout_author_id = shout.get("created_by")
|
||||
thread_id = f"shout-{shout_id}"
|
||||
|
||||
with local_session() as session:
|
||||
author = session.query(Author).where(Author.id == author_id).first()
|
||||
author = session.query(Author).where(Author.id == shout_author_id).first()
|
||||
shout = session.query(Shout).where(Shout.id == shout_id).first()
|
||||
if author and shout:
|
||||
# Проверяем подписку - если не подписан, пропускаем это уведомление
|
||||
if not check_subscription(shout_id, author_id):
|
||||
continue
|
||||
|
||||
author_dict = author.dict()
|
||||
shout_dict = shout.dict()
|
||||
|
||||
group = group_notification(
|
||||
thread_id,
|
||||
shout=shout_dict,
|
||||
@@ -164,6 +200,10 @@ def get_notifications_grouped(author_id: int, after: int = 0, limit: int = 10, o
|
||||
existing_group["reactions"].append(reaction)
|
||||
groups_by_thread[thread_id] = existing_group
|
||||
else:
|
||||
# Проверяем подписку - если не подписан, пропускаем это уведомление
|
||||
if not check_subscription(shout_id, author_id):
|
||||
continue
|
||||
|
||||
group = group_notification(
|
||||
thread_id,
|
||||
authors=[author_dict],
|
||||
|
||||
Reference in New Issue
Block a user