Split ShareFile and SendMessage
continuous-integration/drone/push Build is passing Details
continuous-integration/drone/pr Build is failing Details

This commit is contained in:
Sarah Jamie Lewis 2022-02-03 16:07:49 -08:00
parent dec2b7182c
commit 9621e294c2
2 changed files with 6 additions and 10 deletions

View File

@ -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

View File

@ -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)