import Post from "discourse/models/post";
Post.loadRevision(args.model.id, args.model.version).then((result) => {
const editorUsername = result.username;
doSomethingElse();
});
UPDATE @eviltrout I thought I had this figured out, but I just realized that since Post.loadRevision returns a Promise, I can’t put it inside shouldRender():
import Post from 'discourse/models/post';
export default {
shouldRender(args, component) {
// returning a promise doesn't work
return Post.loadRevision(args.model.id, args.model.version).then((revision) => {
return args.model.username !== revision.username;
});
},
};
You could move it out of the connector into a new component you insert, and have it show a “Loading…” state until the promise is fulfilled, at which point you set the value and display it.
This works, but I wonder if the direct ajax call is needed (when I took the connector path, I had access to the Post but not the Revision; now that I took the component path, I have access to the Revision, but not the Post )
{{! javascripts/discourse/components/reply-to-editor.js.es6 }}
import { ajax } from 'discourse/lib/ajax';
export default Ember.Component.extend({
isVisible: true,
didRender() {
if (!this.get('postId')) return;
ajax(`/posts/${this.get('postId')}`).then((post) => {
// only show the button if the revision author is not the post author
this.set('isVisible', this.get('revisionAuthor') !== post.username);
});
}
});