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

Cannot mention post with deleted author #3427

Closed
clarkwinkelmann opened this issue May 16, 2022 · 0 comments · Fixed by #3432
Closed

Cannot mention post with deleted author #3427

clarkwinkelmann opened this issue May 16, 2022 · 0 comments · Fixed by #3432
Labels
Milestone

Comments

@clarkwinkelmann
Copy link
Member

Bug Report

Current Behavior
If you try mentioning a post whose author is [deleted], the preview will render correctly, but after saving the mention will stay as plain text.

Steps to Reproduce

  1. Create post and delete author, either by deleting the user or setting user_id null in the database
  2. Use reply button or @ syntax to mention the post with deleted author
  3. Preview shows mention as expected
  4. Submit post
  5. Final post doesn't contain mention

Expected Behavior
It should be possible to mention those posts. In fact it works fine if the author is deleted after the reply is created. But if the reply is created afterwards, it doesn't work.

Screenshots
Preview:
image
Submitted:
image

Environment

  • Flarum version: 1.2.1, likely still in 1.3.0 because the master code still contains the issue right now

Possible Solution
The problem is in

public static function addPostId($tag)
{
$post = CommentPost::find($tag->getAttribute('id'));
if ($post && $post->user) {
$tag->setAttribute('discussionid', (int) $post->discussion_id);
$tag->setAttribute('number', (int) $post->number);
$tag->setAttribute('displayname', $post->user->display_name);
return true;
}
}
which only saves a mention if both the post and author exist.

I think we should just move $tag->setAttribute('displayname', $post->user->display_name); to a separate if( $post->user). Not sure if we should put a different default value for displayname. Its value will already be set to [deleted] in Formatter/FormatPostMentions anyway.

The preview JavaScript code doesn't have that limitation

export function filterPostMentions(tag) {
const post = app.store.getById('posts', tag.getAttribute('id'));
if (post) {
tag.setAttribute('discussionid', post.discussion().id());
tag.setAttribute('number', post.number());
tag.setAttribute('displayname', extractText(username(post.user())));
return true;
}
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants