From c21927e4d59c271e9872e5c4b19da8e12ad47659 Mon Sep 17 00:00:00 2001 From: Martin/Geno Date: Sun, 2 Jun 2019 23:49:26 +0200 Subject: [PATCH] [TASK] add support to receive audio from threema --- component/threema/receive.go | 18 ++++++++++++++++++ component/threema/receive_test.go | 26 ++++++++++++++++++++++++++ 2 files changed, 44 insertions(+) diff --git a/component/threema/receive.go b/component/threema/receive.go index 950d5ae..36167d9 100644 --- a/component/threema/receive.go +++ b/component/threema/receive.go @@ -44,6 +44,24 @@ func (a *Account) receiving(receivedMessage o3.ReceivedMsg) (xmpp.Packet, error) requestExtensions(&xMSG) return xMSG, nil + case o3.AudioMessage: + if a.threema.httpUploadPath == "" { + return nil, errors.New("no place to store files at transport configurated") + } + data, err := msg.GetAudioData(a.Session) + if err != nil { + log.Warnf("unable to read data from message: %s", err) + return nil, err + } + xMSG, err := a.FileToXMPP(msg.Sender().String(), msg.ID(), "mp3", data) + if err != nil { + log.Warnf("unable to create data from message: %s", err) + return nil, err + } + xMSG.Type = "chat" + requestExtensions(&xMSG) + return xMSG, nil + case o3.ImageMessage: if a.threema.httpUploadPath == "" { return nil, errors.New("no place to store files at transport configurated") diff --git a/component/threema/receive_test.go b/component/threema/receive_test.go index d8e438c..225b73e 100644 --- a/component/threema/receive_test.go +++ b/component/threema/receive_test.go @@ -69,6 +69,32 @@ func TestReceiveText(t *testing.T) { assert.Equal("Oojoh0Ah", xMSG.Body) } +func TestReceiveAudio(t *testing.T) { + assert := assert.New(t) + + a := createDummyAccount() + a.threema = &Threema{} + + /* receiving image + session := o3.SessionContext{ + ID: o3.ThreemaID{ + ID: o3.NewIDString("12345678"), + Nick: o3.NewPubNick("user"), + }, + }*/ + dataMsg := o3.AudioMessage{} + _, err := a.receiving(o3.ReceivedMsg{ + Msg: dataMsg, + }) + assert.Error(err) + + a.threema.httpUploadPath = "/tmp" + dataMsg = o3.AudioMessage{} + _, err = a.receiving(o3.ReceivedMsg{ + Msg: dataMsg, + }) + assert.Error(err) +} func TestReceiveImage(t *testing.T) { assert := assert.New(t)