Recuperar post.raw funciona apenas logo após criar o post

Hi there,

At the moment I am working on an extra PostMenuButton. Funny thing is that the Cooked post is always available but the Raw post is not!

Running discourse version [v2.3.0.beta8 +103]

<script type = "text/discourse-plugin" version = "0.1" >

  api.addPostMenuButton('trimetrack', attrs => {
    return {
      action: 'createTimeTracking',
      icon: 'calendar-alt',
      className: 'time-tracking',
      title: 'time_tracking',
      position: 'first'
    };
  }
                       );
  api.attachWidgetAction('post-menu', 'createTimeTracking', function() {
    const post = this.findAncestorModel();
    alert("Raw post: " + post.raw);
    alert("Cooked post: " + post.cooked);
  });
  
  </script>

Steps to reproduce:

  1. Create theme component with code as shown above.

  2. Create a new post, do not refresh, click the calendar icon.

  3. See the alert pop-ups.

  4. Refresh the page. Click on the calendar button again for the same post.

  5. Now the post only has the cooked content available, raw content is not getting through.

I hope anyone can either spot my failure or confirm the bug :slight_smile:

This is by design, we prefer to keep our topic payload smaller so if you need raw you have to ask for it on-demand.

Otherwise we would be shipping data to all clients that they do not need the vast majority of the time.

Thanks for your reply! Now I can stop wasting time :slight_smile:

Ahh that makes so much sense!

Could you point me in the right direction to retrieve post data from javascript?
I had a sort of workaround to get the .json by retrieving the /t/raw/{topicid}/{postid}.json but that was really ugly and there must be a better way.

Yeah that is pretty much your only option.

Thank you. I will make my workaround less ugly and post it here when finished!

Isso ainda é verdade? Ao editar uma postagem, a solicitação é, por exemplo, para /posts/13.json

Existe alguma API JS para isso? Ou alguma API JS para fazer uma solicitação autenticada?

@Mathijs_V, você poderia compartilhar seu código?

Obrigado!

Foi assim que fiz no momento:

import {ajax} from "discourse/lib/ajax";

...

let post = this.findAncestorModel();
ajax(`/posts/${post.id}`, { type: "GET", cache: false }).then(
  (result) => {
    console.log(result.raw);
  }
);

Tirado daqui: discourse-checklist/assets/javascripts/discourse/initializers/checklist.js.es6 at a94022393c1fd290e492688041896d4392129052 · discourse/discourse-checklist · GitHub