Notifications with new Flutter app [Kinda work!]
This commit is contained in:
@@ -12,6 +12,6 @@ func NewDummy() NotificationClient {
|
||||
return &DummyConnector{}
|
||||
}
|
||||
|
||||
func (d DummyConnector) SendNotification(ctx context.Context, client models.Client, msg models.Message, compatTitleOverride *string, compatMsgIDOverride *string) (string, error) {
|
||||
func (d DummyConnector) SendNotification(ctx context.Context, user models.User, client models.Client, channel models.Channel, msg models.Message) (string, error) {
|
||||
return "%DUMMY%", nil
|
||||
}
|
||||
|
@@ -11,10 +11,8 @@ import (
|
||||
"fmt"
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/rs/zerolog/log"
|
||||
"gogs.mikescher.com/BlackForestBytes/goext/langext"
|
||||
"io"
|
||||
"net/http"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
@@ -53,32 +51,36 @@ type Notification struct {
|
||||
Priority int
|
||||
}
|
||||
|
||||
func (fb FirebaseConnector) SendNotification(ctx context.Context, client models.Client, msg models.Message, compatTitleOverride *string, compatMsgIDOverride *string) (string, error) {
|
||||
func (fb FirebaseConnector) SendNotification(ctx context.Context, user models.User, client models.Client, channel models.Channel, msg models.Message) (string, error) {
|
||||
|
||||
uri := "https://fcm.googleapis.com/v1/projects/" + fb.fbProject + "/messages:send"
|
||||
|
||||
jsonBody := gin.H{
|
||||
"data": gin.H{
|
||||
"scn_msg_id": langext.Coalesce(compatMsgIDOverride, 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": langext.Coalesce(compatTitleOverride, msg.Title),
|
||||
"body": langext.Coalesce(msg.TrimmedContent(), ""),
|
||||
},
|
||||
"token": client.FCMToken,
|
||||
"android": gin.H{
|
||||
"priority": "high",
|
||||
},
|
||||
"apns": 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",
|
||||
"collapse_key": msg.ChannelID.String(),
|
||||
"notification": gin.H{
|
||||
"event_time": msg.Timestamp().Format(time.RFC3339),
|
||||
"title": msg.FormatNotificationTitle(user, channel),
|
||||
"body": msg.ShortContent(),
|
||||
},
|
||||
"fcm_options": gin.H{},
|
||||
}
|
||||
} else {
|
||||
jsonBody["notification"] = gin.H{
|
||||
"title": msg.FormatNotificationTitle(user, channel),
|
||||
"body": msg.ShortContent(),
|
||||
}
|
||||
}
|
||||
|
||||
bytesBody, err := json.Marshal(gin.H{"message": jsonBody})
|
||||
|
@@ -6,5 +6,5 @@ import (
|
||||
)
|
||||
|
||||
type NotificationClient interface {
|
||||
SendNotification(ctx context.Context, client models.Client, msg models.Message, compatTitleOverride *string, compatMsgIDOverride *string) (string, error)
|
||||
SendNotification(ctx context.Context, user models.User, client models.Client, channel models.Channel, msg models.Message) (string, error)
|
||||
}
|
||||
|
@@ -8,10 +8,8 @@ import (
|
||||
)
|
||||
|
||||
type SinkData struct {
|
||||
Message models.Message
|
||||
Client models.Client
|
||||
CompatTitleOverride *string
|
||||
CompatMsgIDOverride *string
|
||||
Message models.Message
|
||||
Client models.Client
|
||||
}
|
||||
|
||||
type TestSink struct {
|
||||
@@ -26,7 +24,7 @@ func (d *TestSink) Last() SinkData {
|
||||
return d.Data[len(d.Data)-1]
|
||||
}
|
||||
|
||||
func (d *TestSink) SendNotification(ctx context.Context, client models.Client, msg models.Message, compatTitleOverride *string, compatMsgIDOverride *string) (string, error) {
|
||||
func (d *TestSink) SendNotification(ctx context.Context, user models.User, client models.Client, channel models.Channel, msg models.Message) (string, error) {
|
||||
id, err := langext.NewHexUUID()
|
||||
if err != nil {
|
||||
return "", err
|
||||
@@ -35,10 +33,8 @@ func (d *TestSink) SendNotification(ctx context.Context, client models.Client, m
|
||||
key := "TestSink[" + id + "]"
|
||||
|
||||
d.Data = append(d.Data, SinkData{
|
||||
Message: msg,
|
||||
Client: client,
|
||||
CompatTitleOverride: compatTitleOverride,
|
||||
CompatMsgIDOverride: compatMsgIDOverride,
|
||||
Message: msg,
|
||||
Client: client,
|
||||
})
|
||||
|
||||
return key, nil
|
||||
|
Reference in New Issue
Block a user