meowlib/client/helpers/invitationFinalizeHelper.go

54 lines
1.8 KiB
Go
Raw Normal View History

package helpers
import (
"forge.redroom.link/yves/meowlib"
"forge.redroom.link/yves/meowlib/client"
"google.golang.org/protobuf/proto"
)
2024-03-29 15:40:46 +01:00
// Got it by the message background check
// => noInvitationGetAnswer
// InvitationGetAnswerReadResponse
// Called by the invitation initiator
// invitationAnswerData: the data received from the server
// invitationServerUid: the uid of the server holding the invitation
2024-03-29 15:40:46 +01:00
func InvitationGetAnswerReadResponse(invitation *meowlib.Invitation) (*client.Peer, string, error) {
// decode the payload
var invitationAnswer meowlib.PackedUserMessage
2024-03-29 15:40:46 +01:00
err := proto.Unmarshal(invitation.Payload, &invitationAnswer)
if err != nil {
2024-03-29 15:40:46 +01:00
return nil, "InvitationGetAnswerReadResponse: Unmarshal", err
}
// retreive user public key to check usermessage signature
2024-03-29 15:40:46 +01:00
// contactPublikKey := serverMsg.Invitation.From
peer := client.GetConfig().GetIdentity().Peers.GetFromInvitationId(invitation.Uuid)
peer.ContactPublicKey = invitation.From
if peer != nil {
// process the packed user message
usermsg, err := peer.ProcessInboundUserMessage(invitationAnswer.Payload, invitationAnswer.Signature)
if err != nil {
return nil, "InvitationGetAnswerReadResponse: ProcessInboundUserMessage", err
}
decodedInvitation := usermsg.Invitation
var cc meowlib.ContactCard
err = proto.Unmarshal(decodedInvitation.Payload, &cc)
if err != nil {
return nil, "InvitationGetAnswerReadResponse: Unmarshal", err
}
// finalize the invitation
// id := client.GetConfig().GetIdentity()
peer.ContactLookupKey = cc.ContactPublicKey
peer.ContactEncryption = cc.EncryptionPublicKey
for _, server := range cc.PullServers {
peer.ContactPullServers = append(peer.ContactPullServers, server.GetUid())
}
client.GetConfig().GetIdentity().Save()
// cc, err := id.FinalizeInvitation(serverMsg.Invitation.)
}
return peer, "", nil
}