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