package server import ( "time" "forge.redroom.link/yves/meowlib" "forge.redroom.link/yves/meowlib/client" ) // Step1Post builds and returns the packed server message that posts the // InvitationInitPayload to the invitation server. func Step1Post(invitationId string, invitationServerUid string, timeOut int, urlLen int, password string) ([]byte, error) { peer := client.GetConfig().GetIdentity().Peers.GetFromInvitationId(invitationId) if peer == nil { return nil, nil } if peer.InvitationKp == nil { return nil, nil } initPayload := &meowlib.InvitationInitPayload{ Uuid: peer.InvitationId, Name: peer.MyName, PublicKey: peer.InvitationKp.Public, InvitationMessage: peer.InvitationMessage, } invitationServer, err := client.GetConfig().GetIdentity().MessageServers.LoadServer(invitationServerUid) if err != nil { return nil, err } msg, err := invitationServer.BuildToServerMessageInvitationStep1(initPayload, password, timeOut, urlLen) if err != nil { return nil, err } return invitationServer.ProcessOutboundMessage(msg) } // Step1ReadResponse reads the server response to a Step1 post and returns the // shortcode URL and expiry wrapped in an Invitation. func Step1ReadResponse(invitationServerUid string, invitationResponse []byte) (*meowlib.Invitation, error) { srv, err := client.GetConfig().GetIdentity().MessageServers.LoadServer(invitationServerUid) if err != nil { return nil, err } serverMsg, err := srv.ProcessInboundServerResponse(invitationResponse) if err != nil { return nil, err } return serverMsg.Invitation, nil } // SetUrlInfo stores the shortcode URL and expiry on the pending peer. func SetUrlInfo(invitationId string, url string, expiry int64) { id := client.GetConfig().GetIdentity() peer := id.Peers.GetFromInvitationId(invitationId) if peer == nil { return } peer.InvitationUrl = url peer.InvitationExpiry = time.Unix(expiry, 0) id.Peers.StorePeer(peer) }