set remote push notification to post

This commit is contained in:
Roland Osborne 2022-11-15 10:19:02 -08:00
parent df64fef322
commit aae3104457

View File

@ -102,22 +102,12 @@ func sendRemoteNotification(notification *store.Notification) {
return return
} }
var body []byte
var err error
if module == "notification" { if module == "notification" {
body, err = json.Marshal(notification.Event) body, err := json.Marshal(notification.Event)
if err != nil { if err != nil {
ErrMsg(err) ErrMsg(err)
return return
} }
} else {
body, err = json.Marshal(notification.Revision)
if err != nil {
ErrMsg(err)
return
}
}
url := "https://" + notification.Node + "/contact/" + module + "?contact=" + notification.GUID + "." + notification.Token url := "https://" + notification.Node + "/contact/" + module + "?contact=" + notification.GUID + "." + notification.Token
req, err := http.NewRequest(http.MethodPut, url, bytes.NewBuffer(body)) req, err := http.NewRequest(http.MethodPut, url, bytes.NewBuffer(body))
if err != nil { if err != nil {
@ -133,6 +123,28 @@ func sendRemoteNotification(notification *store.Notification) {
if resp.StatusCode != 200 { if resp.StatusCode != 200 {
LogMsg("failed to notify contact") LogMsg("failed to notify contact")
} }
} else {
body, err := json.Marshal(notification.Revision)
if err != nil {
ErrMsg(err)
return
}
url := "https://" + notification.Node + "/contact/" + module + "?contact=" + notification.GUID + "." + notification.Token
req, err := http.NewRequest(http.MethodPost, url, bytes.NewBuffer(body))
if err != nil {
ErrMsg(err)
return
}
req.Header.Set("Content-Type", "application/json; charset=utf-8")
client := &http.Client{}
resp, err := client.Do(req)
if err != nil {
ErrMsg(err)
}
if resp.StatusCode != 200 {
LogMsg("failed to notify contact")
}
}
} }
//SetProfileNotification notifies all connected contacts of profile changes //SetProfileNotification notifies all connected contacts of profile changes