From 3ac6b02e564bd20b8b8111ad8d3f0b65a548304b Mon Sep 17 00:00:00 2001 From: ycc Date: Mon, 1 Apr 2024 20:56:45 +0200 Subject: [PATCH] Refactor file detachment logic in ReadMessage function --- client/helpers/backgroundHelper.go | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/client/helpers/backgroundHelper.go b/client/helpers/backgroundHelper.go index 313c785..4998bf1 100644 --- a/client/helpers/backgroundHelper.go +++ b/client/helpers/backgroundHelper.go @@ -31,7 +31,6 @@ func CheckForMessages(storage_path string, job *client.RequestsJob) (int, string count := 0 - //fmt.Println(jsonjob) // if folder does not exist, create it if _, err := os.Stat(filepath.Join(storage_path, "inbox")); os.IsNotExist(err) { err := os.MkdirAll(filepath.Join(storage_path, "inbox"), 0700) @@ -108,7 +107,7 @@ func SaveCheckJobs() (string, error) { } // ReadMessage -func ReadMessage(messageFilename string, detachFilesStoragePath string) ([]string, []string, string, error) { +func ReadMessage(messageFilename string) ([]string, []string, string, error) { messagesOverview := []string{} filenames := []string{} @@ -151,8 +150,8 @@ func ReadMessage(messageFilename string, detachFilesStoragePath string) ([]strin // 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 := os.Stat(filepath.Join(client.GetConfig().StoragePath, identity.Uuid, "files")); os.IsNotExist(err) { + err = os.MkdirAll(filepath.Join(client.GetConfig().StoragePath, identity.Uuid, "files"), 0700) if err != nil { log.Fatal(err) } @@ -161,7 +160,7 @@ func ReadMessage(messageFilename string, detachFilesStoragePath string) ([]strin filename := uuid.New().String() + "_" + file.Filename filenames = append(filenames, peer.Name+" sent: "+filename) // detach file - os.WriteFile(filepath.Join(detachFilesStoragePath, "files", filename), file.Data, 0600) + os.WriteFile(filepath.Join(client.GetConfig().StoragePath, identity.Uuid, "files", filename), file.Data, 0600) } //? result["invitation finalized"] = peer.Name }