Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#7469 - stop ignoring from hovercards #7748

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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
29 changes: 29 additions & 0 deletions app/assets/javascripts/app/views/unblock_person_view.js
@@ -0,0 +1,29 @@
// @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 unblock = this.person.unblock();
var that = this;

unblock.fail(function() {
app.flashMessages.error(Diaspora.I18.t("unblock_failed"));
});

unblock.done(function() {
that.parent._populateHovercard();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now that this method is called outside of the class it should probably drop the leading underscore since it is no longer private use. The method itself assumes that parent has been set with a parent that has the href attr which is only true if the parent used already went through the showHovercardOn: _.debounce path. It seems any time someone would use it that it would have been through that path already but if want to do some more defensive programming could catch/check that too perhaps.

});
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