| @@ -60,9 +60,9 @@ | ||
| 60 | 60 | |
| 61 | 61 | $notificationContent = \sprintf( |
| 62 | 62 | /* translators: %1$s is the user name, %2$s is the feed title and %3$3s is the space title */ |
| 63 | 63 | __('%1$s posted %2$s in %3$s', 'fluent-community'), |
| 64 | - '<b class="fcom_nudn">' . esc_html($user->display_name) . '</b>', | |
| 64 | + '<b class="fcom_nudn">' . esc_html($user->getPublicDisplayName()) . '</b>', | |
| 65 | 65 | '<span class="fcom_nft">' . $feedTitle . '</span>', |
| 66 | 66 | '<b class="fcom_nst">' . esc_html($space->title) . '</b>' |
| 67 | 67 | ); |
| 68 | 68 | |
| @@ -100,9 +100,9 @@ | ||
| 100 | 100 | if ($existingNotification) { |
| 101 | 101 | $notificationContent = \sprintf( |
| 102 | 102 | /* translators: %1$s is the user name, %2$s is the like count & %3$s is the feed title */ |
| 103 | 103 | __('%1$s and %2$s other people reacted to your post %3$s', 'fluent-community'), |
| 104 | - '<b class="fcom_nudn">' . esc_html($user->display_name) . '</b>', | |
| 104 | + '<b class="fcom_nudn">' . esc_html($user->getPublicDisplayName()) . '</b>', | |
| 105 | 105 | '<b class="fcom_nrc">' . ($feed->reactions_count - 1) . '</b>', |
| 106 | 106 | '<span class="fcom_nft">' . $feedTitle . '</span>' |
| 107 | 107 | ); |
| 108 | 108 | |
| @@ -121,9 +121,9 @@ | ||
| 121 | 121 | |
| 122 | 122 | $notificationContent = \sprintf( |
| 123 | 123 | /* translators: %1$s is the user name, %2$s is the feed title */ |
| 124 | 124 | __('%1$s reacted to your post %2$s', 'fluent-community'), |
| 125 | - '<b class="fcom_nudn">' . esc_html($user->display_name) . '</b>', | |
| 125 | + '<b class="fcom_nudn">' . esc_html($user->getPublicDisplayName()) . '</b>', | |
| 126 | 126 | '<span class="fcom_nft">' . $feedTitle . '</span>' |
| 127 | 127 | ); |
| 128 | 128 | |
| 129 | 129 | $route = $feed->getJsRoute(); |
| @@ -154,9 +154,9 @@ | ||
| 154 | 154 | if ($comment->reactions_count > 1) { |
| 155 | 155 | $notificationContent = \sprintf( |
| 156 | 156 | /* translators: %1$s is the user name, %2$s is the like count & %3$s is the comment excerpt */ |
| 157 | 157 | __('%1$s and %2$s other people reacted to your comment %3$s', 'fluent-community'), |
| 158 | - '<b class="fcom_nudn">' . esc_html($user->display_name) . '</b>', | |
| 158 | + '<b class="fcom_nudn">' . esc_html($user->getPublicDisplayName()) . '</b>', | |
| 159 | 159 | '<b class="fcom_nrc">' . ($comment->reactions_count - 1) . '</b>', |
| 160 | 160 | '<span class="fcom_nft">' . $commentExcerpt . '</span>' |
| 161 | 161 | ); |
| 162 | 162 | } else { |
| @@ -162,9 +162,9 @@ | ||
| 162 | 162 | } else { |
| 163 | 163 | $notificationContent = \sprintf( |
| 164 | 164 | /* translators: %1$s is the user name, %2$s is the comment excerpt */ |
| 165 | 165 | __('%1$s reacted to your comment %2$s', 'fluent-community'), |
| 166 | - '<b class="fcom_nudn">' . esc_html($user->display_name) . '</b>', | |
| 166 | + '<b class="fcom_nudn">' . esc_html($user->getPublicDisplayName()) . '</b>', | |
| 167 | 167 | '<span class="fcom_nft">' . $commentExcerpt . '</span>' |
| 168 | 168 | ); |
| 169 | 169 | } |
| 170 | 170 | |
| @@ -202,10 +202,10 @@ | ||
| 202 | 202 | |
| 203 | 203 | $notificationContent = \sprintf( |
| 204 | 204 | /* translators: %1$s is the role name, %2$s is the space title */ |
| 205 | 205 | __('You have been added as %1$s in %2$s', 'fluent-community'), |
| 206 | - '<b>' . $pivot->role . '</b>', | |
| 207 | - '<b>' . $space->title . '</b>' | |
| 206 | + '<b>' . esc_html($pivot->role) . '</b>', | |
| 207 | + '<b>' . esc_html($space->title) . '</b>' | |
| 208 | 208 | ); |
| 209 | 209 | |
| 210 | 210 | $route = [ |
| 211 | 211 | 'name' => 'space_feeds', |
| @@ -233,14 +233,15 @@ | ||
| 233 | 233 | if ($comment->user_id == $authorId) { |
| 234 | 234 | return; |
| 235 | 235 | } |
| 236 | 236 | |
| 237 | - $mentionedUserIds = Arr::get($feed->meta, 'mentioned_user_ids', []); | |
| 237 | + // Skip a mentioned author here; notifyMentionedUsers() notifies them instead. | |
| 238 | + $mentionedUserIds = Arr::get($comment->meta, 'mentioned_user_ids', []); | |
| 238 | 239 | if (in_array($authorId, $mentionedUserIds)) { |
| 239 | 240 | return; |
| 240 | 241 | } |
| 241 | 242 | |
| 242 | - $commenter = '<b class="fcom_nudn">' . esc_html($comment->user->display_name) . '</b>'; | |
| 243 | + $commenter = '<b class="fcom_nudn">' . esc_html($comment->user->getPublicDisplayName()) . '</b>'; | |
| 243 | 244 | $feedTitle = $feed->getHumanExcerpt(60); |
| 244 | 245 | |
| 245 | 246 | $exist = null; |
| 246 | 247 | if ($feed->comments_count > 1) { |
| @@ -251,13 +252,12 @@ | ||
| 251 | 252 | $q->where('user_id', $authorId); |
| 252 | 253 | }) |
| 253 | 254 | ->first(); |
| 254 | 255 | |
| 255 | - $totalUsers = $feed->comments | |
| 256 | + $totalUsers = Comment::where('post_id', $feed->id) | |
| 256 | 257 | ->where('user_id', '!=', $authorId) |
| 257 | - ->pluck('user_id') | |
| 258 | - ->unique() | |
| 259 | - ->count(); | |
| 258 | + ->distinct() | |
| 259 | + ->count('user_id'); | |
| 260 | 260 | |
| 261 | 261 | if ($feed->space_id) { |
| 262 | 262 | if ($totalUsers > 1) { |
| 263 | 263 | $notificationContent = \sprintf( |
| @@ -265,9 +265,9 @@ | ||
| 265 | 265 | __('%1$s and %2$s other people commented on your post %3$s in %4$s', 'fluent-community'), |
| 266 | 266 | $commenter, |
| 267 | 267 | '<b class="fcom_nrc">' . ($totalUsers - 1) . '</b>', |
| 268 | 268 | '<span class="fcom_nft">' . $feedTitle . '</span>', |
| 269 | - '<b class="fcom_nst">' . $feed->space->title . '</b>' | |
| 269 | + '<b class="fcom_nst">' . esc_html($feed->space->title) . '</b>' | |
| 270 | 270 | ); |
| 271 | 271 | } else { |
| 272 | 272 | $notificationContent = \sprintf( |
| 273 | 273 | /* translators: %1$s is the user name, %2$s is the feed title and %3$s space title*/ |
| @@ -273,9 +273,9 @@ | ||
| 273 | 273 | /* translators: %1$s is the user name, %2$s is the feed title and %3$s space title*/ |
| 274 | 274 | __('%1$s commented on your post: %2$s in %3$s', 'fluent-community'), |
| 275 | 275 | $commenter, |
| 276 | 276 | '<span class="fcom_nft">' . $feedTitle . '</span>', |
| 277 | - '<b class="fcom_nst">' . $feed->space->title . '</b>' | |
| 277 | + '<b class="fcom_nst">' . esc_html($feed->space->title) . '</b>' | |
| 278 | 278 | ); |
| 279 | 279 | } |
| 280 | 280 | } else { |
| 281 | 281 | |
| @@ -302,9 +302,9 @@ | ||
| 302 | 302 | /* translators: %1$s is the commenter name, %2$s is the feed title & %3$s is the space title */ |
| 303 | 303 | __('%1$s commented on your post: %2$s in %3$s', 'fluent-community'), |
| 304 | 304 | $commenter, |
| 305 | 305 | '<span class="fcom_nft">' . $feedTitle . '</span>', |
| 306 | - '<b class="fcom_nst">' . $feed->space->title . '</b>' | |
| 306 | + '<b class="fcom_nst">' . esc_html($feed->space->title) . '</b>' | |
| 307 | 307 | ); |
| 308 | 308 | } else { |
| 309 | 309 | $notificationContent = \sprintf( |
| 310 | 310 | /* translators: %1$s is the commenter name & %2$s is the feed title */ |
| @@ -368,10 +368,17 @@ | ||
| 368 | 368 | } |
| 369 | 369 | |
| 370 | 370 | protected function commentNotificationToFeedCommenters($comment, $feed) |
| 371 | 371 | { |
| 372 | + $mentionedUserIds = Arr::get($comment->meta, 'mentioned_user_ids', []); | |
| 373 | + | |
| 374 | + // Notify mentioned users for both top-level comments and replies. | |
| 375 | + if ($mentionedUserIds) { | |
| 376 | + $this->notifyMentionedUsers($comment, $feed, $mentionedUserIds); | |
| 377 | + } | |
| 378 | + | |
| 372 | 379 | if ($comment->parent_id) { |
| 373 | - return $this->notifyForChildCommentReply($comment, $feed); | |
| 380 | + return $this->notifyForChildCommentReply($comment, $feed, $mentionedUserIds); | |
| 374 | 381 | } |
| 375 | 382 | |
| 376 | 383 | $userIds = Comment::whereNotIn('user_id', [$feed->user_id, $comment->user_id]) |
| 377 | 384 | ->where('post_id', $feed->id) |
| @@ -379,15 +386,13 @@ | ||
| 379 | 386 | ->distinct() |
| 380 | 387 | ->pluck('user_id') |
| 381 | 388 | ->toArray(); |
| 382 | 389 | |
| 383 | - $mentionedUserIds = Arr::get($comment->meta, 'mentioned_user_ids', []); | |
| 384 | - | |
| 385 | 390 | if (!$userIds && !$mentionedUserIds) { |
| 386 | 391 | return; |
| 387 | 392 | } |
| 388 | 393 | |
| 389 | - $commenter = '<b class="fcom_nudn">' . esc_html($comment->user->display_name) . '</b>'; | |
| 394 | + $commenter = '<b class="fcom_nudn">' . esc_html($comment->user->getPublicDisplayName()) . '</b>'; | |
| 390 | 395 | $feedTitle = '<span class="fcom_nft">' . $feed->getHumanExcerpt(60) . '</span>'; |
| 391 | 396 | |
| 392 | 397 | $route = $feed->getJsRoute(); |
| 393 | 398 | $space = $feed->space; |
| @@ -392,13 +397,12 @@ | ||
| 392 | 397 | $route = $feed->getJsRoute(); |
| 393 | 398 | $space = $feed->space; |
| 394 | 399 | |
| 395 | 400 | if ($feed->comments_count > 1) { |
| 396 | - $totalUsers = $feed->comments | |
| 401 | + $totalUsers = Comment::where('post_id', $feed->id) | |
| 397 | 402 | ->where('user_id', '!=', $comment->user_id) |
| 398 | - ->pluck('user_id') | |
| 399 | - ->unique() | |
| 400 | - ->count(); | |
| 403 | + ->distinct() | |
| 404 | + ->count('user_id'); | |
| 401 | 405 | |
| 402 | 406 | if ($feed->space_id) { |
| 403 | 407 | if ($totalUsers > 1) { |
| 404 | 408 | $notificationContent = \sprintf( |
| @@ -406,9 +410,9 @@ | ||
| 406 | 410 | __('%1$s and %2$s other people also commented on %3$s in %4$s', 'fluent-community'), |
| 407 | 411 | $commenter, |
| 408 | 412 | '<b class="fcom_nrc">' . ($totalUsers - 1) . '</b>', |
| 409 | 413 | $feedTitle, |
| 410 | - '<b class="fcom_nst">' . $feed->space->title . '</b>' | |
| 414 | + '<b class="fcom_nst">' . esc_html($feed->space->title) . '</b>' | |
| 411 | 415 | ); |
| 412 | 416 | } else { |
| 413 | 417 | $notificationContent = \sprintf( |
| 414 | 418 | /* translators: %1$s is the user name, %2$s is the feed title and %3$s space title*/ |
| @@ -414,9 +418,9 @@ | ||
| 414 | 418 | /* translators: %1$s is the user name, %2$s is the feed title and %3$s space title*/ |
| 415 | 419 | __('%1$s also commented on %2$s in %3$s', 'fluent-community'), |
| 416 | 420 | $commenter, |
| 417 | 421 | $feedTitle, |
| 418 | - '<b class="fcom_nst">' . $feed->space->title . '</b>' | |
| 422 | + '<b class="fcom_nst">' . esc_html($feed->space->title) . '</b>' | |
| 419 | 423 | ); |
| 420 | 424 | } |
| 421 | 425 | } else { |
| 422 | 426 | if ($totalUsers > 1) { |
| @@ -442,9 +446,9 @@ | ||
| 442 | 446 | /* translators: %1$s is the commenter name, %2$s is the feed title & %3$s is the space title */ |
| 443 | 447 | __('%1$s also commented on %2$s in %3$s', 'fluent-community'), |
| 444 | 448 | $commenter, |
| 445 | 449 | $feedTitle, |
| 446 | - '<b class="fcom_nst">' . $space->title . '</b>' | |
| 450 | + '<b class="fcom_nst">' . esc_html($space->title) . '</b>' | |
| 447 | 451 | ); |
| 448 | 452 | } else { |
| 449 | 453 | $notificationContent = \sprintf( |
| 450 | 454 | /* translators: %1$s is the commenter name & %2$s is the feed title */ |
| @@ -455,35 +459,8 @@ | ||
| 455 | 459 | } |
| 456 | 460 | } |
| 457 | 461 | |
| 458 | 462 | if ($mentionedUserIds) { |
| 459 | - $mentionNotification = Notification::create([ | |
| 460 | - 'feed_id' => $feed->id, | |
| 461 | - 'object_id' => $comment->id, | |
| 462 | - 'src_user_id' => $comment->user_id, | |
| 463 | - 'src_object_type' => 'comment', | |
| 464 | - 'action' => 'mention_added', | |
| 465 | - 'content' => \sprintf( | |
| 466 | - /* translators: %1$s is the commenter name & %2$s is the feed title */ | |
| 467 | - __('%1$s mentioned you in a comment at %2$s', 'fluent-community'), | |
| 468 | - $commenter, | |
| 469 | - $feedTitle, | |
| 470 | - ), | |
| 471 | - 'route' => $route, | |
| 472 | - ]); | |
| 473 | - | |
| 474 | - $mentionNotification->subscribe($mentionedUserIds); | |
| 475 | - | |
| 476 | - do_action('fluent_community/notification/comment/notifed_to_mentions', [ | |
| 477 | - 'user_ids' => $mentionedUserIds, | |
| 478 | - 'notification' => $mentionNotification, | |
| 479 | - 'key' => 'notifed_to_mentions', | |
| 480 | - 'comment' => $comment, | |
| 481 | - 'feed' => $feed | |
| 482 | - ]); | |
| 483 | - } | |
| 484 | - | |
| 485 | - if ($mentionedUserIds) { | |
| 486 | 463 | $userIds = array_values(array_diff($userIds, $mentionedUserIds)); |
| 487 | 464 | } |
| 488 | 465 | |
| 489 | 466 | if (!$userIds) { |
| @@ -549,10 +526,47 @@ | ||
| 549 | 526 | 'feed' => $feed |
| 550 | 527 | ]); |
| 551 | 528 | } |
| 552 | 529 | |
| 553 | - protected function notifyForChildCommentReply($comment, $feed) | |
| 530 | + protected function notifyMentionedUsers($comment, $feed, $mentionedUserIds) | |
| 554 | 531 | { |
| 532 | + if (!$mentionedUserIds) { | |
| 533 | + return; | |
| 534 | + } | |
| 535 | + | |
| 536 | + $commenter = '<b class="fcom_nudn">' . esc_html($comment->user->getPublicDisplayName()) . '</b>'; | |
| 537 | + $feedTitle = '<span class="fcom_nft">' . $feed->getHumanExcerpt(60) . '</span>'; | |
| 538 | + | |
| 539 | + $mentionNotification = Notification::create([ | |
| 540 | + 'feed_id' => $feed->id, | |
| 541 | + 'object_id' => $comment->id, | |
| 542 | + 'src_user_id' => $comment->user_id, | |
| 543 | + 'src_object_type' => 'comment', | |
| 544 | + 'action' => 'mention_added', | |
| 545 | + 'content' => \sprintf( | |
| 546 | + /* translators: %1$s is the commenter name & %2$s is the feed title */ | |
| 547 | + __('%1$s mentioned you in a comment at %2$s', 'fluent-community'), | |
| 548 | + $commenter, | |
| 549 | + $feedTitle, | |
| 550 | + ), | |
| 551 | + 'route' => $feed->getJsRoute(), | |
| 552 | + ]); | |
| 553 | + | |
| 554 | + $mentionNotification->subscribe($mentionedUserIds); | |
| 555 | + | |
| 556 | + do_action('fluent_community/notification/comment/notifed_to_mentions', [ | |
| 557 | + 'user_ids' => $mentionedUserIds, | |
| 558 | + 'notification' => $mentionNotification, | |
| 559 | + 'key' => 'notifed_to_mentions', | |
| 560 | + 'comment' => $comment, | |
| 561 | + 'feed' => $feed | |
| 562 | + ]); | |
| 563 | + | |
| 564 | + return $mentionNotification; | |
| 565 | + } | |
| 566 | + | |
| 567 | + protected function notifyForChildCommentReply($comment, $feed, $mentionedUserIds = []) | |
| 568 | + { | |
| 555 | 569 | // This is a parent comment, so we need to notify the parent comment author & all child comment authors |
| 556 | 570 | $childCommentUserIds = Comment::where(function ($q) use ($comment) { |
| 557 | 571 | $q->where('parent_id', $comment->parent_id) |
| 558 | 572 | ->orWhere('id', $comment->parent_id); |
| @@ -563,13 +577,18 @@ | ||
| 563 | 577 | ->get() |
| 564 | 578 | ->pluck('user_id') |
| 565 | 579 | ->toArray(); |
| 566 | 580 | |
| 581 | + // Mentioned users get a mention notification instead, so skip them here. | |
| 582 | + if ($mentionedUserIds) { | |
| 583 | + $childCommentUserIds = array_values(array_diff($childCommentUserIds, $mentionedUserIds)); | |
| 584 | + } | |
| 585 | + | |
| 567 | 586 | if (!$childCommentUserIds) { |
| 568 | 587 | return false; |
| 569 | 588 | } |
| 570 | 589 | |
| 571 | - $commenter = '<b class="fcom_nudn">' . esc_html($comment->user->display_name) . '</b>'; | |
| 590 | + $commenter = '<b class="fcom_nudn">' . esc_html($comment->user->getPublicDisplayName()) . '</b>'; | |
| 572 | 591 | |
| 573 | 592 | $existingNotification = Notification::where('object_id', $comment->parent_id) |
| 574 | 593 | ->where('action', 'child_comment_added') |
| 575 | 594 | ->whereHas('subscribers', function ($q) use ($childCommentUserIds) { |
| @@ -666,9 +685,9 @@ | ||
| 666 | 685 | |
| 667 | 686 | $notificationContent = \sprintf( |
| 668 | 687 | /* translators: %1$s is the user name, %2$s is the feed title */ |
| 669 | 688 | __('%1$s mentioned you in a post: %2$s', 'fluent-community'), |
| 670 | - '<b class="fcom_nudn">' . esc_html($user->display_name) . '</b>', | |
| 689 | + '<b class="fcom_nudn">' . esc_html($user->getPublicDisplayName()) . '</b>', | |
| 671 | 690 | '<b class="fcom_nft">' . $feedTitle . '</b>' |
| 672 | 691 | ); |
| 673 | 692 | |
| 674 | 693 | $route = $feed->getJsRoute(); |