package migrate import ( "net/http" "maunium.net/go/mautrix/id" ) // maxForgetGhosts bounds one request to forget old ghosts. const maxForgetGhosts = 100 // handleForgetGhosts forgets that the bridge registered old ghosts: once a user's history has moved // and the old rooms are gone, the API deletes the Synapse accounts of the old ghosts that are in no // room any more (they are named after phone numbers and addresses). The appservice state store // would otherwise still say they are registered, and the next plaintext room that needs one of those // contacts (another user's, not switched on yet) would fail to use the deleted account instead of // registering it again. // // POST /_xessenger/v1/e2ee/ghosts/forget {ghostIds} -> {forgotten} func (m *mover) handleForgetGhosts(w http.ResponseWriter, r *http.Request) { var req struct { GhostIDs []id.UserID `json:"ghostIds"` } if !readBody(w, r, &req) { return } if len(req.GhostIDs) == 0 || len(req.GhostIDs) > maxForgetGhosts { writeError(w, http.StatusBadRequest, "M_INVALID_PARAM", "Name 1 to 100 ghosts") return } for _, ghost := range req.GhostIDs { if !m.br.IsGhostMXID(ghost) { writeError(w, http.StatusBadRequest, "M_INVALID_PARAM", "Not a ghost of this bridge") return } } ctx := m.requestContext(r) forgotten := 0 for _, ghost := range req.GhostIDs { res, err := m.conn.StateStore.Exec(ctx, "DELETE FROM mx_registrations WHERE user_id=$1", ghost) if err != nil { answerError(ctx, w, err, "Failed to forget a ghost's registration") return } if n, err := res.RowsAffected(); err == nil { forgotten += int(n) } } writeJSON(w, http.StatusOK, map[string]any{"forgotten": forgotten}) }