MCPcopy Create free account
hub / github.com/hashintel/hash / getAvatarForEntity

Function getAvatarForEntity

apps/plugin-browser/src/shared/get-user.ts:34–50  ·  view source on GitHub ↗
(
  subgraph: Subgraph<EntityRootType<HashEntity>>,
  entityId: EntityId,
)

Source from the content-addressed store, hash-verified

32import type { UserProperties } from "@local/hash-isomorphic-utils/system-types/user";
33
34const getAvatarForEntity = (
35 subgraph: Subgraph<EntityRootType<HashEntity>>,
36 entityId: EntityId,
37): Entity<ImageFile> | undefined => {
38 const avatarLinkAndEntities = getOutgoingLinkAndTargetEntities(
39 subgraph,
40 entityId,
41 intervalForTimestamp(currentTimestamp()),
42 ).filter(({ linkEntity }) =>
43 linkEntity[0]?.metadata.entityTypeIds.includes(
44 systemLinkEntityTypes.hasAvatar.linkEntityTypeId,
45 ),
46 );
47 return avatarLinkAndEntities[0]?.rightEntity[0] as
48 | Entity<ImageFile>
49 | undefined;
50};
51
52/**
53 * Ideally we would use {@link extractWebIdFromEntityId} from @blockprotocol/type-system/slim here,

Callers 1

getUserFunction · 0.85

Calls 4

intervalForTimestampFunction · 0.90
currentTimestampFunction · 0.90
filterMethod · 0.45

Tested by

no test coverage detected