Skip to content

Commit

Permalink
fix(tljson): fill Unparsed
Browse files Browse the repository at this point in the history
  • Loading branch information
tdakkota committed Dec 4, 2021
1 parent a879816 commit bd12740
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
10 changes: 9 additions & 1 deletion telegram/tljson/app_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -371,7 +371,15 @@ func (e *AppConfig) DecodeJSON(d *jx.Decoder) error {
}
e.ChatReadMarkSizeThreshold = v
default:
return d.Skip()
if e.Unparsed == nil {
e.Unparsed = map[string]tg.JSONValueClass{}
}
v, err := Decode(d)
if err != nil {
return errors.Wrapf(err, "decode %q", key)
}
e.Unparsed[string(key)] = v
return nil
}

return nil
Expand Down
10 changes: 7 additions & 3 deletions telegram/tljson/app_config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import (

"github.com/go-faster/jx"
"github.com/stretchr/testify/require"

"github.com/gotd/td/tg"
)

const example = `{
Expand Down Expand Up @@ -140,7 +142,8 @@ const example = `{
"max_size": 12582912
},
"chat_read_mark_size_threshold": 50,
"chat_read_mark_expire_period": 604800
"chat_read_mark_expire_period": 604800,
"unknown": null
}`

func TestDecodeAppConfig(t *testing.T) {
Expand Down Expand Up @@ -312,7 +315,8 @@ func TestDecodeAppConfig(t *testing.T) {
},
ChatReadMarkExpirePeriod: 604800,
ChatReadMarkSizeThreshold: 50,
Unparsed: nil,
Unparsed: map[string]tg.JSONValueClass{
"unknown": &tg.JSONNull{},
},
}, appConfig)

}

0 comments on commit bd12740

Please sign in to comment.