2018-02-01 10:42:56 -05:00
|
|
|
import DropdownSelectBoxComponent from "select-kit/components/dropdown-select-box";
|
2018-03-13 15:59:12 -04:00
|
|
|
import {
|
|
|
|
PRIVATE_MESSAGE,
|
|
|
|
CREATE_TOPIC,
|
|
|
|
CREATE_SHARED_DRAFT,
|
2020-02-03 08:22:14 -05:00
|
|
|
REPLY
|
2018-03-13 15:59:12 -04:00
|
|
|
} from "discourse/models/composer";
|
2020-02-04 10:59:56 -05:00
|
|
|
import Draft from "discourse/models/draft";
|
2020-02-03 08:22:14 -05:00
|
|
|
import { computed } from "@ember/object";
|
2019-11-05 13:43:49 -05:00
|
|
|
import { camelize } from "@ember/string";
|
2020-02-05 11:14:42 -05:00
|
|
|
import { isEmpty } from "@ember/utils";
|
2018-02-08 05:46:55 -05:00
|
|
|
|
|
|
|
// Component can get destroyed and lose state
|
|
|
|
let _topicSnapshot = null;
|
|
|
|
let _postSnapshot = null;
|
|
|
|
|
|
|
|
export function _clearSnapshots() {
|
|
|
|
_topicSnapshot = null;
|
|
|
|
_postSnapshot = null;
|
|
|
|
}
|
2018-02-01 10:42:56 -05:00
|
|
|
|
|
|
|
export default DropdownSelectBoxComponent.extend({
|
2020-04-01 19:21:57 -04:00
|
|
|
seq: 0,
|
2018-02-01 10:42:56 -05:00
|
|
|
pluginApiIdentifiers: ["composer-actions"],
|
2020-02-03 08:22:14 -05:00
|
|
|
classNames: ["composer-actions"],
|
|
|
|
|
|
|
|
selectKitOptions: {
|
|
|
|
icon: "share",
|
|
|
|
filterable: false,
|
|
|
|
showFullTitle: false
|
|
|
|
},
|
2018-02-01 10:42:56 -05:00
|
|
|
|
2020-03-30 23:40:00 -04:00
|
|
|
contentChanged() {
|
2020-04-01 19:21:57 -04:00
|
|
|
this.set("seq", this.seq + 1);
|
2020-03-30 23:40:00 -04:00
|
|
|
},
|
|
|
|
|
2018-02-08 05:46:55 -05:00
|
|
|
didReceiveAttrs() {
|
2019-01-19 04:05:51 -05:00
|
|
|
this._super(...arguments);
|
2018-02-08 05:46:55 -05:00
|
|
|
|
|
|
|
// if we change topic we want to change both snapshots
|
2018-06-15 11:03:24 -04:00
|
|
|
if (
|
2020-03-31 23:23:26 -04:00
|
|
|
this.topic &&
|
|
|
|
(!_topicSnapshot || this.topic.id !== _topicSnapshot.id)
|
2018-06-15 11:03:24 -04:00
|
|
|
) {
|
2020-03-31 23:23:26 -04:00
|
|
|
_topicSnapshot = this.topic;
|
|
|
|
_postSnapshot = this.post;
|
2020-03-30 23:40:00 -04:00
|
|
|
this.contentChanged();
|
2018-02-08 05:46:55 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
// if we hit reply on a different post we want to change postSnapshot
|
2020-03-31 23:23:26 -04:00
|
|
|
if (this.post && (!_postSnapshot || this.post.id !== _postSnapshot.id)) {
|
|
|
|
_postSnapshot = this.post;
|
2020-03-30 23:40:00 -04:00
|
|
|
this.contentChanged();
|
2018-02-08 05:46:55 -05:00
|
|
|
}
|
|
|
|
|
2020-02-05 11:14:42 -05:00
|
|
|
if (isEmpty(this.content)) {
|
2020-02-03 08:22:14 -05:00
|
|
|
this.set("selectKit.isHidden", true);
|
2018-06-15 11:03:24 -04:00
|
|
|
}
|
2020-02-03 08:22:14 -05:00
|
|
|
},
|
2018-02-01 10:42:56 -05:00
|
|
|
|
2020-02-03 08:22:14 -05:00
|
|
|
modifySelection() {
|
|
|
|
return {};
|
2018-02-01 10:42:56 -05:00
|
|
|
},
|
|
|
|
|
2020-04-01 19:21:57 -04:00
|
|
|
content: computed("seq", function() {
|
2018-02-08 05:46:55 -05:00
|
|
|
let items = [];
|
|
|
|
|
2018-06-15 11:03:24 -04:00
|
|
|
if (
|
2020-02-03 08:22:14 -05:00
|
|
|
this.action !== CREATE_TOPIC &&
|
|
|
|
this.action !== CREATE_SHARED_DRAFT &&
|
2018-06-15 11:03:24 -04:00
|
|
|
_topicSnapshot
|
|
|
|
) {
|
2018-02-08 05:46:55 -05:00
|
|
|
items.push({
|
2018-02-01 10:42:56 -05:00
|
|
|
name: I18n.t("composer.composer_actions.reply_as_new_topic.label"),
|
2018-06-15 11:03:24 -04:00
|
|
|
description: I18n.t(
|
|
|
|
"composer.composer_actions.reply_as_new_topic.desc"
|
|
|
|
),
|
2018-02-01 10:42:56 -05:00
|
|
|
icon: "plus",
|
|
|
|
id: "reply_as_new_topic"
|
2018-02-08 05:46:55 -05:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2018-06-15 11:03:24 -04:00
|
|
|
if (
|
2020-02-03 08:22:14 -05:00
|
|
|
(this.action !== REPLY && _postSnapshot) ||
|
|
|
|
(this.action === REPLY &&
|
2018-06-15 11:03:24 -04:00
|
|
|
_postSnapshot &&
|
2020-02-03 08:22:14 -05:00
|
|
|
!(this.replyOptions.userAvatar && this.replyOptions.userLink))
|
2018-06-15 11:03:24 -04:00
|
|
|
) {
|
2018-02-08 05:46:55 -05:00
|
|
|
items.push({
|
|
|
|
name: I18n.t("composer.composer_actions.reply_to_post.label", {
|
2020-02-03 08:22:14 -05:00
|
|
|
postNumber: _postSnapshot.post_number,
|
|
|
|
postUsername: _postSnapshot.username
|
2018-02-08 05:46:55 -05:00
|
|
|
}),
|
|
|
|
description: I18n.t("composer.composer_actions.reply_to_post.desc"),
|
2019-01-22 14:42:00 -05:00
|
|
|
icon: "share",
|
2018-02-08 05:46:55 -05:00
|
|
|
id: "reply_to_post"
|
|
|
|
});
|
|
|
|
}
|
2018-02-01 10:42:56 -05:00
|
|
|
|
2018-06-15 11:03:24 -04:00
|
|
|
if (
|
|
|
|
this.siteSettings.enable_personal_messages &&
|
2020-02-03 08:22:14 -05:00
|
|
|
this.action !== PRIVATE_MESSAGE
|
2018-06-15 11:03:24 -04:00
|
|
|
) {
|
2018-02-01 10:42:56 -05:00
|
|
|
items.push({
|
2018-06-15 11:03:24 -04: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 10:42:56 -05:00
|
|
|
icon: "envelope",
|
|
|
|
id: "reply_as_private_message"
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2018-06-15 11:03:24 -04:00
|
|
|
if (
|
2020-02-03 08:22:14 -05:00
|
|
|
(this.action !== REPLY && _topicSnapshot) ||
|
|
|
|
(this.action === REPLY &&
|
2018-06-15 11:03:24 -04:00
|
|
|
_topicSnapshot &&
|
2020-02-03 08:22:14 -05:00
|
|
|
this.replyOptions.userAvatar &&
|
|
|
|
this.replyOptions.userLink &&
|
|
|
|
this.replyOptions.topicLink)
|
2018-06-15 11:03:24 -04:00
|
|
|
) {
|
2018-02-01 10:42:56 -05: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-22 14:42:00 -05:00
|
|
|
icon: "share",
|
2018-02-01 10:42:56 -05:00
|
|
|
id: "reply_to_topic"
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2018-02-08 05:46:55 -05:00
|
|
|
// if answered post is a whisper, we can only answer with a whisper so no need for toggle
|
2018-06-15 11:03:24 -04:00
|
|
|
if (
|
2020-02-03 08:22:14 -05:00
|
|
|
this.canWhisper &&
|
2018-06-15 11:03:24 -04:00
|
|
|
(!_postSnapshot ||
|
|
|
|
(_postSnapshot &&
|
|
|
|
_postSnapshot.post_type !== this.site.post_types.whisper))
|
|
|
|
) {
|
2018-02-01 17:07:37 -05:00
|
|
|
items.push({
|
|
|
|
name: I18n.t("composer.composer_actions.toggle_whisper.label"),
|
|
|
|
description: I18n.t("composer.composer_actions.toggle_whisper.desc"),
|
2019-01-22 06:02:02 -05:00
|
|
|
icon: "far-eye-slash",
|
2018-02-01 17:07:37 -05:00
|
|
|
id: "toggle_whisper"
|
|
|
|
});
|
2018-02-01 10:42:56 -05:00
|
|
|
}
|
|
|
|
|
2018-03-13 15:59:12 -04:00
|
|
|
let showCreateTopic = false;
|
2020-02-03 08:22:14 -05:00
|
|
|
if (this.action === CREATE_SHARED_DRAFT) {
|
2018-03-13 15:59:12 -04:00
|
|
|
showCreateTopic = true;
|
|
|
|
}
|
|
|
|
|
2020-02-03 08:22:14 -05:00
|
|
|
if (this.action === CREATE_TOPIC) {
|
2018-03-13 15:59:12 -04:00
|
|
|
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"),
|
2019-07-16 11:13:44 -04:00
|
|
|
icon: "far-clipboard",
|
2018-03-13 15:59:12 -04:00
|
|
|
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-09 16:58:04 -05:00
|
|
|
items.push({
|
|
|
|
name: I18n.t("composer.composer_actions.create_topic.label"),
|
2018-06-15 11:03:24 -04:00
|
|
|
description: I18n.t(
|
|
|
|
"composer.composer_actions.reply_as_new_topic.desc"
|
|
|
|
),
|
2019-01-22 14:42:00 -05:00
|
|
|
icon: "share",
|
2018-02-09 16:58:04 -05:00
|
|
|
id: "create_topic"
|
|
|
|
});
|
|
|
|
}
|
2018-03-13 15:59:12 -04:00
|
|
|
|
2019-01-02 14:15:12 -05:00
|
|
|
const showToggleTopicBump =
|
2019-07-26 05:20:11 -04:00
|
|
|
this.get("currentUser.staff") ||
|
|
|
|
this.get("currentUser.trust_level") === 4;
|
2018-08-09 20:48:30 -04:00
|
|
|
|
2020-02-03 08:22:14 -05:00
|
|
|
if (this.action === REPLY && showToggleTopicBump) {
|
2018-08-09 20:48:30 -04: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 10:42:56 -05:00
|
|
|
return items;
|
2020-02-03 08:22:14 -05:00
|
|
|
}),
|
2018-02-01 10:42:56 -05:00
|
|
|
|
2018-02-08 05:46:55 -05:00
|
|
|
_replyFromExisting(options, post, topic) {
|
2019-01-10 05:06:01 -05:00
|
|
|
this.closeComposer();
|
|
|
|
this.openComposer(options, post, topic);
|
2018-02-01 10:42:56 -05:00
|
|
|
},
|
|
|
|
|
2018-03-13 15:59:12 -04:00
|
|
|
_openComposer(options) {
|
2019-01-10 05:06:01 -05:00
|
|
|
this.closeComposer();
|
|
|
|
this.openComposer(options);
|
2018-03-13 15:59:12 -04:00
|
|
|
},
|
|
|
|
|
|
|
|
toggleWhisperSelected(options, model) {
|
2018-06-15 11:03:24 -04:00
|
|
|
model.toggleProperty("whisper");
|
2018-03-13 15:59:12 -04:00
|
|
|
},
|
|
|
|
|
2018-08-09 20:48:30 -04:00
|
|
|
toggleTopicBumpSelected(options, model) {
|
|
|
|
model.toggleProperty("noBump");
|
|
|
|
},
|
|
|
|
|
2018-03-13 15:59:12 -04:00
|
|
|
replyToTopicSelected(options) {
|
|
|
|
options.action = REPLY;
|
|
|
|
options.topic = _topicSnapshot;
|
2019-03-27 16:55:09 -04:00
|
|
|
options.skipDraftCheck = true;
|
2018-03-13 15:59:12 -04:00
|
|
|
this._openComposer(options);
|
|
|
|
},
|
|
|
|
|
|
|
|
replyToPostSelected(options) {
|
|
|
|
options.action = REPLY;
|
|
|
|
options.post = _postSnapshot;
|
2019-03-27 16:55:09 -04:00
|
|
|
options.skipDraftCheck = true;
|
2018-03-13 15:59:12 -04:00
|
|
|
this._openComposer(options);
|
|
|
|
},
|
|
|
|
|
|
|
|
replyAsNewTopicSelected(options) {
|
2020-02-04 10:59:56 -05:00
|
|
|
Draft.get("new_topic").then(response => {
|
|
|
|
if (response.draft) {
|
|
|
|
bootbox.confirm(
|
|
|
|
I18n.t("composer.composer_actions.reply_as_new_topic.confirm"),
|
|
|
|
result => {
|
|
|
|
if (result) this._replyAsNewTopicSelect(options);
|
|
|
|
}
|
|
|
|
);
|
|
|
|
} else {
|
|
|
|
this._replyAsNewTopicSelect(options);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
|
|
|
_replyAsNewTopicSelect(options) {
|
2018-03-13 15:59:12 -04:00
|
|
|
options.action = CREATE_TOPIC;
|
|
|
|
options.categoryId = this.get("composerModel.topic.category.id");
|
2019-02-13 09:19:58 -05:00
|
|
|
options.disableScopedCategory = true;
|
2019-10-20 17:57:55 -04:00
|
|
|
options.skipDraftCheck = true;
|
2018-03-13 15:59:12 -04:00
|
|
|
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 05:09:35 -04: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-13 15:59:12 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
options.action = PRIVATE_MESSAGE;
|
|
|
|
options.usernames = usernames;
|
|
|
|
options.archetypeId = "private_message";
|
2019-10-20 17:57:55 -04:00
|
|
|
options.skipDraftCheck = true;
|
2018-03-13 15:59:12 -04:00
|
|
|
|
|
|
|
this._replyFromExisting(options, _postSnapshot, _topicSnapshot);
|
|
|
|
},
|
|
|
|
|
|
|
|
_switchCreate(options, action) {
|
|
|
|
options.action = action;
|
|
|
|
options.categoryId = this.get("composerModel.categoryId");
|
2018-06-15 11:03:24 -04:00
|
|
|
options.topicTitle = this.get("composerModel.title");
|
2019-01-22 11:26:52 -05:00
|
|
|
options.tags = this.get("composerModel.tags");
|
2018-12-19 04:25:33 -05:00
|
|
|
options.skipDraftCheck = true;
|
2018-03-13 15:59:12 -04:00
|
|
|
this._openComposer(options);
|
|
|
|
},
|
|
|
|
|
|
|
|
createTopicSelected(options) {
|
|
|
|
this._switchCreate(options, CREATE_TOPIC);
|
|
|
|
},
|
|
|
|
|
|
|
|
sharedDraftSelected(options) {
|
|
|
|
this._switchCreate(options, CREATE_SHARED_DRAFT);
|
|
|
|
},
|
|
|
|
|
2018-02-01 10:42:56 -05:00
|
|
|
actions: {
|
2020-02-03 08:22:14 -05:00
|
|
|
onChange(value) {
|
|
|
|
const action = `${camelize(value)}Selected`;
|
2018-03-13 15:59:12 -04:00
|
|
|
if (this[action]) {
|
|
|
|
this[action](
|
2020-02-03 08:22:14 -05:00
|
|
|
this.composerModel.getProperties(
|
2019-02-13 09:19:58 -05:00
|
|
|
"draftKey",
|
|
|
|
"draftSequence",
|
|
|
|
"reply",
|
|
|
|
"disableScopedCategory"
|
|
|
|
),
|
2020-02-03 08:22:14 -05:00
|
|
|
this.composerModel
|
2018-03-13 15:59:12 -04:00
|
|
|
);
|
2020-03-30 23:40:00 -04:00
|
|
|
this.contentChanged();
|
2018-03-13 15:59:12 -04:00
|
|
|
} else {
|
2019-01-10 05:06:01 -05:00
|
|
|
// eslint-disable-next-line no-console
|
|
|
|
console.error(`No method '${action}' found`);
|
2018-02-01 10:42:56 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|