From e2744fc19f649f327b84eb0be0f9a4f296a25504 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?R=C3=A9gis=20Hanol?= <regis@hanol.fr>
Date: Tue, 12 Jan 2016 12:06:51 +0100
Subject: [PATCH] FIX: adding the 'contains_messages' column back

---
 .../discourse/components/category-chooser.js.es6           | 2 +-
 app/assets/javascripts/discourse/controllers/topic.js.es6  | 2 +-
 app/assets/javascripts/discourse/models/category.js.es6    | 2 +-
 app/assets/javascripts/discourse/models/composer.js.es6    | 7 ++++---
 .../templates/components/edit-category-settings.hbs        | 1 +
 app/controllers/categories_controller.rb                   | 2 +-
 app/models/category.rb                                     | 1 +
 app/models/topic.rb                                        | 2 +-
 app/serializers/basic_category_serializer.rb               | 4 ++--
 config/locales/client.en.yml                               | 7 +++----
 ...60112104733_add_contains_messages_back_to_categories.rb | 5 +++++
 lib/topic_query.rb                                         | 1 -
 12 files changed, 21 insertions(+), 15 deletions(-)
 create mode 100644 db/migrate/20160112104733_add_contains_messages_back_to_categories.rb

diff --git a/app/assets/javascripts/discourse/components/category-chooser.js.es6 b/app/assets/javascripts/discourse/components/category-chooser.js.es6
index 6e49537e8..110785db1 100644
--- a/app/assets/javascripts/discourse/components/category-chooser.js.es6
+++ b/app/assets/javascripts/discourse/components/category-chooser.js.es6
@@ -6,9 +6,9 @@ import PermissionType from 'discourse/models/permission-type';
 
 export default ComboboxView.extend({
   classNames: ['combobox category-combobox'],
-  overrideWidths: true,
   dataAttributes: ['id', 'description_text'],
   valueBinding: Ember.Binding.oneWay('source'),
+  overrideWidths: true,
   castInteger: true,
 
   @computed("scopedCategoryId", "categories")
diff --git a/app/assets/javascripts/discourse/controllers/topic.js.es6 b/app/assets/javascripts/discourse/controllers/topic.js.es6
index 617ad97ee..e5f5d19d3 100644
--- a/app/assets/javascripts/discourse/controllers/topic.js.es6
+++ b/app/assets/javascripts/discourse/controllers/topic.js.es6
@@ -18,8 +18,8 @@ export default Ember.Controller.extend(SelectedPostsCount, BufferedContent, {
   queryParams: ['filter', 'username_filters', 'show_deleted'],
   loadedAllPosts: Em.computed.or('model.postStream.loadedAllPosts', 'model.postStream.loadingLastPost'),
   enteredAt: null,
-  firstPostExpanded: false,
   retrying: false,
+  firstPostExpanded: false,
   adminMenuVisible: false,
 
   showRecover: Em.computed.and('model.deleted', 'model.details.can_recover'),
diff --git a/app/assets/javascripts/discourse/models/category.js.es6 b/app/assets/javascripts/discourse/models/category.js.es6
index d26f68f1d..59941cd73 100644
--- a/app/assets/javascripts/discourse/models/category.js.es6
+++ b/app/assets/javascripts/discourse/models/category.js.es6
@@ -86,7 +86,7 @@ const Category = RestModel.extend({
         allow_badges: this.get('allow_badges'),
         custom_fields: this.get('custom_fields'),
         topic_template: this.get('topic_template'),
-        suppress_from_homepage: this.get('suppress_from_homepage'),
+        suppress_from_homepage: this.get('suppress_from_homepage')
       },
       type: this.get('id') ? 'PUT' : 'POST'
     });
diff --git a/app/assets/javascripts/discourse/models/composer.js.es6 b/app/assets/javascripts/discourse/models/composer.js.es6
index 98488a6a4..cc094dc08 100644
--- a/app/assets/javascripts/discourse/models/composer.js.es6
+++ b/app/assets/javascripts/discourse/models/composer.js.es6
@@ -73,9 +73,10 @@ const Composer = RestModel.extend({
     return !isPrivateMessage && (hasOptions || manyCategories);
   },
 
-  privateMessage: function(){
-    return this.get('creatingPrivateMessage') || this.get('topic.archetype') === 'private_message';
-  }.property('creatingPrivateMessage', 'topic'),
+  @computed("creatingPrivateMessage", "topic")
+  privateMessage(creatingPrivateMessage, topic) {
+    return creatingPrivateMessage || (topic && topic.get('archetype') === 'private_message');
+  },
 
   topicFirstPost: Em.computed.or('creatingTopic', 'editingFirstPost'),
 
diff --git a/app/assets/javascripts/discourse/templates/components/edit-category-settings.hbs b/app/assets/javascripts/discourse/templates/components/edit-category-settings.hbs
index 722a9f5e1..01aeb2d15 100644
--- a/app/assets/javascripts/discourse/templates/components/edit-category-settings.hbs
+++ b/app/assets/javascripts/discourse/templates/components/edit-category-settings.hbs
@@ -26,6 +26,7 @@
       {{i18n 'category.email_in_allow_strangers'}}
     </label>
   </section>
+
   <section class='field'>
     <label>
       {{fa-icon "envelope-o"}}
diff --git a/app/controllers/categories_controller.rb b/app/controllers/categories_controller.rb
index 52437468d..be98b2089 100644
--- a/app/controllers/categories_controller.rb
+++ b/app/controllers/categories_controller.rb
@@ -184,8 +184,8 @@ class CategoriesController < ApplicationController
                         :auto_close_based_on_last_post,
                         :logo_url,
                         :background_url,
-                        :allow_badges,
                         :slug,
+                        :allow_badges,
                         :topic_template,
                         :custom_fields => [params[:custom_fields].try(:keys)],
                         :permissions => [*p.try(:keys)])
diff --git a/app/models/category.rb b/app/models/category.rb
index 0ee810e64..93dd8abec 100644
--- a/app/models/category.rb
+++ b/app/models/category.rb
@@ -75,6 +75,7 @@ class Category < ActiveRecord::Base
       scoped_to_permissions(guardian, [:create_post, :full])
     end
   }
+
   delegate :post_template, to: 'self.class'
 
   # permission is just used by serialization
diff --git a/app/models/topic.rb b/app/models/topic.rb
index b0f426666..82472fa41 100644
--- a/app/models/topic.rb
+++ b/app/models/topic.rb
@@ -27,7 +27,7 @@ class Topic < ActiveRecord::Base
   attr_accessor :allowed_user_ids
 
   def self.max_sort_order
-    2**31 - 1
+    @max_sort_order ||= (2 ** 31) - 1
   end
 
   def featured_users
diff --git a/app/serializers/basic_category_serializer.rb b/app/serializers/basic_category_serializer.rb
index 4ab3917e0..c229b94fa 100644
--- a/app/serializers/basic_category_serializer.rb
+++ b/app/serializers/basic_category_serializer.rb
@@ -11,12 +11,12 @@ class BasicCategorySerializer < ApplicationSerializer
              :description,
              :description_text,
              :topic_url,
+             :logo_url,
+             :background_url,
              :read_restricted,
              :permission,
              :parent_category_id,
              :notification_level,
-             :logo_url,
-             :background_url,
              :can_edit,
              :topic_template,
              :has_children
diff --git a/config/locales/client.en.yml b/config/locales/client.en.yml
index 02365e187..f3e0b6789 100644
--- a/config/locales/client.en.yml
+++ b/config/locales/client.en.yml
@@ -1,9 +1,9 @@
 # encoding: utf-8
+#
 # This file contains content for the client portion of Discourse, sent out
 # to the Javascript app.
 #
-# To work with us on translations, see:
-# https://www.transifex.com/projects/p/discourse-org/
+# To work with us on translations, see: https://www.transifex.com/projects/p/discourse-org/
 #
 # This is a "source" file, which is used by Transifex to get translations for other languages.
 # After this file is changed, it needs to be pushed by a maintainer to Transifex:
@@ -12,8 +12,7 @@
 #
 # Read more here: https://meta.discourse.org/t/contribute-a-translation-to-discourse/14882
 #
-# To validate this YAML file after you change it, please paste it into
-# http://yamllint.com/
+# To validate this YAML file after you change it, please paste it into http://yamllint.com/
 
 en:
   js:
diff --git a/db/migrate/20160112104733_add_contains_messages_back_to_categories.rb b/db/migrate/20160112104733_add_contains_messages_back_to_categories.rb
new file mode 100644
index 000000000..c14803adb
--- /dev/null
+++ b/db/migrate/20160112104733_add_contains_messages_back_to_categories.rb
@@ -0,0 +1,5 @@
+class AddContainsMessagesBackToCategories < ActiveRecord::Migration
+  def change
+    add_column :categories, :contains_messages, :boolean
+  end
+end
diff --git a/lib/topic_query.rb b/lib/topic_query.rb
index cde31fffd..c837c429c 100644
--- a/lib/topic_query.rb
+++ b/lib/topic_query.rb
@@ -199,7 +199,6 @@ class TopicQuery
   end
 
   def prioritize_pinned_topics(topics, options)
-
     pinned_clause = options[:category_id] ? "topics.category_id = #{options[:category_id].to_i} AND" : "pinned_globally AND "
     pinned_clause << " pinned_at IS NOT NULL "
     if @user