Fix conversation recipient prefill on contacts page

Use the already available contacts data for the prefill
This commit is contained in:
Steffen van Bergerem 2017-08-28 00:23:39 +02:00 committed by Benjamin Neff
parent 666ada44f1
commit 48630b3a04
No known key found for this signature in database
GPG key ID: 971464C3F1A90194
5 changed files with 21 additions and 20 deletions

View file

@ -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");
},

View file

@ -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

View file

@ -1,2 +1 @@
= include_gon camel_case: true
= render 'conversations/new'
= render "conversations/new"

View file

@ -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

View file

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