From 666ada44f117f1a956694756b1adeed96208aa6e Mon Sep 17 00:00:00 2001 From: Steffen van Bergerem Date: Sun, 27 Aug 2017 22:21:19 +0200 Subject: [PATCH] Fix conversation recipient prefill on profile page Fixes #7586 Use the already available data about the recipient for the prefill --- .../app/views/profile_header_view.js | 9 ++++++-- app/controllers/conversations_controller.rb | 4 +--- .../conversations_controller_spec.rb | 5 ----- .../app/views/profile_header_view_spec.js | 21 ++++++++++--------- 4 files changed, 19 insertions(+), 20 deletions(-) diff --git a/app/assets/javascripts/app/views/profile_header_view.js b/app/assets/javascripts/app/views/profile_header_view.js index 1fb6e0e1d..49fecd656 100644 --- a/app/assets/javascripts/app/views/profile_header_view.js +++ b/app/assets/javascripts/app/views/profile_header_view.js @@ -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"); } }); diff --git a/app/controllers/conversations_controller.rb b/app/controllers/conversations_controller.rb index 3f1977655..87cb28ded 100644 --- a/app/controllers/conversations_controller.rb +++ b/app/controllers/conversations_controller.rb @@ -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 diff --git a/spec/controllers/conversations_controller_spec.rb b/spec/controllers/conversations_controller_spec.rb index 49def945c..1d4206722 100644 --- a/spec/controllers/conversations_controller_spec.rb +++ b/spec/controllers/conversations_controller_spec.rb @@ -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 }) diff --git a/spec/javascripts/app/views/profile_header_view_spec.js b/spec/javascripts/app/views/profile_header_view_spec.js index 999d56cd6..3488d8446 100644 --- a/spec/javascripts/app/views/profile_header_view_spec.js +++ b/spec/javascripts/app/views/profile_header_view_spec.js @@ -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"); }); }); });