Merge pull request 'Split ShareFile and SendMessage' (#430) from profile_images into master
Reviewed-on: #430 Reviewed-by: erinn <erinn@openprivacy.ca>
This commit is contained in:
commit
7d2d3979c1
|
@ -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
|
// ShareFile given a profile and a conversation handle, sets up a file sharing process to share the file
|
||||||
// at filepath
|
// 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)
|
manifest, err := files.CreateManifest(filepath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", err
|
return "", "", err
|
||||||
}
|
}
|
||||||
|
|
||||||
var nonce [24]byte
|
var nonce [24]byte
|
||||||
if _, err := io.ReadFull(rand.Reader, nonce[:]); err != nil {
|
if _, err := io.ReadFull(rand.Reader, nonce[:]); err != nil {
|
||||||
log.Errorf("Cannot read from random: %v\n", err)
|
log.Errorf("Cannot read from random: %v\n", err)
|
||||||
return "", err
|
return "", "", err
|
||||||
}
|
}
|
||||||
|
|
||||||
message := OverlayMessage{
|
message := OverlayMessage{
|
||||||
|
@ -138,12 +138,7 @@ func (f *Functionality) ShareFile(filepath string, profile peer.CwtchPeer, conve
|
||||||
|
|
||||||
profile.ShareFile(key, string(serializedManifest))
|
profile.ShareFile(key, string(serializedManifest))
|
||||||
|
|
||||||
// non-specific conversation
|
return key, string(wrapperJSON), err
|
||||||
if conversationID != -1 {
|
|
||||||
err = profile.SendMessage(conversationID, string(wrapperJSON))
|
|
||||||
}
|
|
||||||
|
|
||||||
return key, err
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// GenerateDownloadPath creates a file path that doesn't currently exist on the filesystem
|
// GenerateDownloadPath creates a file path that doesn't currently exist on the filesystem
|
||||||
|
|
|
@ -132,7 +132,8 @@ func TestFileSharing(t *testing.T) {
|
||||||
|
|
||||||
filesharingFunctionality, _ := filesharing.FunctionalityGate(map[string]bool{constants.FileSharingExperiment: true})
|
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 {
|
if err != nil {
|
||||||
t.Fatalf("Error!: %v", err)
|
t.Fatalf("Error!: %v", err)
|
||||||
|
|
Loading…
Reference in New Issue