GetNotifications handles /_matrix/client/r0/notifications
( req *http.Request, device *userapi.Device, userAPI userapi.ClientUserAPI, )
| 26 | |
| 27 | // GetNotifications handles /_matrix/client/r0/notifications |
| 28 | func GetNotifications( |
| 29 | req *http.Request, device *userapi.Device, |
| 30 | userAPI userapi.ClientUserAPI, |
| 31 | ) util.JSONResponse { |
| 32 | var limit int64 |
| 33 | if limitStr := req.URL.Query().Get("limit"); limitStr != "" { |
| 34 | var err error |
| 35 | limit, err = strconv.ParseInt(limitStr, 10, 64) |
| 36 | if err != nil { |
| 37 | util.GetLogger(req.Context()).WithError(err).Error("ParseInt(limit) failed") |
| 38 | return jsonerror.InternalServerError() |
| 39 | } |
| 40 | } |
| 41 | |
| 42 | var queryRes userapi.QueryNotificationsResponse |
| 43 | localpart, _, err := gomatrixserverlib.SplitID('@', device.UserID) |
| 44 | if err != nil { |
| 45 | util.GetLogger(req.Context()).WithError(err).Error("SplitID failed") |
| 46 | return jsonerror.InternalServerError() |
| 47 | } |
| 48 | err = userAPI.QueryNotifications(req.Context(), &userapi.QueryNotificationsRequest{ |
| 49 | Localpart: localpart, |
| 50 | From: req.URL.Query().Get("from"), |
| 51 | Limit: int(limit), |
| 52 | Only: req.URL.Query().Get("only"), |
| 53 | }, &queryRes) |
| 54 | if err != nil { |
| 55 | util.GetLogger(req.Context()).WithError(err).Error("QueryNotifications failed") |
| 56 | return jsonerror.InternalServerError() |
| 57 | } |
| 58 | util.GetLogger(req.Context()).WithField("from", req.URL.Query().Get("from")).WithField("limit", limit).WithField("only", req.URL.Query().Get("only")).WithField("next", queryRes.NextToken).Infof("QueryNotifications: len %d", len(queryRes.Notifications)) |
| 59 | return util.JSONResponse{ |
| 60 | Code: http.StatusOK, |
| 61 | JSON: queryRes, |
| 62 | } |
| 63 | } |