From d2067f74d84ac5a08e933225e070dbbbd9dc0b03 Mon Sep 17 00:00:00 2001 From: Simon Ser Date: Fri, 17 Mar 2023 10:23:37 +0100 Subject: [PATCH] database/sqlite: delete push subscriptions and msgstore in DeleteUser --- database/sqlite.go | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/database/sqlite.go b/database/sqlite.go index f9062a8..01c9736 100644 --- a/database/sqlite.go +++ b/database/sqlite.go @@ -619,6 +619,35 @@ func (db *SqliteDB) DeleteUser(ctx context.Context, id int64) error { return err } + _, err = tx.ExecContext(ctx, `DELETE FROM Message + WHERE id IN ( + SELECT Message.id + FROM Message, MessageTarget, Network + WHERE Message.target = MessageTarget.id + AND MessageTarget.network = Network.id + AND Network.user = ? + )`, id) + if err != nil { + return err + } + + _, err = tx.ExecContext(ctx, `DELETE FROM MessageTarget + WHERE id IN ( + SELECT MessageTarget.id + FROM MessageTarget, Network + WHERE MessageTarget.network = Network.id + AND Network.user = ? + )`) + if err != nil { + return err + } + + _, err = tx.ExecContext(ctx, `DELETE FROM WebPushSubscription + WHERE user = ?`, id) + if err != nil { + return err + } + _, err = tx.ExecContext(ctx, `DELETE FROM Channel WHERE id IN ( SELECT Channel.id