MCPcopy Create free account
hub / github.com/daodst/chat / getProfile

Function getProfile

clientapi/routing/profile.go:548–584  ·  view source on GitHub ↗

getProfile gets the full profile of a user by querying the database or a remote homeserver. Returns an error when something goes wrong or specifically eventutil.ErrProfileNoExists when the profile doesn't exist.

(
	ctx context.Context, profileAPI userapi.ClientUserAPI, cfg *config.ClientAPI,
	userID string,
	asAPI appserviceAPI.AppServiceInternalAPI,
	federation *gomatrixserverlib.FederationClient,
)

Source from the content-addressed store, hash-verified

546// Returns an error when something goes wrong or specifically
547// eventutil.ErrProfileNoExists when the profile doesn't exist.
548func getProfile(
549 ctx context.Context, profileAPI userapi.ClientUserAPI, cfg *config.ClientAPI,
550 userID string,
551 asAPI appserviceAPI.AppServiceInternalAPI,
552 federation *gomatrixserverlib.FederationClient,
553) (*authtypes.Profile, error) {
554 localpart, domain, err := gomatrixserverlib.SplitID('@', userID)
555 if err != nil {
556 return nil, err
557 }
558
559 if domain != cfg.Matrix.ServerName {
560 profile, fedErr := federation.LookupProfile(ctx, domain, userID, "")
561 if fedErr != nil {
562 if x, ok := fedErr.(gomatrix.HTTPError); ok {
563 if x.Code == http.StatusNotFound {
564 return nil, eventutil.ErrProfileNoExists
565 }
566 }
567
568 return nil, fedErr
569 }
570
571 return &authtypes.Profile{
572 Localpart: localpart,
573 DisplayName: profile.DisplayName,
574 AvatarURL: profile.AvatarURL,
575 }, nil
576 }
577
578 profile, err := appserviceAPI.RetrieveUserProfile(ctx, userID, asAPI, profileAPI)
579 if err != nil {
580 return nil, err
581 }
582
583 return profile, nil
584}
585
586func buildMembershipEvents(
587 ctx context.Context,

Callers 4

GetProfileFunction · 0.85
GetAvatarURLFunction · 0.85
GetDisplayNameFunction · 0.85
GetUserByPhoneFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected