Add topic
This commit is contained in:
parent
95fcdebc8e
commit
e8daee3712
|
@ -4,8 +4,11 @@ import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"encoding/hex"
|
"encoding/hex"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
|
"io/ioutil"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
|
"go.uber.org/zap"
|
||||||
|
|
||||||
"github.com/status-im/status-go/protocol/protobuf"
|
"github.com/status-im/status-go/protocol/protobuf"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -21,6 +24,7 @@ type GoRushRequestNotification struct {
|
||||||
Tokens []string `json:"tokens"`
|
Tokens []string `json:"tokens"`
|
||||||
Platform uint `json:"platform"`
|
Platform uint `json:"platform"`
|
||||||
Message string `json:"message"`
|
Message string `json:"message"`
|
||||||
|
Topic string `json:"topic"`
|
||||||
Data *GoRushRequestData `json:"data"`
|
Data *GoRushRequestData `json:"data"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -53,6 +57,7 @@ func PushNotificationRegistrationToGoRushRequest(requestAndRegistrations []*Requ
|
||||||
Tokens: []string{registration.DeviceToken},
|
Tokens: []string{registration.DeviceToken},
|
||||||
Platform: tokenTypeToGoRushPlatform(registration.TokenType),
|
Platform: tokenTypeToGoRushPlatform(registration.TokenType),
|
||||||
Message: defaultNotificationMessage,
|
Message: defaultNotificationMessage,
|
||||||
|
Topic: "im.status.ethereum.pr",
|
||||||
Data: &GoRushRequestData{
|
Data: &GoRushRequestData{
|
||||||
EncryptedMessage: hex.EncodeToString(request.Message),
|
EncryptedMessage: hex.EncodeToString(request.Message),
|
||||||
ChatID: request.ChatId,
|
ChatID: request.ChatId,
|
||||||
|
@ -63,15 +68,20 @@ func PushNotificationRegistrationToGoRushRequest(requestAndRegistrations []*Requ
|
||||||
return goRushRequests
|
return goRushRequests
|
||||||
}
|
}
|
||||||
|
|
||||||
func sendGoRushNotification(request *GoRushRequest, url string) error {
|
func sendGoRushNotification(request *GoRushRequest, url string, logger *zap.Logger) error {
|
||||||
payload, err := json.Marshal(request)
|
payload, err := json.Marshal(request)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
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 {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
defer response.Body.Close()
|
||||||
|
body, _ := ioutil.ReadAll(response.Body)
|
||||||
|
|
||||||
|
logger.Info("Sent gorush request", zap.String("response", string(body)))
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
|
@ -362,7 +362,7 @@ func (s *Server) buildPushNotificationRequestResponseAndSendNotification(request
|
||||||
|
|
||||||
// This can be done asynchronously
|
// This can be done asynchronously
|
||||||
goRushRequest := PushNotificationRegistrationToGoRushRequest(requestAndRegistrations)
|
goRushRequest := PushNotificationRegistrationToGoRushRequest(requestAndRegistrations)
|
||||||
err := sendGoRushNotification(goRushRequest, s.config.GorushURL)
|
err := sendGoRushNotification(goRushRequest, s.config.GorushURL, s.config.Logger)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
s.config.Logger.Error("failed to send go rush notification", zap.Error(err))
|
s.config.Logger.Error("failed to send go rush notification", zap.Error(err))
|
||||||
// TODO: handle this error?
|
// TODO: handle this error?
|
||||||
|
|
Loading…
Reference in New Issue