Notifications with new Flutter app [Kinda work!]
All checks were successful
Build Docker and Deploy / Build Docker Container (push) Successful in 1m56s
Build Docker and Deploy / Deploy to Server (push) Successful in 5s

This commit is contained in:
2024-06-01 15:37:59 +02:00
parent 0560330f68
commit e397f009b9
19 changed files with 198 additions and 551 deletions

View File

@@ -10,7 +10,6 @@ import (
"blackforestbytes.com/simplecloudnotifier/push"
"context"
"errors"
"fmt"
"github.com/gin-gonic/gin"
"github.com/gin-gonic/gin/binding"
"github.com/rs/zerolog/log"
@@ -356,8 +355,8 @@ func (app *Application) NormalizeUsername(v string) string {
return strings.TrimSpace(v)
}
func (app *Application) DeliverMessage(ctx context.Context, client models.Client, msg models.Message, compatTitleOverride *string, compatMsgIDOverride *string) (string, error) {
fcmDelivID, err := app.Pusher.SendNotification(ctx, client, msg, compatTitleOverride, compatMsgIDOverride)
func (app *Application) DeliverMessage(ctx context.Context, user models.User, client models.Client, channel models.Channel, msg models.Message) (string, error) {
fcmDelivID, err := app.Pusher.SendNotification(ctx, user, client, channel, msg)
if err != nil {
log.Warn().Str("MessageID", msg.MessageID.String()).Str("ClientID", client.ClientID.String()).Err(err).Msg("FCM Delivery failed")
return "", err
@@ -371,20 +370,3 @@ func (app *Application) InsertRequestLog(data models.RequestLog) {
log.Error().Msg("failed to insert request-log (queue full)")
}
}
func (app *Application) CompatizeMessageTitle(ctx TxContext, msg models.Message) string {
if msg.ChannelInternalName == "main" {
if rexCompatTitleChannel.IsMatch(msg.Title) {
return "!" + msg.Title // channel in title ?!
}
return msg.Title
}
channel, err := app.Database.Primary.GetChannelByID(ctx, msg.ChannelID)
if err != nil {
return fmt.Sprintf("[%s] %s", "%SCN-ERR%", msg.Title)
}
return fmt.Sprintf("[%s] %s", channel.DisplayName, msg.Title)
}

View File

@@ -185,19 +185,7 @@ func (app *Application) SendMessage(g *gin.Context, ctx *AppContext, UserID *mod
for _, client := range clients {
isCompatClient, err := app.Database.Primary.IsCompatClient(ctx, client.ClientID)
if err != nil {
return nil, langext.Ptr(ginresp.SendAPIError(g, 500, apierr.DATABASE_ERROR, hl.NONE, "Failed to query compat_clients", err))
}
var titleOverride *string = nil
var msgidOverride *string = nil
if isCompatClient {
titleOverride = langext.Ptr(app.CompatizeMessageTitle(ctx, msg))
msgidOverride = langext.Ptr(fmt.Sprintf("%d", compatMsgID))
}
fcmDelivID, err := app.DeliverMessage(ctx, client, msg, titleOverride, msgidOverride)
fcmDelivID, err := app.DeliverMessage(ctx, user, client, channel, msg)
if err != nil {
_, err = app.Database.Primary.CreateRetryDelivery(ctx, client, msg)
if err != nil {