This commit is contained in:
@@ -122,9 +122,9 @@ def get_notifications_grouped(
|
||||
if (groups_amount + offset) >= limit:
|
||||
break
|
||||
|
||||
payload = json.loads(notification.payload)
|
||||
payload = json.loads(notification.payload.scalar())
|
||||
|
||||
if notification.entity == NotificationEntity.SHOUT.value:
|
||||
if notification.entity.scalar() == NotificationEntity.SHOUT.value:
|
||||
shout = payload
|
||||
shout_id = shout.get('id')
|
||||
author_id = shout.get('created_by')
|
||||
@@ -139,68 +139,71 @@ def get_notifications_grouped(
|
||||
thread_id,
|
||||
shout=shout,
|
||||
authors=[author],
|
||||
action=notification.action,
|
||||
entity=notification.entity,
|
||||
action=notification.action.scalar(),
|
||||
entity=notification.entity.scalar(),
|
||||
)
|
||||
groups_by_thread[thread_id] = group
|
||||
groups_amount += 1
|
||||
|
||||
elif notification.entity == NotificationEntity.REACTION.value:
|
||||
elif notification.entity.scalar() == NotificationEntity.REACTION.value:
|
||||
reaction = payload
|
||||
if not isinstance(shout, dict):
|
||||
raise ValueError('reaction data is not consistent')
|
||||
shout_id = shout.get('shout')
|
||||
author_id = shout.get('created_by')
|
||||
with local_session() as session:
|
||||
author = session.query(Author).filter(Author.id == author_id).first()
|
||||
shout = session.query(Shout).filter(Shout.id == shout_id).first()
|
||||
if shout and author:
|
||||
author = author.dict()
|
||||
shout = shout.dict()
|
||||
reply_id = reaction.get('reply_to')
|
||||
thread_id = f'shout-{shout_id}'
|
||||
if reply_id and reaction.get('kind', '').lower() == 'comment':
|
||||
thread_id += f'{reply_id}'
|
||||
existing_group = groups_by_thread.get(thread_id)
|
||||
if existing_group:
|
||||
existing_group['seen'] = False
|
||||
existing_group['authors'].append(author_id)
|
||||
existing_group['reactions'] = existing_group['reactions'] or []
|
||||
existing_group['reactions'].append(reaction)
|
||||
groups_by_thread[thread_id] = existing_group
|
||||
else:
|
||||
group = group_notification(
|
||||
thread_id,
|
||||
authors=[author],
|
||||
shout=shout,
|
||||
reactions=[reaction],
|
||||
entity=notification.entity,
|
||||
action=notification.action,
|
||||
)
|
||||
if group:
|
||||
groups_by_thread[thread_id] = group
|
||||
groups_amount += 1
|
||||
author_id = shout.get('created_by', 0)
|
||||
if shout_id and author_id:
|
||||
with local_session() as session:
|
||||
author = session.query(Author).filter(Author.id == author_id).first()
|
||||
shout = session.query(Shout).filter(Shout.id == shout_id).first()
|
||||
if shout and author:
|
||||
author = author.dict()
|
||||
shout = shout.dict()
|
||||
reply_id = reaction.get('reply_to')
|
||||
thread_id = f'shout-{shout_id}'
|
||||
if reply_id and reaction.get('kind', '').lower() == 'comment':
|
||||
thread_id += f'{reply_id}'
|
||||
existing_group = groups_by_thread.get(thread_id)
|
||||
if existing_group:
|
||||
existing_group['seen'] = False
|
||||
existing_group['authors'].append(author_id)
|
||||
existing_group['reactions'] = existing_group['reactions'] or []
|
||||
existing_group['reactions'].append(reaction)
|
||||
groups_by_thread[thread_id] = existing_group
|
||||
else:
|
||||
group = group_notification(
|
||||
thread_id,
|
||||
authors=[author],
|
||||
shout=shout,
|
||||
reactions=[reaction],
|
||||
entity=notification.entity.scalar(),
|
||||
action=notification.action.scalar(),
|
||||
)
|
||||
if group:
|
||||
groups_by_thread[thread_id] = group
|
||||
groups_amount += 1
|
||||
|
||||
elif notification.entity == 'follower':
|
||||
thread_id = 'followers'
|
||||
follower = json.loads(payload)
|
||||
group = groups_by_thread.get(thread_id)
|
||||
if group:
|
||||
if notification.action == 'follow':
|
||||
group['authors'].append(follower)
|
||||
elif notification.action == 'unfollow':
|
||||
follower_id = follower.get('id')
|
||||
for author in group['authors']:
|
||||
if author.get('id') == follower_id:
|
||||
group['authors'].remove(author)
|
||||
break
|
||||
else:
|
||||
group = group_notification(
|
||||
thread_id,
|
||||
authors=[follower],
|
||||
entity=notification.entity,
|
||||
action=notification.action,
|
||||
)
|
||||
groups_amount += 1
|
||||
groups_by_thread[thread_id] = group
|
||||
elif notification.entity.scalar() == 'follower':
|
||||
thread_id = 'followers'
|
||||
follower = json.loads(payload)
|
||||
group = groups_by_thread.get(thread_id)
|
||||
if group:
|
||||
if notification.action.scalar() == 'follow':
|
||||
group['authors'].append(follower)
|
||||
elif notification.action.scalar() == 'unfollow':
|
||||
follower_id = follower.get('id')
|
||||
for author in group['authors']:
|
||||
if author.get('id') == follower_id:
|
||||
group['authors'].remove(author)
|
||||
break
|
||||
else:
|
||||
group = group_notification(
|
||||
thread_id,
|
||||
authors=[follower],
|
||||
entity=notification.entity.scalar(),
|
||||
action=notification.action.scalar(),
|
||||
)
|
||||
groups_amount += 1
|
||||
groups_by_thread[thread_id] = group
|
||||
return groups_by_thread, unread, total
|
||||
|
||||
|
||||
@@ -302,11 +305,11 @@ async def notifications_seen_thread(_, info, thread: str, after: int):
|
||||
)
|
||||
exclude = set()
|
||||
for nr in removed_reaction_notifications:
|
||||
reaction = json.loads(nr.payload)
|
||||
reaction = json.loads(nr.payload.scalar())
|
||||
reaction_id = reaction.get('id')
|
||||
exclude.add(reaction_id)
|
||||
for n in new_reaction_notifications:
|
||||
reaction = json.loads(n.payload)
|
||||
reaction = json.loads(n.payload.scalar())
|
||||
reaction_id = reaction.get('id')
|
||||
if (
|
||||
reaction_id not in exclude
|
||||
|
@@ -338,7 +338,7 @@ async def load_shouts_unrated(_, info, limit: int = 50, offset: int = 0):
|
||||
q = add_reaction_stat_columns(q, aliased_reaction)
|
||||
|
||||
q = q.group_by(Shout.id).order_by(func.random()).limit(limit).offset(offset)
|
||||
user_id = info.context.get('user_id') if isinstance(info.context, {}) else None
|
||||
user_id = info.context.get('user_id') if isinstance(info.context, dict) else None
|
||||
if user_id:
|
||||
with local_session() as session:
|
||||
author = session.query(Author).filter(Author.user == user_id).first()
|
||||
|
Reference in New Issue
Block a user