Add topic

This commit is contained in:
Andrea Maria Piana 2020-07-30 08:55:56 +02:00
parent 95fcdebc8e
commit e8daee3712
No known key found for this signature in database
GPG Key ID: AA6CCA6DE0E06424
2 changed files with 13 additions and 3 deletions

View File

@ -4,8 +4,11 @@ import (
"bytes"
"encoding/hex"
"encoding/json"
"io/ioutil"
"net/http"
"go.uber.org/zap"
"github.com/status-im/status-go/protocol/protobuf"
)
@ -21,6 +24,7 @@ type GoRushRequestNotification struct {
Tokens []string `json:"tokens"`
Platform uint `json:"platform"`
Message string `json:"message"`
Topic string `json:"topic"`
Data *GoRushRequestData `json:"data"`
}
@ -53,6 +57,7 @@ func PushNotificationRegistrationToGoRushRequest(requestAndRegistrations []*Requ
Tokens: []string{registration.DeviceToken},
Platform: tokenTypeToGoRushPlatform(registration.TokenType),
Message: defaultNotificationMessage,
Topic: "im.status.ethereum.pr",
Data: &GoRushRequestData{
EncryptedMessage: hex.EncodeToString(request.Message),
ChatID: request.ChatId,
@ -63,15 +68,20 @@ func PushNotificationRegistrationToGoRushRequest(requestAndRegistrations []*Requ
return goRushRequests
}
func sendGoRushNotification(request *GoRushRequest, url string) error {
func sendGoRushNotification(request *GoRushRequest, url string, logger *zap.Logger) error {
payload, err := json.Marshal(request)
if err != nil {
return err
}
_, err = http.Post(url+"/api/push", "application/json", bytes.NewReader(payload))
response, err := http.Post(url+"/api/push", "application/json", bytes.NewReader(payload))
if err != nil {
return err
}
defer response.Body.Close()
body, _ := ioutil.ReadAll(response.Body)
logger.Info("Sent gorush request", zap.String("response", string(body)))
return nil
}

View File

@ -362,7 +362,7 @@ func (s *Server) buildPushNotificationRequestResponseAndSendNotification(request
// This can be done asynchronously
goRushRequest := PushNotificationRegistrationToGoRushRequest(requestAndRegistrations)
err := sendGoRushNotification(goRushRequest, s.config.GorushURL)
err := sendGoRushNotification(goRushRequest, s.config.GorushURL, s.config.Logger)
if err != nil {
s.config.Logger.Error("failed to send go rush notification", zap.Error(err))
// TODO: handle this error?