33 lines
1.2 KiB
Go
33 lines
1.2 KiB
Go
|
|
package messages
|
||
|
|
|
||
|
|
import (
|
||
|
|
"errors"
|
||
|
|
|
||
|
|
"forge.redroom.link/yves/meowlib"
|
||
|
|
"forge.redroom.link/yves/meowlib/client"
|
||
|
|
"google.golang.org/protobuf/proto"
|
||
|
|
)
|
||
|
|
|
||
|
|
// Step4InviteeFinalizesInitiator is called by the invitee's message processor when a
|
||
|
|
// UserMessage with invitation.step == 3 arrives. It unmarshals the initiator's ContactCard
|
||
|
|
// and completes the invitee's peer entry with the initiator's real keys.
|
||
|
|
func Step4InviteeFinalizesInitiator(usermsg *meowlib.UserMessage) (*client.Peer, error) {
|
||
|
|
if usermsg.Invitation == nil || usermsg.Invitation.Step != 3 {
|
||
|
|
return nil, errors.New("expected invitation step 3")
|
||
|
|
}
|
||
|
|
var initiatorCC meowlib.ContactCard
|
||
|
|
if err := proto.Unmarshal(usermsg.Invitation.Payload, &initiatorCC); err != nil {
|
||
|
|
return nil, err
|
||
|
|
}
|
||
|
|
// Patch the invitation ID from the outer message in case it was not set in the CC.
|
||
|
|
if initiatorCC.InvitationId == "" {
|
||
|
|
initiatorCC.InvitationId = usermsg.Invitation.Uuid
|
||
|
|
}
|
||
|
|
if err := client.GetConfig().GetIdentity().InvitationStep4(&initiatorCC); err != nil {
|
||
|
|
return nil, err
|
||
|
|
}
|
||
|
|
client.GetConfig().GetIdentity().Save()
|
||
|
|
peer := client.GetConfig().GetIdentity().Peers.GetFromInvitationId(initiatorCC.InvitationId)
|
||
|
|
return peer, nil
|
||
|
|
}
|