diff --git a/javascripts/discourse/components/user-card-static.js b/javascripts/discourse/components/user-card-static.js index ce41bc9..0cf2847 100644 --- a/javascripts/discourse/components/user-card-static.js +++ b/javascripts/discourse/components/user-card-static.js @@ -1,5 +1,6 @@ import { action } from "@ember/object"; import UserCardContents from "discourse/components/user-card-contents"; +import discourseComputed from "discourse/lib/decorators"; export default class UserCardStaticContents extends UserCardContents { layoutName = "components/user-card-contents"; @@ -13,6 +14,13 @@ export default class UserCardStaticContents extends UserCardContents { willDestroyElement() {} keyUp() {} + @discourseComputed("user.last_seen_at") + contentHidden(lastSeenAt) { + // we don't have the full user data available + // so if last_seen_at is missing, treat the profile as hidden + return !lastSeenAt; + } + // need to override this to work with the loading slider @action handleShowUser() { diff --git a/javascripts/discourse/initializers/user-card-directory.js b/javascripts/discourse/initializers/user-card-directory.js index 2e8ffb6..00ed15e 100644 --- a/javascripts/discourse/initializers/user-card-directory.js +++ b/javascripts/discourse/initializers/user-card-directory.js @@ -90,16 +90,26 @@ export default { // Each user card expects its own promise // Rather than making a separate AJAX request for each // We re-use the `user-cards.json` promise, and manipulate the data - const convertedPromise = promise.then((data) => { + promise.then((data) => { // Find the correct user from users, and put it in the user attribute + const foundUser = data.users?.find( + (u) => u.id === uc.user.id + ); + + // cover disabled or inactive profiles + if (!foundUser) { + uc.set("loading", false); + return; + } + // Use Object.assign to avoid contaminating the source object - return Object.assign({}, data, { - user: data.users.find((u) => u.id === uc.user.id), - }); + const convertedPromise = Promise.resolve( + Object.assign({}, data, { user: foundUser }) + ); + uc.user + .findDetails({ existingRequest: convertedPromise }) + .finally(() => uc.set("loading", false)); }); - return uc.user - .findDetails({ existingRequest: convertedPromise }) - .finally(() => uc.set("loading", false)); }); }