[TASK] add support to receive audio from threema

This commit is contained in:
Martin/Geno 2019-06-02 23:49:26 +02:00
parent b9bf07389c
commit c21927e4d5
No known key found for this signature in database
GPG Key ID: 9D7D3C6BFF600C6A
2 changed files with 44 additions and 0 deletions

View File

@ -44,6 +44,24 @@ func (a *Account) receiving(receivedMessage o3.ReceivedMsg) (xmpp.Packet, error)
requestExtensions(&xMSG) requestExtensions(&xMSG)
return xMSG, nil 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: case o3.ImageMessage:
if a.threema.httpUploadPath == "" { if a.threema.httpUploadPath == "" {
return nil, errors.New("no place to store files at transport configurated") return nil, errors.New("no place to store files at transport configurated")

View File

@ -69,6 +69,32 @@ func TestReceiveText(t *testing.T) {
assert.Equal("Oojoh0Ah", xMSG.Body) 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) { func TestReceiveImage(t *testing.T) {
assert := assert.New(t) assert := assert.New(t)