diff --git a/client/helpers/backgroundHelper.go b/client/helpers/backgroundHelper.go index 69aa279..2512737 100644 --- a/client/helpers/backgroundHelper.go +++ b/client/helpers/backgroundHelper.go @@ -103,7 +103,7 @@ func SaveCheckJobs() (string, error) { } // ReadMessage -func ReadMessage(messageFilename string, storagePath string) (string, string, error) { +func ReadMessage(messageFilename string, detachFilesStoragePath string) (string, string, error) { result := map[string]interface{}{} // read message file @@ -119,7 +119,7 @@ func ReadMessage(messageFilename string, storagePath string) (string, string, er } // check if invitation answer if fromServerMessage.Invitation != nil { - + InvitationGetAnswerReadResponse(fromServerMessage.Invitation) } // Chat messages if len(fromServerMessage.Chat) > 0 { @@ -146,7 +146,7 @@ func ReadMessage(messageFilename string, storagePath string) (string, string, er filename := uuid.New().String() + "_" + file.Filename filenames = append(filenames, filename) // detach file - os.WriteFile(filepath.Join(storagePath, "files", filename), file.Data, 0600) + os.WriteFile(filepath.Join(detachFilesStoragePath, "files", filename), file.Data, 0600) } //? result["invitation finalized"] = peer.Name } diff --git a/client/helpers/invitationFinalizeHelper.go b/client/helpers/invitationFinalizeHelper.go index 5c2b7a7..3388960 100644 --- a/client/helpers/invitationFinalizeHelper.go +++ b/client/helpers/invitationFinalizeHelper.go @@ -6,67 +6,48 @@ import ( "google.golang.org/protobuf/proto" ) -// InvitationGetAnswer -// Called by the invitation initiator -// invitationId: the id of the invitation -// serverUid: the uid of the server holding the invitation answer -func InvitationGetAnswer(invitationId string, serverUid string) ([]byte, string, error) { - - // check if already in msg servers - srv, err := client.GetConfig().GetIdentity().MessageServers.LoadServer(serverUid) - if err != nil { - return nil, "InvitationGetAnswer: LoadServer", err - } - - // buildserver message - toSrvMsg, err := srv.BuildToServerMessageInvitationAnswerRequest(invitationId) - if err != nil { - return nil, "InvitationGetAnswer: BuildToServerMessageInvitationRequest", err - } - // processoutbound - bytemsg, err := srv.ProcessOutboundMessage(toSrvMsg) - if err != nil { - return nil, "InvitationGetAnswer: ProcessOutboundMessage", err - } - - return bytemsg, "", nil -} +// 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 -func InvitationGetAnswerReadResponse(invitationAnswerData []byte, invitationServerUid string) (string, error) { - - server, err := client.GetConfig().GetIdentity().MessageServers.LoadServer(invitationServerUid) - if err != nil { - return "InvitationGetAnswerReadResponse: LoadServer", err - } - // Server inbound processing : get the invitation server - serverMsg, err := server.ProcessInboundServerResponse(invitationAnswerData) - if err != nil { - return "InvitationGetAnswerReadResponse: ProcessInboundServerResponse", err - } - // fmt.Println("Inbound OK, Invitation Step: ", serverMsg.Invitation.Step, len(serverMsg.Invitation.Payload)) - // fmt.Println("Invitation Check") - // fmt.Println(hex.EncodeToString(serverMsg.Invitation.Payload)) - // contactCard decode +func InvitationGetAnswerReadResponse(invitation *meowlib.Invitation) (*client.Peer, string, error) { // decode the payload var invitationAnswer meowlib.PackedUserMessage - err = proto.Unmarshal(serverMsg.Invitation.Payload, &invitationAnswer) + err := proto.Unmarshal(invitation.Payload, &invitationAnswer) if err != nil { - return "InvitationGetAnswerReadResponse: Unmarshal", err + return nil, "InvitationGetAnswerReadResponse: Unmarshal", err } // retreive user public key to check usermessage signature - //contactPublikKey := serverMsg.Invitation.From + // contactPublikKey := serverMsg.Invitation.From + peer := client.GetConfig().GetIdentity().Peers.GetFromInvitationId(invitation.Uuid) + peer.ContactPublicKey = invitation.From + if peer != nil { - // process the packed user message + // 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() - - // cc, err := id.FinalizeInvitation(serverMsg.Invitation.) - - return "", nil + // 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 } diff --git a/client/peerlist.go b/client/peerlist.go index 8c81532..34f60b8 100644 --- a/client/peerlist.go +++ b/client/peerlist.go @@ -15,6 +15,15 @@ func (pl *PeerList) GetFromPublicKey(publickey string) *Peer { return nil } +func (pl *PeerList) GetFromInvitationId(invitationId string) *Peer { + for _, peer := range *pl { + if peer.InvitationId == invitationId { + return peer + } + } + return nil +} + func (pl *PeerList) GetFromMyLookupKey(publickey string) *Peer { for _, peer := range *pl { if peer.MyLookupKp.Public == publickey {