forked from MirrorHub/mautrix-whatsapp
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"
|
"bytes"
|
||||||
"encoding/gob"
|
"encoding/gob"
|
||||||
"encoding/hex"
|
"encoding/hex"
|
||||||
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"html"
|
"html"
|
||||||
"image"
|
"image"
|
||||||
|
@ -912,6 +913,27 @@ type MessageContent struct {
|
||||||
IsCustomPuppet bool `json:"net.maunium.whatsapp.puppet,omitempty"`
|
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) {
|
func (portal *Portal) HandleTextMessage(source *User, message whatsapp.TextMessage) {
|
||||||
if !portal.startHandling(message.Info) {
|
if !portal.startHandling(message.Info) {
|
||||||
return
|
return
|
||||||
|
|
Loading…
Reference in a new issue