2018-02-01 23:42:56 +08:00
|
|
|
import DropdownSelectBoxComponent from "select-kit/components/dropdown-select-box";
|
2018-02-10 05:58:04 +08:00
|
|
|
import computed from "ember-addons/ember-computed-decorators";
|
2018-03-14 03:59:12 +08:00
|
|
|
import {
|
|
|
|
PRIVATE_MESSAGE,
|
|
|
|
CREATE_TOPIC,
|
|
|
|
CREATE_SHARED_DRAFT,
|
|
|
|
REPLY,
|
|
|
|
EDIT,
|
|
|
|
NEW_PRIVATE_MESSAGE_KEY
|
|
|
|
} from "discourse/models/composer";
|
2018-02-08 18:46:55 +08:00
|
|
|
|
|
|
|
// Component can get destroyed and lose state
|
|
|
|
let _topicSnapshot = null;
|
|
|
|
let _postSnapshot = null;
|
|
|
|
|
|
|
|
export function _clearSnapshots() {
|
|
|
|
_topicSnapshot = null;
|
|
|
|
_postSnapshot = null;
|
|
|
|
}
|
2018-02-01 23:42:56 +08:00
|
|
|
|
|
|
|
export default DropdownSelectBoxComponent.extend({
|
|
|
|
pluginApiIdentifiers: ["composer-actions"],
|
|
|
|
classNames: "composer-actions",
|
|
|
|
fullWidthOnMobile: true,
|
|
|
|
autofilterable: false,
|
|
|
|
filterable: false,
|
|
|
|
allowInitialValueMutation: false,
|
|
|
|
allowAutoSelectFirst: false,
|
|
|
|
showFullTitle: false,
|
2018-05-24 00:25:58 +08:00
|
|
|
isHidden: Ember.computed.empty("content"),
|
2018-02-01 23:42:56 +08:00
|
|
|
|
2018-02-08 18:46:55 +08:00
|
|
|
didReceiveAttrs() {
|
2019-01-19 17:05:51 +08:00
|
|
|
this._super(...arguments);
|
2018-02-08 18:46:55 +08:00
|
|
|
|
|
|
|
// if we change topic we want to change both snapshots
|
2018-06-15 23:03:24 +08:00
|
|
|
if (
|
|
|
|
this.get("composerModel.topic") &&
|
|
|
|
(!_topicSnapshot ||
|
|
|
|
this.get("composerModel.topic.id") !== _topicSnapshot.get("id"))
|
|
|
|
) {
|
2018-02-08 18:46:55 +08:00
|
|
|
_topicSnapshot = this.get("composerModel.topic");
|
|
|
|
_postSnapshot = this.get("composerModel.post");
|
|
|
|
}
|
|
|
|
|
|
|
|
// if we hit reply on a different post we want to change postSnapshot
|
2018-06-15 23:03:24 +08:00
|
|
|
if (
|
|
|
|
this.get("composerModel.post") &&
|
|
|
|
(!_postSnapshot ||
|
|
|
|
this.get("composerModel.post.id") !== _postSnapshot.get("id"))
|
|
|
|
) {
|
2018-02-08 18:46:55 +08:00
|
|
|
_postSnapshot = this.get("composerModel.post");
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2018-02-01 23:42:56 +08:00
|
|
|
computeHeaderContent() {
|
2019-01-19 17:05:51 +08:00
|
|
|
let content = this._super(...arguments);
|
2018-02-01 23:42:56 +08:00
|
|
|
|
|
|
|
switch (this.get("action")) {
|
2018-02-08 18:46:55 +08:00
|
|
|
case PRIVATE_MESSAGE:
|
|
|
|
case CREATE_TOPIC:
|
2018-02-01 23:42:56 +08:00
|
|
|
case REPLY:
|
2019-01-23 03:42:00 +08:00
|
|
|
content.icon = "share";
|
2018-06-19 01:01:37 +08:00
|
|
|
content.title = I18n.t("composer.composer_actions.reply");
|
2018-02-01 23:42:56 +08:00
|
|
|
break;
|
|
|
|
case EDIT:
|
2019-01-22 19:02:02 +08:00
|
|
|
content.icon = "pencil-alt";
|
2018-06-19 01:01:37 +08:00
|
|
|
content.title = I18n.t("composer.composer_actions.edit");
|
2018-02-01 23:42:56 +08:00
|
|
|
break;
|
2018-03-14 03:59:12 +08:00
|
|
|
case CREATE_SHARED_DRAFT:
|
2018-06-15 23:03:24 +08:00
|
|
|
content.icon = "clipboard";
|
2018-06-19 01:01:37 +08:00
|
|
|
content.title = I18n.t("composer.composer_actions.draft");
|
2018-03-14 03:59:12 +08:00
|
|
|
break;
|
2018-06-15 23:03:24 +08:00
|
|
|
}
|
2018-02-01 23:42:56 +08:00
|
|
|
|
|
|
|
return content;
|
|
|
|
},
|
|
|
|
|
2018-02-08 18:46:55 +08:00
|
|
|
@computed("options", "canWhisper", "action")
|
|
|
|
content(options, canWhisper, action) {
|
|
|
|
let items = [];
|
|
|
|
|
2018-06-15 23:03:24 +08:00
|
|
|
if (
|
|
|
|
action !== CREATE_TOPIC &&
|
|
|
|
action !== CREATE_SHARED_DRAFT &&
|
|
|
|
_topicSnapshot
|
|
|
|
) {
|
2018-02-08 18:46:55 +08:00
|
|
|
items.push({
|
2018-02-01 23:42:56 +08:00
|
|
|
name: I18n.t("composer.composer_actions.reply_as_new_topic.label"),
|
2018-06-15 23:03:24 +08:00
|
|
|
description: I18n.t(
|
|
|
|
"composer.composer_actions.reply_as_new_topic.desc"
|
|
|
|
),
|
2018-02-01 23:42:56 +08:00
|
|
|
icon: "plus",
|
|
|
|
id: "reply_as_new_topic"
|
2018-02-08 18:46:55 +08:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2018-06-15 23:03:24 +08:00
|
|
|
if (
|
|
|
|
(action !== REPLY && _postSnapshot) ||
|
|
|
|
(action === REPLY &&
|
|
|
|
_postSnapshot &&
|
|
|
|
!(options.userAvatar && options.userLink))
|
|
|
|
) {
|
2018-02-08 18:46:55 +08:00
|
|
|
items.push({
|
|
|
|
name: I18n.t("composer.composer_actions.reply_to_post.label", {
|
|
|
|
postNumber: _postSnapshot.get("post_number"),
|
|
|
|
postUsername: _postSnapshot.get("username")
|
|
|
|
}),
|
|
|
|
description: I18n.t("composer.composer_actions.reply_to_post.desc"),
|
2019-01-23 03:42:00 +08:00
|
|
|
icon: "share",
|
2018-02-08 18:46:55 +08:00
|
|
|
id: "reply_to_post"
|
|
|
|
});
|
|
|
|
}
|
2018-02-01 23:42:56 +08:00
|
|
|
|
2018-06-15 23:03:24 +08:00
|
|
|
if (
|
|
|
|
this.siteSettings.enable_personal_messages &&
|
|
|
|
action !== PRIVATE_MESSAGE
|
|
|
|
) {
|
2018-02-01 23:42:56 +08:00
|
|
|
items.push({
|
2018-06-15 23:03:24 +08:00
|
|
|
name: I18n.t(
|
|
|
|
"composer.composer_actions.reply_as_private_message.label"
|
|
|
|
),
|
|
|
|
description: I18n.t(
|
|
|
|
"composer.composer_actions.reply_as_private_message.desc"
|
|
|
|
),
|
2018-02-01 23:42:56 +08:00
|
|
|
icon: "envelope",
|
|
|
|
id: "reply_as_private_message"
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2018-06-15 23:03:24 +08:00
|
|
|
if (
|
|
|
|
(action !== REPLY && _topicSnapshot) ||
|
|
|
|
(action === REPLY &&
|
|
|
|
_topicSnapshot &&
|
|
|
|
(options.userAvatar && options.userLink && options.topicLink))
|
|
|
|
) {
|
2018-02-01 23:42:56 +08:00
|
|
|
items.push({
|
|
|
|
name: I18n.t("composer.composer_actions.reply_to_topic.label"),
|
|
|
|
description: I18n.t("composer.composer_actions.reply_to_topic.desc"),
|
2019-01-23 03:42:00 +08:00
|
|
|
icon: "share",
|
2018-02-01 23:42:56 +08:00
|
|
|
id: "reply_to_topic"
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2018-02-08 18:46:55 +08:00
|
|
|
// if answered post is a whisper, we can only answer with a whisper so no need for toggle
|
2018-06-15 23:03:24 +08:00
|
|
|
if (
|
|
|
|
canWhisper &&
|
|
|
|
(!_postSnapshot ||
|
|
|
|
(_postSnapshot &&
|
|
|
|
_postSnapshot.post_type !== this.site.post_types.whisper))
|
|
|
|
) {
|
2018-02-02 06:07:37 +08:00
|
|
|
items.push({
|
|
|
|
name: I18n.t("composer.composer_actions.toggle_whisper.label"),
|
|
|
|
description: I18n.t("composer.composer_actions.toggle_whisper.desc"),
|
2019-01-22 19:02:02 +08:00
|
|
|
icon: "far-eye-slash",
|
2018-02-02 06:07:37 +08:00
|
|
|
id: "toggle_whisper"
|
|
|
|
});
|
2018-02-01 23:42:56 +08:00
|
|
|
}
|
|
|
|
|
2018-03-14 03:59:12 +08:00
|
|
|
let showCreateTopic = false;
|
|
|
|
if (action === CREATE_SHARED_DRAFT) {
|
|
|
|
showCreateTopic = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (action === CREATE_TOPIC) {
|
|
|
|
if (this.site.shared_drafts_category_id) {
|
|
|
|
// Shared Drafts Choice
|
|
|
|
items.push({
|
|
|
|
name: I18n.t("composer.composer_actions.shared_draft.label"),
|
|
|
|
description: I18n.t("composer.composer_actions.shared_draft.desc"),
|
|
|
|
icon: "clipboard",
|
|
|
|
id: "shared_draft"
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
// Edge case: If personal messages are disabled, it is possible to have
|
|
|
|
// no items which stil renders a button that pops up nothing. In this
|
|
|
|
// case, add an option for what you're currently doing.
|
|
|
|
if (items.length === 0) {
|
|
|
|
showCreateTopic = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (showCreateTopic) {
|
2018-02-10 05:58:04 +08:00
|
|
|
items.push({
|
|
|
|
name: I18n.t("composer.composer_actions.create_topic.label"),
|
2018-06-15 23:03:24 +08:00
|
|
|
description: I18n.t(
|
|
|
|
"composer.composer_actions.reply_as_new_topic.desc"
|
|
|
|
),
|
2019-01-23 03:42:00 +08:00
|
|
|
icon: "share",
|
2018-02-10 05:58:04 +08:00
|
|
|
id: "create_topic"
|
|
|
|
});
|
|
|
|
}
|
2018-03-14 03:59:12 +08:00
|
|
|
|
2018-08-10 08:48:30 +08:00
|
|
|
const currentUser = Discourse.User.current();
|
2019-01-03 03:15:12 +08:00
|
|
|
const showToggleTopicBump =
|
|
|
|
currentUser &&
|
|
|
|
(currentUser.get("staff") || currentUser.trust_level === 4);
|
2018-08-10 08:48:30 +08:00
|
|
|
|
2019-01-03 03:15:12 +08:00
|
|
|
if (action === REPLY && showToggleTopicBump) {
|
2018-08-10 08:48:30 +08:00
|
|
|
items.push({
|
|
|
|
name: I18n.t("composer.composer_actions.toggle_topic_bump.label"),
|
|
|
|
description: I18n.t("composer.composer_actions.toggle_topic_bump.desc"),
|
|
|
|
icon: "anchor",
|
|
|
|
id: "toggle_topic_bump"
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2018-02-01 23:42:56 +08:00
|
|
|
return items;
|
|
|
|
},
|
|
|
|
|
2018-02-08 18:46:55 +08:00
|
|
|
_replyFromExisting(options, post, topic) {
|
2019-01-10 18:06:01 +08:00
|
|
|
this.closeComposer();
|
2018-02-08 18:46:55 +08:00
|
|
|
|
2019-01-10 18:06:01 +08:00
|
|
|
this.openComposer(options, post, topic);
|
2018-02-01 23:42:56 +08:00
|
|
|
},
|
|
|
|
|
2018-03-14 03:59:12 +08:00
|
|
|
_openComposer(options) {
|
2019-01-10 18:06:01 +08:00
|
|
|
this.closeComposer();
|
|
|
|
this.openComposer(options);
|
2018-03-14 03:59:12 +08:00
|
|
|
},
|
|
|
|
|
|
|
|
toggleWhisperSelected(options, model) {
|
2018-06-15 23:03:24 +08:00
|
|
|
model.toggleProperty("whisper");
|
2018-03-14 03:59:12 +08:00
|
|
|
},
|
|
|
|
|
2018-08-10 08:48:30 +08:00
|
|
|
toggleTopicBumpSelected(options, model) {
|
|
|
|
model.toggleProperty("noBump");
|
|
|
|
},
|
|
|
|
|
2018-03-14 03:59:12 +08:00
|
|
|
replyToTopicSelected(options) {
|
|
|
|
options.action = REPLY;
|
|
|
|
options.topic = _topicSnapshot;
|
|
|
|
this._openComposer(options);
|
|
|
|
},
|
|
|
|
|
|
|
|
replyToPostSelected(options) {
|
|
|
|
options.action = REPLY;
|
|
|
|
options.post = _postSnapshot;
|
|
|
|
this._openComposer(options);
|
|
|
|
},
|
|
|
|
|
|
|
|
replyAsNewTopicSelected(options) {
|
|
|
|
options.action = CREATE_TOPIC;
|
|
|
|
options.categoryId = this.get("composerModel.topic.category.id");
|
|
|
|
this._replyFromExisting(options, _postSnapshot, _topicSnapshot);
|
|
|
|
},
|
|
|
|
|
|
|
|
replyAsPrivateMessageSelected(options) {
|
|
|
|
let usernames;
|
|
|
|
|
|
|
|
if (_postSnapshot && !_postSnapshot.get("yours")) {
|
|
|
|
const postUsername = _postSnapshot.get("username");
|
|
|
|
if (postUsername) {
|
|
|
|
usernames = postUsername;
|
|
|
|
}
|
2018-08-23 17:09:35 +08:00
|
|
|
} else if (this.get("composerModel.topic")) {
|
|
|
|
const stream = this.get("composerModel.topic.postStream");
|
|
|
|
|
|
|
|
if (stream.get("firstPostPresent")) {
|
|
|
|
const post = stream.get("posts.firstObject");
|
|
|
|
if (post && !post.get("yours") && post.get("username")) {
|
|
|
|
usernames = post.get("username");
|
|
|
|
}
|
|
|
|
}
|
2018-03-14 03:59:12 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
options.action = PRIVATE_MESSAGE;
|
|
|
|
options.usernames = usernames;
|
|
|
|
options.archetypeId = "private_message";
|
|
|
|
options.draftKey = NEW_PRIVATE_MESSAGE_KEY;
|
|
|
|
|
|
|
|
this._replyFromExisting(options, _postSnapshot, _topicSnapshot);
|
|
|
|
},
|
|
|
|
|
|
|
|
_switchCreate(options, action) {
|
|
|
|
options.action = action;
|
|
|
|
options.categoryId = this.get("composerModel.categoryId");
|
2018-06-15 23:03:24 +08:00
|
|
|
options.topicTitle = this.get("composerModel.title");
|
2019-01-23 00:26:52 +08:00
|
|
|
options.tags = this.get("composerModel.tags");
|
2018-12-19 17:25:33 +08:00
|
|
|
options.skipDraftCheck = true;
|
2018-03-14 03:59:12 +08:00
|
|
|
this._openComposer(options);
|
|
|
|
},
|
|
|
|
|
|
|
|
createTopicSelected(options) {
|
|
|
|
this._switchCreate(options, CREATE_TOPIC);
|
|
|
|
},
|
|
|
|
|
|
|
|
sharedDraftSelected(options) {
|
|
|
|
this._switchCreate(options, CREATE_SHARED_DRAFT);
|
|
|
|
},
|
|
|
|
|
2018-02-01 23:42:56 +08:00
|
|
|
actions: {
|
|
|
|
onSelect(value) {
|
2018-03-14 03:59:12 +08:00
|
|
|
let action = `${Ember.String.camelize(value)}Selected`;
|
|
|
|
if (this[action]) {
|
2018-06-15 23:03:24 +08:00
|
|
|
let model = this.get("composerModel");
|
2018-03-14 03:59:12 +08:00
|
|
|
this[action](
|
2018-06-15 23:03:24 +08:00
|
|
|
model.getProperties("draftKey", "draftSequence", "reply"),
|
2018-03-14 03:59:12 +08:00
|
|
|
model
|
|
|
|
);
|
|
|
|
} else {
|
2019-01-10 18:06:01 +08:00
|
|
|
// eslint-disable-next-line no-console
|
|
|
|
console.error(`No method '${action}' found`);
|
2018-02-01 23:42:56 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|