Send channel as prefix for compat clients
This commit is contained in:
@@ -9,6 +9,7 @@ import (
|
||||
"blackforestbytes.com/simplecloudnotifier/logic"
|
||||
"blackforestbytes.com/simplecloudnotifier/models"
|
||||
"database/sql"
|
||||
"fmt"
|
||||
"github.com/gin-gonic/gin"
|
||||
"gogs.mikescher.com/BlackForestBytes/goext/dataext"
|
||||
"gogs.mikescher.com/BlackForestBytes/goext/langext"
|
||||
@@ -540,7 +541,7 @@ func (h CompatHandler) Requery(g *gin.Context) ginresp.HTTPResponse {
|
||||
}
|
||||
|
||||
compMsgs = append(compMsgs, models.CompatMessage{
|
||||
Title: v.Title,
|
||||
Title: compatizeMessageTitle(ctx, h.app, v),
|
||||
Body: v.Content,
|
||||
Priority: v.Priority,
|
||||
Timestamp: v.Timestamp().Unix(),
|
||||
@@ -788,7 +789,7 @@ func (h CompatHandler) Expand(g *gin.Context) ginresp.HTTPResponse {
|
||||
Success: true,
|
||||
Message: "ok",
|
||||
Data: models.CompatMessage{
|
||||
Title: msg.Title,
|
||||
Title: compatizeMessageTitle(ctx, h.app, msg),
|
||||
Body: msg.Content,
|
||||
Trimmed: langext.Ptr(false),
|
||||
Priority: msg.Priority,
|
||||
@@ -935,3 +936,16 @@ func (h CompatHandler) Upgrade(g *gin.Context) ginresp.HTTPResponse {
|
||||
IsPro: user.IsPro,
|
||||
}))
|
||||
}
|
||||
|
||||
func compatizeMessageTitle(ctx *logic.AppContext, app *logic.Application, msg models.Message) string {
|
||||
if msg.ChannelInternalName == "main" {
|
||||
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)
|
||||
}
|
||||
|
||||
@@ -284,7 +284,17 @@ func (h MessageHandler) sendMessageInternal(g *gin.Context, ctx *logic.AppContex
|
||||
|
||||
for _, client := range clients {
|
||||
|
||||
fcmDelivID, err := h.app.DeliverMessage(ctx, client, msg)
|
||||
isCompatClient, err := h.database.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
|
||||
if isCompatClient {
|
||||
titleOverride = langext.Ptr(compatizeMessageTitle(ctx, h.app, msg))
|
||||
}
|
||||
|
||||
fcmDelivID, err := h.app.DeliverMessage(ctx, client, msg, titleOverride)
|
||||
if err != nil {
|
||||
_, err = h.database.CreateRetryDelivery(ctx, client, msg)
|
||||
if err != nil {
|
||||
|
||||
Reference in New Issue
Block a user