mirror of
https://github.com/tulir/mautrix-whatsapp
synced 2024-12-13 17:13:11 +01:00
Fix bridge->bridge file names
WhatsApp uses the "title" and "fileName" fields for document names. The bridge was only reading title and sending fileName, so sending a document from one bridge to another through WhatsApp would lose the file name. Also use names like "image.png" instead of "<random id>.png" for unnamed files
This commit is contained in:
parent
0c60516702
commit
a1740db0d7
3 changed files with 16 additions and 3 deletions
2
go.mod
2
go.mod
|
@ -16,4 +16,4 @@ require (
|
||||||
maunium.net/go/mautrix v0.7.13
|
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
|
||||||
|
|
2
go.sum
2
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.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 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.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-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-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
|
||||||
golang.org/x/crypto v0.0.0-20200604202706-70a84ac30bf9 h1:vEg9joUBmeBcK9iSJftGNf3coIG4HqZElCPehJsfAYM=
|
golang.org/x/crypto v0.0.0-20200604202706-70a84ac30bf9 h1:vEg9joUBmeBcK9iSJftGNf3coIG4HqZElCPehJsfAYM=
|
||||||
|
|
15
portal.go
15
portal.go
|
@ -241,10 +241,14 @@ func (portal *Portal) handleMessage(msg PortalMessage) {
|
||||||
length: data.Length,
|
length: data.Length,
|
||||||
})
|
})
|
||||||
case whatsapp.DocumentMessage:
|
case whatsapp.DocumentMessage:
|
||||||
|
fileName := data.FileName
|
||||||
|
if len(fileName) == 0 {
|
||||||
|
fileName = data.Title
|
||||||
|
}
|
||||||
portal.HandleMediaMessage(msg.source, mediaMessage{
|
portal.HandleMediaMessage(msg.source, mediaMessage{
|
||||||
base: base{data.Download, data.Info, data.ContextInfo, data.Type},
|
base: base{data.Download, data.Info, data.ContextInfo, data.Type},
|
||||||
thumbnail: data.Thumbnail,
|
thumbnail: data.Thumbnail,
|
||||||
fileName: data.Title,
|
fileName: fileName,
|
||||||
})
|
})
|
||||||
case whatsapp.ContactMessage:
|
case whatsapp.ContactMessage:
|
||||||
portal.HandleContactMessage(msg.source, data)
|
portal.HandleContactMessage(msg.source, data)
|
||||||
|
@ -1471,7 +1475,13 @@ func (portal *Portal) HandleMediaMessage(source *User, msg mediaMessage) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if msg.fileName == "" {
|
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)
|
exts, _ := mime.ExtensionsByType(msg.mimeType)
|
||||||
if exts != nil && len(exts) > 0 {
|
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{
|
info.Message.DocumentMessage = &waProto.DocumentMessage{
|
||||||
ContextInfo: ctxInfo,
|
ContextInfo: ctxInfo,
|
||||||
Url: &media.URL,
|
Url: &media.URL,
|
||||||
|
Title: &content.Body,
|
||||||
FileName: &content.Body,
|
FileName: &content.Body,
|
||||||
MediaKey: media.MediaKey,
|
MediaKey: media.MediaKey,
|
||||||
Mimetype: &content.GetInfo().MimeType,
|
Mimetype: &content.GetInfo().MimeType,
|
||||||
|
|
Loading…
Reference in a new issue