Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[likes] Don't send liked notification for posts without plain content. #4095

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public function __construct(

public function handle(PostWasLiked $event): void
{
if ($event->post->user && $event->post->user->id != $event->user->id) {
if (gettype($event->post->content) == 'string' && $event->post->user && $event->post->user->id != $event->user->id) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • It would be better to do an exact === comparison while using comparisons like these
  • Instead of using gettype, just using the php is_string() method would probably be sufficient, it also reads better instead of seeing a 'string' for something that is a native php type

My biggest gripe with this is however that there's no guarantee whatsoever that content is going to be just post body; what I would probably do is:

Suggested change
if (gettype($event->post->content) == 'string' && $event->post->user && $event->post->user->id != $event->user->id) {
if ($event->post->content instanceof CommentPost && $event->post->user && $event->post->user->id != $event->user->id) {

Now this gripe is based on the idea that notifications for likes would only be sent for posts that have readable content, but it would probably be better to completely separate the logic into a "Post Types that send Notifications" logic, so that it becomes flexible enough for extending; what do you think @flarum/core ?

$this->notifications->sync(
new PostLikedBlueprint($event->post, $event->user),
[$event->post->user]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public function __construct(

public function handle(PostWasUnliked $event): void
{
if ($event->post->user && $event->post->user->id != $event->user->id) {
if (gettype($event->post->content) == 'string' && $event->post->user && $event->post->user->id != $event->user->id) {
$this->notifications->sync(
new PostLikedBlueprint($event->post, $event->user),
[]
Expand Down
Loading