Only update mentions in publisher before opening suggestions or preview
This commit is contained in:
parent
90b379b110
commit
9217df43cd
4 changed files with 42 additions and 28 deletions
|
|
@ -80,6 +80,8 @@ app.views.PublisherMention = app.views.SearchBase.extend({
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
this.cleanMentionedPeople();
|
||||||
|
|
||||||
// result[1] is the string between the last '@' and the current caret position
|
// result[1] is the string between the last '@' and the current caret position
|
||||||
this.typeaheadInput.typeahead("val", result[1]);
|
this.typeaheadInput.typeahead("val", result[1]);
|
||||||
this.typeaheadInput.typeahead("open");
|
this.typeaheadInput.typeahead("open");
|
||||||
|
|
@ -122,7 +124,6 @@ app.views.PublisherMention = app.views.SearchBase.extend({
|
||||||
* Listens for user input and opens results dropdown when input contains the trigger char
|
* Listens for user input and opens results dropdown when input contains the trigger char
|
||||||
*/
|
*/
|
||||||
onInputBoxInput: function() {
|
onInputBoxInput: function() {
|
||||||
this.cleanMentionedPeople();
|
|
||||||
this.updateTypeaheadInput();
|
this.updateTypeaheadInput();
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
@ -178,5 +179,10 @@ app.views.PublisherMention = app.views.SearchBase.extend({
|
||||||
|
|
||||||
isVisible: function() {
|
isVisible: function() {
|
||||||
return this.$(".tt-menu").is(":visible");
|
return this.$(".tt-menu").is(":visible");
|
||||||
|
},
|
||||||
|
|
||||||
|
getMentionedPeople: function() {
|
||||||
|
this.cleanMentionedPeople();
|
||||||
|
return this.mentionedPeople;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -192,9 +192,6 @@ app.views.Publisher = Backbone.View.extend({
|
||||||
// empty poll answer and failing validation.
|
// empty poll answer and failing validation.
|
||||||
this.viewPollCreator.removeLastAnswer();
|
this.viewPollCreator.removeLastAnswer();
|
||||||
|
|
||||||
//add missing mentions at end of post:
|
|
||||||
this.handleTextchange();
|
|
||||||
|
|
||||||
var serializedForm = $(evt.target).closest("form").serializeObject();
|
var serializedForm = $(evt.target).closest("form").serializeObject();
|
||||||
// disable input while posting, must be after the form is serialized
|
// disable input while posting, must be after the form is serialized
|
||||||
this.setInputEnabled(false);
|
this.setInputEnabled(false);
|
||||||
|
|
@ -320,13 +317,10 @@ app.views.Publisher = Backbone.View.extend({
|
||||||
},
|
},
|
||||||
|
|
||||||
createPostPreview: function() {
|
createPostPreview: function() {
|
||||||
//add missing mentions at end of post:
|
|
||||||
this.handleTextchange();
|
|
||||||
|
|
||||||
var serializedForm = $("#new_status_message").serializeObject();
|
var serializedForm = $("#new_status_message").serializeObject();
|
||||||
var text = serializedForm["status_message[text]"];
|
var text = serializedForm["status_message[text]"];
|
||||||
var photos = this.getUploadedPhotos();
|
var photos = this.getUploadedPhotos();
|
||||||
var mentionedPeople = this.mention.mentionedPeople;
|
var mentionedPeople = this.mention.getMentionedPeople();
|
||||||
var poll = this.getPollData(serializedForm);
|
var poll = this.getPollData(serializedForm);
|
||||||
var locationCoords = serializedForm["location[coords]"];
|
var locationCoords = serializedForm["location[coords]"];
|
||||||
if(!locationCoords || locationCoords === "") {
|
if(!locationCoords || locationCoords === "") {
|
||||||
|
|
|
||||||
|
|
@ -229,6 +229,22 @@ describe("app.views.PublisherMention", function() {
|
||||||
expect(this.view.closeSuggestions).not.toHaveBeenCalled();
|
expect(this.view.closeSuggestions).not.toHaveBeenCalled();
|
||||||
expect(this.view.typeaheadInput.val()).toBe("user");
|
expect(this.view.typeaheadInput.val()).toBe("user");
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("doesn't call 'cleanMentionedPeople' if there is no '@' in front of the caret", function() {
|
||||||
|
spyOn(this.view, "cleanMentionedPeople");
|
||||||
|
this.view.inputBox.val("user1337 Text before @user1 text after");
|
||||||
|
this.view.inputBox[0].setSelectionRange(9, 9);
|
||||||
|
this.view.updateTypeaheadInput();
|
||||||
|
expect(this.view.cleanMentionedPeople).not.toHaveBeenCalled();
|
||||||
|
});
|
||||||
|
|
||||||
|
it("calls 'cleanMentionedPeople' if there is an '@' in front of the caret", function() {
|
||||||
|
spyOn(this.view, "cleanMentionedPeople");
|
||||||
|
this.view.inputBox.val("@user1337 Text before @user1 text after");
|
||||||
|
this.view.inputBox[0].setSelectionRange(9, 9);
|
||||||
|
this.view.updateTypeaheadInput();
|
||||||
|
expect(this.view.cleanMentionedPeople).toHaveBeenCalled();
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("prefillMention", function() {
|
describe("prefillMention", function() {
|
||||||
|
|
@ -352,12 +368,6 @@ describe("app.views.PublisherMention", function() {
|
||||||
this.view = new app.views.PublisherMention({ el: "#publisher" });
|
this.view = new app.views.PublisherMention({ el: "#publisher" });
|
||||||
});
|
});
|
||||||
|
|
||||||
it("calls 'cleanMentionedPeople'", function() {
|
|
||||||
spyOn(this.view, "cleanMentionedPeople");
|
|
||||||
this.view.onInputBoxInput();
|
|
||||||
expect(this.view.cleanMentionedPeople).toHaveBeenCalled();
|
|
||||||
});
|
|
||||||
|
|
||||||
it("calls 'updateTypeaheadInput'", function() {
|
it("calls 'updateTypeaheadInput'", function() {
|
||||||
spyOn(this.view, "updateTypeaheadInput");
|
spyOn(this.view, "updateTypeaheadInput");
|
||||||
this.view.onInputBoxInput();
|
this.view.onInputBoxInput();
|
||||||
|
|
@ -422,4 +432,22 @@ describe("app.views.PublisherMention", function() {
|
||||||
expect(this.view.typeaheadInput.val()).toBe("");
|
expect(this.view.typeaheadInput.val()).toBe("");
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe("getMentionedPeople", function() {
|
||||||
|
beforeEach(function() {
|
||||||
|
this.view = new app.views.PublisherMention({el: "#publisher"});
|
||||||
|
});
|
||||||
|
|
||||||
|
it("calls 'cleanMentionedPeople'", function() {
|
||||||
|
spyOn(this.view, "cleanMentionedPeople");
|
||||||
|
this.view.getMentionedPeople();
|
||||||
|
expect(this.view.cleanMentionedPeople).toHaveBeenCalled();
|
||||||
|
});
|
||||||
|
|
||||||
|
it("returns the cleaned mentionedPeople", function() {
|
||||||
|
this.view.inputBox.val("@{user1@pod.tld} user2@pod.tld");
|
||||||
|
this.view.mentionedPeople = [{name: "user1", handle: "user1@pod.tld"}, {name: "user2", handle: "user2@pod.tld"}];
|
||||||
|
expect(this.view.getMentionedPeople()).toEqual([{name: "user1", handle: "user1@pod.tld"}]);
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -203,12 +203,6 @@ describe("app.views.Publisher", function() {
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("createStatusMessage", function(){
|
describe("createStatusMessage", function(){
|
||||||
it("calls handleTextchange to complete missing mentions", function(){
|
|
||||||
spyOn(this.view, "handleTextchange");
|
|
||||||
this.view.createStatusMessage($.Event());
|
|
||||||
expect(this.view.handleTextchange).toHaveBeenCalled();
|
|
||||||
});
|
|
||||||
|
|
||||||
it("adds the status message to the stream", function() {
|
it("adds the status message to the stream", function() {
|
||||||
app.stream = { addNow: $.noop };
|
app.stream = { addNow: $.noop };
|
||||||
spyOn(app.stream, "addNow");
|
spyOn(app.stream, "addNow");
|
||||||
|
|
@ -224,14 +218,6 @@ describe("app.views.Publisher", function() {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("createPostPreview", function(){
|
|
||||||
it("calls handleTextchange to complete missing mentions", function(){
|
|
||||||
spyOn(this.view, "handleTextchange");
|
|
||||||
this.view.createPostPreview();
|
|
||||||
expect(this.view.handleTextchange).toHaveBeenCalled();
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('#setText', function() {
|
describe('#setText', function() {
|
||||||
it("sets the content text", function() {
|
it("sets the content text", function() {
|
||||||
this.view.setText("FOO bar");
|
this.view.setText("FOO bar");
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue