Skip to content

Commit

Permalink
Added post moderation buttons in SPV
Browse files Browse the repository at this point in the history
  • Loading branch information
Faldrian committed Jan 25, 2015
1 parent d48b787 commit d7cfe71
Show file tree
Hide file tree
Showing 12 changed files with 226 additions and 11 deletions.
1 change: 1 addition & 0 deletions Changelog.md
Expand Up @@ -152,6 +152,7 @@ diaspora.yml file**. The existing settings from 0.4.x and before will not work a
* Allows users to export their data in gzipped JSON format from their user settings page [#5499](https://github.com/diaspora/diaspora/pull/5499)
* Strip EXIF data from newly uploaded images [#5510](https://github.com/diaspora/diaspora/pull/5510)
* Hide user setting if the community spotlight is not enabled on the pod [#5562](https://github.com/diaspora/diaspora/pull/5562)
* Added/Moved hide, block user, report and delete button in SPV [#5547](https://github.com/diaspora/diaspora/pull/5547)

# 0.4.1.2

Expand Down
46 changes: 44 additions & 2 deletions app/assets/javascripts/app/views/feedback_view.js
Expand Up @@ -8,7 +8,10 @@ app.views.Feedback = app.views.Base.extend({
events: {
"click .like" : "toggleLike",
"click .reshare" : "resharePost",
"click .post_report" : "report"

"click .post_report" : "report",
"click .block_user" : "blockUser",
"click .hide_post" : "hidePost",
},

tooltipSelector : ".label",
Expand Down Expand Up @@ -40,7 +43,46 @@ app.views.Feedback = app.views.Base.extend({
if(evt) { evt.preventDefault(); }
if(!window.confirm(Diaspora.I18n.t("reshares.post", {name: this.model.reshareAuthor().name}))) { return }
this.model.interactions.reshare();
}
},

blockUser: function(evt) {
if(evt) { evt.preventDefault(); }
if(!confirm(Diaspora.I18n.t('ignore_user'))) { return; }

this.model.blockAuthor()
.done(function() {
// return to stream
document.location.href = "/stream";
})
.fail(function() {
Diaspora.page.flashMessages.render({
success: false,
notice: Diaspora.I18n.t('hide_post_failed')
});
});
},

hidePost : function(evt) {
if(evt) { evt.preventDefault(); }
if(!confirm(Diaspora.I18n.t('hide_post'))) { return; }

$.ajax({
url : "/share_visibilities/42",
type : "PUT",
data : {
post_id : this.model.id
}
}).done(function() {
// return to stream
document.location.href = "/stream";
})
.fail(function() {
Diaspora.page.flashMessages.render({
success: false,
notice: Diaspora.I18n.t('ignore_post_failed')
});
});
},
});
// @license-end

Expand Up @@ -6,6 +6,7 @@ app.views.SinglePostContent = app.views.Base.extend({

subviews : {
"#single-post-actions" : "singlePostActionsView",
'#single-post-moderation': "singlePostModerationView",
'#real-post-content' : 'postContentView',
".oembed" : "oEmbedView",
".opengraph" : "openGraphView",
Expand All @@ -15,6 +16,7 @@ app.views.SinglePostContent = app.views.Base.extend({

initialize : function() {
this.singlePostActionsView = new app.views.SinglePostActions({model: this.model});
this.singlePostModerationView = new app.views.SinglePostModeration({model: this.model});
this.oEmbedView = new app.views.OEmbed({model : this.model});
this.openGraphView = new app.views.SPVOpenGraph({model : this.model});
this.postContentView = new app.views.ExpandedStatusMessage({model: this.model});
Expand Down
@@ -0,0 +1,47 @@
app.views.SinglePostModeration = app.views.Feedback.extend({
templateName: "single-post-viewer/single-post-moderation",

events: function() {
return _.defaults({
"click .remove_post": "destroyModel",
}, app.views.Feedback.prototype.events);
},

presenter: function() {
var interactions = this.model.interactions;

return _.extend(this.defaultPresenter(), {
authorIsCurrentUser : this.authorIsCurrentUser(),
});
},

renderPluginWidgets : function() {
app.views.Base.prototype.renderPluginWidgets.apply(this);
this.$('a').tooltip({placement: 'bottom'});
},

authorIsCurrentUser: function() {
return app.currentUser.authenticated() && this.model.get("author").id == app.user().id;
},

destroyModel: function(evt) {
if(evt) { evt.preventDefault(); }
var url = this.model.urlRoot + '/' + this.model.id;

if (confirm(Diaspora.I18n.t("remove_post"))) {
this.model.destroy({ url: url })
.done(function() {
// return to stream
document.location.href = "/stream";
})
.fail(function() {
var flash = new Diaspora.Widgets.FlashMessages;
flash.render({
success: false,
notice: Diaspora.I18n.t('failed_to_remove')
});
});
}
}

});
13 changes: 10 additions & 3 deletions app/assets/javascripts/app/views/stream_post_views.js
Expand Up @@ -95,15 +95,22 @@ app.views.StreamPost = app.views.Post.extend({
if(evt) { evt.preventDefault(); }
if(!confirm(Diaspora.I18n.t('confirm_dialog'))) { return }

var self = this;
$.ajax({
url : "/share_visibilities/42",
type : "PUT",
data : {
post_id : this.model.id
}
})

this.remove();
}).done(function() {
self.remove();
})
.fail(function() {
Diaspora.page.flashMessages.render({
success: false,
notice: Diaspora.I18n.t('hide_post_failed')
});
});
},

focusCommentTextarea: function(evt){
Expand Down
18 changes: 18 additions & 0 deletions app/assets/stylesheets/single-post-view.css.scss
Expand Up @@ -84,6 +84,24 @@
}
}
}
#single-post-moderation {
a:hover {
text-decoration: none;
}
i {
padding-right: 5px;
vertical-align: top;
&:hover {
color: #424242;
}
}
a.post_report > i {
font-size: 14px;
}
i.cross {
font-size: 20px;
}
}
}

#body {
Expand Down
Expand Up @@ -23,11 +23,5 @@
</a>
{{/if}}
{{/if}}

{{#if authorIsNotCurrentUser}}
<a href="#" data-type="post" class="post_report" title="{{t "report.name"}}">
<i class="entypo gray large">&#x21;</i>
</a>
{{/if}}
{{/if}}
</div>
Expand Up @@ -58,6 +58,7 @@
{{/if}}
<div class='status-message-location' />
</div>
<div id='single-post-moderation' />
</div>
</div>
{{#unless root}}
Expand Down
@@ -0,0 +1,19 @@
<div>
{{#if loggedIn}}
{{#if authorIsCurrentUser}}
<a href="#" class="remove_post" title="{{t "delete"}}">
<i class="entypo gray cross"></i>
</a>
{{else}}
<a href="#" data-type="post" class="post_report" title="{{t "report.name"}}">
<i class="entypo gray">&#x21;</i>
</a>
<a href="#" data-type="post" class="block_user" title="{{t "ignore"}}">
<i class="entypo gray">&#128683;</i>
</a>
<a href="#" data-type="post" class="hide_post" title="{{t "stream.hide"}}">
<i class="entypo gray cross"></i>
</a>
{{/if}}
{{/if}}
</div>
3 changes: 3 additions & 0 deletions config/locales/javascript/javascript.en.yml
Expand Up @@ -18,6 +18,9 @@ en:
exists: "The report already exists"
ignore_user: "Ignore this user?"
ignore_failed: "Unable to ignore this user"
hide_post: "Hide this post?"
hide_post_failed: "Unable to hide this post"
remove_post: "Remove this post?"
unblock_failed: "Unblocking this user has failed"
and: "and"
comma: ","
Expand Down
66 changes: 66 additions & 0 deletions features/desktop/single_post_view_moderation.feature
@@ -0,0 +1,66 @@
@javascript
Feature: using SPV moderation buttons

Background:
Given following users exist:
| username |
| bob |
| alice |
And I sign in as "bob@bob.bob"
And a user with username "bob" is connected with "alice"
And I am on the home page

Scenario: hide a contact's post
Given I expand the publisher
When I write the status message "Here is a post to test with"
And I submit the publisher

And I log out
And I sign in as "alice@alice.alice"

And I open the show page of the "Here is a post to test with" post
And I click to hide the post
And I confirm the alert

Then I should be on the stream page

Scenario: block a contact
Given I expand the publisher
When I write the status message "Here is a post to test with"
And I submit the publisher

And I log out
And I sign in as "alice@alice.alice"

And I open the show page of the "Here is a post to test with" post
And I click to block the user
And I confirm the alert

Then I should be on the stream page

Scenario: report a contact
Given I expand the publisher
When I write the status message "Here is a post to test with"
And I submit the publisher

And I log out
And I sign in as "alice@alice.alice"

And I open the show page of the "Here is a post to test with" post
And I click to report the post
And I confirm the alert

And I should see a flash message containing "The report was successfully created"

Scenario: delete own post
Given I expand the publisher
When I write the status message "Here is a post to test with"
And I submit the publisher

And I open the show page of the "Here is a post to test with" post
And I click to delete the post
And I confirm the alert

Then I should be on the stream page


15 changes: 15 additions & 0 deletions features/step_definitions/single_post_view_steps.rb
@@ -0,0 +1,15 @@
And /^I click to hide the post/ do
find('.hide_post').click
end

And /^I click to block the user/ do
find('.block_user').click
end

And /^I click to report the post/ do
find('.post_report').click
end

And /^I click to delete the post/ do
find('.remove_post').click
end

0 comments on commit d7cfe71

Please sign in to comment.