From 8300a699a30c99209f49138899d9be4113e98ee0 Mon Sep 17 00:00:00 2001 From: ycc Date: Fri, 29 Mar 2024 16:17:07 +0100 Subject: [PATCH] background return improve --- client/helpers/backgroundHelper.go | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/client/helpers/backgroundHelper.go b/client/helpers/backgroundHelper.go index 935a8c4..0f27375 100644 --- a/client/helpers/backgroundHelper.go +++ b/client/helpers/backgroundHelper.go @@ -110,19 +110,20 @@ func SaveCheckJobs() (string, error) { } // ReadMessage -func ReadMessage(messageFilename string, detachFilesStoragePath string) (string, string, error) { +func ReadMessage(messageFilename string, detachFilesStoragePath string) ([]string, []string, string, error) { result := map[string]interface{}{} - + messagesOverview := []string{} + filenames := []string{} // read message file msg, err := os.ReadFile(messageFilename) if err != nil { - return "", "ReadMessage: ReadFile", err + return nil, nil, "ReadMessage: ReadFile", err } // protobuf unmarshal message var fromServerMessage meowlib.FromServerMessage err = proto.Unmarshal(msg, &fromServerMessage) if err != nil { - return "", "ReadMessage: Unmarshal FromServerMessage", err + return nil, nil, "ReadMessage: Unmarshal FromServerMessage", err } // check if invitation answer if fromServerMessage.Invitation != nil { @@ -135,19 +136,19 @@ func ReadMessage(messageFilename string, detachFilesStoragePath string) (string, // find the peer with that lookup key peer := client.GetConfig().GetIdentity().Peers.GetFromMyLookupKey(packedUserMessage.Destination) if peer == nil { - return "", "ReadMessage: GetFromMyLookupKey", errors.New("no visible peer for that message") + return nil, nil, "ReadMessage: GetFromMyLookupKey", errors.New("no visible peer for that message") } // Unpack the message usermsg, err := peer.ProcessInboundUserMessage(packedUserMessage.Payload, packedUserMessage.Signature) if err != nil { - return "", "ReadMessage: ProcessInboundUserMessage", err + return nil, nil, "ReadMessage: ProcessInboundUserMessage", err } fmt.Println("From:", usermsg.From) jsonUserMessage, _ := json.Marshal(usermsg) fmt.Println(string(jsonUserMessage)) // detach files - filenames := []string{} + if usermsg.Files != nil { for _, file := range usermsg.Files { filename := uuid.New().String() + "_" + file.Filename @@ -158,14 +159,15 @@ func ReadMessage(messageFilename string, detachFilesStoragePath string) (string, //? result["invitation finalized"] = peer.Name } // user message - result["message"] = string(usermsg.Data) + messagesOverview = append(messagesOverview, usermsg.From+" > "+string(usermsg.Data)) // add message to storage err = peer.StoreMessage(usermsg, filenames) if err != nil { - return "", "ReadMessage: StoreMessage", err + return nil, nil, "ReadMessage: StoreMessage", err } } + return messagesOverview, filenames, "", nil } // fmt.Println("have read fromServerMessage, will unmarshal packed") @@ -176,8 +178,9 @@ func ReadMessage(messageFilename string, detachFilesStoragePath string) (string, // return C.CString(errorToJson(err, "ReadMessage: Unmarshal PackedUserMessage")) // } // fmt.Println("Destination:", packedMessage.Destination) - // fmt.Println("Payload lengh:", len(packedMessage.Payload)) + // fmt.Println("Payload lengh:", len(packedMessage.Pay ""load)) // server invitation finalize or more ? +/* if fromServerMessage.Invitation != nil { fmt.Println("Invitation from:", fromServerMessage.Invitation.From) // find the peer with that lookup key @@ -185,7 +188,7 @@ func ReadMessage(messageFilename string, detachFilesStoragePath string) (string, //! FOLOWING statement is WRONG ! peer := client.GetConfig().GetIdentity().Peers.GetFromPublicKey(fromServerMessage.Invitation.From) if peer == nil { - return "", "ReadMessage: GetFromPublicKey", errors.New("no visible peer for that message") + return nil, nil, "ReadMessage: GetFromPublicKey", errors.New("no visible peer for that message") } peer.ContactPublicKey = fromServerMessage.Invitation.From str, _ := json.Marshal(peer) @@ -201,6 +204,7 @@ func ReadMessage(messageFilename string, detachFilesStoragePath string) (string, return "", "ReadMessage: FinalizeInvitation", err } result["invitation finalized"] = peer.Name + */ }