Skip to content

Commit

Permalink
Update follow_unfollow.py
Browse files Browse the repository at this point in the history
  • Loading branch information
oktayozel authored Nov 19, 2024
1 parent f59bb45 commit ee8dbba
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion backend/app/views_directory/follow_unfollow.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from django.shortcuts import get_object_or_404
from django.http import JsonResponse
from app.models import Profile
from app.models import Profile, ActivityStream
from rest_framework.decorators import api_view, permission_classes
from rest_framework.permissions import IsAuthenticated

Expand All @@ -13,6 +13,15 @@ def follow_user(request):

if user_to_follow != current_user_profile:
current_user_profile.following.add(user_to_follow)

ActivityStream.objects.create(
actor=request.user,
verb="followed",
object_type="Profile",
object_id=user_to_follow.user.id,
target=None # Optional: could be used for specific contexts
)

return JsonResponse({"message": "Followed successfully"}, status=200)
return JsonResponse({"error": "Cannot follow yourself"}, status=400)

Expand Down

0 comments on commit ee8dbba

Please sign in to comment.