mirror of
https://github.com/discourse/discourse.git
synced 2025-06-10 01:43:41 +08:00
Don't use the container to look up the store for drafts
This commit is contained in:
@ -2,6 +2,44 @@ import { setting } from 'discourse/lib/computed';
|
|||||||
import DiscourseURL from 'discourse/lib/url';
|
import DiscourseURL from 'discourse/lib/url';
|
||||||
import Quote from 'discourse/lib/quote';
|
import Quote from 'discourse/lib/quote';
|
||||||
import Draft from 'discourse/models/draft';
|
import Draft from 'discourse/models/draft';
|
||||||
|
import Composer from 'discourse/models/composer';
|
||||||
|
|
||||||
|
function loadDraft(store, opts) {
|
||||||
|
opts = opts || {};
|
||||||
|
|
||||||
|
let draft = opts.draft;
|
||||||
|
const draftKey = opts.draftKey;
|
||||||
|
const draftSequence = opts.draftSequence;
|
||||||
|
|
||||||
|
try {
|
||||||
|
if (draft && typeof draft === 'string') {
|
||||||
|
draft = JSON.parse(draft);
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
draft = null;
|
||||||
|
Draft.clear(draftKey, draftSequence);
|
||||||
|
}
|
||||||
|
if (draft && ((draft.title && draft.title !== '') || (draft.reply && draft.reply !== ''))) {
|
||||||
|
const composer = store.createRecord('composer');
|
||||||
|
composer.open({
|
||||||
|
draftKey,
|
||||||
|
draftSequence,
|
||||||
|
action: draft.action,
|
||||||
|
title: draft.title,
|
||||||
|
categoryId: draft.categoryId || opts.categoryId,
|
||||||
|
postId: draft.postId,
|
||||||
|
archetypeId: draft.archetypeId,
|
||||||
|
reply: draft.reply,
|
||||||
|
metaData: draft.metaData,
|
||||||
|
usernames: draft.usernames,
|
||||||
|
draft: true,
|
||||||
|
composerState: Composer.DRAFT,
|
||||||
|
composerTime: draft.composerTime,
|
||||||
|
typingTime: draft.typingTime
|
||||||
|
});
|
||||||
|
return composer;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
export default Ember.Controller.extend({
|
export default Ember.Controller.extend({
|
||||||
needs: ['modal', 'topic', 'composer-messages', 'application'],
|
needs: ['modal', 'topic', 'composer-messages', 'application'],
|
||||||
@ -438,7 +476,7 @@ export default Ember.Controller.extend({
|
|||||||
// Given a potential instance and options, set the model for this composer.
|
// Given a potential instance and options, set the model for this composer.
|
||||||
_setModel(composerModel, opts) {
|
_setModel(composerModel, opts) {
|
||||||
if (opts.draft) {
|
if (opts.draft) {
|
||||||
composerModel = Discourse.Composer.loadDraft(opts);
|
composerModel = loadDraft(this.store, opts);
|
||||||
if (composerModel) {
|
if (composerModel) {
|
||||||
composerModel.set('topic', opts.topic);
|
composerModel.set('topic', opts.topic);
|
||||||
}
|
}
|
||||||
|
@ -690,47 +690,6 @@ const Composer = RestModel.extend({
|
|||||||
|
|
||||||
Composer.reopenClass({
|
Composer.reopenClass({
|
||||||
|
|
||||||
open(opts) {
|
|
||||||
const composer = Discourse.__container__.lookup('store:main').createRecord('composer');
|
|
||||||
composer.open(opts);
|
|
||||||
return composer;
|
|
||||||
},
|
|
||||||
|
|
||||||
loadDraft(opts) {
|
|
||||||
opts = opts || {};
|
|
||||||
|
|
||||||
let draft = opts.draft;
|
|
||||||
const draftKey = opts.draftKey;
|
|
||||||
const draftSequence = opts.draftSequence;
|
|
||||||
|
|
||||||
try {
|
|
||||||
if (draft && typeof draft === 'string') {
|
|
||||||
draft = JSON.parse(draft);
|
|
||||||
}
|
|
||||||
} catch (error) {
|
|
||||||
draft = null;
|
|
||||||
Draft.clear(draftKey, draftSequence);
|
|
||||||
}
|
|
||||||
if (draft && ((draft.title && draft.title !== '') || (draft.reply && draft.reply !== ''))) {
|
|
||||||
return this.open({
|
|
||||||
draftKey,
|
|
||||||
draftSequence,
|
|
||||||
action: draft.action,
|
|
||||||
title: draft.title,
|
|
||||||
categoryId: draft.categoryId || opts.categoryId,
|
|
||||||
postId: draft.postId,
|
|
||||||
archetypeId: draft.archetypeId,
|
|
||||||
reply: draft.reply,
|
|
||||||
metaData: draft.metaData,
|
|
||||||
usernames: draft.usernames,
|
|
||||||
draft: true,
|
|
||||||
composerState: DRAFT,
|
|
||||||
composerTime: draft.composerTime,
|
|
||||||
typingTime: draft.typingTime
|
|
||||||
});
|
|
||||||
}
|
|
||||||
},
|
|
||||||
|
|
||||||
// TODO: Replace with injection
|
// TODO: Replace with injection
|
||||||
create(args) {
|
create(args) {
|
||||||
args = args || {};
|
args = args || {};
|
||||||
|
Reference in New Issue
Block a user