Server: switch android back to data-only notifications
This commit is contained in:
parent
b0a6736f70
commit
63c25317eb
@ -11,8 +11,10 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
"github.com/rs/zerolog/log"
|
"github.com/rs/zerolog/log"
|
||||||
|
"gogs.mikescher.com/BlackForestBytes/goext/langext"
|
||||||
"io"
|
"io"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
@ -55,30 +57,43 @@ func (fb FirebaseConnector) SendNotification(ctx context.Context, user models.Us
|
|||||||
|
|
||||||
uri := "https://fcm.googleapis.com/v1/projects/" + fb.fbProject + "/messages:send"
|
uri := "https://fcm.googleapis.com/v1/projects/" + fb.fbProject + "/messages:send"
|
||||||
|
|
||||||
jsonBody := gin.H{
|
jsonBody := gin.H{}
|
||||||
"token": client.FCMToken,
|
|
||||||
}
|
|
||||||
|
|
||||||
if client.Type == models.ClientTypeIOS {
|
if client.Type == models.ClientTypeIOS {
|
||||||
jsonBody["notification"] = gin.H{
|
jsonBody = gin.H{
|
||||||
"title": msg.Title,
|
"token": client.FCMToken,
|
||||||
"body": msg.ShortContent(),
|
|
||||||
}
|
|
||||||
jsonBody["apns"] = gin.H{}
|
|
||||||
} else if client.Type == models.ClientTypeAndroid {
|
|
||||||
jsonBody["android"] = gin.H{
|
|
||||||
"priority": "high",
|
|
||||||
"notification": gin.H{
|
"notification": gin.H{
|
||||||
"event_time": msg.Timestamp().Format(time.RFC3339),
|
"title": msg.Title,
|
||||||
"title": msg.FormatNotificationTitle(user, channel),
|
"body": msg.ShortContent(),
|
||||||
"body": msg.ShortContent(),
|
},
|
||||||
|
"apns": gin.H{},
|
||||||
|
}
|
||||||
|
} else if client.Type == models.ClientTypeAndroid {
|
||||||
|
jsonBody = gin.H{
|
||||||
|
"token": client.FCMToken,
|
||||||
|
"android": gin.H{
|
||||||
|
"priority": "high",
|
||||||
|
"fcm_options": gin.H{},
|
||||||
|
},
|
||||||
|
"data": gin.H{
|
||||||
|
"scn_msg_id": msg.MessageID.String(),
|
||||||
|
"usr_msg_id": langext.Coalesce(msg.UserMessageID, ""),
|
||||||
|
"client_id": client.ClientID.String(),
|
||||||
|
"timestamp": strconv.FormatInt(msg.Timestamp().Unix(), 10),
|
||||||
|
"priority": strconv.Itoa(msg.Priority),
|
||||||
|
"trimmed": langext.Conditional(msg.NeedsTrim(), "true", "false"),
|
||||||
|
"title": msg.Title,
|
||||||
|
"channel": channel.DisplayName,
|
||||||
|
"body": langext.Coalesce(msg.TrimmedContent(), ""),
|
||||||
},
|
},
|
||||||
"fcm_options": gin.H{},
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
jsonBody["notification"] = gin.H{
|
jsonBody = gin.H{
|
||||||
"title": msg.FormatNotificationTitle(user, channel),
|
"token": client.FCMToken,
|
||||||
"body": msg.ShortContent(),
|
"notification": gin.H{
|
||||||
|
"title": msg.FormatNotificationTitle(user, channel),
|
||||||
|
"body": msg.ShortContent(),
|
||||||
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user