Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

User#_onUpdate is hard-coded to construct User documents from core class #5929

Closed
aaclayton opened this issue Sep 23, 2021 · 2 comments
Closed
Assignees
Labels
api Issues related to the API used by Mod Devs bug Functionality which is not working as intended

Comments

@aaclayton
Copy link
Contributor

Originally in GitLab by @stwlam

Environment Details

  • Foundry VTT Version: 0.8.9
  • Operating System: Linux (Ubuntu 20.10)
  • How Are You Using Foundry: Native Application (Electron)
  • Which Game System: pf2e (or any system which has a registered User subclass
  • Modules Enabled?: random assortment

Issue Description

This one is only explody when a user is kicked:

        callback: li => {
          const user = game.users.get(li[0].dataset.userId);
          const role = user.role;
          user.update({role: CONST.USER_ROLES.NONE}).then(u => u.update({role}));
          ui.notifications.info(`${user.name} has been kicked from the world.`);
        }

When User#_onUpdate is called:

  /** @inheritdoc  */
  _onUpdate(data, options, userId) {
    super._onUpdate(data, options, userId);

    // If the user role changed, we need to re-build the immutable User object
    if ( this.data.role !== this.role ) {
      const user = new User(this.data); // 😰
      game.users.remove(user.id);
      game.users.insert(user);  // 😱

The second update from the context menu callback is never reached:

  /** @inheritdoc */
  set(id, document) {
    const cls = this.documentClass; // <-- UserPF2e
    if (!(document instanceof cls)) { // 🤯
      throw new Error(`You may only push instances of ${cls.documentName} to the ${this.name} collection`);
    }
    return super.set(document.id, document);
  }
@aaclayton
Copy link
Contributor Author

of course pf2e would have a custom User class! I'm not shocked at all!

@aaclayton
Copy link
Contributor Author

Originally in GitLab by @stwlam

We were plugging in a bunch of others around it, and CONFIG.User.documentClass was just sitting there looking back at us. :slight_frown:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api Issues related to the API used by Mod Devs bug Functionality which is not working as intended
Projects
No open projects
Status: No status
Development

No branches or pull requests

2 participants