Bypass mautrix.Content's MarshalJSON. Fixes #132

This commit is contained in:
Tulir Asokan 2020-01-07 22:27:37 +02:00
parent 8c3807a16d
commit 302fae6649

View file

@ -20,6 +20,7 @@ import (
"bytes"
"encoding/gob"
"encoding/hex"
"encoding/json"
"fmt"
"html"
"image"
@ -912,6 +913,27 @@ type MessageContent struct {
IsCustomPuppet bool `json:"net.maunium.whatsapp.puppet,omitempty"`
}
type serializableContent mautrix.Content
type serializableMessageContent struct {
*serializableContent
IsCustomPuppet bool `json:"net.maunium.whatsapp.puppet,omitempty"`
}
// Hacky bypass for mautrix.Content's MarshalSJSON
func (content *MessageContent) MarshalJSON() ([]byte, error) {
if mautrix.DisableFancyEventParsing {
if content.IsCustomPuppet {
content.Raw["net.maunium.whatsapp.puppet"] = content.IsCustomPuppet
}
return json.Marshal(content.Raw)
}
return json.Marshal(&serializableMessageContent{
serializableContent: (*serializableContent)(content.Content),
IsCustomPuppet: content.IsCustomPuppet,
})
}
func (portal *Portal) HandleTextMessage(source *User, message whatsapp.TextMessage) {
if !portal.startHandling(message.Info) {
return