cleaner invitation step messages
This commit is contained in:
@@ -1,27 +1,25 @@
|
||||
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 {
|
||||
// Step4InviteeFinalizesInitiator is called by the invitee when the step-3 answer
|
||||
// (serialized Invitation bytes) arrives. It unmarshals the initiator's ContactCard and
|
||||
// completes the invitee's peer entry with the initiator's real keys.
|
||||
func Step4InviteeFinalizesInitiator(invitationBytes []byte) (*client.Peer, error) {
|
||||
var inv meowlib.Invitation
|
||||
if err := proto.Unmarshal(invitationBytes, &inv); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
var initiatorCC meowlib.ContactCard
|
||||
if err := proto.Unmarshal(inv.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
|
||||
initiatorCC.InvitationId = inv.Uuid
|
||||
}
|
||||
if err := client.GetConfig().GetIdentity().InvitationStep4(&initiatorCC); err != nil {
|
||||
return nil, err
|
||||
|
||||
Reference in New Issue
Block a user