* add drafts.json endpoint, user profile tab with drafts stream * improve drafts stream display in user profile * truncate excerpts in drafts list, better handling for resume draft action * improve draft stream SQL query, add rspec tests * if composer is open, quietly close it when user opens another draft from drafts stream; load PM draft only when user is in /u/username/messages (instead of /u/username) * cleanup * linting fixes * apply prettier styling to modified files * add client tests for drafts, includes a fixture for drafts.json * improvements to code following review * refresh drafts route when user deletes a draft open in the composer while being in the drafts route; minor prettier scss fix * added more spec tests, deleted an acceptance test for removing drafts that was too finicky, formatting and code style fixes, added appEvent for draft:destroyed * prettier, eslint fixes * use "username_lower" from users table, added error handling for rejected promises * adds guardian spec for can_see_drafts, adds improvements following code review * move DraftsController spec to its own file * fix failing drafts qunit test, use getOwner instead of deprecated this.container * limit test fixture for draft.json testing to new_topic request only
48 lines
1.2 KiB
JavaScript
48 lines
1.2 KiB
JavaScript
import RestModel from "discourse/models/rest";
|
|
import computed from "ember-addons/ember-computed-decorators";
|
|
import { postUrl } from "discourse/lib/utilities";
|
|
import { userPath } from "discourse/lib/url";
|
|
import User from "discourse/models/user";
|
|
|
|
import {
|
|
NEW_TOPIC_KEY,
|
|
NEW_PRIVATE_MESSAGE_KEY
|
|
} from "discourse/models/composer";
|
|
|
|
export default RestModel.extend({
|
|
@computed("draft_username")
|
|
editableDraft(draftUsername) {
|
|
return draftUsername === User.currentProp("username");
|
|
},
|
|
|
|
@computed("username_lower")
|
|
userUrl(usernameLower) {
|
|
return userPath(usernameLower);
|
|
},
|
|
|
|
@computed("topic_id")
|
|
postUrl(topicId) {
|
|
if (!topicId) return;
|
|
|
|
return postUrl(
|
|
this.get("slug"),
|
|
this.get("topic_id"),
|
|
this.get("post_number")
|
|
);
|
|
},
|
|
|
|
@computed("draft_key", "post_number")
|
|
draftType(draftKey, postNumber) {
|
|
switch (draftKey) {
|
|
case NEW_TOPIC_KEY:
|
|
return I18n.t("drafts.new_topic");
|
|
case NEW_PRIVATE_MESSAGE_KEY:
|
|
return I18n.t("drafts.new_private_message");
|
|
default:
|
|
return postNumber
|
|
? I18n.t("drafts.post_reply", { postNumber })
|
|
: I18n.t("drafts.topic_reply");
|
|
}
|
|
}
|
|
});
|