WIP Actions
This commit is contained in:
		
							parent
							
								
									06fd7327de
								
							
						
					
					
						commit
						26efd481e3
					
				
					 2 changed files with 23 additions and 0 deletions
				
			
		|  | @ -535,6 +535,14 @@ func (s *Server) parsePublishParams(r *http.Request, v *visitor, m *message) (ca | ||||||
| 		} | 		} | ||||||
| 		m.Time = delay.Unix() | 		m.Time = delay.Unix() | ||||||
| 	} | 	} | ||||||
|  | 	actionsStr := readParam(r, "x-actions", "actions", "action") | ||||||
|  | 	if actionsStr != "" { | ||||||
|  | 		actions := make([]action, 0) | ||||||
|  | 		if err := json.Unmarshal([]byte(actionsStr), &actions); err != nil { | ||||||
|  | 			return false, false, "", false, errHTTPBadRequestDelayNoCache // FIXME error | ||||||
|  | 		} | ||||||
|  | 		m.Actions = actions | ||||||
|  | 	} | ||||||
| 	unifiedpush = readBoolParam(r, false, "x-unifiedpush", "unifiedpush", "up") // see GET too! | 	unifiedpush = readBoolParam(r, false, "x-unifiedpush", "unifiedpush", "up") // see GET too! | ||||||
| 	if unifiedpush { | 	if unifiedpush { | ||||||
| 		firebase = false | 		firebase = false | ||||||
|  | @ -1150,6 +1158,13 @@ func (s *Server) transformBodyJSON(next handleFunc) handleFunc { | ||||||
| 		if m.Click != "" { | 		if m.Click != "" { | ||||||
| 			r.Header.Set("X-Click", m.Click) | 			r.Header.Set("X-Click", m.Click) | ||||||
| 		} | 		} | ||||||
|  | 		if len(m.Actions) > 0 { | ||||||
|  | 			actionsStr, err := json.Marshal(m.Actions) | ||||||
|  | 			if err != nil { | ||||||
|  | 				return errHTTPBadRequestJSONInvalid | ||||||
|  | 			} | ||||||
|  | 			r.Header.Set("X-Actions", string(actionsStr)) | ||||||
|  | 		} | ||||||
| 		if m.Email != "" { | 		if m.Email != "" { | ||||||
| 			r.Header.Set("X-Email", m.Email) | 			r.Header.Set("X-Email", m.Email) | ||||||
| 		} | 		} | ||||||
|  |  | ||||||
|  | @ -27,6 +27,7 @@ type message struct { | ||||||
| 	Priority   int         `json:"priority,omitempty"` | 	Priority   int         `json:"priority,omitempty"` | ||||||
| 	Tags       []string    `json:"tags,omitempty"` | 	Tags       []string    `json:"tags,omitempty"` | ||||||
| 	Click      string      `json:"click,omitempty"` | 	Click      string      `json:"click,omitempty"` | ||||||
|  | 	Actions    []action    `json:"actions,omitempty"` | ||||||
| 	Attachment *attachment `json:"attachment,omitempty"` | 	Attachment *attachment `json:"attachment,omitempty"` | ||||||
| 	Title      string      `json:"title,omitempty"` | 	Title      string      `json:"title,omitempty"` | ||||||
| 	Message    string      `json:"message,omitempty"` | 	Message    string      `json:"message,omitempty"` | ||||||
|  | @ -42,6 +43,12 @@ type attachment struct { | ||||||
| 	Owner   string `json:"-"` // IP address of uploader, used for rate limiting | 	Owner   string `json:"-"` // IP address of uploader, used for rate limiting | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | type action struct { | ||||||
|  | 	Action string `json:"action"` | ||||||
|  | 	Label  string `json:"label"` | ||||||
|  | 	URL    string `json:"URL,omitempty"` | ||||||
|  | } | ||||||
|  | 
 | ||||||
| // publishMessage is used as input when publishing as JSON | // publishMessage is used as input when publishing as JSON | ||||||
| type publishMessage struct { | type publishMessage struct { | ||||||
| 	Topic    string   `json:"topic"` | 	Topic    string   `json:"topic"` | ||||||
|  | @ -50,6 +57,7 @@ type publishMessage struct { | ||||||
| 	Priority int      `json:"priority"` | 	Priority int      `json:"priority"` | ||||||
| 	Tags     []string `json:"tags"` | 	Tags     []string `json:"tags"` | ||||||
| 	Click    string   `json:"click"` | 	Click    string   `json:"click"` | ||||||
|  | 	Actions  []action `json:"actions"` | ||||||
| 	Attach   string   `json:"attach"` | 	Attach   string   `json:"attach"` | ||||||
| 	Filename string   `json:"filename"` | 	Filename string   `json:"filename"` | ||||||
| 	Email    string   `json:"email"` | 	Email    string   `json:"email"` | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue