mirror of
https://github.com/discourse/discourse.git
synced 2024-11-22 09:42:02 +08:00
REFACTOR: Move composer messages to store
This commit is contained in:
parent
4253141700
commit
6aaa484baa
|
@ -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));
|
||||
});
|
||||
}
|
||||
|
||||
});
|
||||
|
|
|
@ -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'
|
||||
});
|
||||
|
|
|
@ -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);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
});
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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',
|
||||
|
|
|
@ -23,10 +23,6 @@ describe ComposerMessagesController do
|
|||
finder.expects(:find)
|
||||
xhr :get, :index, args
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user