Skip to content

Commit

Permalink
Fix not getting notified on replies
Browse files Browse the repository at this point in the history
- if the magazine was not on default (e.g.: on loud) and you had "notify on replies" enabled it didn't work -> fix that
- rename some variables for readability
- add log statement with all the variables
  • Loading branch information
BentiGorlich committed Jan 7, 2025
1 parent 8e70e81 commit 1d6efed
Showing 1 changed file with 23 additions and 8 deletions.
31 changes: 23 additions & 8 deletions src/Repository/NotificationSettingsRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ public function findNotificationSubscribersByTarget(Entry|EntryComment|Post|Post
if ($target instanceof Entry) {
$targetId = $target->getId();
$notifyCol = 'notify_on_new_entry';
$activateMagazineNotifications = true;
$isMagazineLevel = true;
$dontNeedSubscription = false;
$dontNeedToBeAuthor = true;
$targetParentUserId = null;
Expand All @@ -99,7 +99,7 @@ public function findNotificationSubscribersByTarget(Entry|EntryComment|Post|Post
$notifyCol = 'notify_on_new_entry_comment_reply';
$targetParentUserId = $target->parent->user->getId();
}
$activateMagazineNotifications = false;
$isMagazineLevel = false;
$dontNeedSubscription = true;
$dontNeedToBeAuthor = false;
}
Expand All @@ -108,7 +108,7 @@ public function findNotificationSubscribersByTarget(Entry|EntryComment|Post|Post
if ($target instanceof Post) {
$targetId = $target->getId();
$notifyCol = 'notify_on_new_post';
$activateMagazineNotifications = true;
$isMagazineLevel = true;
$dontNeedSubscription = false;
$dontNeedToBeAuthor = true;
$targetParentUserId = null;
Expand All @@ -121,13 +121,14 @@ public function findNotificationSubscribersByTarget(Entry|EntryComment|Post|Post
$notifyCol = 'notify_on_new_post_comment_reply';
$targetParentUserId = $target->parent->user->getId();
}
$activateMagazineNotifications = false;
$isMagazineLevel = false;
$dontNeedSubscription = true;
$dontNeedToBeAuthor = false;
}
}

$activateMagazineNotificationsString = $activateMagazineNotifications ? 'true' : 'false';
$isMagazineLevelString = $isMagazineLevel ? 'true' : 'false';
$isNotMagazineLevelString = !$isMagazineLevel ? 'true' : 'false';
$dontNeedSubscriptionString = $dontNeedSubscription ? 'true' : 'false';
$dontNeedToBeAuthorString = $dontNeedToBeAuthor ? 'true' : 'false';

Expand All @@ -149,12 +150,16 @@ public function findNotificationSubscribersByTarget(Entry|EntryComment|Post|Post
AND COALESCE(ns_post.notification_status, :normal) = :normal
AND COALESCE(ns_mag.notification_status, :normal) = :loud
-- deactivate loud magazine notifications for comments
AND $activateMagazineNotificationsString
AND $isMagazineLevelString
)
OR (
COALESCE(ns_user.notification_status, :normal) = :normal
AND COALESCE(ns_post.notification_status, :normal) = :normal
AND COALESCE(ns_mag.notification_status, :normal) = :normal
AND (
-- ignore the magazine level settings for comments
COALESCE(ns_mag.notification_status, :normal) = :normal
OR $isNotMagazineLevelString
)
AND u.$notifyCol = true
AND (
-- deactivate magazine subscription need for comments
Expand All @@ -181,7 +186,17 @@ public function findNotificationSubscribersByTarget(Entry|EntryComment|Post|Post
'targetParentUserId' => $targetParentUserId,
]);
$rows = $result->fetchAllAssociative();
$this->logger->debug('got subscribers for target {c} id {id}: {subs}', ['c' => \get_class($target), 'id' => $target->getId(), 'subs' => $rows]);
$this->logger->debug('got subscribers for target {c} id {id}: {subs}, (magLevel: {ml}, notMagLevel: {nml}, targetCol: {tc}, notifyCol: {nc}, dontNeedSubs: {dns}, doneNeedAuthor: {dna})', [
'c' => \get_class($target),
'id' => $target->getId(),
'subs' => $rows,
'ml' => $isMagazineLevelString,
'nml' => $isNotMagazineLevelString,
'tc' => $targetCol,
'nc' => $notifyCol,
'dns' => $dontNeedSubscriptionString,
'dna' => $dontNeedToBeAuthorString,
]);

return array_map(fn (array $row) => $row['id'], $rows);
}
Expand Down

0 comments on commit 1d6efed

Please sign in to comment.