use whatsapp document filename for document type files

Fixes #199
This commit is contained in:
Lieuwe Rooijakkers 2020-06-20 17:26:45 +02:00
parent 9d6b9a901d
commit 9cc8b04c8e

View file

@ -199,15 +199,15 @@ func (portal *Portal) handleMessage(msg PortalMessage) {
case whatsapp.TextMessage:
portal.HandleTextMessage(msg.source, data)
case whatsapp.ImageMessage:
portal.HandleMediaMessage(msg.source, data.Download, data.Thumbnail, data.Info, data.ContextInfo, data.Type, data.Caption, 0, false)
portal.HandleMediaMessage(msg.source, data.Download, data.Thumbnail, data.Info, data.ContextInfo, data.Type, data.Caption, "", 0, false)
case whatsapp.StickerMessage:
portal.HandleMediaMessage(msg.source, data.Download, nil, data.Info, data.ContextInfo, data.Type, "", 0, true)
portal.HandleMediaMessage(msg.source, data.Download, nil, data.Info, data.ContextInfo, data.Type, "", "", 0, true)
case whatsapp.VideoMessage:
portal.HandleMediaMessage(msg.source, data.Download, data.Thumbnail, data.Info, data.ContextInfo, data.Type, data.Caption, data.Length, false)
portal.HandleMediaMessage(msg.source, data.Download, data.Thumbnail, data.Info, data.ContextInfo, data.Type, data.Caption, "", data.Length, false)
case whatsapp.AudioMessage:
portal.HandleMediaMessage(msg.source, data.Download, nil, data.Info, data.ContextInfo, data.Type, "", data.Length, false)
portal.HandleMediaMessage(msg.source, data.Download, nil, data.Info, data.ContextInfo, data.Type, "", "", data.Length, false)
case whatsapp.DocumentMessage:
portal.HandleMediaMessage(msg.source, data.Download, data.Thumbnail, data.Info, data.ContextInfo, data.Type, data.Title, 0, false)
portal.HandleMediaMessage(msg.source, data.Download, data.Thumbnail, data.Info, data.ContextInfo, data.Type, "", data.Title, 0, false)
case whatsapp.ContactMessage:
portal.HandleContactMessage(msg.source, data)
case whatsapp.LocationMessage:
@ -1253,7 +1253,7 @@ func (portal *Portal) encryptFile(data []byte, mimeType string) ([]byte, string,
}
func (portal *Portal) HandleMediaMessage(source *User, download func() ([]byte, error), thumbnail []byte, info whatsapp.MessageInfo, context whatsapp.ContextInfo, mimeType, caption string, length uint32, sendAsSticker bool) {
func (portal *Portal) HandleMediaMessage(source *User, download func() ([]byte, error), thumbnail []byte, info whatsapp.MessageInfo, context whatsapp.ContextInfo, mimeType, caption, fileName string, length uint32, sendAsSticker bool) {
intent := portal.startHandling(source, info)
if intent == nil {
return
@ -1309,11 +1309,14 @@ func (portal *Portal) HandleMediaMessage(source *User, download func() ([]byte,
return
}
fileName := info.Id
if fileName == "" {
fileName = info.Id
exts, _ := mime.ExtensionsByType(mimeType)
if exts != nil && len(exts) > 0 {
fileName += exts[0]
}
}
content := &event.MessageEventContent{
Body: fileName,