add image+audio support + refactory group

This commit is contained in:
Martin/Geno 2019-09-09 13:27:06 +02:00 committed by genofire
parent 836efe59a4
commit eef58dcfba
3 changed files with 58 additions and 62 deletions

View File

@ -58,65 +58,57 @@ func (a *Account) receiving(receivedMessage o3.Message) (stanza.Packet, error) {
})
sender = strings.ToLower(sender)
switch msg := receivedMessage.(type) {
case *o3.GroupTextMessage:
xMSG := stanza.NewMessage(stanza.Attrs{Type: stanza.MessageTypeGroupchat, From: jidFromThreemaGroup(sender, msg.GroupMessageHeader), To: a.XMPP.String(), Id: strconv.FormatUint(header.ID, 10)})
xMSG.Body = msg.Body
requestExtensions(&xMSG)
logger.WithFields(map[string]interface{}{
"from_x": xMSG.From,
"id": xMSG.Id,
"text": xMSG.Body,
}).Debug("recv grouptext")
return xMSG, nil
case *o3.TextMessage:
dbText := "recv text"
xMSG := stanza.NewMessage(stanza.Attrs{Type: stanza.MessageTypeChat, From: sender, To: a.XMPP.String(), Id: strconv.FormatUint(header.ID, 10)})
xMSG.Body = msg.Body
if msg.GroupMessageHeader != nil {
xMSG = stanza.NewMessage(stanza.Attrs{Type: stanza.MessageTypeGroupchat, From: jidFromThreemaGroup(sender, msg.GroupMessageHeader), To: a.XMPP.String(), Id: strconv.FormatUint(header.ID, 10)})
dbText = "recv grouptext"
} else {
requestExtensions(&xMSG)
}
xMSG.Body = msg.Body
logger.WithFields(map[string]interface{}{
"from_x": xMSG.From,
"id": xMSG.Id,
"text": xMSG.Body,
}).Debug("recv text")
}).Debug(dbText)
return xMSG, nil
/*
case o3.AudioMessage:
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)
data, err := msg.GetData()
if err != nil {
logger.Warnf("unable to read data from message: %s", err)
return nil, err
}
xMSG, err := a.FileToXMPP(sender.String(), header.ID, "mp3", data)
xMSG, err := a.FileToXMPP(sender, header.ID, "mp3", data)
if err != nil {
logger.Warnf("unable to create data from message: %s", err)
return nil, err
}
xMSG.Type = "chat"
requestExtensions(&xMSG)
logger.WithField("url", xMSG.Body).Debug("recv audio")
return xMSG, nil
case o3.ImageMessage:
case *o3.ImageMessage:
if a.threema.httpUploadPath == "" {
return nil, errors.New("no place to store files at transport configurated")
}
data, err := msg.GetImageData(a.Session)
data, err := msg.GetData(a.ThreemaID)
if err != nil {
logger.Warnf("unable to read data from message: %s", err)
return nil, err
}
xMSG, err := a.FileToXMPP(sender.String(), header.ID, "jpg", data)
xMSG, err := a.FileToXMPP(sender, header.ID, "jpg", data)
if err != nil {
logger.Warnf("unable to create data from message: %s", err)
return nil, err
}
xMSG.Type = "chat"
requestExtensions(&xMSG)
logger.WithField("url", xMSG.Body).Debug("recv image")
return xMSG, nil
*/
case *o3.DeliveryReceiptMessage:
xMSG := stanza.NewMessage(stanza.Attrs{Type: stanza.MessageTypeChat, From: sender, To: a.XMPP.String()})
state := ""

View File

@ -60,14 +60,13 @@ func TestReceiveText(t *testing.T) {
assert.Equal("Oojoh0Ah", xMSG.Body)
}
/*
func TestReceiveAudio(t *testing.T) {
assert := assert.New(t)
a := createDummyAccount()
a.threema = &Threema{}
dataMsg := o3.ImageMessage{
dataMsg := o3.AudioMessage{
MessageHeader: &o3.MessageHeader{
Sender: threemaFromIDByte,
},
@ -76,7 +75,11 @@ func TestReceiveAudio(t *testing.T) {
assert.Error(err)
a.threema.httpUploadPath = "/tmp"
dataMsg = o3.AudioMessage{}
dataMsg = o3.AudioMessage{
MessageHeader: &o3.MessageHeader{
Sender: threemaFromIDByte,
},
}
_, err = a.receiving(dataMsg)
assert.Error(err)
}
@ -96,16 +99,19 @@ func TestReceiveImage(t *testing.T) {
assert.Error(err)
a.threema.httpUploadPath = "/tmp"
dataMsg := o3.ImageMessage{
dataMsg = o3.ImageMessage{
MessageHeader: &o3.MessageHeader{
Sender: threemaFromIDByte,
},
}
dataMsg = o3.ImageMessage{
MessageHeader: &o3.MessageHeader{
Sender: threemaFromIDByte,
},
}
dataMsg = o3.ImageMessage{}
_, err = a.receiving(dataMsg)
assert.Error(err)
}
*/
func TestReceiveDeliveryReceipt(t *testing.T) {
assert := assert.New(t)

View File

@ -113,6 +113,7 @@ func (a *Account) sending(to string, msg stanza.Message) (o3.Message, error) {
// send text message
msg3 := &o3.TextMessage{
GroupMessageHeader: groupHeader,
MessageHeader: header,
Body: msg.Body,
}
@ -124,10 +125,7 @@ func (a *Account) sending(to string, msg stanza.Message) (o3.Message, error) {
if groupHeader != nil {
logger.Debug("send grouptext")
// TODO iterate of all occupants
return &o3.GroupTextMessage{
GroupMessageHeader: groupHeader,
TextMessage: msg3,
}, nil
return msg3, nil
}
a.deliveredMSG[msg3ID] = msg.Id
a.readedMSG[msg3ID] = msg.Id