From 9621e294c273de1dbf077fc8d75a0049bdb3344b Mon Sep 17 00:00:00 2001 From: Sarah Jamie Lewis Date: Thu, 3 Feb 2022 16:07:49 -0800 Subject: [PATCH] Split ShareFile and SendMessage --- .../filesharing/filesharing_functionality.go | 13 ++++--------- .../filesharing/file_sharing_integration_test.go | 3 ++- 2 files changed, 6 insertions(+), 10 deletions(-) diff --git a/functionality/filesharing/filesharing_functionality.go b/functionality/filesharing/filesharing_functionality.go index 9b03864..a66639a 100644 --- a/functionality/filesharing/filesharing_functionality.go +++ b/functionality/filesharing/filesharing_functionality.go @@ -88,16 +88,16 @@ func (f *Functionality) DownloadFile(profile peer.CwtchPeer, conversationID int, // ShareFile given a profile and a conversation handle, sets up a file sharing process to share the file // at filepath -func (f *Functionality) ShareFile(filepath string, profile peer.CwtchPeer, conversationID int) (string, error) { +func (f *Functionality) ShareFile(filepath string, profile peer.CwtchPeer) (string, string, error) { manifest, err := files.CreateManifest(filepath) if err != nil { - return "", err + return "", "", err } var nonce [24]byte if _, err := io.ReadFull(rand.Reader, nonce[:]); err != nil { log.Errorf("Cannot read from random: %v\n", err) - return "", err + return "", "", err } message := OverlayMessage{ @@ -138,12 +138,7 @@ func (f *Functionality) ShareFile(filepath string, profile peer.CwtchPeer, conve profile.ShareFile(key, string(serializedManifest)) - // non-specific conversation - if conversationID != -1 { - err = profile.SendMessage(conversationID, string(wrapperJSON)) - } - - return key, err + return key, string(wrapperJSON), err } // GenerateDownloadPath creates a file path that doesn't currently exist on the filesystem diff --git a/testing/filesharing/file_sharing_integration_test.go b/testing/filesharing/file_sharing_integration_test.go index c8e0afd..c09c67a 100644 --- a/testing/filesharing/file_sharing_integration_test.go +++ b/testing/filesharing/file_sharing_integration_test.go @@ -132,7 +132,8 @@ func TestFileSharing(t *testing.T) { filesharingFunctionality, _ := filesharing.FunctionalityGate(map[string]bool{constants.FileSharingExperiment: true}) - _, err = filesharingFunctionality.ShareFile("cwtch.png", alice, 1) + _, fileSharingMessage, err := filesharingFunctionality.ShareFile("cwtch.png", alice) + alice.SendMessage(1, fileSharingMessage) if err != nil { t.Fatalf("Error!: %v", err)