From 6a1d689f6535f430a50092785c2b3e5f78ff5acd Mon Sep 17 00:00:00 2001 From: Till Faelligen <2353100+S7evinK@users.noreply.github.com> Date: Tue, 13 Jun 2023 13:59:09 +0200 Subject: [PATCH] Rename method --- roomserver/api/api.go | 4 ++-- roomserver/internal/api.go | 4 ++-- roomserver/internal/perform/perform_create_room.go | 4 ++-- roomserver/internal/perform/perform_invite.go | 2 +- roomserver/internal/perform/perform_join.go | 4 ++-- 5 files changed, 9 insertions(+), 9 deletions(-) diff --git a/roomserver/api/api.go b/roomserver/api/api.go index c5d12f9a4..fec28841e 100644 --- a/roomserver/api/api.go +++ b/roomserver/api/api.go @@ -68,8 +68,8 @@ type RoomserverInternalAPI interface { res *QueryAuthChainResponse, ) error - // GetUserRoomPrivateKey gets the user room key for the specified user. If no key exists yet, a new one is created. - GetUserRoomPrivateKey(ctx context.Context, userID spec.UserID, roomID spec.RoomID) (ed25519.PrivateKey, error) + // GetOrCreateUserRoomPrivateKey gets the user room key for the specified user. If no key exists yet, a new one is created. + GetOrCreateUserRoomPrivateKey(ctx context.Context, userID spec.UserID, roomID spec.RoomID) (ed25519.PrivateKey, error) } type InputRoomEventsAPI interface { diff --git a/roomserver/internal/api.go b/roomserver/internal/api.go index bc08942d8..4bcd3f3ed 100644 --- a/roomserver/internal/api.go +++ b/roomserver/internal/api.go @@ -272,8 +272,8 @@ func (r *RoomserverInternalAPI) PerformForget( return r.Forgetter.PerformForget(ctx, req, resp) } -// GetUserRoomPrivateKey gets the user room key for the specified user. If no key exists yet, a new one is created. -func (r *RoomserverInternalAPI) GetUserRoomPrivateKey(ctx context.Context, userID spec.UserID, roomID spec.RoomID) (ed25519.PrivateKey, error) { +// GetOrCreateUserRoomPrivateKey gets the user room key for the specified user. If no key exists yet, a new one is created. +func (r *RoomserverInternalAPI) GetOrCreateUserRoomPrivateKey(ctx context.Context, userID spec.UserID, roomID spec.RoomID) (ed25519.PrivateKey, error) { key, err := r.DB.SelectUserRoomPrivateKey(ctx, userID, roomID) if err != nil { return nil, err diff --git a/roomserver/internal/perform/perform_create_room.go b/roomserver/internal/perform/perform_create_room.go index 75cb9cca2..121b257ed 100644 --- a/roomserver/internal/perform/perform_create_room.go +++ b/roomserver/internal/perform/perform_create_room.go @@ -366,9 +366,9 @@ func (c *Creator) PerformCreateRoom(ctx context.Context, userID spec.UserID, roo // create user room key if needed if createRequest.RoomVersion == gomatrixserverlib.RoomVersionPseudoIDs { - _, err = c.RSAPI.GetUserRoomPrivateKey(ctx, userID, roomID) + _, err = c.RSAPI.GetOrCreateUserRoomPrivateKey(ctx, userID, roomID) if err != nil { - util.GetLogger(ctx).WithError(err).Error("GetUserRoomPrivateKey failed") + util.GetLogger(ctx).WithError(err).Error("GetOrCreateUserRoomPrivateKey failed") return "", &util.JSONResponse{ Code: http.StatusInternalServerError, JSON: spec.InternalServerError{}, diff --git a/roomserver/internal/perform/perform_invite.go b/roomserver/internal/perform/perform_invite.go index 98fbdb879..cc2c5c191 100644 --- a/roomserver/internal/perform/perform_invite.go +++ b/roomserver/internal/perform/perform_invite.go @@ -185,7 +185,7 @@ func (r *Inviter) PerformInvite( // if we invited a local user, we can also create a user room key, if it doesn't exist yet. if isTargetLocal && event.Version() == gomatrixserverlib.RoomVersionPseudoIDs { - _, err = r.RSAPI.GetUserRoomPrivateKey(ctx, *invitedUser, *validRoomID) + _, err = r.RSAPI.GetOrCreateUserRoomPrivateKey(ctx, *invitedUser, *validRoomID) if err != nil { return fmt.Errorf("failed to get user room private key: %w", err) } diff --git a/roomserver/internal/perform/perform_join.go b/roomserver/internal/perform/perform_join.go index e7ddeaead..c0d4b7468 100644 --- a/roomserver/internal/perform/perform_join.go +++ b/roomserver/internal/perform/perform_join.go @@ -296,9 +296,9 @@ func (r *Joiner) performJoinRoomByID( case nil: // create user room key if needed if buildRes.RoomVersion == gomatrixserverlib.RoomVersionPseudoIDs { - _, err = r.RSAPI.GetUserRoomPrivateKey(ctx, *userID, *roomID) + _, err = r.RSAPI.GetOrCreateUserRoomPrivateKey(ctx, *userID, *roomID) if err != nil { - util.GetLogger(ctx).WithError(err).Error("GetUserRoomPrivateKey failed") + util.GetLogger(ctx).WithError(err).Error("GetOrCreateUserRoomPrivateKey failed") return "", "", fmt.Errorf("failed to get user room private key: %w", err) } }