Bypass mautrix.Content's MarshalJSON. Fixes #132
This commit is contained in:
parent
8c3807a16d
commit
302fae6649
1 changed files with 22 additions and 0 deletions
22
portal.go
22
portal.go
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue