REFACTOR: Cleaner quoteButton object, and some bug fixes
This commit is contained in:
@@ -11,6 +11,7 @@ import { categoryBadgeHTML } from 'discourse/helpers/category-link';
|
||||
import Post from 'discourse/models/post';
|
||||
import debounce from 'discourse/lib/debounce';
|
||||
import isElementInViewport from "discourse/lib/is-element-in-viewport";
|
||||
import QuoteState from 'discourse/lib/quote-state';
|
||||
|
||||
export default Ember.Controller.extend(SelectedPostsCount, BufferedContent, {
|
||||
composer: Ember.inject.controller(),
|
||||
@@ -119,7 +120,7 @@ export default Ember.Controller.extend(SelectedPostsCount, BufferedContent, {
|
||||
this._super();
|
||||
this.set('selectedPosts', []);
|
||||
this.set('selectedReplies', []);
|
||||
this.set('quoteState', Ember.Object.create({ buffer: null, postId: null }));
|
||||
this.set('quoteState', new QuoteState());
|
||||
},
|
||||
|
||||
showCategoryChooser: Ember.computed.not("model.isPrivateMessage"),
|
||||
@@ -167,16 +168,8 @@ export default Ember.Controller.extend(SelectedPostsCount, BufferedContent, {
|
||||
this.send('showFeatureTopic');
|
||||
},
|
||||
|
||||
deselectText() {
|
||||
this.get('quoteState').setProperties({ buffer: null, postId: null });
|
||||
},
|
||||
|
||||
selectText() {
|
||||
const { postId, buffer } = this.get('quoteState');
|
||||
|
||||
this.send('deselectText');
|
||||
|
||||
this.get('model.postStream').loadPost(postId).then(post => {
|
||||
selectText(postId, buffer) {
|
||||
return this.get('model.postStream').loadPost(postId).then(post => {
|
||||
// If we can't create a post, delegate to reply as new topic
|
||||
if (!this.get('model.details.can_create_post')) {
|
||||
this.send('replyAsNewTopic', post);
|
||||
@@ -196,15 +189,19 @@ export default Ember.Controller.extend(SelectedPostsCount, BufferedContent, {
|
||||
|
||||
// If the composer is associated with a different post, we don't change it.
|
||||
const composer = this.get('composer');
|
||||
const composerPost = composer.get('content.post');
|
||||
const composerPost = composer.get('model.post');
|
||||
if (composerPost && (composerPost.get('id') !== this.get('post.id'))) {
|
||||
composerOpts.post = composerPost;
|
||||
}
|
||||
|
||||
const quotedText = Quote.build(post, buffer);
|
||||
composerOpts.quote = quotedText;
|
||||
if (composer.get('content.viewOpen') || composer.get('content.viewDraft')) {
|
||||
if (composer.get('model.viewOpen')) {
|
||||
this.appEvents.trigger('composer:insert-text', quotedText);
|
||||
} else if (composer.get('model.viewDraft')) {
|
||||
const model = composer.get('model');
|
||||
model.set('reply', model.get('reply') + quotedText);
|
||||
composer.send('openIfDraft');
|
||||
} else {
|
||||
composer.open(composerOpts);
|
||||
}
|
||||
@@ -314,9 +311,10 @@ export default Ember.Controller.extend(SelectedPostsCount, BufferedContent, {
|
||||
|
||||
const quoteState = this.get('quoteState');
|
||||
const postStream = this.get('model.postStream');
|
||||
const quotedPost = postStream.findLoadedPost(quoteState.get('postId'));
|
||||
const quotedText = Quote.build(quotedPost, quoteState.get('buffer'));
|
||||
this.send('deselectText');
|
||||
const quotedPost = postStream.findLoadedPost(quoteState.postId);
|
||||
const quotedText = Quote.build(quotedPost, quoteState.buffer);
|
||||
|
||||
quoteState.clear();
|
||||
|
||||
if (composerController.get('content.topic.id') === topic.get('id') &&
|
||||
composerController.get('content.action') === Composer.REPLY) {
|
||||
@@ -652,10 +650,9 @@ export default Ember.Controller.extend(SelectedPostsCount, BufferedContent, {
|
||||
replyAsNewTopic(post) {
|
||||
const composerController = this.get('composer');
|
||||
|
||||
const quoteState = this.get('quoteState');
|
||||
post = post || quoteState.get('post');
|
||||
const quotedText = Quote.build(post, quoteState.get('buffer'));
|
||||
this.send('deselectText');
|
||||
const { quoteState } = this;
|
||||
const quotedText = Quote.build(post, quoteState.buffer);
|
||||
quoteState.clear();
|
||||
|
||||
composerController.open({
|
||||
action: Composer.CREATE_TOPIC,
|
||||
|
||||
Reference in New Issue
Block a user