From c1f6169b48e7568126cecfdaeb49d061373bbbf8 Mon Sep 17 00:00:00 2001 From: Sam Date: Wed, 12 Jun 2013 11:14:08 +1000 Subject: [PATCH] hidden and deleted state in user stream --- .../templates/user/stream.js.handlebars | 2 +- .../stylesheets/application/user.css.scss | 8 +++++++ app/models/user_action.rb | 23 ++++++++++++++----- app/serializers/user_action_serializer.rb | 4 +++- lib/sql_builder.rb | 14 +++++------ spec/components/sql_builder_spec.rb | 12 +++++++--- .../templates/poll_controls.js.handlebars | 2 +- 7 files changed, 46 insertions(+), 19 deletions(-) diff --git a/app/assets/javascripts/discourse/templates/user/stream.js.handlebars b/app/assets/javascripts/discourse/templates/user/stream.js.handlebars index 645be0a1bed..6dff8d2d862 100644 --- a/app/assets/javascripts/discourse/templates/user/stream.js.handlebars +++ b/app/assets/javascripts/discourse/templates/user/stream.js.handlebars @@ -1,6 +1,6 @@
{{#each view.stream.content}} -
+
{{avatar this imageSize="large" extraClasses="actor" ignoreTitle="true"}}
{{date path="created_at" leaveAgo="true"}} diff --git a/app/assets/stylesheets/application/user.css.scss b/app/assets/stylesheets/application/user.css.scss index 5119c5fcf4f..175b8f910b2 100644 --- a/app/assets/stylesheets/application/user.css.scss +++ b/app/assets/stylesheets/application/user.css.scss @@ -251,6 +251,14 @@ word-wrap: break-word; color: lighten($black, 30%); } + .item.deleted { + opacity: 0.8; + background-color: #ffcece; + } + .item.hidden { + display: block; + opacity: 0.4; + } .item { padding: 10px 8px; background-color: white; diff --git a/app/models/user_action.rb b/app/models/user_action.rb index de7d6f1c397..9c62f0dd427 100644 --- a/app/models/user_action.rb +++ b/app/models/user_action.rb @@ -34,6 +34,13 @@ class UserAction < ActiveRecord::Base EDIT ].each_with_index.to_a.flatten] + # note, this is temporary until we upgrade to rails 4 + # in rails 4 types are mapped correctly so you dont end up + # having strings where you would expect bools + class UserActionRow < OpenStruct + include ActiveModel::SerializerSupport + end + def self.stats(user_id, guardian) @@ -77,7 +84,7 @@ SQL # The weird thing is that target_post_id can be null, so it makes everything # ever so more complex. Should we allow this, not sure. - builder = UserAction.sql_builder(" + builder = SqlBuilder.new(" SELECT t.title, a.action_type, a.created_at, t.id topic_id, a.user_id AS target_user_id, au.name AS target_name, au.username AS target_username, @@ -85,7 +92,9 @@ SELECT p.reply_to_post_number, pu.email ,pu.username, pu.name, pu.id user_id, u.email acting_email, u.username acting_username, u.name acting_name, u.id acting_user_id, - coalesce(p.cooked, p2.cooked) cooked + coalesce(p.cooked, p2.cooked) cooked, + CASE WHEN coalesce(p.deleted_at, p2.deleted_at, t.deleted_at) IS NULL THEN false ELSE true END deleted, + p.hidden FROM user_actions as a JOIN topics t on t.id = a.target_topic_id LEFT JOIN posts p on p.id = a.target_post_id @@ -113,7 +122,7 @@ LEFT JOIN categories c on c.id = t.category_id .limit(limit.to_i) end - builder.exec.to_a + builder.map_exec(UserActionRow) end # slightly different to standard stream, it collapses replies @@ -122,7 +131,7 @@ LEFT JOIN categories c on c.id = t.category_id user_id = opts[:user_id] return [] unless opts[:guardian].can_see_private_messages?(user_id) - builder = UserAction.sql_builder(" + builder = SqlBuilder.new(" SELECT t.title, :action_type action_type, p.created_at, t.id topic_id, :user_id AS target_user_id, au.name AS target_name, au.username AS target_username, @@ -130,7 +139,9 @@ SELECT p.reply_to_post_number, pu.email ,pu.username, pu.name, pu.id user_id, pu.email acting_email, pu.username acting_username, pu.name acting_name, pu.id acting_user_id, - p.cooked + p.cooked, + CASE WHEN coalesce(p.deleted_at, t.deleted_at) IS NULL THEN false ELSE true END deleted, + p.hidden FROM topics t JOIN posts p ON p.topic_id = t.id and p.post_number = t.highest_post_number @@ -147,7 +158,7 @@ ORDER BY p.created_at desc builder .offset((opts[:offset] || 0).to_i) .limit((opts[:limit] || 60).to_i) - .exec(user_id: user_id, action_type: action_type).to_a + .map_exec(UserActionRow, user_id: user_id, action_type: action_type) end def self.log_action!(hash) diff --git a/app/serializers/user_action_serializer.rb b/app/serializers/user_action_serializer.rb index d00d5ddc5a8..de90f7be7a2 100644 --- a/app/serializers/user_action_serializer.rb +++ b/app/serializers/user_action_serializer.rb @@ -18,7 +18,9 @@ class UserActionSerializer < ApplicationSerializer :acting_username, :acting_name, :acting_user_id, - :title + :title, + :deleted, + :hidden def excerpt diff --git a/lib/sql_builder.rb b/lib/sql_builder.rb index 3eb93e5c1ba..c06539dcd00 100644 --- a/lib/sql_builder.rb +++ b/lib/sql_builder.rb @@ -65,13 +65,13 @@ class SqlBuilder end end - #weird AS reloading - unless defined? FTYPE_MAP - FTYPE_MAP = { - 23 => :value_to_integer, - 1114 => :string_to_time - } - end + #AS reloads this on tests + remove_const :FTYPE_MAP if defined? FTYPE_MAP + FTYPE_MAP = { + 23 => :value_to_integer, + 1114 => :string_to_time, + 16 => :value_to_boolean + } def map_exec(klass, args = {}) results = exec(args) diff --git a/spec/components/sql_builder_spec.rb b/spec/components/sql_builder_spec.rb index 15cfdab6926..d0555ef10c6 100644 --- a/spec/components/sql_builder_spec.rb +++ b/spec/components/sql_builder_spec.rb @@ -18,13 +18,18 @@ describe SqlBuilder do end end - describe "map" do + describe "map_exec" do class SqlBuilder::TestClass - attr_accessor :int, :string, :date, :text + attr_accessor :int, :string, :date, :text, :bool end it "correctly maps to a klass" do - rows = SqlBuilder.new("SELECT 1 AS int, 'string' AS string, CAST(NOW() at time zone 'utc' AS timestamp without time zone) AS date, 'text'::text AS text") + rows = SqlBuilder.new("SELECT + 1 AS int, + 'string' AS string, + CAST(NOW() at time zone 'utc' AS timestamp without time zone) AS date, + 'text'::text AS text, + true AS bool") .map_exec(SqlBuilder::TestClass) rows.count.should == 1 @@ -32,6 +37,7 @@ describe SqlBuilder do row.int.should == 1 row.string.should == "string" row.text.should == "text" + row.bool.should == true row.date.should be_within(10.seconds).of(DateTime.now) end end diff --git a/vendor/gems/discourse_poll/vendor/assets/javascripts/discourse_poll/templates/poll_controls.js.handlebars b/vendor/gems/discourse_poll/vendor/assets/javascripts/discourse_poll/templates/poll_controls.js.handlebars index 6c20d6fe0a6..8546db941d0 100644 --- a/vendor/gems/discourse_poll/vendor/assets/javascripts/discourse_poll/templates/poll_controls.js.handlebars +++ b/vendor/gems/discourse_poll/vendor/assets/javascripts/discourse_poll/templates/poll_controls.js.handlebars @@ -13,5 +13,5 @@ {{#if view.post.voteAction.can_undo}} undo - {{/if}} + {{/if}} {{/if}}