Recently, I started looking into a bug with the Events plugin where the events data shown on the composer is lost if the post is saved to drafts.
I tried to fix the issue and soon found out that there’s no API exposed by Discourse which allows us to do that.
I think this is an important feature from a UX standpoint with many potential use cases other than what I’m faced with.
For that, I am making a PR, which fixes this issue by introducing a new method in the Composer Model called serializeToDraft. This method will add those custom fields while saving the post to draft. Also, those fields will be set to the composer model when the draft is reopened.
@angus is helping me out on this PR by reviewing the code and suggesting the important improvements to be made.
I would like to know the thoughts of the Discourse team on this feature.
There are some things I dont understand: why is serializeToDraft part of the plugin api while serializeOnCreate and serializeToTopic are not? under what circumstance is serializeToDraft useful without the other two and vice versa? shouldnt there be a wrapper that does the serialization on both post/topic and also the draft?
Mi sono imbattuto in un altro problema: cosa dire del metodo saveDraft()? In qualche modo è necessario un osservatore per i campi aggiunti con serializeToDraft(), simile a questo:
altrimenti la bozza non verrà inviata all’endpoint se cambiano solo i campi personalizzati della bozza.
Quindi saveDraft() dovrebbe far parte anche dell’API, oppure in realtà questa funzionalità dovrebbe essere in qualche modo astratta.
Ho anche trovato questo osservatore dataChanged nel composermodel. Ritengo molto strano che abbiamo due osservatori che monitorano la stessa cosa. La logica all’interno di questo osservatore dovrebbe probabilmente essere attivata anche per i campi personalizzati della bozza. Mi chiedo inoltre quale dei due osservatori venga eseguito per primo e quali siano le implicazioni.