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" "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
} }

View File

@ -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?