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 return resp, nil
} }
func browserExtensionPush(token, body string) (string, error) { func browserExtensionPush(token string, data map[string]string) (string, error) {
var resp struct { var resp struct {
Response string `json:"response"` Response string `json:"response"`
} }
req := struct { 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 { 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 return
} }
pushResp, err := browserExtensionPush(requestSyncResp.BrowserExtensionWaitToken, "body") pushResp, err := browserExtensionPush(requestSyncResp.BrowserExtensionWaitToken, map[string]string{"hello": "world!"})
if err != nil { if err != nil {
t.Errorf("Error when Browser Extension tried to send push notification: %v", err) t.Errorf("Error when Browser Extension tried to send push notification: %v", err)
return return

View File

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

View File

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