aboutsummaryrefslogtreecommitdiff
path: root/roomserver/storage/sqlite3/membership_table.go
diff options
context:
space:
mode:
authorNeil Alexander <neilalexander@users.noreply.github.com>2022-07-22 14:44:04 +0100
committerGitHub <noreply@github.com>2022-07-22 14:44:04 +0100
commitf0c8a03649ab270bb15156a3cc47cae2aee3f36a (patch)
tree61ba370970ecead0161a7ab59811d16613e233e9 /roomserver/storage/sqlite3/membership_table.go
parenta201b4400dd4fe99b4c391f94ac31884deccc12c (diff)
Membership updater refactoring (#2541)
* Membership updater refactoring * Pass in membership state * Use membership check rather than referring to state directly * Delete irrelevant membership states * We don't need the leave event after all * Tweaks * Put a log entry in that I might stand a chance of finding * Be less panicky * Tweak invite handling * Don't freak if we can't find the event NID * Use event NID from `types.Event` * Clean up * Better invite handling * Placate the almighty linter * Blacklist a Sytest which is otherwise fine under Complement for reasons I don't understand * Fix the sytest after all (thanks @S7evinK for the spot)
Diffstat (limited to 'roomserver/storage/sqlite3/membership_table.go')
-rw-r--r--roomserver/storage/sqlite3/membership_table.go15
1 files changed, 15 insertions, 0 deletions
diff --git a/roomserver/storage/sqlite3/membership_table.go b/roomserver/storage/sqlite3/membership_table.go
index 570d3919..00a9bd4f 100644
--- a/roomserver/storage/sqlite3/membership_table.go
+++ b/roomserver/storage/sqlite3/membership_table.go
@@ -125,6 +125,9 @@ const selectServerInRoomSQL = "" +
" JOIN roomserver_event_state_keys ON roomserver_membership.target_nid = roomserver_event_state_keys.event_state_key_nid" +
" WHERE membership_nid = $1 AND room_nid = $2 AND event_state_key LIKE '%:' || $3 LIMIT 1"
+const deleteMembershipSQL = "" +
+ "DELETE FROM roomserver_membership WHERE room_nid = $1 AND target_nid = $2"
+
type membershipStatements struct {
db *sql.DB
insertMembershipStmt *sql.Stmt
@@ -140,6 +143,7 @@ type membershipStatements struct {
updateMembershipForgetRoomStmt *sql.Stmt
selectLocalServerInRoomStmt *sql.Stmt
selectServerInRoomStmt *sql.Stmt
+ deleteMembershipStmt *sql.Stmt
}
func CreateMembershipTable(db *sql.DB) error {
@@ -166,6 +170,7 @@ func PrepareMembershipTable(db *sql.DB) (tables.Membership, error) {
{&s.updateMembershipForgetRoomStmt, updateMembershipForgetRoom},
{&s.selectLocalServerInRoomStmt, selectLocalServerInRoomSQL},
{&s.selectServerInRoomStmt, selectServerInRoomSQL},
+ {&s.deleteMembershipStmt, deleteMembershipSQL},
}.Prepare(db)
}
@@ -383,3 +388,13 @@ func (s *membershipStatements) SelectServerInRoom(ctx context.Context, txn *sql.
}
return roomNID == nid, nil
}
+
+func (s *membershipStatements) DeleteMembership(
+ ctx context.Context, txn *sql.Tx,
+ roomNID types.RoomNID, targetUserNID types.EventStateKeyNID,
+) error {
+ _, err := sqlutil.TxStmt(txn, s.deleteMembershipStmt).ExecContext(
+ ctx, roomNID, targetUserNID,
+ )
+ return err
+}