커넥터에서 다른 모델에 액세스하는 방법?

거의 다 왔는데, 어떻게 해야 할지 모르겠어요. connectors/revision-user-details-after에 커넥터를 만들었는데:

커넥터 클래스에서 shouldRender 메서드를 통해 args와 component에 접근할 수 있고, 이를 통해 현재 사용자 이름과 게시물 ID를 가져올 수 있어요:

export default {
  shouldRender(args, component) {
    console.log('postAuthor', args.model.username)
    console.log('postId', args.model.id)
  }
};

게시물을 수정한 사용자의 사용자 이름(이 경우 “nachocab”)도 가져오고 싶은데, args.model은 PostRevision이 아니라 Post입니다.

히스토리 모달은 다음과 같이 생겼어요:

https://github.com/discourse/discourse/blob/main/app/assets/javascripts/discourse/app/templates/modal/history.hbs#L5

그리고 히스토리 컨트롤러는:

https://github.com/discourse/discourse/blob/main/app/assets/javascripts/discourse/app/controllers/history.js#L74

커넥터에서 리비전에 접근하는 방법은 무엇인가요?

아, 방금 내가 이걸 할 수 있다는 걸 깨달았어요!

import Post from "discourse/models/post";

Post.loadRevision(args.model.id, args.model.version).then((result) => {
  const editorUsername = result.username;
  doSomethingElse();
});

업데이트
@eviltrout 이걸 해결했다고 생각했는데, 방금 Post.loadRevision이 Promise를 반환하기 때문에 shouldRender() 안에 넣을 수 없다는 걸 깨달았어요:

import Post from 'discourse/models/post';

export default {
  shouldRender(args, component) {
    // promise를 반환하는 것은 작동하지 않음
    return Post.loadRevision(args.model.id, args.model.version).then((revision) => {
      return args.model.username !== revision.username;
    });
  },
};

이것을 하는 다른 방법이 있을까요?

이를 커넥터에서 꺼내서 새로 삽입할 컴포넌트로 옮기고, Promise가 이행될 때까지 “로딩 중…” 상태를 표시한 뒤, 그 시점에 값을 set하여 표시할 수 있습니다.

고마워요, Robin. 알려주신 팁이 딱 필요했던 거였어요. :tada:

이 방법은 작동하긴 하는데, 직접적인 ajax 호출이 정말 필요한지 궁금합니다. (컨넥터 경로를 사용할 때는 Post에는 접근할 수 있었지만 Revision에는 접근할 수 없었고, 이번에는 컴포넌트 경로를 사용하니 Revision에는 접근할 수 있지만 Post에는 접근할 수 없네요 :thinking:)

{{! templates/connectors/revision-user-details-after/reply-to-editor.hbs }}
{{reply-to-editor
  postId=model.post_id
  postVersion=model.current_version
  revisionAuthor=model.username
}}
{{! templates/components/reply-to-editor.hbs }}
{{#if isVisible}}
  {{d-button
    action=(action 'replyToEditor')
    label='test'
  }}
{{/if}}
{{! 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);
    });
  }
});

템플릿에서 커넥터와 동일한 변수에 접근할 수 없는 이유를 잘 모르겠어요. 동일해야 합니다!