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

Function GetNotifications

clientapi/routing/notification.go:28–63  ·  view source on GitHub ↗

GetNotifications handles /_matrix/client/r0/notifications

(
	req *http.Request, device *userapi.Device,
	userAPI userapi.ClientUserAPI,
)

Source from the content-addressed store, hash-verified

26
27// GetNotifications handles /_matrix/client/r0/notifications
28func 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}

Callers 1

SetupFunction · 0.85

Calls 5

ContextMethod · 0.80
InfofMethod · 0.80
GetMethod · 0.65
QueryNotificationsMethod · 0.65
ErrorMethod · 0.45

Tested by

no test coverage detected