toggle all nsfw posts

This commit is contained in:
Dennis Collinson 2012-02-14 14:15:00 -08:00 committed by Maxwell Salzberg
parent e7c1903765
commit 32d58e8a9b
16 changed files with 140 additions and 56 deletions

View file

@ -83,7 +83,9 @@ en:
reshare: "Reshare" reshare: "Reshare"
comment: "Comment" comment: "Comment"
original_post_deleted: "Original post deleted by author." original_post_deleted: "Original post deleted by author."
show_post: "Show post" show_nsfw_post: "Show post"
show_nsfw_posts: "Show all"
hide_nsfw_posts: "Hide #nsfw posts"
follow: "Follow" follow: "Follow"
unfollow: "Unfollow" unfollow: "Unfollow"

View file

@ -14,14 +14,30 @@ Scenario: Setting not safe for work
And I submit the form And I submit the form
Then I should see the "you are safe for work" message Then I should see the "you are safe for work" message
Scenario: NSFWs users posts are nsfw Scenario: Toggling nsfw state
#Nsfw users posts are marked nsfw
Given a nsfw user with email "tommy@pr0nking.com" Given a nsfw user with email "tommy@pr0nking.com"
And I sign in as "tommy@pr0nking.com" And a user with email "laura@officeworkers.com"
Then I should not see "I love 0bj3ction4bl3 c0nt3nt!" And a user with email "laura@officeworkers.com" is connected with "tommy@pr0nking.com"
#And I post "I love 0bj3ction4bl3 c0nt3nt!" When I sign in as "tommy@pr0nking.com"
#Then the post "I love 0bj3ction4bl3 c0nt3nt!" should be marked nsfw And I post "I love 0bj3ction4bl3 c0nt3nt!"
And I post "Sexy Senators Gone Wild!"
Then I should have 2 nsfw posts
# And I log out #toggling global nsfw state
# And I log in as an office worker When I log out
# And I am folllowing "tommy@pr0n.xxx" And I sign in as "laura@officeworkers.com"
# Then I should not see "I love 0bj3ction4bl3 c0nt3nt!" in my stream Then I should not see "I love 0bj3ction4bl3 c0nt3nt!"
When I toggle nsfw posts
Then I should see "I love 0bj3ction4bl3 c0nt3nt!"
And I should see "Sexy Senators Gone Wild!"
#cookies
#When I refresh the page
#Then I should see "I love 0bj3ction4bl3 c0nt3nt!"
#And I should see "Sexy Senators Gone Wild!"
#hiding
When I toggle nsfw posts
Then I should not see "I love 0bj3ction4bl3 c0nt3nt!"
And I should not see "Sexy Senators Gone Wild!"

View file

@ -21,13 +21,13 @@ When /^I try to sign in manually$/ do
step %(I press "Sign in") step %(I press "Sign in")
end end
When /^I sign in as "([^"]*)"$/ do |email| When /^I (?:sign|log) in as "([^"]*)"$/ do |email|
@me = User.find_by_email(email) @me = User.find_by_email(email)
@me.password ||= 'password' @me.password ||= 'password'
step 'I am signed in' step 'I am signed in'
end end
When /^I sign in with password "([^"]*)"$/ do |password| When /^I (?:sign|log) in with password "([^"]*)"$/ do |password|
@me.password = password @me.password = password
step 'I am signed in' step 'I am signed in'
end end

View file

@ -9,3 +9,11 @@ end
Then /^"([^"]*)" should be post (\d+)$/ do |post_text, position| Then /^"([^"]*)" should be post (\d+)$/ do |post_text, position|
find(".stream_element:nth-child(#{position}) .post-content").text.should == post_text find(".stream_element:nth-child(#{position}) .post-content").text.should == post_text
end end
When /^I toggle nsfw posts$/ do
find(".toggle_nsfw_state").click
end
Then /^I should have (\d+) nsfw posts$/ do |num_posts|
all(".nsfw-shield").size.should == num_posts.to_i
end

View file

@ -4,8 +4,8 @@ var app = {
helpers: {}, helpers: {},
views: {}, views: {},
user: function(user) { user: function(userAttrs) {
if(user) { return this._user = user } if(userAttrs) { return this._user = new app.models.User(userAttrs) }
return this._user || false return this._user || false
}, },

View file

@ -0,0 +1,6 @@
app.models.User = Backbone.Model.extend({
toggleNsfwState : function() {
this.set({showNsfw : !this.get("showNsfw")});
this.trigger("nsfwChanged");
}
});

View file

@ -44,24 +44,37 @@
</span> </span>
</div> </div>
{{#if nsfw}} {{#if showPost}}
<div class="nsfw-shield"> {{#if nsfw}}
<strong> <div class="nsfw_off">
NSFW <strong>
</strong> #NSFW
| </strong>
<a href="#"> |
{{t "stream.show_post"}} <a href="#" class="toggle_nsfw_state">
</a> {{t "stream.hide_nsfw_posts"}}
</div> </a>
</div>
{{else}} {{/if}}
<div class="post-content"> </div> <div class="post-content"> </div>
<div class="feedback"> </div> <div class="feedback"> </div>
<div class="likes"> </div> <div class="likes"> </div>
<div class="comments"> </div> <div class="comments"> </div>
{{else}}
<div class="nsfw-shield">
<strong>
#NSFW
</strong>
|
<a href="#" class="show_nsfw_post">
{{t "stream.show_nsfw_post"}}
</a>
|
<a href="#" class="toggle_nsfw_state">
{{t "stream.show_nsfw_posts"}}
</a>
</div>
{{/if}} {{/if}}
</div> </div>

View file

@ -11,7 +11,7 @@ app.views.Base = Backbone.View.extend({
defaultPresenter : function(){ defaultPresenter : function(){
var modelJson = this.model ? this.model.toJSON() : {} var modelJson = this.model ? this.model.toJSON() : {}
return _.extend(modelJson, {current_user: app.user()}); return _.extend(modelJson, {current_user: app.user().attributes});
}, },
render : function() { render : function() {

View file

@ -16,11 +16,11 @@ app.views.Comment = app.views.Content.extend({
}, },
ownComment : function() { ownComment : function() {
return this.model.get("author").diaspora_id == app.user().diaspora_id return this.model.get("author").diaspora_id == app.user().get("diaspora_id")
}, },
postOwner : function() { postOwner : function() {
return this.model.get("parent").author.diaspora_id == app.user().diaspora_id return this.model.get("parent").author.diaspora_id == app.user().get("diaspora_id")
}, },
canRemove : function() { canRemove : function() {

View file

@ -43,8 +43,8 @@ app.views.Feedback = app.views.StreamObject.extend({
var rootExists = (isReshare ? this.model.get("root") : true) var rootExists = (isReshare ? this.model.get("root") : true)
var publicPost = this.model.get("public"); var publicPost = this.model.get("public");
var userIsNotAuthor = this.model.get("author").diaspora_id != app.user().diaspora_id; var userIsNotAuthor = this.model.get("author").diaspora_id != app.user().get("diaspora_id");
var userIsNotRootAuthor = rootExists && (isReshare ? this.model.get("root").author.diaspora_id != app.user().diaspora_id : true) var userIsNotRootAuthor = rootExists && (isReshare ? this.model.get("root").author.diaspora_id != app.user().get("diaspora_id") : true)
return publicPost && userIsNotAuthor && userIsNotRootAuthor; return publicPost && userIsNotAuthor && userIsNotRootAuthor;
} }

View file

@ -6,7 +6,9 @@ app.views.Post = app.views.StreamObject.extend({
events: { events: {
"click .focus_comment_textarea": "focusCommentTextarea", "click .focus_comment_textarea": "focusCommentTextarea",
"click .nsfw-shield a": "removeNsfwShield", "click .show_nsfw_post": "removeNsfwShield",
"click .toggle_nsfw_state": "toggleNsfwState",
"click .remove_post": "destroyModel", "click .remove_post": "destroyModel",
"click .hide_post": "hidePost", "click .hide_post": "hidePost",
"click .block_user": "blockUser" "click .block_user": "blockUser"
@ -49,15 +51,24 @@ app.views.Post = app.views.StreamObject.extend({
presenter : function() { presenter : function() {
return _.extend(this.defaultPresenter(), { return _.extend(this.defaultPresenter(), {
authorIsCurrentUser : this.authorIsCurrentUser() authorIsCurrentUser : this.authorIsCurrentUser(),
showPost : this.showPost()
}) })
}, },
showPost : function() {
return (app.user() && app.user().get("showNsfw")) || !this.model.get("nsfw")
},
removeNsfwShield: function(evt){ removeNsfwShield: function(evt){
if(evt){ evt.preventDefault(); } if(evt){ evt.preventDefault(); }
this.model.set({nsfw : false}) this.model.set({nsfw : false})
this.render(); this.render();
return this; },
toggleNsfwState: function(evt){
if(evt){ evt.preventDefault(); }
app.user().toggleNsfwState();
}, },
blockUser: function(evt){ blockUser: function(evt){

View file

@ -11,12 +11,16 @@ app.views.Stream = Backbone.View.extend({
this.setupEvents() this.setupEvents()
this.setupInfiniteScroll() this.setupInfiniteScroll()
this.setupLightbox() this.setupLightbox()
this.postViews = []
}, },
setupEvents : function(){ setupEvents : function(){
this.stream.bind("fetched", this.removeLoader, this) this.stream.bind("fetched", this.removeLoader, this)
this.stream.bind("allPostsLoaded", this.unbindInfScroll, this) this.stream.bind("allPostsLoaded", this.unbindInfScroll, this)
this.collection.bind("add", this.addPost, this); this.collection.bind("add", this.addPost, this);
app.user().bind("nsfwChanged", function() {
_.map(this.postViews, function(view){ view.render() })
}, this)
}, },
addPost : function(post) { addPost : function(post) {
@ -28,6 +32,7 @@ app.views.Stream = Backbone.View.extend({
: "append" : "append"
](postView.render().el); ](postView.render().el);
this.postViews.push(postView)
return this; return this;
}, },

View file

@ -2815,3 +2815,9 @@ a.toggle_selector
.float-right .float-right
:float right :float right
:margin-top 5px :margin-top 5px
.nsfw_off
:font-size smaller
:color #999
a
:color #666

View file

@ -5,7 +5,7 @@ describe("app", function() {
app.user({name: "alice"}); app.user({name: "alice"});
expect(app.user()).toEqual({name: "alice"}); expect(app.user().get("name")).toEqual("alice");
}); });
it("returns false if the current_user isn't set", function() { it("returns false if the current_user isn't set", function() {

View file

@ -61,23 +61,40 @@ describe("app.views.Post", function(){
}) })
context("NSFW", function(){ context("NSFW", function(){
it("contains a shield element", function(){ beforeEach(function(){
this.statusMessage.set({nsfw: true}); this.statusMessage.set({nsfw: true});
this.view = new app.views.Post({model : this.statusMessage}).render();
var view = new app.views.Post({model : this.statusMessage}).render(); this.hiddenPosts = function(){
var statusElement = $(view.el) return this.view.$(".nsfw-shield")
}
});
expect(statusElement.find(".nsfw-shield").length).toBe(1) it("contains a shield element", function(){
expect(this.hiddenPosts().length).toBe(1)
});
it("does not contain a shield element when nsfw is false", function(){
this.statusMessage.set({nsfw: false});
this.view.render();
expect(this.hiddenPosts()).not.toExist();
}) })
it("does not contain a shield element", function(){ context("showing a single post", function(){
this.statusMessage.set({nsfw: false}); it("removes the shields when the post is clicked", function(){
expect(this.hiddenPosts()).toExist();
this.view.$(".nsfw-shield .show_nsfw_post").click();
expect(this.hiddenPosts()).not.toExist();
});
});
var view = new app.views.Post({model : this.statusMessage}).render(); context("clicking the toggle nsfw link toggles it on the user", function(){
var statusElement = $(view.el) it("calls toggleNsfw on the user", function(){
spyOn(app.user(), "toggleNsfwState")
expect(statusElement.find(".shield").html()).toBe(null); this.view.$(".toggle_nsfw_state").first().click();
expect(app.user().toggleNsfwState).toHaveBeenCalled();
});
}) })
}) })
}) })
}) });

View file

@ -35,15 +35,15 @@ factory = {
userAttrs : function(overrides){ userAttrs : function(overrides){
var id = this.id.next() var id = this.id.next()
var defaultAttrs = { var defaultAttrs = {
"name":"Awesome User" + id, "name":"Awesome User" + id,
"id": id, "id": id,
"diaspora_id": "bob@bob.com", "diaspora_id": "bob@bob.com",
"avatar":{ "avatar":{
"large":"http://localhost:3000/images/user/uma.jpg", "large":"http://localhost:3000/images/user/uma.jpg",
"medium":"http://localhost:3000/images/user/uma.jpg", "medium":"http://localhost:3000/images/user/uma.jpg",
"small":"http://localhost:3000/images/user/uma.jpg"} "small":"http://localhost:3000/images/user/uma.jpg"}
} }
return _.extend(defaultAttrs, overrides) return _.extend(defaultAttrs, overrides)
}, },