|
@@ -2015,6 +2015,17 @@ func (portal *Portal) addRelaybotFormat(sender *User, content *event.MessageEven
|
|
return true
|
|
return true
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+func addCodecToMime(mimeType, codec string) string {
|
|
|
|
+ mediaType, params, err := mime.ParseMediaType(mimeType)
|
|
|
|
+ if err != nil {
|
|
|
|
+ return mimeType
|
|
|
|
+ }
|
|
|
|
+ if _, ok := params["codecs"]; !ok {
|
|
|
|
+ params["codecs"] = codec
|
|
|
|
+ }
|
|
|
|
+ return mime.FormatMediaType(mediaType, params)
|
|
|
|
+}
|
|
|
|
+
|
|
func (portal *Portal) convertMatrixMessage(sender *User, evt *event.Event) (*waProto.WebMessageInfo, *User) {
|
|
func (portal *Portal) convertMatrixMessage(sender *User, evt *event.Event) (*waProto.WebMessageInfo, *User) {
|
|
content, ok := evt.Content.Parsed.(*event.MessageEventContent)
|
|
content, ok := evt.Content.Parsed.(*event.MessageEventContent)
|
|
if !ok {
|
|
if !ok {
|
|
@@ -2024,10 +2035,10 @@ func (portal *Portal) convertMatrixMessage(sender *User, evt *event.Event) (*waP
|
|
|
|
|
|
ts := uint64(evt.Timestamp / 1000)
|
|
ts := uint64(evt.Timestamp / 1000)
|
|
status := waProto.WebMessageInfo_PENDING
|
|
status := waProto.WebMessageInfo_PENDING
|
|
- fromMe := true
|
|
|
|
|
|
+ trueVal := true
|
|
info := &waProto.WebMessageInfo{
|
|
info := &waProto.WebMessageInfo{
|
|
Key: &waProto.MessageKey{
|
|
Key: &waProto.MessageKey{
|
|
- FromMe: &fromMe,
|
|
|
|
|
|
+ FromMe: &trueVal,
|
|
Id: makeMessageID(),
|
|
Id: makeMessageID(),
|
|
RemoteJid: &portal.Key.JID,
|
|
RemoteJid: &portal.Key.JID,
|
|
},
|
|
},
|
|
@@ -2141,6 +2152,12 @@ func (portal *Portal) convertMatrixMessage(sender *User, evt *event.Event) (*waP
|
|
FileSha256: media.FileSHA256,
|
|
FileSha256: media.FileSHA256,
|
|
FileLength: &media.FileLength,
|
|
FileLength: &media.FileLength,
|
|
}
|
|
}
|
|
|
|
+ if _, isVoice := evt.Content.Raw["org.matrix.msc3245.voice"]; isVoice {
|
|
|
|
+ info.Message.AudioMessage.Ptt = &trueVal
|
|
|
|
+ // hacky hack to add the codecs param that whatsapp seems to require
|
|
|
|
+ mimeWithCodec := addCodecToMime(content.GetInfo().MimeType, "opus")
|
|
|
|
+ info.Message.AudioMessage.Mimetype = &mimeWithCodec
|
|
|
|
+ }
|
|
case event.MsgFile:
|
|
case event.MsgFile:
|
|
media := portal.preprocessMatrixMedia(sender, relaybotFormatted, content, evt.ID, whatsapp.MediaDocument)
|
|
media := portal.preprocessMatrixMedia(sender, relaybotFormatted, content, evt.ID, whatsapp.MediaDocument)
|
|
if media == nil {
|
|
if media == nil {
|