mirror of
https://github.com/codeninjasllc/discourse.git
synced 2025-03-22 04:45:46 -04:00
hidden and deleted state in user stream
This commit is contained in:
parent
6bf2f15610
commit
c1f6169b48
7 changed files with 46 additions and 19 deletions
app
assets
models
serializers
lib
spec/components
vendor/gems/discourse_poll/vendor/assets/javascripts/discourse_poll/templates
|
@ -1,6 +1,6 @@
|
|||
<div id='user-stream'>
|
||||
{{#each view.stream.content}}
|
||||
<div class='item'>
|
||||
<div {{bindAttr class=":item hidden:hidden deleted:deleted"}}>
|
||||
<div class='clearfix info'>
|
||||
<a href="{{unbound userUrl}}" class='avatar-link'><div class='avatar-wrapper'>{{avatar this imageSize="large" extraClasses="actor" ignoreTitle="true"}}</div></a>
|
||||
<span class='time'>{{date path="created_at" leaveAgo="true"}}</span>
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -18,7 +18,9 @@ class UserActionSerializer < ApplicationSerializer
|
|||
:acting_username,
|
||||
:acting_name,
|
||||
:acting_user_id,
|
||||
:title
|
||||
:title,
|
||||
:deleted,
|
||||
:hidden
|
||||
|
||||
|
||||
def excerpt
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -13,5 +13,5 @@
|
|||
|
||||
{{#if view.post.voteAction.can_undo}}
|
||||
<a href="#" class='undo' {{action undoVote target="view.post"}}>undo</a>
|
||||
{{/if}}
|
||||
{{/if}}
|
||||
{{/if}}
|
||||
|
|
Loading…
Reference in a new issue