(req *http.Request, device *api.Device, profileAPI userapi.ClientUserAPI, cfg *config.ClientAPI, asAPI appserviceAPI.AppServiceInternalAPI, federation *gomatrixserverlib.FederationClient)
| 52 | } |
| 53 | |
| 54 | func 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 | } |
no test coverage detected