aboutsummaryrefslogtreecommitdiff
path: root/userapi/api
diff options
context:
space:
mode:
authorDan <dan@globekeeper.com>2022-03-03 13:40:53 +0200
committerGitHub <noreply@github.com>2022-03-03 11:40:53 +0000
commitf05ce478f05dcaf650fbae68a39aaf5d9880a580 (patch)
treea6a47f77bba03ec7a05a8d98bea6791d47f3b48a /userapi/api
parent111f01ddc81d775dfdaab6e6a3a6afa6fa5608ea (diff)
Implement Push Notifications (#1842)
* Add Pushserver component with Pushers API Co-authored-by: Tommie Gannert <tommie@gannert.se> Co-authored-by: Dan Peleg <dan@globekeeper.com> * Wire Pushserver component Co-authored-by: Neil Alexander <neilalexander@users.noreply.github.com> * Add PushGatewayClient. The full event format is required for Sytest. * Add a pushrules module. * Change user API account creation to use the new pushrules module's defaults. Introduces "scope" as required by client API, and some small field tweaks to make some 61push Sytests pass. * Add push rules query/put API in Pushserver. This manipulates account data over User API, and fires sync messages for changes. Those sync messages should, according to an existing TODO in clientapi, be moved to userapi. Forks clientapi/producers/syncapi.go to pushserver/ for later extension. * Add clientapi routes for push rules to Pushserver. A cleanup would be to move more of the name-splitting logic into pushrules.go, to depollute routing.go. * Output rooms.join.unread_notifications in /sync. This is the read-side. Pushserver will be the write-side. * Implement pushserver/storage for notifications. * Use PushGatewayClient and the pushrules module in Pushserver's room consumer. * Use one goroutine per user to avoid locking up the entire server for one bad push gateway. * Split pushing by format. * Send one device per push. Sytest does not support coalescing multiple devices into one push. Matches Synapse. Either we change Sytest, or remove the group-by-url-and-format logic. * Write OutputNotificationData from push server. Sync API is already the consumer. * Implement read receipt consumers in Pushserver. Supports m.read and m.fully_read receipts. * Add clientapi route for /unstable/notifications. * Rename to UpsertPusher for clarity and handle pusher update * Fix linter errors * Ignore body.Close() error check * Fix push server internal http wiring * Add 40 newly passing 61push tests to whitelist * Add next 12 newly passing 61push tests to whitelist * Send notification data before notifying users in EDU server consumer * NATS JetStream * Goodbye sarama * Fix `NewStreamTokenFromString` * Consume on the correct topic for the roomserver * Don't panic, NAK instead * Move push notifications into the User API * Don't set null values since that apparently causes Element upsetti * Also set omitempty on conditions * Fix bug so that we don't override the push rules unnecessarily * Tweak defaults * Update defaults * More tweaks * Move `/notifications` onto `r0`/`v3` mux * User API will consume events and read/fully read markers from the sync API with stream positions, instead of consuming directly Co-authored-by: Piotr Kozimor <p1996k@gmail.com> Co-authored-by: Tommie Gannert <tommie@gannert.se> Co-authored-by: Neil Alexander <neilalexander@users.noreply.github.com>
Diffstat (limited to 'userapi/api')
-rw-r--r--userapi/api/api.go83
-rw-r--r--userapi/api/api_trace.go30
2 files changed, 113 insertions, 0 deletions
diff --git a/userapi/api/api.go b/userapi/api/api.go
index 2be662e5..e9cdbe01 100644
--- a/userapi/api/api.go
+++ b/userapi/api/api.go
@@ -21,6 +21,7 @@ import (
"github.com/matrix-org/gomatrixserverlib"
"github.com/matrix-org/dendrite/clientapi/auth/authtypes"
+ "github.com/matrix-org/dendrite/internal/pushrules"
)
// UserInternalAPI is the internal API for information about users and devices.
@@ -28,6 +29,7 @@ type UserInternalAPI interface {
LoginTokenInternalAPI
InputAccountData(ctx context.Context, req *InputAccountDataRequest, res *InputAccountDataResponse) error
+
PerformAccountCreation(ctx context.Context, req *PerformAccountCreationRequest, res *PerformAccountCreationResponse) error
PerformPasswordUpdate(ctx context.Context, req *PerformPasswordUpdateRequest, res *PerformPasswordUpdateResponse) error
PerformDeviceCreation(ctx context.Context, req *PerformDeviceCreationRequest, res *PerformDeviceCreationResponse) error
@@ -37,6 +39,10 @@ type UserInternalAPI interface {
PerformAccountDeactivation(ctx context.Context, req *PerformAccountDeactivationRequest, res *PerformAccountDeactivationResponse) error
PerformOpenIDTokenCreation(ctx context.Context, req *PerformOpenIDTokenCreationRequest, res *PerformOpenIDTokenCreationResponse) error
PerformKeyBackup(ctx context.Context, req *PerformKeyBackupRequest, res *PerformKeyBackupResponse) error
+ PerformPusherSet(ctx context.Context, req *PerformPusherSetRequest, res *struct{}) error
+ PerformPusherDeletion(ctx context.Context, req *PerformPusherDeletionRequest, res *struct{}) error
+ PerformPushRulesPut(ctx context.Context, req *PerformPushRulesPutRequest, res *struct{}) error
+
QueryKeyBackup(ctx context.Context, req *QueryKeyBackupRequest, res *QueryKeyBackupResponse)
QueryProfile(ctx context.Context, req *QueryProfileRequest, res *QueryProfileResponse) error
QueryAccessToken(ctx context.Context, req *QueryAccessTokenRequest, res *QueryAccessTokenResponse) error
@@ -45,6 +51,9 @@ type UserInternalAPI interface {
QueryDeviceInfos(ctx context.Context, req *QueryDeviceInfosRequest, res *QueryDeviceInfosResponse) error
QuerySearchProfiles(ctx context.Context, req *QuerySearchProfilesRequest, res *QuerySearchProfilesResponse) error
QueryOpenIDToken(ctx context.Context, req *QueryOpenIDTokenRequest, res *QueryOpenIDTokenResponse) error
+ QueryPushers(ctx context.Context, req *QueryPushersRequest, res *QueryPushersResponse) error
+ QueryPushRules(ctx context.Context, req *QueryPushRulesRequest, res *QueryPushRulesResponse) error
+ QueryNotifications(ctx context.Context, req *QueryNotificationsRequest, res *QueryNotificationsResponse) error
}
type PerformKeyBackupRequest struct {
@@ -424,3 +433,77 @@ const (
// AccountTypeAppService indicates this is an appservice account
AccountTypeAppService AccountType = 4
)
+
+type QueryPushersRequest struct {
+ Localpart string
+}
+
+type QueryPushersResponse struct {
+ Pushers []Pusher `json:"pushers"`
+}
+
+type PerformPusherSetRequest struct {
+ Pusher // Anonymous field because that's how clientapi unmarshals it.
+ Localpart string
+ Append bool `json:"append"`
+}
+
+type PerformPusherDeletionRequest struct {
+ Localpart string
+ SessionID int64
+}
+
+// Pusher represents a push notification subscriber
+type Pusher struct {
+ SessionID int64 `json:"session_id,omitempty"`
+ PushKey string `json:"pushkey"`
+ PushKeyTS gomatrixserverlib.Timestamp `json:"pushkey_ts,omitempty"`
+ Kind PusherKind `json:"kind"`
+ AppID string `json:"app_id"`
+ AppDisplayName string `json:"app_display_name"`
+ DeviceDisplayName string `json:"device_display_name"`
+ ProfileTag string `json:"profile_tag"`
+ Language string `json:"lang"`
+ Data map[string]interface{} `json:"data"`
+}
+
+type PusherKind string
+
+const (
+ EmailKind PusherKind = "email"
+ HTTPKind PusherKind = "http"
+)
+
+type PerformPushRulesPutRequest struct {
+ UserID string `json:"user_id"`
+ RuleSets *pushrules.AccountRuleSets `json:"rule_sets"`
+}
+
+type QueryPushRulesRequest struct {
+ UserID string `json:"user_id"`
+}
+
+type QueryPushRulesResponse struct {
+ RuleSets *pushrules.AccountRuleSets `json:"rule_sets"`
+}
+
+type QueryNotificationsRequest struct {
+ Localpart string `json:"localpart"` // Required.
+ From string `json:"from,omitempty"`
+ Limit int `json:"limit,omitempty"`
+ Only string `json:"only,omitempty"`
+}
+
+type QueryNotificationsResponse struct {
+ NextToken string `json:"next_token"`
+ Notifications []*Notification `json:"notifications"` // Required.
+}
+
+type Notification struct {
+ Actions []*pushrules.Action `json:"actions"` // Required.
+ Event gomatrixserverlib.ClientEvent `json:"event"` // Required.
+ ProfileTag string `json:"profile_tag"` // Required by Sytest, but actually optional.
+ Read bool `json:"read"` // Required.
+ RoomID string `json:"room_id"` // Required.
+ TS gomatrixserverlib.Timestamp `json:"ts"` // Required.
+}
diff --git a/userapi/api/api_trace.go b/userapi/api/api_trace.go
index aa069f40..9334f445 100644
--- a/userapi/api/api_trace.go
+++ b/userapi/api/api_trace.go
@@ -79,6 +79,21 @@ func (t *UserInternalAPITrace) PerformKeyBackup(ctx context.Context, req *Perfor
util.GetLogger(ctx).Infof("PerformKeyBackup req=%+v res=%+v", js(req), js(res))
return err
}
+func (t *UserInternalAPITrace) PerformPusherSet(ctx context.Context, req *PerformPusherSetRequest, res *struct{}) error {
+ err := t.Impl.PerformPusherSet(ctx, req, res)
+ util.GetLogger(ctx).Infof("PerformPusherSet req=%+v res=%+v", js(req), js(res))
+ return err
+}
+func (t *UserInternalAPITrace) PerformPusherDeletion(ctx context.Context, req *PerformPusherDeletionRequest, res *struct{}) error {
+ err := t.Impl.PerformPusherDeletion(ctx, req, res)
+ util.GetLogger(ctx).Infof("PerformPusherDeletion req=%+v res=%+v", js(req), js(res))
+ return err
+}
+func (t *UserInternalAPITrace) PerformPushRulesPut(ctx context.Context, req *PerformPushRulesPutRequest, res *struct{}) error {
+ err := t.Impl.PerformPushRulesPut(ctx, req, res)
+ util.GetLogger(ctx).Infof("PerformPushRulesPut req=%+v res=%+v", js(req), js(res))
+ return err
+}
func (t *UserInternalAPITrace) QueryKeyBackup(ctx context.Context, req *QueryKeyBackupRequest, res *QueryKeyBackupResponse) {
t.Impl.QueryKeyBackup(ctx, req, res)
util.GetLogger(ctx).Infof("QueryKeyBackup req=%+v res=%+v", js(req), js(res))
@@ -118,6 +133,21 @@ func (t *UserInternalAPITrace) QueryOpenIDToken(ctx context.Context, req *QueryO
util.GetLogger(ctx).Infof("QueryOpenIDToken req=%+v res=%+v", js(req), js(res))
return err
}
+func (t *UserInternalAPITrace) QueryPushers(ctx context.Context, req *QueryPushersRequest, res *QueryPushersResponse) error {
+ err := t.Impl.QueryPushers(ctx, req, res)
+ util.GetLogger(ctx).Infof("QueryPushers req=%+v res=%+v", js(req), js(res))
+ return err
+}
+func (t *UserInternalAPITrace) QueryPushRules(ctx context.Context, req *QueryPushRulesRequest, res *QueryPushRulesResponse) error {
+ err := t.Impl.QueryPushRules(ctx, req, res)
+ util.GetLogger(ctx).Infof("QueryPushRules req=%+v res=%+v", js(req), js(res))
+ return err
+}
+func (t *UserInternalAPITrace) QueryNotifications(ctx context.Context, req *QueryNotificationsRequest, res *QueryNotificationsResponse) error {
+ err := t.Impl.QueryNotifications(ctx, req, res)
+ util.GetLogger(ctx).Infof("QueryNotifications req=%+v res=%+v", js(req), js(res))
+ return err
+}
func js(thing interface{}) string {
b, err := json.Marshal(thing)