diff --git a/extensions/mentions/js/forum/src/addComposerAutocomplete.js b/extensions/mentions/js/forum/src/addComposerAutocomplete.js
index c6c9dd2c4..c65022744 100644
--- a/extensions/mentions/js/forum/src/addComposerAutocomplete.js
+++ b/extensions/mentions/js/forum/src/addComposerAutocomplete.js
@@ -107,7 +107,7 @@ export default function addComposerAutocomplete() {
.forEach(post => {
const user = post.user();
suggestions.push(
- makeSuggestion(user, '@' + user.username() + '#' + post.number(), [
+ makeSuggestion(user, '@' + user.username() + '#' + post.id(), [
app.trans('mentions.reply_to_post', {number: post.number()}), ' — ',
truncate(post.contentPlain(), 200)
], 'MentionsDropdown-post')
diff --git a/extensions/mentions/js/forum/src/addPostMentionPreviews.js b/extensions/mentions/js/forum/src/addPostMentionPreviews.js
index 3d8c279d5..2177cbc55 100644
--- a/extensions/mentions/js/forum/src/addPostMentionPreviews.js
+++ b/extensions/mentions/js/forum/src/addPostMentionPreviews.js
@@ -7,11 +7,11 @@ export default function addPostMentionPreviews() {
extend(CommentPost.prototype, 'config', function() {
const contentHtml = this.props.post.contentHtml();
- if (contentHtml === this.oldPostContentHtml) return;
+ if (contentHtml === this.oldPostContentHtml || this.isEditing()) return;
this.oldPostContentHtml = contentHtml;
- const discussion = this.props.post.discussion();
+ const parentPost = this.props.post;
this.$('.UserMention, .PostMention').each(function() {
m.route.call(this, this, false, {}, {attrs: {href: this.getAttribute('href')}});
@@ -19,7 +19,7 @@ export default function addPostMentionPreviews() {
this.$('.PostMention').each(function() {
const $this = $(this);
- const number = $this.data('number');
+ const id = $this.data('id');
let timeout;
// Wrap the mention link in a wrapper element so that we can insert a
@@ -29,7 +29,7 @@ export default function addPostMentionPreviews() {
$this.wrap($wrapper).after($preview);
const getPostElement = () => {
- return $(`.PostStream-item[data-number="${number}"]`);
+ return $(`.PostStream-item[data-id="${id}"]`);
};
const showPreview = () => {
@@ -57,18 +57,23 @@ export default function addPostMentionPreviews() {
};
const showPost = post => {
- m.render($preview[0],
{PostPreview.component({post})});
+ const discussion = post.discussion();
+
+ m.render($preview[0], [
+ discussion !== parentPost.discussion()
+ ? {discussion.title()}
+ : '',
+ {PostPreview.component({post})}
+ ]);
positionPreview();
};
- const post = discussion.posts().filter(p => p && p.number() === number)[0];
+ const post = app.store.getById('posts', id);
if (post) {
showPost(post);
} else {
m.render($preview[0], LoadingIndicator.component());
- app.store.find('posts', {
- filter: {discussion: discussion.id(), number}
- }).then(posts => showPost(posts[0]));
+ app.store.find('posts', id).then(showPost);
positionPreview();
}
diff --git a/extensions/mentions/js/forum/src/addPostReplyAction.js b/extensions/mentions/js/forum/src/addPostReplyAction.js
index 8be0001d6..d793c4e65 100644
--- a/extensions/mentions/js/forum/src/addPostReplyAction.js
+++ b/extensions/mentions/js/forum/src/addPostReplyAction.js
@@ -10,7 +10,7 @@ export default function() {
if (post.isHidden() || (app.session.user && !post.discussion().canReply())) return;
function insertMention(component, quote) {
- const mention = '@' + post.user().username() + '#' + post.number() + ' ';
+ const mention = '@' + post.user().username() + '#' + post.id() + ' ';
// If the composer is empty, then assume we're starting a new reply.
// In which case we don't want the user to have to confirm if they
diff --git a/extensions/mentions/less/forum/extension.less b/extensions/mentions/less/forum/extension.less
index 5c5c7f521..9e9e743e7 100644
--- a/extensions/mentions/less/forum/extension.less
+++ b/extensions/mentions/less/forum/extension.less
@@ -81,3 +81,7 @@
border-bottom: 0;
}
}
+.PostMention-preview-discussion {
+ padding-top: 0 !important;
+ font-weight: bold !important;
+}
diff --git a/extensions/mentions/src/Listeners/AddPostMentionsFormatter.php b/extensions/mentions/src/Listeners/AddPostMentionsFormatter.php
index 3b3b56b70..e4ac9d8bc 100755
--- a/extensions/mentions/src/Listeners/AddPostMentionsFormatter.php
+++ b/extensions/mentions/src/Listeners/AddPostMentionsFormatter.php
@@ -1,7 +1,6 @@
listen(FormatterConfigurator::class, [$this, 'configure']);
- $events->listen(FormatterRenderer::class, [$this, 'render']);
}
public function configure(FormatterConfigurator $event)
@@ -21,32 +19,28 @@ class AddPostMentionsFormatter
$tag = $configurator->tags->add($tagName);
$tag->attributes->add('username');
- $tag->attributes->add('number');
+ $tag->attributes->add('number')->filterChain->append('#uint');
+ $tag->attributes->add('discussionid')->filterChain->append('#uint');
$tag->attributes->add('id')->filterChain->append('#uint');
- $tag->attributes['id']->required = false;
+ $tag->attributes['number']->required = false;
+ $tag->attributes['discussionid']->required = false;
- $tag->template = '';
- $tag->filterChain->prepend([static::class, 'addId'])
- ->addParameterByName('post')
+ $tag->template = '';
+
+ $tag->filterChain
+ ->prepend([static::class, 'addId'])
->setJS('function() { return true; }');
- $configurator->Preg->match('/\B@(?[a-z0-9_-]+)#(?\d+)/i', $tagName);
+ $configurator->Preg->match('/\B@(?[a-z0-9_-]+)#(?\d+)/i', $tagName);
}
- public function render(FormatterRenderer $event)
+ public static function addId($tag)
{
- // TODO: use URL generator
- $event->renderer->setParameter('DISCUSSION_URL', '/d/' . $event->post->discussion_id . '/-/');
- }
+ $post = CommentPost::find($tag->getAttribute('id'));
- public static function addId($tag, CommentPost $post)
- {
- $id = CommentPost::where('discussion_id', $post->discussion_id)
- ->where('number', $tag->getAttribute('number'))
- ->pluck('id');
-
- if ($id) {
- $tag->setAttribute('id', $id);
+ if ($post) {
+ $tag->setAttribute('discussionid', (int) $post->discussion_id);
+ $tag->setAttribute('number', (int) $post->number);
return true;
}