Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use pointers for querying sender ID #405

Merged
merged 1 commit into from
Aug 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions performinvite.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,8 @@ func PerformInvite(ctx context.Context, input PerformInviteInput, fedClient Fede
return nil, err
}

if invitedSenderID != "" {
err = abortIfAlreadyJoined(ctx, input.RoomID, invitedSenderID, input.MembershipQuerier)
if invitedSenderID != nil {
err = abortIfAlreadyJoined(ctx, input.RoomID, *invitedSenderID, input.MembershipQuerier)
if err != nil {
return nil, err
}
Expand Down
5 changes: 3 additions & 2 deletions performinvite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,9 @@ import (
"golang.org/x/crypto/ed25519"
)

func SenderIDForUserTest(roomID spec.RoomID, userID spec.UserID) (spec.SenderID, error) {
return spec.SenderID(userID.String()), nil
func SenderIDForUserTest(roomID spec.RoomID, userID spec.UserID) (*spec.SenderID, error) {
senderID := spec.SenderID(userID.String())
return &senderID, nil
}

func CreateSenderID(ctx context.Context, userID spec.UserID, roomID spec.RoomID, roomVersion string) (spec.SenderID, ed25519.PrivateKey, error) {
Expand Down
13 changes: 12 additions & 1 deletion spec/senderid.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
type SenderID string

type UserIDForSender func(roomID RoomID, senderID SenderID) (*UserID, error)
type SenderIDForUser func(roomID RoomID, userID UserID) (SenderID, error)
type SenderIDForUser func(roomID RoomID, userID UserID) (*SenderID, error)

// CreateSenderID is a function used to create the pseudoID private key.
type CreateSenderID func(ctx context.Context, userID UserID, roomID RoomID, roomVersion string) (SenderID, ed25519.PrivateKey, error)
Expand All @@ -42,3 +42,14 @@
}
return res, nil
}

func (s SenderID) IsUserID() bool {
// Key is base64, @ is not a valid base64 char
// So if string starts with @, then this sender ID must
// be a user ID
return string(s)[0] == '@'

Check warning on line 50 in spec/senderid.go

View check run for this annotation

Codecov / codecov/patch

spec/senderid.go#L46-L50

Added lines #L46 - L50 were not covered by tests
}

func (s SenderID) IsPseudoID() bool {
return !s.IsUserID()

Check warning on line 54 in spec/senderid.go

View check run for this annotation

Codecov / codecov/patch

spec/senderid.go#L53-L54

Added lines #L53 - L54 were not covered by tests
}
Loading