mirror of
https://github.com/discourse/discourse.git
synced 2025-04-17 12:59:07 +08:00
hidden and deleted state in user stream
This commit is contained in:
parent
6bf2f15610
commit
c1f6169b48
@ -1,6 +1,6 @@
|
|||||||
<div id='user-stream'>
|
<div id='user-stream'>
|
||||||
{{#each view.stream.content}}
|
{{#each view.stream.content}}
|
||||||
<div class='item'>
|
<div {{bindAttr class=":item hidden:hidden deleted:deleted"}}>
|
||||||
<div class='clearfix info'>
|
<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>
|
<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>
|
<span class='time'>{{date path="created_at" leaveAgo="true"}}</span>
|
||||||
|
@ -251,6 +251,14 @@
|
|||||||
word-wrap: break-word;
|
word-wrap: break-word;
|
||||||
color: lighten($black, 30%);
|
color: lighten($black, 30%);
|
||||||
}
|
}
|
||||||
|
.item.deleted {
|
||||||
|
opacity: 0.8;
|
||||||
|
background-color: #ffcece;
|
||||||
|
}
|
||||||
|
.item.hidden {
|
||||||
|
display: block;
|
||||||
|
opacity: 0.4;
|
||||||
|
}
|
||||||
.item {
|
.item {
|
||||||
padding: 10px 8px;
|
padding: 10px 8px;
|
||||||
background-color: white;
|
background-color: white;
|
||||||
|
@ -34,6 +34,13 @@ class UserAction < ActiveRecord::Base
|
|||||||
EDIT
|
EDIT
|
||||||
].each_with_index.to_a.flatten]
|
].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)
|
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
|
# 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.
|
# ever so more complex. Should we allow this, not sure.
|
||||||
|
|
||||||
builder = UserAction.sql_builder("
|
builder = SqlBuilder.new("
|
||||||
SELECT
|
SELECT
|
||||||
t.title, a.action_type, a.created_at, t.id topic_id,
|
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,
|
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,
|
p.reply_to_post_number,
|
||||||
pu.email ,pu.username, pu.name, pu.id user_id,
|
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,
|
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
|
FROM user_actions as a
|
||||||
JOIN topics t on t.id = a.target_topic_id
|
JOIN topics t on t.id = a.target_topic_id
|
||||||
LEFT JOIN posts p on p.id = a.target_post_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)
|
.limit(limit.to_i)
|
||||||
end
|
end
|
||||||
|
|
||||||
builder.exec.to_a
|
builder.map_exec(UserActionRow)
|
||||||
end
|
end
|
||||||
|
|
||||||
# slightly different to standard stream, it collapses replies
|
# 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]
|
user_id = opts[:user_id]
|
||||||
return [] unless opts[:guardian].can_see_private_messages?(user_id)
|
return [] unless opts[:guardian].can_see_private_messages?(user_id)
|
||||||
|
|
||||||
builder = UserAction.sql_builder("
|
builder = SqlBuilder.new("
|
||||||
SELECT
|
SELECT
|
||||||
t.title, :action_type action_type, p.created_at, t.id topic_id,
|
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,
|
: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,
|
p.reply_to_post_number,
|
||||||
pu.email ,pu.username, pu.name, pu.id user_id,
|
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,
|
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
|
FROM topics t
|
||||||
JOIN posts p ON p.topic_id = t.id and p.post_number = t.highest_post_number
|
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
|
builder
|
||||||
.offset((opts[:offset] || 0).to_i)
|
.offset((opts[:offset] || 0).to_i)
|
||||||
.limit((opts[:limit] || 60).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
|
end
|
||||||
|
|
||||||
def self.log_action!(hash)
|
def self.log_action!(hash)
|
||||||
|
@ -18,7 +18,9 @@ class UserActionSerializer < ApplicationSerializer
|
|||||||
:acting_username,
|
:acting_username,
|
||||||
:acting_name,
|
:acting_name,
|
||||||
:acting_user_id,
|
:acting_user_id,
|
||||||
:title
|
:title,
|
||||||
|
:deleted,
|
||||||
|
:hidden
|
||||||
|
|
||||||
|
|
||||||
def excerpt
|
def excerpt
|
||||||
|
@ -65,13 +65,13 @@ class SqlBuilder
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
#weird AS reloading
|
#AS reloads this on tests
|
||||||
unless defined? FTYPE_MAP
|
remove_const :FTYPE_MAP if defined? FTYPE_MAP
|
||||||
FTYPE_MAP = {
|
FTYPE_MAP = {
|
||||||
23 => :value_to_integer,
|
23 => :value_to_integer,
|
||||||
1114 => :string_to_time
|
1114 => :string_to_time,
|
||||||
}
|
16 => :value_to_boolean
|
||||||
end
|
}
|
||||||
|
|
||||||
def map_exec(klass, args = {})
|
def map_exec(klass, args = {})
|
||||||
results = exec(args)
|
results = exec(args)
|
||||||
|
@ -18,13 +18,18 @@ describe SqlBuilder do
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe "map" do
|
describe "map_exec" do
|
||||||
class SqlBuilder::TestClass
|
class SqlBuilder::TestClass
|
||||||
attr_accessor :int, :string, :date, :text
|
attr_accessor :int, :string, :date, :text, :bool
|
||||||
end
|
end
|
||||||
|
|
||||||
it "correctly maps to a klass" do
|
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)
|
.map_exec(SqlBuilder::TestClass)
|
||||||
|
|
||||||
rows.count.should == 1
|
rows.count.should == 1
|
||||||
@ -32,6 +37,7 @@ describe SqlBuilder do
|
|||||||
row.int.should == 1
|
row.int.should == 1
|
||||||
row.string.should == "string"
|
row.string.should == "string"
|
||||||
row.text.should == "text"
|
row.text.should == "text"
|
||||||
|
row.bool.should == true
|
||||||
row.date.should be_within(10.seconds).of(DateTime.now)
|
row.date.should be_within(10.seconds).of(DateTime.now)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -13,5 +13,5 @@
|
|||||||
|
|
||||||
{{#if view.post.voteAction.can_undo}}
|
{{#if view.post.voteAction.can_undo}}
|
||||||
<a href="#" class='undo' {{action undoVote target="view.post"}}>undo</a>
|
<a href="#" class='undo' {{action undoVote target="view.post"}}>undo</a>
|
||||||
{{/if}}
|
{{/if}}
|
||||||
{{/if}}
|
{{/if}}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user