mirror of
https://github.com/discourse/discourse.git
synced 2025-03-29 02:15:38 +08:00
FIX: makes whisper state more resilient (#6889)
This commit also moves some logic from model to controller.
This commit is contained in:
parent
b46b6e72d1
commit
1ac4dc5b73
@ -16,6 +16,7 @@ import {
|
|||||||
} from "discourse/lib/utilities";
|
} from "discourse/lib/utilities";
|
||||||
import { emojiUnescape } from "discourse/lib/text";
|
import { emojiUnescape } from "discourse/lib/text";
|
||||||
import { shortDate } from "discourse/lib/formatter";
|
import { shortDate } from "discourse/lib/formatter";
|
||||||
|
import { SAVE_LABELS, SAVE_ICONS } from "discourse/models/composer";
|
||||||
|
|
||||||
function loadDraft(store, opts) {
|
function loadDraft(store, opts) {
|
||||||
opts = opts || {};
|
opts = opts || {};
|
||||||
@ -101,7 +102,7 @@ export default Ember.Controller.extend({
|
|||||||
linkLookup: null,
|
linkLookup: null,
|
||||||
showPreview: true,
|
showPreview: true,
|
||||||
forcePreview: Ember.computed.and("site.mobileView", "showPreview"),
|
forcePreview: Ember.computed.and("site.mobileView", "showPreview"),
|
||||||
whisperOrUnlistTopic: Ember.computed.or("model.whisper", "model.unlistTopic"),
|
whisperOrUnlistTopic: Ember.computed.or("isWhispering", "model.unlistTopic"),
|
||||||
categories: Ember.computed.alias("site.categoriesList"),
|
categories: Ember.computed.alias("site.categoriesList"),
|
||||||
|
|
||||||
@on("init")
|
@on("init")
|
||||||
@ -200,15 +201,42 @@ export default Ember.Controller.extend({
|
|||||||
|
|
||||||
canUnlistTopic: Ember.computed.and("model.creatingTopic", "isStaffUser"),
|
canUnlistTopic: Ember.computed.and("model.creatingTopic", "isStaffUser"),
|
||||||
|
|
||||||
@computed("canWhisper", "model.post")
|
@computed("canWhisper", "replyingToWhisper")
|
||||||
showWhisperToggle(canWhisper, repliedToPost) {
|
showWhisperToggle(canWhisper, replyingToWhisper) {
|
||||||
const replyingToWhisper =
|
|
||||||
repliedToPost &&
|
|
||||||
repliedToPost.get("post_type") === this.site.post_types.whisper;
|
|
||||||
|
|
||||||
return canWhisper && !replyingToWhisper;
|
return canWhisper && !replyingToWhisper;
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@computed("model.post")
|
||||||
|
replyingToWhisper(repliedToPost) {
|
||||||
|
return (
|
||||||
|
repliedToPost &&
|
||||||
|
repliedToPost.get("post_type") === this.site.post_types.whisper
|
||||||
|
);
|
||||||
|
},
|
||||||
|
|
||||||
|
@computed("replyingToWhisper", "model.whisper")
|
||||||
|
isWhispering(replyingToWhisper, whisper) {
|
||||||
|
return replyingToWhisper || whisper;
|
||||||
|
},
|
||||||
|
|
||||||
|
@computed("model.action", "isWhispering")
|
||||||
|
saveIcon(action, isWhispering) {
|
||||||
|
if (isWhispering) {
|
||||||
|
return "eye-slash";
|
||||||
|
}
|
||||||
|
return SAVE_ICONS[action];
|
||||||
|
},
|
||||||
|
|
||||||
|
@computed("model.action", "isWhispering", "model.editConflict")
|
||||||
|
saveLabel(action, isWhispering, editConflict) {
|
||||||
|
if (editConflict) {
|
||||||
|
return "composer.overwrite_edit";
|
||||||
|
} else if (isWhispering) {
|
||||||
|
return "composer.create_whisper";
|
||||||
|
}
|
||||||
|
return SAVE_LABELS[action];
|
||||||
|
},
|
||||||
|
|
||||||
@computed("isStaffUser", "model.action")
|
@computed("isStaffUser", "model.action")
|
||||||
canWhisper(isStaffUser, action) {
|
canWhisper(isStaffUser, action) {
|
||||||
return (
|
return (
|
||||||
|
@ -52,7 +52,7 @@ const CLOSED = "closed",
|
|||||||
featuredLink: "topic.featured_link"
|
featuredLink: "topic.featured_link"
|
||||||
};
|
};
|
||||||
|
|
||||||
const SAVE_LABELS = {
|
export const SAVE_LABELS = {
|
||||||
[EDIT]: "composer.save_edit",
|
[EDIT]: "composer.save_edit",
|
||||||
[REPLY]: "composer.reply",
|
[REPLY]: "composer.reply",
|
||||||
[CREATE_TOPIC]: "composer.create_topic",
|
[CREATE_TOPIC]: "composer.create_topic",
|
||||||
@ -61,7 +61,7 @@ const SAVE_LABELS = {
|
|||||||
[EDIT_SHARED_DRAFT]: "composer.save_edit"
|
[EDIT_SHARED_DRAFT]: "composer.save_edit"
|
||||||
};
|
};
|
||||||
|
|
||||||
const SAVE_ICONS = {
|
export const SAVE_ICONS = {
|
||||||
[EDIT]: "pencil",
|
[EDIT]: "pencil",
|
||||||
[EDIT_SHARED_DRAFT]: "clipboard",
|
[EDIT_SHARED_DRAFT]: "clipboard",
|
||||||
[REPLY]: "reply",
|
[REPLY]: "reply",
|
||||||
@ -385,24 +385,6 @@ const Composer = RestModel.extend({
|
|||||||
return this.get("titleLength") <= this.siteSettings.max_topic_title_length;
|
return this.get("titleLength") <= this.siteSettings.max_topic_title_length;
|
||||||
}.property("minimumTitleLength", "titleLength", "post.static_doc"),
|
}.property("minimumTitleLength", "titleLength", "post.static_doc"),
|
||||||
|
|
||||||
@computed("action", "whisper")
|
|
||||||
saveIcon(action, whisper) {
|
|
||||||
if (whisper) {
|
|
||||||
return "eye-slash";
|
|
||||||
}
|
|
||||||
return SAVE_ICONS[action];
|
|
||||||
},
|
|
||||||
|
|
||||||
@computed("action", "whisper", "editConflict")
|
|
||||||
saveLabel(action, whisper, editConflict) {
|
|
||||||
if (editConflict) {
|
|
||||||
return "composer.overwrite_edit";
|
|
||||||
} else if (whisper) {
|
|
||||||
return "composer.create_whisper";
|
|
||||||
}
|
|
||||||
return SAVE_LABELS[action];
|
|
||||||
},
|
|
||||||
|
|
||||||
hasMetaData: function() {
|
hasMetaData: function() {
|
||||||
const metaData = this.get("metaData");
|
const metaData = this.get("metaData");
|
||||||
return metaData ? Ember.isEmpty(Ember.keys(this.get("metaData"))) : false;
|
return metaData ? Ember.isEmpty(Ember.keys(this.get("metaData"))) : false;
|
||||||
|
@ -25,7 +25,7 @@
|
|||||||
{{plugin-outlet name="composer-action-after" noTags=true args=(hash model=model)}}
|
{{plugin-outlet name="composer-action-after" noTags=true args=(hash model=model)}}
|
||||||
|
|
||||||
{{#unless site.mobileView}}
|
{{#unless site.mobileView}}
|
||||||
{{#if model.whisper}}
|
{{#if isWhispering}}
|
||||||
<span class='whisper'>{{d-icon 'eye-slash'}}</span>
|
<span class='whisper'>{{d-icon 'eye-slash'}}</span>
|
||||||
{{/if}}
|
{{/if}}
|
||||||
{{#if model.unlistTopic}}
|
{{#if model.unlistTopic}}
|
||||||
@ -119,8 +119,8 @@
|
|||||||
<div class='save-or-cancel'>
|
<div class='save-or-cancel'>
|
||||||
{{#unless model.viewFullscreen}}
|
{{#unless model.viewFullscreen}}
|
||||||
{{composer-save-button action=(action "save")
|
{{composer-save-button action=(action "save")
|
||||||
icon=model.saveIcon
|
icon=saveIcon
|
||||||
label=model.saveLabel
|
label=saveLabel
|
||||||
disableSubmit=disableSubmit}}
|
disableSubmit=disableSubmit}}
|
||||||
|
|
||||||
{{#if site.mobileView}}
|
{{#if site.mobileView}}
|
||||||
|
@ -407,6 +407,44 @@ QUnit.test("Composer can toggle whispers", async assert => {
|
|||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
QUnit.test("Switching composer whisper state", async assert => {
|
||||||
|
const menu = selectKit(".toolbar-popup-menu-options");
|
||||||
|
|
||||||
|
await visit("/t/this-is-a-test-topic/9");
|
||||||
|
await click(".topic-post:eq(0) button.reply");
|
||||||
|
|
||||||
|
await menu.expand();
|
||||||
|
await menu.selectRowByValue("toggleWhisper");
|
||||||
|
|
||||||
|
await fillIn(".d-editor-input", "this is the content of my reply");
|
||||||
|
await click("#reply-control button.create");
|
||||||
|
|
||||||
|
assert.ok(find(".topic-post:last").hasClass("whisper"));
|
||||||
|
|
||||||
|
await click("#topic-footer-buttons .btn.create");
|
||||||
|
|
||||||
|
assert.ok(
|
||||||
|
find(".composer-fields .whisper .d-icon-eye-slash").length === 0,
|
||||||
|
"doesn’t set topic reply as whisper"
|
||||||
|
);
|
||||||
|
|
||||||
|
await click(".topic-post:last button.reply");
|
||||||
|
|
||||||
|
assert.ok(find(".topic-post:last").hasClass("whisper"));
|
||||||
|
assert.ok(
|
||||||
|
find(".composer-fields .whisper .d-icon-eye-slash").length === 1,
|
||||||
|
"sets post reply as a whisper"
|
||||||
|
);
|
||||||
|
|
||||||
|
await click(".topic-post:nth-last-child(2) button.reply");
|
||||||
|
|
||||||
|
assert.notOk(find(".topic-post:nth-last-child(2)").hasClass("whisper"));
|
||||||
|
assert.ok(
|
||||||
|
find(".composer-fields .whisper .d-icon-eye-slash").length === 0,
|
||||||
|
"doesn’t set post reply as a whisper"
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
QUnit.test(
|
QUnit.test(
|
||||||
"Composer can toggle layouts (open, fullscreen and draft)",
|
"Composer can toggle layouts (open, fullscreen and draft)",
|
||||||
async assert => {
|
async assert => {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user