From e397f009b93502ae94e13cc4a3b9b8b3cb6ebb89 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mike=20Schw=C3=B6rer?= Date: Sat, 1 Jun 2024 15:37:59 +0200 Subject: [PATCH] Notifications with new Flutter app [Kinda work!] --- flutter/TODO.md | 6 +- flutter/lib/pages/account/account.dart | 42 ++-- flutter/lib/pages/account/login.dart | 3 +- flutter/lib/pages/debug/debug_main.dart | 2 +- scnserver/api/handler/compat.go | 4 +- scnserver/jobs/DeliveryRetryJob.go | 44 ++--- scnserver/logic/application.go | 22 +-- scnserver/logic/message.go | 14 +- scnserver/models/enums_gen.go | 2 +- scnserver/models/ids_gen.go | 2 +- scnserver/models/message.go | 9 + scnserver/push/dummy.go | 2 +- scnserver/push/firebase.go | 36 ++-- scnserver/push/notificationClient.go | 2 +- scnserver/push/testSink.go | 14 +- scnserver/swagger/swagger.json | 250 ++++-------------------- scnserver/swagger/swagger.yaml | 245 ++++++----------------- scnserver/test/compat_test.go | 38 ---- scnserver/test/util/internals.go | 12 -- 19 files changed, 198 insertions(+), 551 deletions(-) diff --git a/flutter/TODO.md b/flutter/TODO.md index cea51e1..0f7f2e4 100644 --- a/flutter/TODO.md +++ b/flutter/TODO.md @@ -32,4 +32,8 @@ - [ ] use sq.Query | sq.Update | sq.InsertAndQuery | .... - [ ] sq.DBOptions - enable CommentTrimmer and DefaultConverter - [ ] run unit-tests... - - [ ] Copy db.Migrate code \ No newline at end of file + - [ ] Copy db.Migrate code + + - [ ] Disable compat | remove code + - [x] compat message title + - [ ] ... \ No newline at end of file diff --git a/flutter/lib/pages/account/account.dart b/flutter/lib/pages/account/account.dart index 17bcc8e..bf42c2c 100644 --- a/flutter/lib/pages/account/account.dart +++ b/flutter/lib/pages/account/account.dart @@ -216,7 +216,7 @@ class _AccountRootPageState extends State { padding: const EdgeInsets.fromLTRB(4, 1, 4, 1), decoration: BoxDecoration( color: Colors.blue, - borderRadius: BorderRadius.only(topLeft: Radius.circular(8)), + borderRadius: BorderRadius.only(topLeft: Radius.circular(4)), ), ), ), @@ -228,7 +228,7 @@ class _AccountRootPageState extends State { padding: const EdgeInsets.fromLTRB(4, 1, 4, 1), decoration: BoxDecoration( color: Colors.purple, - borderRadius: BorderRadius.only(topLeft: Radius.circular(8)), + borderRadius: BorderRadius.only(topLeft: Radius.circular(4)), ), ), ), @@ -240,18 +240,7 @@ class _AccountRootPageState extends State { child: Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ - Row( - children: [ - Expanded(child: Text(user.username ?? user.userID, overflow: TextOverflow.ellipsis)), - IconButton( - icon: FaIcon(FontAwesomeIcons.pen), - iconSize: 18, - padding: EdgeInsets.fromLTRB(0, 0, 4, 0), - constraints: BoxConstraints(), - onPressed: () {/*TODO*/}, - ), - ], - ), + Text(user.username ?? user.userID, overflow: TextOverflow.ellipsis), const SizedBox(height: 4), Row( children: [ @@ -282,6 +271,29 @@ class _AccountRootPageState extends State { ], ), ), + Column( + mainAxisAlignment: MainAxisAlignment.start, + children: [ + IconButton( + icon: FaIcon(FontAwesomeIcons.pen), + iconSize: 18, + padding: EdgeInsets.all(4), + constraints: BoxConstraints(), + style: ButtonStyle(tapTargetSize: MaterialTapTargetSize.shrinkWrap), + onPressed: () {/*TODO*/}, + ), + const SizedBox(height: 4), + if (!user.isPro) + IconButton( + icon: FaIcon(FontAwesomeIcons.cartCircleArrowUp), + iconSize: 18, + padding: EdgeInsets.all(4), + constraints: BoxConstraints(), + style: ButtonStyle(tapTargetSize: MaterialTapTargetSize.shrinkWrap), + onPressed: () {/*TODO*/}, + ), + ], + ), ], ); } @@ -458,6 +470,7 @@ class _AccountRootPageState extends State { acc.set(user.user, user.clients[0], KeyTokenAuth(userId: user.user.userID, tokenAdmin: user.adminKey, tokenSend: user.sendKey)); await acc.save(); + Toaster.success("Success", 'Successfully Created a new account'); } catch (exc, trace) { ApplicationLog.error('Failed to create user account: ' + exc.toString(), trace: trace); Toaster.error("Error", 'Failed to create user account'); @@ -469,6 +482,7 @@ class _AccountRootPageState extends State { void _logout() async { final acc = Provider.of(context, listen: false); + //TODO clear messages/channels/etc in open views acc.clear(); await acc.save(); diff --git a/flutter/lib/pages/account/login.dart b/flutter/lib/pages/account/login.dart index 9713308..90dba6e 100644 --- a/flutter/lib/pages/account/login.dart +++ b/flutter/lib/pages/account/login.dart @@ -149,12 +149,13 @@ class _AccountLoginPageState extends State { final user = await APIClient.getUser(kta, uid); - final client = await APIClient.addClient(acc.auth, fcmToken, Globals().deviceModel, Globals().version, Globals().hostname, Globals().clientType); + final client = await APIClient.addClient(kta, fcmToken, Globals().deviceModel, Globals().version, Globals().hostname, Globals().clientType); acc.set(user, client, kta); await acc.save(); Toaster.success("Login", "Successfully logged in"); + Navigator.popUntil(context, (route) => route.isFirst); } catch (exc, trace) { ApplicationLog.error('Failed to verify token: ' + exc.toString(), trace: trace); Toaster.error("Error", 'Failed to verify token'); diff --git a/flutter/lib/pages/debug/debug_main.dart b/flutter/lib/pages/debug/debug_main.dart index 2e0d58f..3b0b957 100644 --- a/flutter/lib/pages/debug/debug_main.dart +++ b/flutter/lib/pages/debug/debug_main.dart @@ -57,7 +57,7 @@ class _DebugMainPageState extends State { ButtonSegment(value: DebugMainPageSubPage.colors, icon: Icon(FontAwesomeIcons.solidPaintRoller, size: 14)), ButtonSegment(value: DebugMainPageSubPage.actions, icon: Icon(FontAwesomeIcons.solidHammer, size: 14)), ButtonSegment(value: DebugMainPageSubPage.requests, icon: Icon(FontAwesomeIcons.solidNetworkWired, size: 14)), - ButtonSegment(value: DebugMainPageSubPage.persistence, icon: Icon(FontAwesomeIcons.solidFloppyDisk, size: 14)), + ButtonSegment(value: DebugMainPageSubPage.persistence, icon: Icon(FontAwesomeIcons.solidDatabase, size: 14)), ButtonSegment(value: DebugMainPageSubPage.logs, icon: Icon(FontAwesomeIcons.solidFileLines, size: 14)), ], style: ButtonStyle( diff --git a/scnserver/api/handler/compat.go b/scnserver/api/handler/compat.go index 180465d..7074c38 100644 --- a/scnserver/api/handler/compat.go +++ b/scnserver/api/handler/compat.go @@ -535,7 +535,7 @@ func (h CompatHandler) Requery(g *gin.Context) ginresp.HTTPResponse { } compMsgs = append(compMsgs, models.CompatMessage{ - Title: h.app.CompatizeMessageTitle(ctx, v), + Title: v.Title, Body: v.Content, Priority: v.Priority, Timestamp: v.Timestamp().Unix(), @@ -783,7 +783,7 @@ func (h CompatHandler) Expand(g *gin.Context) ginresp.HTTPResponse { Success: true, Message: "ok", Data: models.CompatMessage{ - Title: h.app.CompatizeMessageTitle(ctx, msg), + Title: msg.Title, Body: msg.Content, Trimmed: langext.Ptr(false), Priority: msg.Priority, diff --git a/scnserver/jobs/DeliveryRetryJob.go b/scnserver/jobs/DeliveryRetryJob.go index 13a7c15..87c99c0 100644 --- a/scnserver/jobs/DeliveryRetryJob.go +++ b/scnserver/jobs/DeliveryRetryJob.go @@ -7,7 +7,6 @@ import ( "errors" "fmt" "github.com/rs/zerolog/log" - "gogs.mikescher.com/BlackForestBytes/goext/langext" "gogs.mikescher.com/BlackForestBytes/goext/syncext" "time" ) @@ -149,6 +148,25 @@ func (j *DeliveryRetryJob) redeliver(ctx *simplectx.SimpleContext, delivery mode return } + user, err := j.app.Database.Primary.GetUser(ctx, delivery.ReceiverUserID) + if err != nil { + log.Err(err).Str("ReceiverUserID", delivery.ReceiverUserID.String()).Msg("Failed to get user") + ctx.RollbackTransaction() + return + } + + channel, err := j.app.Database.Primary.GetChannelByID(ctx, msg.ChannelID) + if err != nil { + log.Err(err).Str("ChannelID", msg.ChannelID.String()).Msg("Failed to get channel") + ctx.RollbackTransaction() + return + } + if channel == nil { + log.Error().Str("ChannelID", msg.ChannelID.String()).Msg("Failed to get channel") + ctx.RollbackTransaction() + return + } + if msg.Deleted { err = j.app.Database.Primary.SetDeliveryFailed(ctx, delivery) if err != nil { @@ -158,29 +176,7 @@ func (j *DeliveryRetryJob) redeliver(ctx *simplectx.SimpleContext, delivery mode } } else { - isCompatClient, err := j.app.Database.Primary.IsCompatClient(ctx, client.ClientID) - if err != nil { - log.Err(err).Str("MessageID", delivery.MessageID.String()).Str("ClientID", client.ClientID.String()).Msg("Failed to get ") - ctx.RollbackTransaction() - return - } - - var titleOverride *string = nil - var msgidOverride *string = nil - if isCompatClient { - - messageIdComp, err := j.app.Database.Primary.ConvertToCompatIDOrCreate(ctx, "messageid", msg.MessageID.String()) - if err != nil { - log.Err(err).Str("MessageID", delivery.MessageID.String()).Str("ClientID", client.ClientID.String()).Msg("Failed to query/create messageid") - ctx.RollbackTransaction() - return - } - - titleOverride = langext.Ptr(j.app.CompatizeMessageTitle(ctx, msg)) - msgidOverride = langext.Ptr(fmt.Sprintf("%d", messageIdComp)) - } - - fcmDelivID, err := j.app.DeliverMessage(ctx, client, msg, titleOverride, msgidOverride) + fcmDelivID, err := j.app.DeliverMessage(ctx, user, client, *channel, msg) if err == nil { err = j.app.Database.Primary.SetDeliverySuccess(ctx, delivery, fcmDelivID) if err != nil { diff --git a/scnserver/logic/application.go b/scnserver/logic/application.go index cd386d1..6d058e4 100644 --- a/scnserver/logic/application.go +++ b/scnserver/logic/application.go @@ -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) -} diff --git a/scnserver/logic/message.go b/scnserver/logic/message.go index 5f98765..bb792c3 100644 --- a/scnserver/logic/message.go +++ b/scnserver/logic/message.go @@ -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 { diff --git a/scnserver/models/enums_gen.go b/scnserver/models/enums_gen.go index d2f9863..41c9794 100644 --- a/scnserver/models/enums_gen.go +++ b/scnserver/models/enums_gen.go @@ -5,7 +5,7 @@ package models import "gogs.mikescher.com/BlackForestBytes/goext/langext" import "gogs.mikescher.com/BlackForestBytes/goext/enums" -const ChecksumEnumGenerator = "08404cad6879118878e2b64db01bb6bf54cda9d51e3d3ff91b239e9a8459fecd" // GoExtVersion: 0.0.463 +const ChecksumEnumGenerator = "5b115c5f107801af608630d2c5adce57cd4b050d176c8cd3db5c132020bf153c" // GoExtVersion: 0.0.463 // ================================ ClientType ================================ // diff --git a/scnserver/models/ids_gen.go b/scnserver/models/ids_gen.go index 6b9512a..d74da26 100644 --- a/scnserver/models/ids_gen.go +++ b/scnserver/models/ids_gen.go @@ -15,7 +15,7 @@ import "reflect" import "regexp" import "strings" -const ChecksumCharsetIDGenerator = "08404cad6879118878e2b64db01bb6bf54cda9d51e3d3ff91b239e9a8459fecd" // GoExtVersion: 0.0.463 +const ChecksumCharsetIDGenerator = "5b115c5f107801af608630d2c5adce57cd4b050d176c8cd3db5c132020bf153c" // GoExtVersion: 0.0.463 const idlen = 24 diff --git a/scnserver/models/message.go b/scnserver/models/message.go index 51b1a0b..73f9302 100644 --- a/scnserver/models/message.go +++ b/scnserver/models/message.go @@ -2,6 +2,7 @@ package models import ( "context" + "fmt" "github.com/jmoiron/sqlx" "gogs.mikescher.com/BlackForestBytes/goext/langext" "gogs.mikescher.com/BlackForestBytes/goext/sq" @@ -94,6 +95,14 @@ func (m Message) ShortContent() string { return (*m.Content)[0:ContentLengthShort-3] + "..." } +func (m Message) FormatNotificationTitle(user User, channel Channel) string { + if m.ChannelInternalName == user.DefaultChannel() { + return m.Title + } + + return fmt.Sprintf("[%s] %s", channel.DisplayName, m.Title) +} + type MessageJSON struct { MessageID MessageID `json:"message_id"` SenderUserID UserID `json:"sender_user_id"` diff --git a/scnserver/push/dummy.go b/scnserver/push/dummy.go index 58d81cc..66fe308 100644 --- a/scnserver/push/dummy.go +++ b/scnserver/push/dummy.go @@ -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 } diff --git a/scnserver/push/firebase.go b/scnserver/push/firebase.go index 22eb8ba..0c6cf68 100644 --- a/scnserver/push/firebase.go +++ b/scnserver/push/firebase.go @@ -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}) diff --git a/scnserver/push/notificationClient.go b/scnserver/push/notificationClient.go index 2990db8..c6c86a8 100644 --- a/scnserver/push/notificationClient.go +++ b/scnserver/push/notificationClient.go @@ -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) } diff --git a/scnserver/push/testSink.go b/scnserver/push/testSink.go index 74671c5..901ab5c 100644 --- a/scnserver/push/testSink.go +++ b/scnserver/push/testSink.go @@ -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 diff --git a/scnserver/swagger/swagger.json b/scnserver/swagger/swagger.json index af8eac7..6286cee 100644 --- a/scnserver/swagger/swagger.json +++ b/scnserver/swagger/swagger.json @@ -19,63 +19,39 @@ "parameters": [ { "type": "string", - "example": "test", - "name": "channel", - "in": "query" - }, - { - "type": "string", - "example": "This is a message", "name": "content", "in": "query" }, { "type": "string", - "example": "P3TNH8mvv14fm", - "name": "key", - "in": "query" - }, - { - "type": "string", - "example": "db8b0e6a-a08c-4646", "name": "msg_id", "in": "query" }, { - "enum": [ - 0, - 1, - 2 - ], "type": "integer", - "example": 1, "name": "priority", "in": "query" }, - { - "type": "string", - "example": "example-server", - "name": "sender_name", - "in": "query" - }, { "type": "number", - "example": 1669824037, "name": "timestamp", "in": "query" }, { "type": "string", - "example": "Hello World", "name": "title", "in": "query" }, { - "type": "string", - "example": "7725", + "type": "integer", "name": "user_id", "in": "query" }, + { + "type": "string", + "name": "user_key", + "in": "query" + }, { "description": " ", "name": "post_body", @@ -86,62 +62,38 @@ }, { "type": "string", - "example": "test", - "name": "channel", - "in": "formData" - }, - { - "type": "string", - "example": "This is a message", "name": "content", "in": "formData" }, { "type": "string", - "example": "P3TNH8mvv14fm", - "name": "key", - "in": "formData" - }, - { - "type": "string", - "example": "db8b0e6a-a08c-4646", "name": "msg_id", "in": "formData" }, { - "enum": [ - 0, - 1, - 2 - ], "type": "integer", - "example": 1, "name": "priority", "in": "formData" }, - { - "type": "string", - "example": "example-server", - "name": "sender_name", - "in": "formData" - }, { "type": "number", - "example": 1669824037, "name": "timestamp", "in": "formData" }, { "type": "string", - "example": "Hello World", "name": "title", "in": "formData" }, { - "type": "string", - "example": "7725", + "type": "integer", "name": "user_id", "in": "formData" + }, + { + "type": "string", + "name": "user_key", + "in": "formData" } ], "responses": { @@ -2615,63 +2567,39 @@ "parameters": [ { "type": "string", - "example": "test", - "name": "channel", - "in": "query" - }, - { - "type": "string", - "example": "This is a message", "name": "content", "in": "query" }, { "type": "string", - "example": "P3TNH8mvv14fm", - "name": "key", - "in": "query" - }, - { - "type": "string", - "example": "db8b0e6a-a08c-4646", "name": "msg_id", "in": "query" }, { - "enum": [ - 0, - 1, - 2 - ], "type": "integer", - "example": 1, "name": "priority", "in": "query" }, - { - "type": "string", - "example": "example-server", - "name": "sender_name", - "in": "query" - }, { "type": "number", - "example": 1669824037, "name": "timestamp", "in": "query" }, { "type": "string", - "example": "Hello World", "name": "title", "in": "query" }, { - "type": "string", - "example": "7725", + "type": "integer", "name": "user_id", "in": "query" }, + { + "type": "string", + "name": "user_key", + "in": "query" + }, { "description": " ", "name": "post_body", @@ -2682,62 +2610,38 @@ }, { "type": "string", - "example": "test", - "name": "channel", - "in": "formData" - }, - { - "type": "string", - "example": "This is a message", "name": "content", "in": "formData" }, { "type": "string", - "example": "P3TNH8mvv14fm", - "name": "key", - "in": "formData" - }, - { - "type": "string", - "example": "db8b0e6a-a08c-4646", "name": "msg_id", "in": "formData" }, { - "enum": [ - 0, - 1, - 2 - ], "type": "integer", - "example": 1, "name": "priority", "in": "formData" }, - { - "type": "string", - "example": "example-server", - "name": "sender_name", - "in": "formData" - }, { "type": "number", - "example": 1669824037, "name": "timestamp", "in": "formData" }, { "type": "string", - "example": "Hello World", "name": "title", "in": "formData" }, { - "type": "string", - "example": "7725", + "type": "integer", "name": "user_id", "in": "formData" + }, + { + "type": "string", + "name": "user_key", + "in": "formData" } ], "responses": { @@ -2785,121 +2689,73 @@ "parameters": [ { "type": "string", - "example": "test", - "name": "channel", - "in": "query" - }, - { - "type": "string", - "example": "This is a message", "name": "content", "in": "query" }, { "type": "string", - "example": "P3TNH8mvv14fm", - "name": "key", - "in": "query" - }, - { - "type": "string", - "example": "db8b0e6a-a08c-4646", "name": "msg_id", "in": "query" }, { - "enum": [ - 0, - 1, - 2 - ], "type": "integer", - "example": 1, "name": "priority", "in": "query" }, - { - "type": "string", - "example": "example-server", - "name": "sender_name", - "in": "query" - }, { "type": "number", - "example": 1669824037, "name": "timestamp", "in": "query" }, { "type": "string", - "example": "Hello World", "name": "title", "in": "query" }, { - "type": "string", - "example": "7725", + "type": "integer", "name": "user_id", "in": "query" }, { "type": "string", - "example": "test", - "name": "channel", - "in": "formData" + "name": "user_key", + "in": "query" }, { "type": "string", - "example": "This is a message", "name": "content", "in": "formData" }, { "type": "string", - "example": "P3TNH8mvv14fm", - "name": "key", - "in": "formData" - }, - { - "type": "string", - "example": "db8b0e6a-a08c-4646", "name": "msg_id", "in": "formData" }, { - "enum": [ - 0, - 1, - 2 - ], "type": "integer", - "example": 1, "name": "priority", "in": "formData" }, - { - "type": "string", - "example": "example-server", - "name": "sender_name", - "in": "formData" - }, { "type": "number", - "example": 1669824037, "name": "timestamp", "in": "formData" }, { "type": "string", - "example": "Hello World", "name": "title", "in": "formData" }, { - "type": "string", - "example": "7725", + "type": "integer", "name": "user_id", "in": "formData" + }, + { + "type": "string", + "name": "user_key", + "in": "formData" } ], "responses": { @@ -3395,46 +3251,26 @@ "handler.SendMessage.combined": { "type": "object", "properties": { - "channel": { - "type": "string", - "example": "test" - }, "content": { - "type": "string", - "example": "This is a message" - }, - "key": { - "type": "string", - "example": "P3TNH8mvv14fm" + "type": "string" }, "msg_id": { - "type": "string", - "example": "db8b0e6a-a08c-4646" + "type": "string" }, "priority": { - "type": "integer", - "enum": [ - 0, - 1, - 2 - ], - "example": 1 - }, - "sender_name": { - "type": "string", - "example": "example-server" + "type": "integer" }, "timestamp": { - "type": "number", - "example": 1669824037 + "type": "number" }, "title": { - "type": "string", - "example": "Hello World" + "type": "string" }, "user_id": { - "type": "string", - "example": "7725" + "type": "integer" + }, + "user_key": { + "type": "string" } } }, @@ -3463,7 +3299,7 @@ "type": "integer" }, "scn_msg_id": { - "type": "string" + "type": "integer" }, "success": { "type": "boolean" diff --git a/scnserver/swagger/swagger.yaml b/scnserver/swagger/swagger.yaml index ca74f8d..8cdb0c0 100644 --- a/scnserver/swagger/swagger.yaml +++ b/scnserver/swagger/swagger.yaml @@ -327,36 +327,19 @@ definitions: type: object handler.SendMessage.combined: properties: - channel: - example: test - type: string content: - example: This is a message - type: string - key: - example: P3TNH8mvv14fm type: string msg_id: - example: db8b0e6a-a08c-4646 type: string priority: - enum: - - 0 - - 1 - - 2 - example: 1 type: integer - sender_name: - example: example-server - type: string timestamp: - example: 1669824037 type: number title: - example: Hello World type: string user_id: - example: "7725" + type: integer + user_key: type: string type: object handler.SendMessage.response: @@ -376,7 +359,7 @@ definitions: quota_max: type: integer scn_msg_id: - type: string + type: integer success: type: boolean suppress_send: @@ -765,90 +748,52 @@ paths: description: All parameter can be set via query-parameter or the json body. Only UserID, UserKey and Title are required parameters: - - example: test - in: query - name: channel - type: string - - example: This is a message - in: query + - in: query name: content type: string - - example: P3TNH8mvv14fm - in: query - name: key - type: string - - example: db8b0e6a-a08c-4646 - in: query + - in: query name: msg_id type: string - - enum: - - 0 - - 1 - - 2 - example: 1 - in: query + - in: query name: priority type: integer - - example: example-server - in: query - name: sender_name - type: string - - example: 1669824037 - in: query + - in: query name: timestamp type: number - - example: Hello World - in: query + - in: query name: title type: string - - example: "7725" - in: query + - in: query name: user_id + type: integer + - in: query + name: user_key type: string - description: ' ' in: body name: post_body schema: $ref: '#/definitions/handler.SendMessage.combined' - - example: test - in: formData - name: channel - type: string - - example: This is a message - in: formData + - in: formData name: content type: string - - example: P3TNH8mvv14fm - in: formData - name: key - type: string - - example: db8b0e6a-a08c-4646 - in: formData + - in: formData name: msg_id type: string - - enum: - - 0 - - 1 - - 2 - example: 1 - in: formData + - in: formData name: priority type: integer - - example: example-server - in: formData - name: sender_name - type: string - - example: 1669824037 - in: formData + - in: formData name: timestamp type: number - - example: Hello World - in: formData + - in: formData name: title type: string - - example: "7725" - in: formData + - in: formData name: user_id + type: integer + - in: formData + name: user_key type: string responses: "200": @@ -2546,90 +2491,52 @@ paths: description: All parameter can be set via query-parameter or the json body. Only UserID, UserKey and Title are required parameters: - - example: test - in: query - name: channel - type: string - - example: This is a message - in: query + - in: query name: content type: string - - example: P3TNH8mvv14fm - in: query - name: key - type: string - - example: db8b0e6a-a08c-4646 - in: query + - in: query name: msg_id type: string - - enum: - - 0 - - 1 - - 2 - example: 1 - in: query + - in: query name: priority type: integer - - example: example-server - in: query - name: sender_name - type: string - - example: 1669824037 - in: query + - in: query name: timestamp type: number - - example: Hello World - in: query + - in: query name: title type: string - - example: "7725" - in: query + - in: query name: user_id + type: integer + - in: query + name: user_key type: string - description: ' ' in: body name: post_body schema: $ref: '#/definitions/handler.SendMessage.combined' - - example: test - in: formData - name: channel - type: string - - example: This is a message - in: formData + - in: formData name: content type: string - - example: P3TNH8mvv14fm - in: formData - name: key - type: string - - example: db8b0e6a-a08c-4646 - in: formData + - in: formData name: msg_id type: string - - enum: - - 0 - - 1 - - 2 - example: 1 - in: formData + - in: formData name: priority type: integer - - example: example-server - in: formData - name: sender_name - type: string - - example: 1669824037 - in: formData + - in: formData name: timestamp type: number - - example: Hello World - in: formData + - in: formData name: title type: string - - example: "7725" - in: formData + - in: formData name: user_id + type: integer + - in: formData + name: user_key type: string responses: "200": @@ -2662,85 +2569,47 @@ paths: description: All parameter can be set via query-parameter or form-data body. Only UserID, UserKey and Title are required parameters: - - example: test - in: query - name: channel - type: string - - example: This is a message - in: query + - in: query name: content type: string - - example: P3TNH8mvv14fm - in: query - name: key - type: string - - example: db8b0e6a-a08c-4646 - in: query + - in: query name: msg_id type: string - - enum: - - 0 - - 1 - - 2 - example: 1 - in: query + - in: query name: priority type: integer - - example: example-server - in: query - name: sender_name - type: string - - example: 1669824037 - in: query + - in: query name: timestamp type: number - - example: Hello World - in: query + - in: query name: title type: string - - example: "7725" - in: query + - in: query name: user_id + type: integer + - in: query + name: user_key type: string - - example: test - in: formData - name: channel - type: string - - example: This is a message - in: formData + - in: formData name: content type: string - - example: P3TNH8mvv14fm - in: formData - name: key - type: string - - example: db8b0e6a-a08c-4646 - in: formData + - in: formData name: msg_id type: string - - enum: - - 0 - - 1 - - 2 - example: 1 - in: formData + - in: formData name: priority type: integer - - example: example-server - in: formData - name: sender_name - type: string - - example: 1669824037 - in: formData + - in: formData name: timestamp type: number - - example: Hello World - in: formData + - in: formData name: title type: string - - example: "7725" - in: formData + - in: formData name: user_id + type: integer + - in: formData + name: user_key type: string responses: "200": diff --git a/scnserver/test/compat_test.go b/scnserver/test/compat_test.go index 280310c..dc12749 100644 --- a/scnserver/test/compat_test.go +++ b/scnserver/test/compat_test.go @@ -704,44 +704,6 @@ func TestCompatRequery(t *testing.T) { } -func TestCompatTitlePatch(t *testing.T) { - ws, baseUrl, stop := tt.StartSimpleWebserver(t) - defer stop() - - pusher := ws.Pusher.(*push.TestSink) - - r0 := tt.RequestPost[gin.H](t, baseUrl, "/api/v2/users", gin.H{ - "agent_model": "DUMMY_PHONE", - "agent_version": "4X", - "client_type": "ANDROID", - "fcm_token": "DUMMY_FCM", - }) - - uid := r0["user_id"].(string) - admintok := r0["admin_key"].(string) - sendtok := r0["send_key"].(string) - - type clientlist struct { - Clients []gin.H `json:"clients"` - } - - clist1 := tt.RequestAuthGet[clientlist](t, admintok, baseUrl, fmt.Sprintf("/api/v2/users/%s/clients", url.QueryEscape(uid))) - - tt.SetCompatClient(t, ws, clist1.Clients[0]["client_id"].(string)) - - _ = tt.RequestPost[gin.H](t, baseUrl, "/", gin.H{ - "key": sendtok, - "user_id": uid, - "title": "HelloWorld_001", - "channel": "TestChan", - }) - - tt.AssertEqual(t, "messageCount", 1, len(pusher.Data)) - tt.AssertStrRepEqual(t, "msg.title", "HelloWorld_001", pusher.Last().Message.Title) - tt.AssertStrRepEqual(t, "msg.ovrTitle", "[TestChan] HelloWorld_001", pusher.Last().CompatTitleOverride) - -} - func TestCompatAckCount(t *testing.T) { _, baseUrl, stop := tt.StartSimpleWebserver(t) defer stop() diff --git a/scnserver/test/util/internals.go b/scnserver/test/util/internals.go index 359ef90..a51c560 100644 --- a/scnserver/test/util/internals.go +++ b/scnserver/test/util/internals.go @@ -2,7 +2,6 @@ package util import ( "blackforestbytes.com/simplecloudnotifier/logic" - "gogs.mikescher.com/BlackForestBytes/goext/sq" "testing" "time" ) @@ -65,14 +64,3 @@ func CreateCompatID(t *testing.T, ws *logic.Application, idtype string, newid st return uidold } - -func SetCompatClient(t *testing.T, ws *logic.Application, cid string) { - ctx := ws.NewSimpleTransactionContext(5 * time.Second) - defer ctx.Cancel() - - _, err := ws.Database.Primary.DB().Exec(ctx, "INSERT INTO compat_clients (client_id) VALUES (:cid)", sq.PP{"cid": cid}) - TestFailIfErr(t, err) - - err = ctx.CommitTransaction() - TestFailIfErr(t, err) -}