forked from MirrorHub/mautrix-whatsapp
Add config option to bundle caption with media message
This commit is contained in:
parent
8012368de5
commit
aa0daceb85
5 changed files with 32 additions and 0 deletions
|
@ -106,6 +106,7 @@ type BridgeConfig struct {
|
||||||
AllowUserInvite bool `yaml:"allow_user_invite"`
|
AllowUserInvite bool `yaml:"allow_user_invite"`
|
||||||
FederateRooms bool `yaml:"federate_rooms"`
|
FederateRooms bool `yaml:"federate_rooms"`
|
||||||
URLPreviews bool `yaml:"url_previews"`
|
URLPreviews bool `yaml:"url_previews"`
|
||||||
|
CaptionInMessage bool `yaml:"caption_in_message"`
|
||||||
|
|
||||||
DisableStatusBroadcastSend bool `yaml:"disable_status_broadcast_send"`
|
DisableStatusBroadcastSend bool `yaml:"disable_status_broadcast_send"`
|
||||||
DisappearingMessagesInGroups bool `yaml:"disappearing_messages_in_groups"`
|
DisappearingMessagesInGroups bool `yaml:"disappearing_messages_in_groups"`
|
||||||
|
|
|
@ -90,6 +90,7 @@ func DoUpgrade(helper *up.Helper) {
|
||||||
helper.Copy(up.Bool, "bridge", "disappearing_messages_in_groups")
|
helper.Copy(up.Bool, "bridge", "disappearing_messages_in_groups")
|
||||||
helper.Copy(up.Bool, "bridge", "disable_bridge_alerts")
|
helper.Copy(up.Bool, "bridge", "disable_bridge_alerts")
|
||||||
helper.Copy(up.Bool, "bridge", "url_previews")
|
helper.Copy(up.Bool, "bridge", "url_previews")
|
||||||
|
helper.Copy(up.Bool, "bridge", "caption_in_message")
|
||||||
helper.Copy(up.Str, "bridge", "management_room_text", "welcome")
|
helper.Copy(up.Str, "bridge", "management_room_text", "welcome")
|
||||||
helper.Copy(up.Str, "bridge", "management_room_text", "welcome_connected")
|
helper.Copy(up.Str, "bridge", "management_room_text", "welcome_connected")
|
||||||
helper.Copy(up.Str, "bridge", "management_room_text", "welcome_unconnected")
|
helper.Copy(up.Str, "bridge", "management_room_text", "welcome_unconnected")
|
||||||
|
|
|
@ -277,6 +277,9 @@ bridge:
|
||||||
# and send it to WhatsApp? URL previews can always be sent using the `com.beeper.linkpreviews`
|
# and send it to WhatsApp? URL previews can always be sent using the `com.beeper.linkpreviews`
|
||||||
# key in the event content even if this is disabled.
|
# key in the event content even if this is disabled.
|
||||||
url_previews: false
|
url_previews: false
|
||||||
|
# Send captions in the same message as images. This will send data compatible with both MSC2530 and MSC3552.
|
||||||
|
# This is currently not supported in most clients.
|
||||||
|
caption_in_message: false
|
||||||
|
|
||||||
# The prefix for commands. Only required in non-management rooms.
|
# The prefix for commands. Only required in non-management rooms.
|
||||||
command_prefix: "!wa"
|
command_prefix: "!wa"
|
||||||
|
|
|
@ -629,6 +629,9 @@ func (portal *Portal) appendBatchEvents(converted *ConvertedMessage, info *types
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
if portal.bridge.Config.Bridge.CaptionInMessage {
|
||||||
|
converted.MergeCaption()
|
||||||
|
}
|
||||||
if converted.Caption != nil {
|
if converted.Caption != nil {
|
||||||
captionEvt, err := portal.wrapBatchEvent(info, converted.Intent, converted.Type, converted.Caption, nil)
|
captionEvt, err := portal.wrapBatchEvent(info, converted.Intent, converted.Type, converted.Caption, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
24
portal.go
24
portal.go
|
@ -680,6 +680,9 @@ func (portal *Portal) handleMessage(source *User, evt *events.Message) {
|
||||||
}
|
}
|
||||||
converted.Extra["fi.mau.whatsapp.source_broadcast_list"] = evt.Info.Chat.String()
|
converted.Extra["fi.mau.whatsapp.source_broadcast_list"] = evt.Info.Chat.String()
|
||||||
}
|
}
|
||||||
|
if portal.bridge.Config.Bridge.CaptionInMessage {
|
||||||
|
converted.MergeCaption()
|
||||||
|
}
|
||||||
var eventID id.EventID
|
var eventID id.EventID
|
||||||
var lastEventID id.EventID
|
var lastEventID id.EventID
|
||||||
if existingMsg != nil {
|
if existingMsg != nil {
|
||||||
|
@ -1674,6 +1677,24 @@ type ConvertedMessage struct {
|
||||||
MediaKey []byte
|
MediaKey []byte
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (cm *ConvertedMessage) MergeCaption() {
|
||||||
|
if cm.Caption == nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
cm.Extra["filename"] = cm.Content.Body
|
||||||
|
extensibleCaption := map[string]interface{}{
|
||||||
|
"org.matrix.msc1767.text": cm.Caption.Body,
|
||||||
|
}
|
||||||
|
cm.Extra["org.matrix.msc1767.caption"] = extensibleCaption
|
||||||
|
cm.Content.Body = cm.Caption.Body
|
||||||
|
if cm.Caption.Format == event.FormatHTML {
|
||||||
|
cm.Content.Format = event.FormatHTML
|
||||||
|
cm.Content.FormattedBody = cm.Caption.FormattedBody
|
||||||
|
extensibleCaption["org.matrix.msc1767.html"] = cm.Caption.FormattedBody
|
||||||
|
}
|
||||||
|
cm.Caption = nil
|
||||||
|
}
|
||||||
|
|
||||||
func (portal *Portal) convertTextMessage(intent *appservice.IntentAPI, source *User, msg *waProto.Message) *ConvertedMessage {
|
func (portal *Portal) convertTextMessage(intent *appservice.IntentAPI, source *User, msg *waProto.Message) *ConvertedMessage {
|
||||||
content := &event.MessageEventContent{
|
content := &event.MessageEventContent{
|
||||||
Body: msg.GetConversation(),
|
Body: msg.GetConversation(),
|
||||||
|
@ -2004,6 +2025,9 @@ func (portal *Portal) makeMediaBridgeFailureMessage(info *types.MessageInfo, bri
|
||||||
portal.log.Errorfln("Failed to bridge media for %s: %v", info.ID, bridgeErr)
|
portal.log.Errorfln("Failed to bridge media for %s: %v", info.ID, bridgeErr)
|
||||||
}
|
}
|
||||||
if keys != nil {
|
if keys != nil {
|
||||||
|
if portal.bridge.Config.Bridge.CaptionInMessage {
|
||||||
|
converted.MergeCaption()
|
||||||
|
}
|
||||||
meta := &FailedMediaMeta{
|
meta := &FailedMediaMeta{
|
||||||
Type: converted.Type,
|
Type: converted.Type,
|
||||||
Content: converted.Content,
|
Content: converted.Content,
|
||||||
|
|
Loading…
Reference in a new issue