2018-03-13 15:59:12 -04:00
|
|
|
import {
|
|
|
|
CREATE_SHARED_DRAFT,
|
2020-05-14 01:56:45 -04:00
|
|
|
CREATE_TOPIC,
|
|
|
|
EDIT,
|
2018-03-13 15:59:12 -04:00
|
|
|
PRIVATE_MESSAGE,
|
2020-12-01 13:31:26 -05:00
|
|
|
REPLY,
|
2018-03-13 15:59:12 -04:00
|
|
|
} from "discourse/models/composer";
|
2021-04-17 15:40:09 -04:00
|
|
|
import discourseComputed from "discourse-common/utils/decorators";
|
2020-02-04 10:59:56 -05:00
|
|
|
import Draft from "discourse/models/draft";
|
2018-02-01 10:42:56 -05:00
|
|
|
import DropdownSelectBoxComponent from "select-kit/components/dropdown-select-box";
|
2020-05-13 16:23:41 -04:00
|
|
|
import I18n from "I18n";
|
2019-11-05 13:43:49 -05:00
|
|
|
import { camelize } from "@ember/string";
|
2021-04-17 15:40:09 -04:00
|
|
|
import { equal, gt } from "@ember/object/computed";
|
2020-02-05 11:14:42 -05:00
|
|
|
import { isEmpty } from "@ember/utils";
|
2022-10-07 11:38:27 -04:00
|
|
|
import { inject as service } from "@ember/service";
|
2018-02-08 05:46:55 -05:00
|
|
|
|
|
|
|
// Component can get destroyed and lose state
|
|
|
|
let _topicSnapshot = null;
|
|
|
|
let _postSnapshot = null;
|
2020-05-15 13:54:44 -04:00
|
|
|
let _actionSnapshot = null;
|
2018-02-08 05:46:55 -05:00
|
|
|
|
|
|
|
export function _clearSnapshots() {
|
|
|
|
_topicSnapshot = null;
|
|
|
|
_postSnapshot = null;
|
2020-05-15 13:54:44 -04:00
|
|
|
_actionSnapshot = null;
|
2018-02-08 05:46:55 -05:00
|
|
|
}
|
2018-02-01 10:42:56 -05:00
|
|
|
|
|
|
|
export default DropdownSelectBoxComponent.extend({
|
2022-10-07 11:38:27 -04:00
|
|
|
dialog: service(),
|
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"],
|
2020-05-14 01:56:45 -04:00
|
|
|
isEditing: equal("action", EDIT),
|
2021-04-17 15:40:09 -04:00
|
|
|
isInSlowMode: gt("topic.slow_mode_seconds", 0),
|
2020-02-03 08:22:14 -05:00
|
|
|
|
|
|
|
selectKitOptions: {
|
2020-05-14 01:56:45 -04:00
|
|
|
icon: "iconForComposerAction",
|
2020-02-03 08:22:14 -05:00
|
|
|
filterable: false,
|
|
|
|
showFullTitle: false,
|
2021-04-16 11:10:02 -04:00
|
|
|
preventHeaderFocus: true,
|
2021-05-20 02:00:45 -04:00
|
|
|
customStyle: true,
|
2020-02-03 08:22:14 -05:00
|
|
|
},
|
2018-02-01 10:42:56 -05:00
|
|
|
|
2021-04-17 15:40:09 -04:00
|
|
|
@discourseComputed("isEditing", "action", "whisper", "noBump", "isInSlowMode")
|
|
|
|
iconForComposerAction(isEditing, action, whisper, noBump, isInSlowMode) {
|
|
|
|
if (action === CREATE_TOPIC) {
|
2020-05-15 04:40:49 -04:00
|
|
|
return "plus";
|
2021-04-17 15:40:09 -04:00
|
|
|
} else if (action === PRIVATE_MESSAGE) {
|
2021-03-19 10:48:43 -04:00
|
|
|
return "envelope";
|
2021-04-17 15:40:09 -04:00
|
|
|
} else if (action === CREATE_SHARED_DRAFT) {
|
2021-03-19 10:48:43 -04:00
|
|
|
return "far-clipboard";
|
2021-04-17 15:40:09 -04:00
|
|
|
} else if (whisper) {
|
2021-03-19 10:48:43 -04:00
|
|
|
return "far-eye-slash";
|
2021-04-17 15:40:09 -04:00
|
|
|
} else if (noBump) {
|
2021-03-19 10:48:43 -04:00
|
|
|
return "anchor";
|
2021-04-17 15:40:09 -04:00
|
|
|
} else if (isInSlowMode) {
|
|
|
|
return "hourglass-start";
|
|
|
|
} else if (isEditing) {
|
|
|
|
return "pencil-alt";
|
2020-05-15 04:40:49 -04:00
|
|
|
} else {
|
|
|
|
return "share";
|
|
|
|
}
|
2021-04-17 15:40:09 -04:00
|
|
|
},
|
2020-05-14 01:56:45 -04: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);
|
2020-05-15 13:54:44 -04:00
|
|
|
let changeContent = false;
|
2018-02-08 05:46:55 -05:00
|
|
|
|
|
|
|
// if we change topic we want to change both snapshots
|
|
|
|
if (
|
2020-03-31 23:23:26 -04:00
|
|
|
this.topic &&
|
|
|
|
(!_topicSnapshot || this.topic.id !== _topicSnapshot.id)
|
2018-02-08 05:46:55 -05:00
|
|
|
) {
|
2020-03-31 23:23:26 -04:00
|
|
|
_topicSnapshot = this.topic;
|
|
|
|
_postSnapshot = this.post;
|
2020-05-15 13:54:44 -04:00
|
|
|
changeContent = true;
|
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-05-15 13:54:44 -04:00
|
|
|
changeContent = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (this.action !== _actionSnapshot) {
|
|
|
|
_actionSnapshot = this.action;
|
|
|
|
changeContent = true;
|
2018-02-08 05:46:55 -05:00
|
|
|
}
|
|
|
|
|
2020-05-15 13:54:44 -04:00
|
|
|
if (changeContent) {
|
|
|
|
this.contentChanged();
|
2018-02-01 10:42:56 -05:00
|
|
|
}
|
2020-05-15 13:54:44 -04:00
|
|
|
|
|
|
|
this.set("selectKit.isHidden", isEmpty(this.content));
|
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
|
|
|
},
|
|
|
|
|
2021-04-17 15:40:09 -04:00
|
|
|
@discourseComputed("seq")
|
|
|
|
content() {
|
2018-02-08 05:46:55 -05:00
|
|
|
let items = [];
|
|
|
|
|
2020-07-07 11:30:48 -04:00
|
|
|
if (
|
|
|
|
this.action === REPLY &&
|
2020-07-14 21:38:28 -04:00
|
|
|
this.topic &&
|
2020-07-07 11:30:48 -04:00
|
|
|
this.topic.isPrivateMessage &&
|
2020-07-14 21:38:28 -04:00
|
|
|
this.topic.details &&
|
2020-07-07 11:30:48 -04:00
|
|
|
(this.topic.details.allowed_users.length > 1 ||
|
|
|
|
this.topic.details.allowed_groups.length > 0) &&
|
|
|
|
!this.isEditing &&
|
|
|
|
_topicSnapshot
|
|
|
|
) {
|
|
|
|
items.push({
|
|
|
|
name: I18n.t(
|
|
|
|
"composer.composer_actions.reply_as_new_group_message.label"
|
|
|
|
),
|
|
|
|
description: I18n.t(
|
|
|
|
"composer.composer_actions.reply_as_new_group_message.desc"
|
|
|
|
),
|
|
|
|
icon: "plus",
|
|
|
|
id: "reply_as_new_group_message",
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2018-05-23 12:25:58 -04:00
|
|
|
if (
|
2020-02-03 08:22:14 -05:00
|
|
|
this.action !== CREATE_TOPIC &&
|
|
|
|
this.action !== CREATE_SHARED_DRAFT &&
|
2022-06-07 12:06:42 -04:00
|
|
|
this.action === REPLY &&
|
|
|
|
this.topic &&
|
|
|
|
!this.topic.isPrivateMessage &&
|
2020-05-14 01:56:45 -04:00
|
|
|
!this.isEditing &&
|
2018-05-23 12:25:58 -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"),
|
|
|
|
description: I18n.t(
|
|
|
|
"composer.composer_actions.reply_as_new_topic.desc"
|
|
|
|
),
|
|
|
|
icon: "plus",
|
|
|
|
id: "reply_as_new_topic",
|
2018-02-08 05:46:55 -05:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
if (
|
2020-02-03 08:22:14 -05:00
|
|
|
(this.action !== REPLY && _postSnapshot) ||
|
|
|
|
(this.action === REPLY &&
|
2018-02-08 05:46:55 -05:00
|
|
|
_postSnapshot &&
|
2020-02-03 08:22:14 -05:00
|
|
|
!(this.replyOptions.userAvatar && this.replyOptions.userLink))
|
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
|
|
|
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-02-08 05:46:55 -05:00
|
|
|
if (
|
2020-05-14 01:56:45 -04:00
|
|
|
!this.isEditing &&
|
|
|
|
((this.action !== REPLY && _topicSnapshot) ||
|
|
|
|
(this.action === REPLY &&
|
|
|
|
_topicSnapshot &&
|
|
|
|
this.replyOptions.userAvatar &&
|
|
|
|
this.replyOptions.userLink &&
|
|
|
|
this.replyOptions.topicLink))
|
2018-02-08 05:46:55 -05: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-02-08 08:18:53 -05:00
|
|
|
if (
|
2020-02-03 08:22:14 -05:00
|
|
|
this.canWhisper &&
|
2022-06-14 19:59:57 -04:00
|
|
|
(!this.replyOptions.postLink ||
|
|
|
|
!_postSnapshot ||
|
2020-05-07 10:28:28 -04:00
|
|
|
_postSnapshot.post_type !== this.site.post_types.whisper)
|
2018-02-08 08:18:53 -05:00
|
|
|
) {
|
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
|
|
|
}
|
|
|
|
|
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",
|
|
|
|
});
|
|
|
|
}
|
2018-02-09 16:58:04 -05:00
|
|
|
}
|
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",
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2021-12-02 13:46:40 -05:00
|
|
|
if (items.length === 0) {
|
|
|
|
items.push({
|
|
|
|
name: I18n.t("composer.composer_actions.create_topic.label"),
|
|
|
|
description: I18n.t(
|
|
|
|
"composer.composer_actions.reply_as_new_topic.desc"
|
|
|
|
),
|
|
|
|
icon: "share",
|
|
|
|
id: "create_topic",
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2018-02-01 10:42:56 -05:00
|
|
|
return items;
|
2021-04-17 15:40:09 -04: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) {
|
|
|
|
model.toggleProperty("whisper");
|
|
|
|
},
|
|
|
|
|
2018-08-09 20:48:30 -04:00
|
|
|
toggleTopicBumpSelected(options, model) {
|
|
|
|
model.toggleProperty("noBump");
|
|
|
|
},
|
|
|
|
|
2020-07-07 11:30:48 -04:00
|
|
|
replyAsNewGroupMessageSelected(options) {
|
|
|
|
const recipients = [];
|
|
|
|
|
|
|
|
const details = this.topic.details;
|
|
|
|
details.allowed_users.forEach((u) => recipients.push(u.username));
|
|
|
|
details.allowed_groups.forEach((g) => recipients.push(g.name));
|
|
|
|
|
|
|
|
options.action = PRIVATE_MESSAGE;
|
|
|
|
options.recipients = recipients.join(",");
|
|
|
|
options.archetypeId = "private_message";
|
|
|
|
options.skipDraftCheck = true;
|
|
|
|
|
|
|
|
this._replyFromExisting(options, _postSnapshot, _topicSnapshot);
|
|
|
|
},
|
|
|
|
|
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) {
|
2022-10-07 11:38:27 -04:00
|
|
|
this.dialog.confirm({
|
|
|
|
message: I18n.t(
|
|
|
|
"composer.composer_actions.reply_as_new_topic.confirm"
|
|
|
|
),
|
|
|
|
confirmButtonLabel: "composer.ok_proceed",
|
|
|
|
didConfirm: () => this._replyAsNewTopicSelect(options),
|
|
|
|
});
|
2020-02-04 10:59:56 -05:00
|
|
|
} 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;
|
2020-07-16 15:23:08 -04:00
|
|
|
options.recipients = usernames;
|
2018-03-13 15:59:12 -04:00
|
|
|
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");
|
|
|
|
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",
|
2020-05-25 01:46:02 -04:00
|
|
|
"title",
|
2019-02-13 09:19:58 -05:00
|
|
|
"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
|
|
|
}
|
|
|
|
},
|
|
|
|
},
|
|
|
|
});
|