Commit 666ada44 authored by Steffen van Bergerem's avatar Steffen van Bergerem Committed by Benjamin Neff

Fix conversation recipient prefill on profile page

Fixes #7586

Use the already available data about the recipient for the prefill
parent 9d276308
......@@ -81,8 +81,13 @@ app.views.ProfileHeader = app.views.Base.extend({
showMessageModal: function(){
$("#conversationModal").on("modal:loaded", function() {
new app.views.ConversationsForm({prefill: gon.conversationPrefill});
});
new app.views.ConversationsForm({
prefill: [_.extend({
avatar: this.model.get("profile").avatar.small,
handle: this.model.get("diaspora_id")
}, this.model.attributes)]
});
}.bind(this));
app.helpers.showModal("#conversationModal");
}
});
......
......@@ -103,9 +103,7 @@ class ConversationsController < ApplicationController
render :layout => true
else
if params[:contact_id]
gon.push conversation_prefill: [current_user.contacts.find(params[:contact_id]).person.as_json]
elsif params[:aspect_id]
if params[:aspect_id]
gon.push conversation_prefill: current_user.aspects
.find(params[:aspect_id]).contacts.map {|c| c.person.as_json }
end
......
......@@ -21,11 +21,6 @@ describe ConversationsController, :type => :controller do
expect(response).to be_success
end
it "assigns a contact if passed a contact id" do
get :new, params: {contact_id: alice.contacts.first.id, modal: true}
expect(controller.gon.conversation_prefill).to eq([alice.contacts.first.person.as_json])
end
it "assigns a set of contacts if passed an aspect id" do
get :new, params: {aspect_id: alice.aspects.first.id, modal: true}
expect(controller.gon.conversation_prefill).to eq(alice.aspects.first.contacts.map {|c| c.person.as_json })
......
......@@ -4,8 +4,11 @@ describe("app.views.ProfileHeader", function() {
this.model = factory.personWithProfile({
diaspora_id: "my@pod",
name: "User Name",
relationship: 'mutual',
profile: { tags: ['test'] }
relationship: "mutual",
profile: {
avatar: {small: "http://example.org/avatar.jpg"},
tags: ["test"]
}
});
this.view = new app.views.ProfileHeader({model: this.model});
loginAs(factory.userAttrs());
......@@ -71,17 +74,15 @@ describe("app.views.ProfileHeader", function() {
});
it("initializes app.views.ConversationsForm with correct parameters when modal is loaded", function() {
gon.conversationPrefill = [
{id: 1, name: "diaspora user", handle: "diaspora-user@pod.tld"},
{id: 2, name: "other diaspora user", handle: "other-diaspora-user@pod.tld"},
{id: 3, name: "user@pod.tld", handle: "user@pod.tld"}
];
spyOn(app.views.ConversationsForm.prototype, "initialize");
spyOn($.fn, "load").and.callFake(function(url, callback) { callback(); });
this.view.showMessageModal();
expect(app.views.ConversationsForm.prototype.initialize)
.toHaveBeenCalledWith({prefill: gon.conversationPrefill});
expect(app.views.ConversationsForm.prototype.initialize).toHaveBeenCalled();
var prefill = app.views.ConversationsForm.prototype.initialize.calls.mostRecent().args[0].prefill;
expect(prefill.length).toBe(1);
expect(prefill[0].handle).toBe("my@pod");
expect(prefill[0].name).toBe("User Name");
expect(prefill[0].avatar).toBe("http://example.org/avatar.jpg");
});
});
});
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment