diff --git a/client/helpers/backgroundHelper.go b/client/helpers/backgroundHelper.go index 1d7fb81..2fb7ba1 100644 --- a/client/helpers/backgroundHelper.go +++ b/client/helpers/backgroundHelper.go @@ -2,6 +2,7 @@ package helpers import ( "errors" + "log" "os" "path/filepath" "strconv" @@ -145,19 +146,27 @@ func ReadMessage(messageFilename string, detachFilesStoragePath string) ([]strin //fmt.Println("From:", usermsg.From) //jsonUserMessage, _ := json.Marshal(usermsg) //fmt.Println(string(jsonUserMessage)) - // detach files + peer = client.GetConfig().GetIdentity().Peers.GetFromPublicKey(usermsg.From) + // detach files if usermsg.Files != nil { + // create files folder + if _, err := os.Stat(filepath.Join(detachFilesStoragePath, "files")); os.IsNotExist(err) { + err = os.MkdirAll(filepath.Join(detachFilesStoragePath, "files"), 0700) + if err != nil { + log.Fatal(err) + } + } for _, file := range usermsg.Files { filename := uuid.New().String() + "_" + file.Filename - filenames = append(filenames, filename) + filenames = append(filenames, peer.Name+" sent: "+filename) // detach file os.WriteFile(filepath.Join(detachFilesStoragePath, "files", filename), file.Data, 0600) } //? result["invitation finalized"] = peer.Name } // user message - peer = client.GetConfig().GetIdentity().Peers.GetFromPublicKey(usermsg.From) + messagesOverview = append(messagesOverview, peer.Name+" > "+string(usermsg.Data)) // add message to storage err = peer.StoreMessage(usermsg, filenames)