Server: switch android back to data-only notifications

This commit is contained in:
Mike Schwörer 2024-06-15 18:24:33 +02:00
parent b0a6736f70
commit 63c25317eb
Signed by: Mikescher
GPG Key ID: D3C7172E0A70F8CF

View File

@ -11,8 +11,10 @@ import (
"fmt"
"github.com/gin-gonic/gin"
"github.com/rs/zerolog/log"
"gogs.mikescher.com/BlackForestBytes/goext/langext"
"io"
"net/http"
"strconv"
"strings"
"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"
jsonBody := gin.H{
"token": client.FCMToken,
}
jsonBody := gin.H{}
if client.Type == models.ClientTypeIOS {
jsonBody["notification"] = gin.H{
"title": msg.Title,
"body": msg.ShortContent(),
}
jsonBody["apns"] = gin.H{}
} else if client.Type == models.ClientTypeAndroid {
jsonBody["android"] = gin.H{
"priority": "high",
jsonBody = gin.H{
"token": client.FCMToken,
"notification": gin.H{
"event_time": msg.Timestamp().Format(time.RFC3339),
"title": msg.FormatNotificationTitle(user, channel),
"body": msg.ShortContent(),
"title": msg.Title,
"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 {
jsonBody["notification"] = gin.H{
"title": msg.FormatNotificationTitle(user, channel),
"body": msg.ShortContent(),
jsonBody = gin.H{
"token": client.FCMToken,
"notification": gin.H{
"title": msg.FormatNotificationTitle(user, channel),
"body": msg.ShortContent(),
},
}
}