Unverified Commit 02d9d350 authored by Steffen van Bergerem's avatar Steffen van Bergerem Committed by Benjamin Neff

Move person extension for prefills to conversations form view

closes #7599
parent 48630b3a
......@@ -15,6 +15,7 @@
* Fix S3 support [#7566](https://github.com/diaspora/diaspora/pull/7566)
* Fix mixed username and timestamp with LTR/RTL scripts [#7575](https://github.com/diaspora/diaspora/pull/7575)
* Prevent users from zooming in IE Mobile [#7589](https://github.com/diaspora/diaspora/pull/7589)
* Fix recipient prefill on contacts and profile page [#7599](https://github.com/diaspora/diaspora/pull/7599)
## Features
* Ask for confirmation when leaving a submittable comment field [#7530](https://github.com/diaspora/diaspora/pull/7530)
......
......@@ -80,14 +80,9 @@ app.pages.Contacts = Backbone.View.extend({
showMessageModal: function(){
$("#conversationModal").on("modal:loaded", function() {
var people = app.contacts.filter(function(contact) {
var people = _.pluck(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);
});
}), "person");
new app.views.ConversationsForm({prefill: people});
});
app.helpers.showModal("#conversationModal");
......
......@@ -52,8 +52,13 @@ app.views.ConversationsForm = app.views.Base.extend({
this.setupAvatarFallback(personEl);
},
prefill: function(handles) {
handles.forEach(this.addRecipient.bind(this));
prefill: function(people) {
people.forEach(function(person) {
this.addRecipient(_.extend({
avatar: person.get("profile").avatar.small,
handle: person.get("diaspora_id")
}, person.attributes));
}, this);
},
updateContactIdsListInput: function() {
......
......@@ -81,12 +81,7 @@ app.views.ProfileHeader = app.views.Base.extend({
showMessageModal: function(){
$("#conversationModal").on("modal:loaded", function() {
new app.views.ConversationsForm({
prefill: [_.extend({
avatar: this.model.get("profile").avatar.small,
handle: this.model.get("diaspora_id")
}, this.model.attributes)]
});
new app.views.ConversationsForm({prefill: [this.model]});
}.bind(this));
app.helpers.showModal("#conversationModal");
}
......
......@@ -297,13 +297,8 @@ describe("app.pages.Contacts", function(){
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);
var contacts = app.contacts.filter(function(contact) { return contact.inAspect(app.aspect.get("id")); });
expect(_.pluck(prefill, "id")).toEqual(contacts.map(function(contact) { return contact.person.id; }));
});
});
});
......@@ -85,7 +85,11 @@ describe("app.views.ConversationsForm", function() {
describe("prefill", function() {
beforeEach(function() {
this.prefills = [{name: "diaspora user"}, {name: "other diaspora user"}, {name: "user"}];
this.prefills = [
factory.personWithProfile({"diaspora_id": "alice@pod.tld"}),
factory.personWithProfile({"diaspora_id": "bob@pod.tld"}),
factory.personWithProfile({"diaspora_id": "carol@pod.tld"})
];
});
it("calls addRecipient for each prefilled participant", function() {
......@@ -95,7 +99,14 @@ describe("app.views.ConversationsForm", function() {
var allArgsFlattened = app.views.ConversationsForm.prototype.addRecipient.calls.allArgs().map(function(arg) {
return arg[0];
});
expect(allArgsFlattened).toEqual(this.prefills);
expect(_.pluck(allArgsFlattened, "handle")).toEqual(
this.prefills.map(function(person) { return person.get("diaspora_id"); })
);
expect(_.pluck(allArgsFlattened, "avatar")).toEqual(
this.prefills.map(function(person) { return person.get("profile").avatar.small; })
);
});
});
......
......@@ -77,12 +77,9 @@ describe("app.views.ProfileHeader", function() {
spyOn(app.views.ConversationsForm.prototype, "initialize");
spyOn($.fn, "load").and.callFake(function(url, callback) { callback(); });
this.view.showMessageModal();
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");
expect(app.views.ConversationsForm.prototype.initialize).toHaveBeenCalledWith({
prefill: [this.model]
});
});
});
});
......@@ -138,9 +138,11 @@ var factory = {
"full_name": "bob grimm",
"gender": "robot",
"id": id,
"image_url": "http://localhost:3000/assets/user/default.png",
"image_url_medium": "http://localhost:3000/assets/user/default.png",
"image_url_small": "http://localhost:3000/assets/user/default.png",
"avatar": {
"small": "http://localhost:3000/assets/user/default.png",
"medium": "http://localhost:3000/assets/user/default.png",
"large": "http://localhost:3000/assets/user/default.png"
},
"last_name": "Grimm",
"location": "Earth",
"nsfw": false,
......
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