aboutsummaryrefslogtreecommitdiff
path: root/userapi/internal
diff options
context:
space:
mode:
authorKegsay <kegan@matrix.org>2020-07-30 18:00:56 +0100
committerGitHub <noreply@github.com>2020-07-30 18:00:56 +0100
commita7e67e65a8662387f1a5ba6860698743f9dbd60f (patch)
tree90714c83c20fee10ee3c758f3ba00b7f9eee6d1c /userapi/internal
parent292a9ddd82a7cfc64ed43b70454040fb009601a7 (diff)
Notify clients when devices are deleted (#1233)
* Recheck device lists when join/leave events come in * Add PerformDeviceDeletion * Notify clients when devices are deleted * Unbreak things * Remove debug logging
Diffstat (limited to 'userapi/internal')
-rw-r--r--userapi/internal/api.go39
1 files changed, 39 insertions, 0 deletions
diff --git a/userapi/internal/api.go b/userapi/internal/api.go
index 5b154196..738023dd 100644
--- a/userapi/internal/api.go
+++ b/userapi/internal/api.go
@@ -25,10 +25,12 @@ import (
"github.com/matrix-org/dendrite/clientapi/userutil"
"github.com/matrix-org/dendrite/internal/config"
"github.com/matrix-org/dendrite/internal/sqlutil"
+ keyapi "github.com/matrix-org/dendrite/keyserver/api"
"github.com/matrix-org/dendrite/userapi/api"
"github.com/matrix-org/dendrite/userapi/storage/accounts"
"github.com/matrix-org/dendrite/userapi/storage/devices"
"github.com/matrix-org/gomatrixserverlib"
+ "github.com/matrix-org/util"
)
type UserInternalAPI struct {
@@ -37,6 +39,7 @@ type UserInternalAPI struct {
ServerName gomatrixserverlib.ServerName
// AppServices is the list of all registered AS
AppServices []config.ApplicationService
+ KeyAPI keyapi.KeyInternalAPI
}
func (a *UserInternalAPI) InputAccountData(ctx context.Context, req *api.InputAccountDataRequest, res *api.InputAccountDataResponse) error {
@@ -104,6 +107,42 @@ func (a *UserInternalAPI) PerformDeviceCreation(ctx context.Context, req *api.Pe
return nil
}
+func (a *UserInternalAPI) PerformDeviceDeletion(ctx context.Context, req *api.PerformDeviceDeletionRequest, res *api.PerformDeviceDeletionResponse) error {
+ util.GetLogger(ctx).WithField("user_id", req.UserID).WithField("devices", req.DeviceIDs).Info("PerformDeviceDeletion")
+ local, domain, err := gomatrixserverlib.SplitID('@', req.UserID)
+ if err != nil {
+ return err
+ }
+ if domain != a.ServerName {
+ return fmt.Errorf("cannot PerformDeviceDeletion of remote users: got %s want %s", domain, a.ServerName)
+ }
+ err = a.DeviceDB.RemoveDevices(ctx, local, req.DeviceIDs)
+ if err != nil {
+ return err
+ }
+ // create empty device keys and upload them to delete what was once there and trigger device list changes
+ deviceKeys := make([]keyapi.DeviceKeys, len(req.DeviceIDs))
+ for i, did := range req.DeviceIDs {
+ deviceKeys[i] = keyapi.DeviceKeys{
+ UserID: req.UserID,
+ DeviceID: did,
+ KeyJSON: nil,
+ }
+ }
+
+ var uploadRes keyapi.PerformUploadKeysResponse
+ a.KeyAPI.PerformUploadKeys(context.Background(), &keyapi.PerformUploadKeysRequest{
+ DeviceKeys: deviceKeys,
+ }, &uploadRes)
+ if uploadRes.Error != nil {
+ return fmt.Errorf("Failed to delete device keys: %v", uploadRes.Error)
+ }
+ if len(uploadRes.KeyErrors) > 0 {
+ return fmt.Errorf("Failed to delete device keys, key errors: %+v", uploadRes.KeyErrors)
+ }
+ return nil
+}
+
func (a *UserInternalAPI) QueryProfile(ctx context.Context, req *api.QueryProfileRequest, res *api.QueryProfileResponse) error {
local, domain, err := gomatrixserverlib.SplitID('@', req.UserID)
if err != nil {