diff --git a/clientapi/clientapi.go b/clientapi/clientapi.go index cc5b36f54..e2f8d3f32 100644 --- a/clientapi/clientapi.go +++ b/clientapi/clientapi.go @@ -68,4 +68,3 @@ func AddPublicRoutes( extRoomsProvider, mscCfg, natsClient, ) } - diff --git a/clientapi/routing/server_notices.go b/clientapi/routing/server_notices.go index 016aa51d5..c0dc31945 100644 --- a/clientapi/routing/server_notices.go +++ b/clientapi/routing/server_notices.go @@ -107,7 +107,7 @@ func sendServerNotice( return util.JSONResponse{ Code: http.StatusBadRequest, JSON: jsonerror.BadJSON("Invalid request"), - }, fmt.Errorf("invalid server notice request") + }, fmt.Errorf("Invalid JSON") } qryServerNoticeRoom := &userapi.QueryServerNoticeRoomResponse{} @@ -177,7 +177,7 @@ func sendServerNotice( default: // if we didn't get a createRoomResponse, we probably received an error, so return that. - return roomRes, err + return roomRes, fmt.Errorf("Unable to create room") } } else { @@ -188,10 +188,10 @@ func sendServerNotice( } // re-invite the user if res.Membership != gomatrixserverlib.Join { - var sendInviteRes util.JSONResponse - sendInviteRes, err = sendInvite(ctx, userAPI, senderDevice, roomID, serverNoticeRequest.UserID, "Server notice room", cfgClient, rsAPI, asAPI, time.Now()) + var inviteRes util.JSONResponse + inviteRes, err = sendInvite(ctx, userAPI, senderDevice, roomID, serverNoticeRequest.UserID, "Server notice room", cfgClient, rsAPI, asAPI, time.Now()) if err != nil { - return sendInviteRes, err + return inviteRes, err } } } @@ -205,7 +205,7 @@ func sendServerNotice( e, resErr := generateSendEvent(ctx, request, senderDevice, roomID, "m.room.message", nil, cfgClient, rsAPI, time.Now()) if resErr != nil { logrus.Errorf("failed to send message: %+v", resErr) - return *resErr, err + return *resErr, fmt.Errorf("Unable to send event") } timeToGenerateEvent := time.Since(startedGeneratingEvent) @@ -220,7 +220,7 @@ func sendServerNotice( // pass the new event to the roomserver and receive the correct event ID // event ID in case of duplicate transaction is discarded startedSubmittingEvent := time.Now() - if err := api.SendEvents( + if err = api.SendEvents( ctx, rsAPI, api.KindNew, []*gomatrixserverlib.HeaderedEvent{ diff --git a/userapi/internal/api.go b/userapi/internal/api.go index ed9dadcca..ce62b0eb4 100644 --- a/userapi/internal/api.go +++ b/userapi/internal/api.go @@ -882,4 +882,4 @@ func (a *UserInternalAPI) UpdateServerNoticeRoomID( res *api.UpdateServerNoticeRoomResponse, ) (err error) { return a.DB.UpdateServerNoticeRoomID(ctx, req.Localpart, req.RoomID) -} \ No newline at end of file +} diff --git a/userapi/inthttp/client.go b/userapi/inthttp/client.go index 072cdc7b6..d938a70cb 100644 --- a/userapi/inthttp/client.go +++ b/userapi/inthttp/client.go @@ -44,8 +44,8 @@ const ( PerformSetDisplayNamePath = "/userapi/performSetDisplayName" PerformForgetThreePIDPath = "/userapi/performForgetThreePID" PerformSaveThreePIDAssociationPath = "/userapi/performSaveThreePIDAssociation" - PerformUpdatePolicyVersionPath = "/userapi/performUpdatePolicyVersion" - PerformUpdateServerNoticeRoomPath = "/userapi/performUpdateServerNoticeRoom" + PerformUpdatePolicyVersionPath = "/userapi/performUpdatePolicyVersion" + PerformUpdateServerNoticeRoomPath = "/userapi/performUpdateServerNoticeRoom" QueryKeyBackupPath = "/userapi/queryKeyBackup" QueryProfilePath = "/userapi/queryProfile" @@ -63,9 +63,9 @@ const ( QueryAccountByPasswordPath = "/userapi/queryAccountByPassword" QueryLocalpartForThreePIDPath = "/userapi/queryLocalpartForThreePID" QueryThreePIDsForLocalpartPath = "/userapi/queryThreePIDsForLocalpart" - QueryPolicyVersionPath = "/userapi/queryPolicyVersion" - QueryOutdatedPolicyUsersPath = "/userapi/queryOutdatedPolicy" - QueryServerNoticeRoomPath = "/userapi/queryServerNoticeRoom" + QueryPolicyVersionPath = "/userapi/queryPolicyVersion" + QueryOutdatedPolicyUsersPath = "/userapi/queryOutdatedPolicy" + QueryServerNoticeRoomPath = "/userapi/queryServerNoticeRoom" ) // NewUserAPIClient creates a UserInternalAPI implemented by talking to a HTTP POST API. @@ -397,14 +397,6 @@ func (h *httpUserInternalAPI) PerformSaveThreePIDAssociation(ctx context.Context return httputil.PostJSON(ctx, span, h.httpClient, apiURL, req, res) } -func (h *httpUserInternalAPI) QueryPolicyVersion(ctx context.Context, req *api.QueryPolicyVersionRequest, res *api.QueryPolicyVersionResponse) error { - span, ctx := opentracing.StartSpanFromContext(ctx, "QueryPolicyVersion") - defer span.Finish() - - apiURL := h.apiURL + QueryPolicyVersionPath - return httputil.PostJSON(ctx, span, h.httpClient, apiURL, req, res) -} - func (h *httpUserInternalAPI) QueryOutdatedPolicy(ctx context.Context, req *api.QueryOutdatedPolicyRequest, res *api.QueryOutdatedPolicyResponse) error { span, ctx := opentracing.StartSpanFromContext(ctx, "QueryOutdatedPolicy") defer span.Finish() @@ -429,10 +421,18 @@ func (h *httpUserInternalAPI) SelectServerNoticeRoomID(ctx context.Context, req return httputil.PostJSON(ctx, span, h.httpClient, apiURL, req, res) } +func (h *httpUserInternalAPI) QueryPolicyVersion(ctx context.Context, req *api.QueryPolicyVersionRequest, res *api.QueryPolicyVersionResponse) error { + span, ctx := opentracing.StartSpanFromContext(ctx, "QueryPolicyVersion") + defer span.Finish() + + apiURL := h.apiURL + QueryPolicyVersionPath + return httputil.PostJSON(ctx, span, h.httpClient, apiURL, req, res) +} + func (h *httpUserInternalAPI) UpdateServerNoticeRoomID(ctx context.Context, req *api.UpdateServerNoticeRoomRequest, res *api.UpdateServerNoticeRoomResponse) (err error) { span, ctx := opentracing.StartSpanFromContext(ctx, "UpdateServerNoticeRoomID") defer span.Finish() apiURL := h.apiURL + PerformUpdateServerNoticeRoomPath return httputil.PostJSON(ctx, span, h.httpClient, apiURL, req, res) -} \ No newline at end of file +} diff --git a/userapi/storage/postgres/accounts_table.go b/userapi/storage/postgres/accounts_table.go index 097fe8998..c7ae8f103 100644 --- a/userapi/storage/postgres/accounts_table.go +++ b/userapi/storage/postgres/accounts_table.go @@ -19,6 +19,7 @@ import ( "database/sql" "time" + "github.com/matrix-org/dendrite/internal" "github.com/matrix-org/gomatrixserverlib" "github.com/matrix-org/dendrite/clientapi/userutil" @@ -232,7 +233,7 @@ func (s *accountsStatements) BatchSelectPrivacyPolicy( stmt = sqlutil.TxStmt(txn, stmt) } rows, err := stmt.QueryContext(ctx, policyVersion) - defer rows.Close() + defer internal.CloseAndLogIfError(ctx, rows, "BatchSelectPrivacyPolicy: rows.close() failed") for rows.Next() { var userID string if err := rows.Scan(&userID); err != nil { @@ -289,4 +290,4 @@ func (s *accountsStatements) UpdateServerNoticeRoomID( } _, err = stmt.ExecContext(ctx, roomID, localpart) return -} \ No newline at end of file +} diff --git a/userapi/storage/shared/storage.go b/userapi/storage/shared/storage.go index e69aaf55e..eadf6f816 100644 --- a/userapi/storage/shared/storage.go +++ b/userapi/storage/shared/storage.go @@ -809,4 +809,4 @@ func (d *Database) UpdateServerNoticeRoomID(ctx context.Context, localpart, room return d.Accounts.UpdateServerNoticeRoomID(ctx, txn, localpart, roomID) }) return -} \ No newline at end of file +} diff --git a/userapi/storage/sqlite3/accounts_table.go b/userapi/storage/sqlite3/accounts_table.go index 9f7e75226..5fb6b5ffe 100644 --- a/userapi/storage/sqlite3/accounts_table.go +++ b/userapi/storage/sqlite3/accounts_table.go @@ -19,6 +19,7 @@ import ( "database/sql" "time" + "github.com/matrix-org/dendrite/internal" "github.com/matrix-org/gomatrixserverlib" "github.com/matrix-org/dendrite/clientapi/userutil" @@ -235,7 +236,7 @@ func (s *accountsStatements) BatchSelectPrivacyPolicy( if err != nil { return nil, err } - defer rows.Close() + defer internal.CloseAndLogIfError(ctx, rows, "BatchSelectPrivacyPolicy: rows.close() failed") for rows.Next() { var userID string if err := rows.Scan(&userID); err != nil { @@ -292,4 +293,4 @@ func (s *accountsStatements) UpdateServerNoticeRoomID( } _, err = stmt.ExecContext(ctx, roomID, localpart) return -} \ No newline at end of file +}