diff --git a/app/assets/javascripts/discourse/controllers/composer-messages.js.es6 b/app/assets/javascripts/discourse/controllers/composer-messages.js.es6 index 7a712ba74..a821c758e 100644 --- a/app/assets/javascripts/discourse/controllers/composer-messages.js.es6 +++ b/app/assets/javascripts/discourse/controllers/composer-messages.js.es6 @@ -69,13 +69,17 @@ export default Ember.ArrayController.extend({ queryFor(composer) { if (this.get('checkedMessages')) { return; } - const self = this; - var queuedForTyping = self.get('queuedForTyping'); + const args = { composerAction: composer.get('action') }; + const topicId = composer.get('topic.id'); + const postId = composer.get('post.id'); - Discourse.ComposerMessage.find(composer).then(messages => { - self.set('checkedMessages', true); - messages.forEach(msg => msg.wait_for_typing ? queuedForTyping.addObject(msg) : self.send("popup", msg)); + if (topicId) { args.topic_id = topicId; } + if (postId) { args.post_id = postId; } + + const queuedForTyping = this.get('queuedForTyping'); + this.store.findAll('composer-message', args).then(messages => { + this.set('checkedMessages', true); + messages.forEach(msg => msg.wait_for_typing ? queuedForTyping.addObject(msg) : this.send('popup', msg)); }); } - }); diff --git a/app/assets/javascripts/discourse/controllers/composer.js.es6 b/app/assets/javascripts/discourse/controllers/composer.js.es6 index c32f08990..6d306e26f 100644 --- a/app/assets/javascripts/discourse/controllers/composer.js.es6 +++ b/app/assets/javascripts/discourse/controllers/composer.js.es6 @@ -43,7 +43,6 @@ function loadDraft(store, opts) { export default Ember.Controller.extend({ needs: ['modal', 'topic', 'composer-messages', 'application'], - replyAsNewTopicDraft: Em.computed.equal('model.draftKey', Composer.REPLY_AS_NEW_TOPIC_KEY), checkedMessages: false, @@ -395,7 +394,8 @@ export default Ember.Controller.extend({ let message = this.get('similarTopicsMessage'); if (!message) { - message = Discourse.ComposerMessage.create({ + message = this.store.createRecord('composer-message', { + id: 'similar_topics', templateName: 'composer/similar-topics', extraClass: 'similar-topics' }); diff --git a/app/assets/javascripts/discourse/models/composer_message.js b/app/assets/javascripts/discourse/models/composer_message.js deleted file mode 100644 index 106a4d12b..000000000 --- a/app/assets/javascripts/discourse/models/composer_message.js +++ /dev/null @@ -1,35 +0,0 @@ -/** - Represents a pop up message displayed over the composer - - @class ComposerMessage - @extends Ember.Object - @namespace Discourse - @module Discourse -**/ -Discourse.ComposerMessage = Em.Object.extend({}); - -Discourse.ComposerMessage.reopenClass({ - /** - Look for composer messages given the current composing settings. - - @method find - @param {Discourse.Composer} composer The current composer - @returns {Discourse.ComposerMessage} the composer message to display (or null) - **/ - find: function(composer) { - - var data = { composerAction: composer.get('action') }, - topicId = composer.get('topic.id'), - postId = composer.get('post.id'); - - if (topicId) { data.topic_id = topicId; } - if (postId) { data.post_id = postId; } - - return Discourse.ajax('/composer-messages', { data: data }).then(function (messages) { - return messages.map(function (message) { - return Discourse.ComposerMessage.create(message); - }); - }); - } - -}); diff --git a/app/controllers/composer_messages_controller.rb b/app/controllers/composer_messages_controller.rb index 161988ac8..51ce6d4c2 100644 --- a/app/controllers/composer_messages_controller.rb +++ b/app/controllers/composer_messages_controller.rb @@ -6,8 +6,8 @@ class ComposerMessagesController < ApplicationController def index finder = ComposerMessagesFinder.new(current_user, params.slice(:composerAction, :topic_id, :post_id)) - render_json_dump([finder.find].compact) + json = { composer_messages: [finder.find].compact } + + render_json_dump(json, rest_serializer: true) end - end - diff --git a/config/routes.rb b/config/routes.rb index 6baaabd8d..ff509dbf7 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -249,7 +249,7 @@ Discourse::Application.routes.draw do get "session/sso_provider" => "session#sso_provider" get "session/current" => "session#current" get "session/csrf" => "session#csrf" - get "composer-messages" => "composer_messages#index" + get "composer_messages" => "composer_messages#index" resources :users, except: [:show, :update, :destroy] do collection do diff --git a/lib/composer_messages_finder.rb b/lib/composer_messages_finder.rb index 8dbf1f08b..68d13189d 100644 --- a/lib/composer_messages_finder.rb +++ b/lib/composer_messages_finder.rb @@ -28,6 +28,7 @@ class ComposerMessagesFinder if count < SiteSetting.educate_until_posts education_posts_text = I18n.t('education.until_posts', count: SiteSetting.educate_until_posts) return { + id: 'education', templateName: 'composer/education', wait_for_typing: true, body: PrettyText.cook(I18n.t(education_key, education_posts_text: education_posts_text, site_name: SiteSetting.title)) @@ -42,6 +43,7 @@ class ComposerMessagesFinder return unless replying? && @user.posted_too_much_in_topic?(@details[:topic_id]) { + id: 'too_many_replies', templateName: 'composer/education', body: PrettyText.cook(I18n.t('education.too_many_replies', newuser_max_replies_per_topic: SiteSetting.newuser_max_replies_per_topic)) } @@ -67,6 +69,7 @@ class ComposerMessagesFinder # Return the message { + id: 'avatar', templateName: 'composer/education', body: PrettyText.cook(I18n.t('education.avatar', profile_path: "/users/#{@user.username_lower}")) } @@ -104,6 +107,7 @@ class ComposerMessagesFinder topic_id: @details[:topic_id] ) { + id: 'sequential_replies', templateName: 'composer/education', wait_for_typing: true, extraClass: 'education-message', @@ -135,6 +139,7 @@ class ComposerMessagesFinder topic_id: @details[:topic_id]) { + id: 'dominating_topic', templateName: 'composer/education', wait_for_typing: true, extraClass: 'education-message', @@ -150,6 +155,7 @@ class ComposerMessagesFinder @topic.last_posted_at > SiteSetting.warn_reviving_old_topic_age.days.ago { + id: 'reviving_old', templateName: 'composer/education', wait_for_typing: false, extraClass: 'education-message', diff --git a/spec/controllers/composer_messages_controller_spec.rb b/spec/controllers/composer_messages_controller_spec.rb index 236543915..90738f77b 100644 --- a/spec/controllers/composer_messages_controller_spec.rb +++ b/spec/controllers/composer_messages_controller_spec.rb @@ -23,10 +23,6 @@ describe ComposerMessagesController do finder.expects(:find) xhr :get, :index, args end - end - end - end -