Commit 48630b3a authored by Steffen van Bergerem's avatar Steffen van Bergerem Committed by Benjamin Neff

Fix conversation recipient prefill on contacts page

Use the already available contacts data for the prefill
parent 666ada44
......@@ -80,7 +80,15 @@ app.pages.Contacts = Backbone.View.extend({
showMessageModal: function(){
$("#conversationModal").on("modal:loaded", function() {
new app.views.ConversationsForm({prefill: gon.conversationPrefill});
var people = app.contacts.filter(function(contact) {
return contact.inAspect(app.aspect.get("id"));
}).map(function(contact) {
return _.extend({
avatar: contact.person.get("profile").avatar.small,
handle: contact.person.get("diaspora_id")
}, contact.person.attributes);
});
new app.views.ConversationsForm({prefill: people});
});
app.helpers.showModal("#conversationModal");
},
......
......@@ -103,10 +103,6 @@ class ConversationsController < ApplicationController
render :layout => true
else
if params[:aspect_id]
gon.push conversation_prefill: current_user.aspects
.find(params[:aspect_id]).contacts.map {|c| c.person.as_json }
end
render :layout => false
end
end
......
= include_gon camel_case: true
= render 'conversations/new'
= render "conversations/new"
......@@ -20,11 +20,6 @@ describe ConversationsController, :type => :controller do
get :new, params: {modal: true}
expect(response).to be_success
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 })
end
end
context "mobile" do
......
......@@ -290,17 +290,20 @@ describe("app.pages.Contacts", 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");
app.aspect = new app.models.Aspect(app.contacts.first().get("aspect_memberships")[0].aspect);
this.view.showMessageModal();
$("#conversationModal").trigger("modal:loaded");
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;
var people = app.contacts.filter(function(contact) { return contact.inAspect(app.aspect.get("id")); });
expect(prefill.length).toBe(people.length);
var person = app.contacts.first().person;
expect(prefill[0].handle).toBe(person.get("diaspora_id"));
expect(prefill[0].name).toBe(person.get("name"));
expect(prefill[0].avatar).toBe(person.get("profile").avatar.small);
});
});
});
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