Fixes replies showing up twice in feed

This commit is contained in:
Mouse Reeve 2021-01-03 08:17:00 -08:00
parent 470c095678
commit 4d4b27e844

View file

@ -45,7 +45,8 @@ def is_api_request(request):
def is_bookworm_request(request): def is_bookworm_request(request):
''' check if the request is coming from another bookworm instance ''' ''' check if the request is coming from another bookworm instance '''
user_agent = request.headers.get('User-Agent') user_agent = request.headers.get('User-Agent')
if user_agent is None or re.search(regex.bookwyrm_user_agent, user_agent) is None: if user_agent is None or \
re.search(regex.bookwyrm_user_agent, user_agent) is None:
return False return False
return True return True
@ -180,7 +181,7 @@ def get_activity_feed(user, filter_level, model=models.Status):
return activities.filter( return activities.filter(
Q(user=user) | Q(mention_users=user), Q(user=user) | Q(mention_users=user),
privacy='direct' privacy='direct'
) ).distinct()
# never show DMs in the regular feed # never show DMs in the regular feed
activities = activities.filter(~Q(privacy='direct')) activities = activities.filter(~Q(privacy='direct'))
@ -195,7 +196,7 @@ def get_activity_feed(user, filter_level, model=models.Status):
Q(user__in=following, privacy__in=[ Q(user__in=following, privacy__in=[
'public', 'unlisted', 'followers' 'public', 'unlisted', 'followers'
]) | Q(mention_users=user) | Q(user=user) ]) | Q(mention_users=user) | Q(user=user)
) ).distinct()
elif filter_level == 'self': elif filter_level == 'self':
activities = activities.filter(user=user, privacy='public') activities = activities.filter(user=user, privacy='public')
elif filter_level == 'local': elif filter_level == 'local':
@ -512,7 +513,8 @@ def status_page(request, username, status_id):
return HttpResponseNotFound() return HttpResponseNotFound()
if is_api_request(request): if is_api_request(request):
return ActivitypubResponse(status.to_activity(pure=not is_bookworm_request(request))) return ActivitypubResponse(
status.to_activity(pure=not is_bookworm_request(request)))
data = { data = {
'title': 'Status by %s' % user.username, 'title': 'Status by %s' % user.username,