Send channel as prefix for compat clients

This commit is contained in:
2023-05-27 20:02:16 +02:00
parent 8826cb0312
commit b2df0a5a02
15 changed files with 136 additions and 33 deletions

View File

@@ -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)
}

View File

@@ -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 {