feat(pass/sync): use data notifications in push

This commit is contained in:
Krzysztof Dryś 2024-06-05 07:32:34 +02:00
parent 7bf9bfb906
commit 6ce9d1a7ca
4 changed files with 8 additions and 13 deletions

View File

@ -156,14 +156,14 @@ func browserExtensionRequestSync(token string) (RequestSyncResponse, error) {
return resp, nil
}
func browserExtensionPush(token, body string) (string, error) {
func browserExtensionPush(token string, data map[string]string) (string, error) {
var resp struct {
Response string `json:"response"`
}
req := struct {
Body string `json:"push_body"`
Data map[string]string `json:"data"`
}{
Body: body,
Data: data,
}
if err := request("POST", "/browser_extension/sync/push", token, req, &resp); err != nil {

View File

@ -33,7 +33,7 @@ func TestSyncHappyFlow(t *testing.T) {
return
}
pushResp, err := browserExtensionPush(requestSyncResp.BrowserExtensionWaitToken, "body")
pushResp, err := browserExtensionPush(requestSyncResp.BrowserExtensionWaitToken, map[string]string{"hello": "world!"})
if err != nil {
t.Errorf("Error when Browser Extension tried to send push notification: %v", err)
return

View File

@ -39,7 +39,7 @@ func ExtensionRequestSync(syncingApp *Syncing) gin.HandlerFunc {
}
type PushToMobileRequest struct {
Body string `json:"push_body"`
DataMessage map[string]string `json:"data_message"`
}
func ExtensionRequestPush(syncingApp *Syncing) gin.HandlerFunc {
@ -64,7 +64,7 @@ func ExtensionRequestPush(syncingApp *Syncing) gin.HandlerFunc {
return
}
resp, err := syncingApp.SendPush(gCtx, fcmToken, req.Body)
resp, err := syncingApp.SendPush(gCtx, fcmToken, req.DataMessage)
if err != nil {
log.Errorf("Failed to send push message: %v", err)
gCtx.Status(http.StatusInternalServerError)

View File

@ -183,16 +183,11 @@ func (s *Syncing) RequestSync(ctx *gin.Context, token string) (RequestSyncRespon
}, nil
}
func (s *Syncing) SendPush(ctx *gin.Context, token string, body string) (fcm.Response, error) {
func (s *Syncing) SendPush(ctx *gin.Context, token string, body map[string]string) (fcm.Response, error) {
msg := &messaging.Message{
Token: token,
Android: &messaging.AndroidConfig{
Notification: &messaging.AndroidNotification{
Title: "2pass push request",
},
Data: map[string]string{
"data": body,
},
Data: body,
},
}
return s.fcmClient.Send(ctx, msg)