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

Function getUser

apps/plugin-browser/src/shared/get-user.ts:63–261  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

61 entityId.split("~")[0] as WebId;
62
63export const getUser = (): Promise<LocalStorage["user"] | null> => {
64 return queryGraphQlApi<MeQuery, MeQueryVariables>(meQuery)
65 .then(async ({ data }) => {
66 const subgraph = mapGqlSubgraphFieldsFragmentToSubgraph<
67 EntityRootType<HashEntity>
68 >(data.me.subgraph);
69
70 const user = getRoots(subgraph)[0]!;
71
72 const simpleProperties = simplifyProperties(
73 user.properties as UserProperties,
74 );
75
76 const { email, shortname, displayName } = simpleProperties;
77
78 if (!shortname || !displayName) {
79 // User has not completed signup
80 return null;
81 }
82
83 const userAvatar = getAvatarForEntity(
84 subgraph,
85 user.metadata.recordId.entityId,
86 );
87
88 const orgLinksAndEntities = getOutgoingLinkAndTargetEntities(
89 subgraph,
90 user.metadata.recordId.entityId,
91 ).filter(({ linkEntity }) =>
92 linkEntity[0]?.metadata.entityTypeIds.includes(
93 systemLinkEntityTypes.isMemberOf.linkEntityTypeId,
94 ),
95 );
96
97 const userBrowserPreferences = getOutgoingLinkAndTargetEntities(
98 subgraph,
99 user.metadata.recordId.entityId,
100 ).filter(
101 ({ linkEntity, rightEntity }) =>
102 linkEntity[0]?.metadata.entityTypeIds.includes(
103 systemLinkEntityTypes.has.linkEntityTypeId,
104 ) &&
105 rightEntity[0]?.metadata.entityTypeIds.includes(
106 systemEntityTypes.browserPluginSettings.entityTypeId,
107 ),
108 )[0]?.rightEntity[0];
109
110 let settingsEntityId: EntityId;
111
112 if (userBrowserPreferences) {
113 settingsEntityId = userBrowserPreferences.metadata.recordId.entityId;
114
115 const {
116 automaticInferenceConfiguration,
117 manualInferenceConfiguration,
118 draftNote,
119 browserPluginTab,
120 } = simplifyProperties(

Callers 3

initFunction · 0.90
background.tsFile · 0.90
user.test.tsFile · 0.90

Calls 15

queryGraphQlApiFunction · 0.90
getRootsFunction · 0.90
simplifyPropertiesFunction · 0.90
setInLocalStorageFunction · 0.90
createDefaultSettingsFunction · 0.90
getFromLocalStorageFunction · 0.90
createEntityFunction · 0.90
getAvatarForEntityFunction · 0.85
getWebIdFromEntityIdFunction · 0.85
thenMethod · 0.80

Tested by

no test coverage detected