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)