Skip to content

Commit 07860a3

Browse files
committed
fixed: comment on answer notified comment owner
1 parent 1a1fc27 commit 07860a3

File tree

2 files changed

+22
-7
lines changed

2 files changed

+22
-7
lines changed

classes/ColdTrick/Questions/Notifications.php

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,12 @@ public static function addQuestionOwnerToCommentSubscribers(\Elgg\Hook $hook) {
8383

8484
/* @var $owner \ElggUser */
8585
$owner = $question->getOwnerEntity();
86+
if ($object->owner_guid === $owner->guid) {
87+
// don't add question owner if it's the comment owner
88+
return;
89+
}
8690

87-
$filtered_methods = array_keys(array_filter($owner->getNotificationSettings()));
91+
$filtered_methods = array_keys(array_filter($owner->getNotificationSettings('create_comment')));
8892
if (empty($filtered_methods)) {
8993
return;
9094
}
@@ -109,17 +113,17 @@ public static function addQuestionSubscribersToCommentSubscribers(\Elgg\Hook $ho
109113
return;
110114
}
111115

112-
$object = $event->getObject();
113-
if (!$object instanceof \ElggComment) {
116+
$comment = $event->getObject();
117+
if (!$comment instanceof \ElggComment) {
114118
return;
115119
}
116120

117-
$container = $object->getContainerEntity();
118-
if (!$container instanceof \ElggAnswer) {
121+
$answer = $comment->getContainerEntity();
122+
if (!$answer instanceof \ElggAnswer) {
119123
return;
120124
}
121125

122-
$question = $container->getContainerEntity();
126+
$question = $answer->getContainerEntity();
123127
if (!$question instanceof \ElggQuestion) {
124128
// something went wrong, maybe access
125129
return;
@@ -130,6 +134,11 @@ public static function addQuestionSubscribersToCommentSubscribers(\Elgg\Hook $ho
130134
return;
131135
}
132136

137+
if (isset($subscribers[$comment->owner_guid])) {
138+
// remove the comment owner from the subscribers
139+
unset($subscribers[$comment->owner_guid]);
140+
}
141+
133142
return ($hook->getValue() + $subscribers);
134143
}
135144
}

classes/ColdTrick/Questions/Notifications/Subscriptions.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@ public static function createAnswer(\Elgg\Event $event) {
2121
/* @var $owner \ElggUser */
2222
$owner = $object->getOwnerEntity();
2323
$question = $object->getContainerEntity();
24+
if (!$question instanceof \ElggQuestion) {
25+
return;
26+
}
2427

2528
if ($question->hasMutedNotifications($owner->guid)) {
2629
return;
@@ -57,7 +60,10 @@ public static function createCommentOnAnswer(\Elgg\Event $event) {
5760

5861
/* @var $owner \ElggUser */
5962
$owner = $object->getOwnerEntity();
60-
$question = $object->getContainerEntity();
63+
$question = $answer->getContainerEntity();
64+
if (!$question instanceof \ElggQuestion) {
65+
return;
66+
}
6167

6268
if ($question->hasMutedNotifications($owner->guid)) {
6369
return;

0 commit comments

Comments
 (0)