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

Function GetUserByPhone

clientapi/routing/new_feature.go:54–95  ·  view source on GitHub ↗
(req *http.Request, device *api.Device, profileAPI userapi.ClientUserAPI, cfg *config.ClientAPI,
	asAPI appserviceAPI.AppServiceInternalAPI,
	federation *gomatrixserverlib.FederationClient)

Source from the content-addressed store, hash-verified

52}
53
54func GetUserByPhone(req *http.Request, device *api.Device, profileAPI userapi.ClientUserAPI, cfg *config.ClientAPI,
55 asAPI appserviceAPI.AppServiceInternalAPI,
56 federation *gomatrixserverlib.FederationClient) util.JSONResponse {
57 r := GetUserByPhoneReq{}
58 if resErr := httputil.UnmarshalJSONRequest(req, &r); resErr != nil {
59 return *resErr
60 }
61 if r.Phone == 0 {
62 return util.JSONResponse{
63 Code: http.StatusBadRequest,
64 JSON: jsonerror.BadJSON("'phone' must be supplied."),
65 }
66 }
67 localpart, _, err := gomatrixserverlib.SplitID('@', device.UserID)
68 if err != nil {
69 util.GetLogger(req.Context()).WithError(err).Error("gomatrixserverlib.SplitID failed")
70 return jsonerror.InternalServerError()
71 }
72 res, err := new_feature.GetUserByPhone(localpart, r.Phone)
73 if err != nil {
74 return util.JSONResponse{
75 Code: http.StatusInternalServerError,
76 JSON: jsonerror.Unknown(err.Error()),
77 }
78 }
79
80 userId := "@" + res.Localpart + ":" + res.Servername
81 profile, err := getProfile(req.Context(), profileAPI, cfg, userId, asAPI, federation)
82 if err != nil {
83 return util.JSONResponse{
84 Code: http.StatusInternalServerError,
85 JSON: jsonerror.Unknown(err.Error()),
86 }
87 }
88 res.DisplayName = profile.DisplayName
89 res.AvatarURL = profile.AvatarURL
90
91 return util.JSONResponse{
92 Code: http.StatusOK,
93 JSON: res,
94 }
95}

Callers 1

SetupFunction · 0.70

Calls 3

getProfileFunction · 0.85
ContextMethod · 0.80
ErrorMethod · 0.45

Tested by

no test coverage detected