implemented follow notifications with profile redirection

This commit is contained in:
nvrl committed 2026-02-19 15:47:54 +01:00
1 parent e86baaddb7
commit 68a9e71d04
5 files changed
+48 -17

No files matched your search

+1
View File
@@ -128,6 +128,7 @@ class Notification(models.Model):
TYPE_CHOICES = [
('reply', 'Reply'),
('mention', 'Mention'),
('follow', 'Follow'),
('ticket_new', 'New Ticket'),
('ticket_reply', 'Ticket Reply'),
('profile_comment', 'Profile Comment'),
+10 -1
View File
@@ -553,7 +553,16 @@ class UserViewSet(viewsets.ModelViewSet):
user_to_follow = self.get_object()
if user_to_follow == request.user:
return Response({'error': 'You cannot follow yourself'}, status=status.HTTP_400_BAD_REQUEST)
request.user.following.add(user_to_follow)
if not request.user.following.filter(pk=user_to_follow.pk).exists():
request.user.following.add(user_to_follow)
# Notify the user being followed
Notification.objects.create(
recipient=user_to_follow,
actor=request.user,
notification_type='follow'
)
return Response({'status': 'followed'})
@action(detail=True, methods=['post'], permission_classes=[permissions.IsAuthenticated])
+4
View File
@@ -512,6 +512,9 @@ const App: React.FC = () => {
} else if (n.notification_type === 'profile_comment') {
handleNotificationClick(n);
navigate(`/profile/${user?.username}`);
} else if (n.notification_type === 'follow') {
handleNotificationClick(n);
navigate(`/profile/${n.actor_username}`);
} else {
handleNotificationClick(n);
}
@@ -541,6 +544,7 @@ const App: React.FC = () => {
<strong>{n.actor_username}</strong> {
n.notification_type === 'reply' ? `replied to your review on ${n.flavor_name}` :
n.notification_type === 'mention' ? `mentioned you on ${n.flavor_name}` :
n.notification_type === 'follow' ? t('community.notifFollow') :
n.notification_type === 'profile_comment' ? `left a message on your guestbook` :
n.notification_type === 'ticket_new' ? t('community.notifTicketNew') :
user?.is_superuser ? t('community.notifTicketReplyAdmin') : t('community.notifTicketReply')
+2
View File
@@ -141,6 +141,7 @@ const resources = {
"notifications": "Recent Notifications",
"notifReply": "replied",
"notifMention": "mentioned you",
"notifFollow": "started following you",
"notifTicketNew": "opened a new support ticket",
"notifTicketReply": "replied to your support ticket",
"notifTicketReplyAdmin": "replied to a support ticket",
@@ -381,6 +382,7 @@ const resources = {
"notifications": "Neueste Benachrichtigungen",
"notifReply": "hat geantwortet",
"notifMention": "hat dich erwähnt",
"notifFollow": "folgt dir jetzt",
"notifTicketNew": "hat ein neues Support-Ticket eröffnet",
"notifTicketReply": "hat auf dein Support-Ticket geantwortet",
"notifTicketReplyAdmin": "hat auf ein Support-Ticket geantwortet",
+31 -16
View File
@@ -385,22 +385,37 @@ const CommunityFeed: React.FC<CommunityFeedProps> = ({ adminMode }) => {
{notifications.length === 0 ? (
<Box sx={{ p: 3, textAlign: 'center' }}><Typography variant="body2" color="text.secondary">{t('community.noNotifications')}</Typography></Box>
) : (
notifications.map(n => (
<ListItemButton key={n.id} onClick={() => n.flavor_id && navigate(`/flavor/${n.flavor_id}`)} sx={{ py: 1.5 }}>
<ListItemAvatar sx={{ minWidth: 40 }}>
<Avatar src={n.actor_avatar || undefined} sx={{ width: 30, height: 30, fontSize: '0.8rem' }}>{n.actor_username.charAt(0)}</Avatar>
</ListItemAvatar>
<ListItemText
primary={
<Typography variant="body2" sx={{ fontSize: '0.8rem' }}>
<strong>{n.actor_username}</strong> {n.notification_type === 'reply' ? t('community.notifReply') : t('community.notifMention')}
</Typography>
}
secondary={formatTimestamp(n.created_at)}
secondaryTypographyProps={{ sx: { fontSize: '0.7rem' } }}
/>
</ListItemButton>
))
notifications.map(n => {
const handleClick = () => {
if (n.notification_type === 'follow') {
navigate(`/profile/${n.actor_username}`);
} else if (n.flavor_id) {
navigate(`/flavor/${n.flavor_id}`);
}
};
return (
<ListItemButton key={n.id} onClick={handleClick} sx={{ py: 1.5 }}>
<ListItemAvatar sx={{ minWidth: 40 }}>
<Avatar src={n.actor_avatar || undefined} sx={{ width: 30, height: 30, fontSize: '0.8rem' }}>{n.actor_username.charAt(0)}</Avatar>
</ListItemAvatar>
<ListItemText
primary={
<Typography variant="body2" sx={{ fontSize: '0.8rem' }}>
<strong>{n.actor_username}</strong> {
n.notification_type === 'reply' ? t('community.notifReply') :
n.notification_type === 'mention' ? t('community.notifMention') :
n.notification_type === 'follow' ? t('community.notifFollow') :
n.notification_type
}
</Typography>
}
secondary={formatTimestamp(n.created_at)}
secondaryTypographyProps={{ sx: { fontSize: '0.7rem' } }}
/>
</ListItemButton>
);
})
)}
</List>
</Card>