refactor invitation
This commit is contained in:
46
client/invitation/messages/step3.go
Normal file
46
client/invitation/messages/step3.go
Normal file
@@ -0,0 +1,46 @@
|
||||
package messages
|
||||
|
||||
import (
|
||||
"errors"
|
||||
|
||||
"forge.redroom.link/yves/meowlib"
|
||||
"forge.redroom.link/yves/meowlib/client"
|
||||
"google.golang.org/protobuf/proto"
|
||||
)
|
||||
|
||||
// Step3InitiatorFinalizesInviteeAndCreatesContactCard is called by the initiator when a
|
||||
// step-2 answer (invitee's encrypted ContactCard) arrives. It decrypts the card, upgrades
|
||||
// the invitee's peer entry with the real keys, and returns the initiator's own ContactCard
|
||||
// ready to be sent to the invitee via any transport.
|
||||
func Step3InitiatorFinalizesInviteeAndCreatesContactCard(invitation *meowlib.Invitation) (*client.Peer, *meowlib.ContactCard, error) {
|
||||
var invitationAnswer meowlib.PackedUserMessage
|
||||
if err := proto.Unmarshal(invitation.Payload, &invitationAnswer); err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
|
||||
peer := client.GetConfig().GetIdentity().Peers.GetFromInvitationId(invitation.Uuid)
|
||||
if peer == nil {
|
||||
return nil, nil, errors.New("no peer for invitation uuid " + invitation.Uuid)
|
||||
}
|
||||
// Guard against duplicate delivery (e.g., same answer from multiple servers).
|
||||
if peer.InvitationKp == nil {
|
||||
return nil, nil, nil
|
||||
}
|
||||
|
||||
usermsg, err := peer.ProcessInboundStep2UserMessage(&invitationAnswer, invitation.From)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
|
||||
var inviteeCC meowlib.ContactCard
|
||||
if err := proto.Unmarshal(usermsg.Invitation.Payload, &inviteeCC); err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
|
||||
myCC, peer, err := client.GetConfig().GetIdentity().InvitationStep3(&inviteeCC)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
client.GetConfig().GetIdentity().Save()
|
||||
return peer, myCC, nil
|
||||
}
|
||||
Reference in New Issue
Block a user