diff --git a/go.mod b/go.mod index cf7d8a9..8b4747a 100644 --- a/go.mod +++ b/go.mod @@ -16,4 +16,4 @@ require ( maunium.net/go/mautrix v0.7.13 ) -replace github.com/Rhymen/go-whatsapp => github.com/tulir/go-whatsapp v0.3.11 +replace github.com/Rhymen/go-whatsapp => github.com/tulir/go-whatsapp v0.3.12 diff --git a/go.sum b/go.sum index 042519d..2b2b573 100644 --- a/go.sum +++ b/go.sum @@ -111,6 +111,8 @@ github.com/tulir/go-whatsapp v0.3.10 h1:LfzRj6V3dshKemad3HZsgYgKAZtaT0wNITmobJYA github.com/tulir/go-whatsapp v0.3.10/go.mod h1:U5+sm33vrv3wz62YyRM/VS7q2ObXkxU4Xqj/3KOmN9o= github.com/tulir/go-whatsapp v0.3.11 h1:z9AvTb8YXYP8t6Y0jium3reshgDpFCg//WNiCGo9esQ= github.com/tulir/go-whatsapp v0.3.11/go.mod h1:U5+sm33vrv3wz62YyRM/VS7q2ObXkxU4Xqj/3KOmN9o= +github.com/tulir/go-whatsapp v0.3.12 h1:4ovBn1GNMUsCrFR7KdAcByQnkh0o+VoA7Q/wY2UD36A= +github.com/tulir/go-whatsapp v0.3.12/go.mod h1:U5+sm33vrv3wz62YyRM/VS7q2ObXkxU4Xqj/3KOmN9o= golang.org/x/crypto v0.0.0-20180904163835-0709b304e793/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= golang.org/x/crypto v0.0.0-20200604202706-70a84ac30bf9 h1:vEg9joUBmeBcK9iSJftGNf3coIG4HqZElCPehJsfAYM= diff --git a/portal.go b/portal.go index 3a8bee5..8260bf7 100644 --- a/portal.go +++ b/portal.go @@ -241,10 +241,14 @@ func (portal *Portal) handleMessage(msg PortalMessage) { length: data.Length, }) case whatsapp.DocumentMessage: + fileName := data.FileName + if len(fileName) == 0 { + fileName = data.Title + } portal.HandleMediaMessage(msg.source, mediaMessage{ base: base{data.Download, data.Info, data.ContextInfo, data.Type}, thumbnail: data.Thumbnail, - fileName: data.Title, + fileName: fileName, }) case whatsapp.ContactMessage: portal.HandleContactMessage(msg.source, data) @@ -1471,7 +1475,13 @@ func (portal *Portal) HandleMediaMessage(source *User, msg mediaMessage) { } if msg.fileName == "" { - msg.fileName = msg.info.Id + mimeClass := strings.Split(msg.mimeType, "/")[0] + switch mimeClass { + case "application": + msg.fileName = "file" + default: + msg.fileName = mimeClass + } exts, _ := mime.ExtensionsByType(msg.mimeType) if exts != nil && len(exts) > 0 { @@ -1895,6 +1905,7 @@ func (portal *Portal) convertMatrixMessage(sender *User, evt *event.Event) (*waP info.Message.DocumentMessage = &waProto.DocumentMessage{ ContextInfo: ctxInfo, Url: &media.URL, + Title: &content.Body, FileName: &content.Body, MediaKey: media.MediaKey, Mimetype: &content.GetInfo().MimeType,