MCPcopy Create free account
hub / github.com/chanify/chanify / ParseJSON

Method ParseJSON

core/msgparam.go:46–94  ·  view source on GitHub ↗

ParseJSON process application/json

(c *Core, ctx *gin.Context)

Source from the content-addressed store, hash-verified

44
45// ParseJSON process application/json
46func (m *MsgParam) ParseJSON(c *Core, ctx *gin.Context) {
47 defer ctx.Request.Body.Close()
48 var params struct {
49 Token string `json:"token,omitempty"`
50 Title string `json:"title,omitempty"`
51 Text string `json:"text,omitempty"`
52 Copy string `json:"copy,omitempty"`
53 AutoCopy JSONString `json:"autocopy,omitempty"`
54 Link string `json:"link,omitempty"`
55 Sound JSONString `json:"sound,omitempty"`
56 Priority int `json:"priority,omitempty"`
57 InterruptionLevel string `json:"interruption-level,omitempty"`
58 Actions []string `json:"actions,omitempty"`
59 Timeline struct {
60 Code string `json:"code"`
61 Timstamp interface{} `json:"timestamp,omitempty"`
62 Items map[string]interface{} `json:"items"`
63 } `json:"timeline,omitempty"`
64 }
65 if err := ctx.BindJSON(&params); err == nil {
66 if m.Token == nil && len(params.Token) > 0 {
67 m.Token, _ = c.parseToken(params.Token)
68 }
69 m.Link = tryStringValue(m.Link, params.Link)
70 m.Title = tryStringValue(m.Title, params.Title)
71 if len(m.Sound) <= 0 && len(params.Sound) > 0 {
72 m.Sound = string(params.Sound)
73 }
74 m.CopyText = tryStringValue(m.CopyText, params.Copy)
75 if len(m.AutoCopy) <= 0 && len(params.AutoCopy) > 0 {
76 m.AutoCopy = string(params.AutoCopy)
77 }
78 if len(m.Actions) <= 0 {
79 m.Actions = params.Actions
80 }
81 if m.Priority <= 0 {
82 m.Priority = params.Priority
83 }
84 if len(m.InterruptionLevel) <= 0 {
85 m.InterruptionLevel = params.InterruptionLevel
86 }
87 if len(m.TimeContent.Code) <= 0 {
88 m.TimeContent.Code = params.Timeline.Code
89 m.TimeContent.Timestamp = parseTimestamp(params.Timeline.Timstamp)
90 m.TimeContent.Items = parseTimeContentItems(params.Timeline.Items)
91 }
92 m.Text = params.Text
93 }
94}
95
96// ParseForm process form
97func (m *MsgParam) ParseForm(c *Core, ctx *gin.Context) {

Callers 1

handlePostSenderMethod · 0.95

Calls 5

tryStringValueFunction · 0.85
parseTimestampFunction · 0.85
parseTimeContentItemsFunction · 0.85
parseTokenMethod · 0.80
CloseMethod · 0.65

Tested by

no test coverage detected