Skip to content

Commit

Permalink
show 'stop ignoring' button in hovercards
Browse files Browse the repository at this point in the history
  • Loading branch information
kas70 committed Mar 31, 2018
1 parent c84411e commit a2c5b2b
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 6 deletions.
6 changes: 4 additions & 2 deletions app/assets/javascripts/app/views/hovercard_view.js
Expand Up @@ -5,7 +5,7 @@ app.views.Hovercard = app.views.Base.extend({
id: 'hovercard_container',

subviews: {
"#hovercard_dropdown_container": "aspectMembershipDropdown"
"#hovercard_dropdown_container": "aspectDropdownOrUnblock"
},

events: {
Expand Down Expand Up @@ -104,7 +104,9 @@ app.views.Hovercard = app.views.Base.extend({
}

if (app.currentUser.authenticated()) {
self.aspectMembershipDropdown = new app.views.AspectMembership({person: new app.models.Person(person)});
self.aspectDropdownOrUnblock = person.block ?
new app.views.UnblockPerson({person: new app.models.Person(person), parent: self}) :
new app.views.AspectMembership({person: new app.models.Person(person)});
}

self.render();
Expand Down
24 changes: 24 additions & 0 deletions app/assets/javascripts/app/views/unblock_person_view.js
@@ -0,0 +1,24 @@
// @license magnet:?xt=urn:btih:0b31508aeb0634b347b8270c7bee4d411b5d4109&dn=agpl-3.0.txt AGPL-v3-or-Later

app.views.UnblockPerson = app.views.Base.extend({
templateName: "unblock_person",

events: {
"click #unblock_user_button": "unblock"
},

initialize: function(opts) {
_.extend(this, opts);
this.parent = opts.parent;
},

unblock: function() {
var block = this.person.unblock();
block.fail(function() {
app.flashMessages.error(Diaspora.I18.t("unblock_failed"));
});
this.parent._populateHovercard();
return false;
}
});
// @license-end
3 changes: 3 additions & 0 deletions app/assets/templates/unblock_person_tpl.jst.hbs
@@ -0,0 +1,3 @@
<button id="unblock_user_button" class="btn btn-danger">
<span class="text">{{ t "people.stop_ignoring" }}</span>
</button>
8 changes: 6 additions & 2 deletions app/presenters/person_presenter.rb
Expand Up @@ -13,7 +13,7 @@ def base_hash
def full_hash
base_hash_with_contact.merge(
relationship: relationship,
block: is_blocked? ? BlockPresenter.new(current_user_person_block).base_hash : false,
block: block_details,
is_own_profile: own_profile?,
show_profile_info: public_details? || own_profile? || person_is_following_current_user
)
Expand All @@ -24,7 +24,7 @@ def as_json(_options={})
end

def hovercard
base_hash_with_contact.merge(profile: ProfilePresenter.new(profile).for_hovercard)
base_hash_with_contact.merge(block: block_details, profile: ProfilePresenter.new(profile).for_hovercard)
end

def metas_attributes
Expand Down Expand Up @@ -109,6 +109,10 @@ def is_blocked?
current_user_person_block.present?
end

def block_details
is_blocked? ? BlockPresenter.new(current_user_person_block).base_hash : false
end

def title
name
end
Expand Down
13 changes: 11 additions & 2 deletions spec/javascripts/app/views/hovercard_view_spec.js
Expand Up @@ -52,13 +52,22 @@ describe("app.views.Hovercard", function() {
expect(jQuery.ajax).toHaveBeenCalledWith("undefined/hovercard.json", {preventGlobalErrorHandling: true});
});

it("creates the aspect dropdown", function() {
it("creates the aspect dropdown if person is not blocked", function() {
this.view._populateHovercard();
jasmine.Ajax.requests.mostRecent().respondWith({
status: 200,
responseText: JSON.stringify({id: 1337})
});
expect(this.view.aspectMembershipDropdown).not.toEqual(undefined);
expect(String(this.view.aspectDropdownOrUnblock.templateName)).toEqual("aspect_membership_dropdown");
});

it("creates the stop-ignoring button if person is blocked", function() {
this.view._populateHovercard();
jasmine.Ajax.requests.mostRecent().respondWith({
status: 200,
responseText: JSON.stringify({id: 1337, block: {id: 5}})
});
expect(this.view.aspectDropdownOrUnblock.templateName).toEqual('unblock_person');
});

it("renders tags properly", function() {
Expand Down

0 comments on commit a2c5b2b

Please sign in to comment.