From b3bb7cb582176dc94d2f34c55b083797c125d426 Mon Sep 17 00:00:00 2001 From: LittleSheep Date: Fri, 19 Jul 2024 23:35:15 +0800 Subject: [PATCH] :sparkles: Provide API to try out our newest notification feature --- go.mod | 2 +- go.sum | 2 ++ pkg/internal/grpc/notifier.go | 7 +++++++ pkg/internal/server/admin/notify_api.go | 5 +++++ pkg/internal/server/api/notify_api.go | 5 +++++ 5 files changed, 20 insertions(+), 1 deletion(-) diff --git a/go.mod b/go.mod index 98f552f..316b350 100644 --- a/go.mod +++ b/go.mod @@ -6,7 +6,7 @@ toolchain go1.22.1 require ( firebase.google.com/go v3.13.0+incompatible - git.solsynth.dev/hydrogen/dealer v0.0.0-20240717054512-da433c88615a + git.solsynth.dev/hydrogen/dealer v0.0.0-20240719153055-607eba001f65 git.solsynth.dev/hydrogen/paperclip v0.0.0-20240622051057-0f56dba45745 github.com/go-playground/validator/v10 v10.17.0 github.com/gofiber/fiber/v2 v2.52.4 diff --git a/go.sum b/go.sum index ac229f6..7c73c8a 100644 --- a/go.sum +++ b/go.sum @@ -19,6 +19,8 @@ firebase.google.com/go v3.13.0+incompatible h1:3TdYC3DDi6aHn20qoRkxwGqNgdjtblwVA firebase.google.com/go v3.13.0+incompatible/go.mod h1:xlah6XbEyW6tbfSklcfe5FHJIwjt8toICdV5Wh9ptHs= git.solsynth.dev/hydrogen/dealer v0.0.0-20240717054512-da433c88615a h1:08YaBgZtkrPfiw08l4RjtKI1fdt6wlHc3Ea7NDFtLPg= git.solsynth.dev/hydrogen/dealer v0.0.0-20240717054512-da433c88615a/go.mod h1:oPdUxLy6TFeRxiRC/BoNb3YUNcnSiOnJrzFTnCPSoCA= +git.solsynth.dev/hydrogen/dealer v0.0.0-20240719153055-607eba001f65 h1:p9PIsp5RyrLdlOR7MXyeGBx04v3+1IMEEBBV22fJZPo= +git.solsynth.dev/hydrogen/dealer v0.0.0-20240719153055-607eba001f65/go.mod h1:oPdUxLy6TFeRxiRC/BoNb3YUNcnSiOnJrzFTnCPSoCA= git.solsynth.dev/hydrogen/paperclip v0.0.0-20240622051057-0f56dba45745 h1:40BUsQMNXjqHyytkyF9py1HjTAWlRgO6R57YXUrHNy4= git.solsynth.dev/hydrogen/paperclip v0.0.0-20240622051057-0f56dba45745/go.mod h1:FsQGSLTl0gvo+9Jmbot02S72suyF9tFTrzDj70Xhifo= github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= diff --git a/pkg/internal/grpc/notifier.go b/pkg/internal/grpc/notifier.go index bad598b..bb7669b 100644 --- a/pkg/internal/grpc/notifier.go +++ b/pkg/internal/grpc/notifier.go @@ -3,6 +3,7 @@ package grpc import ( "context" "fmt" + "git.solsynth.dev/hydrogen/passport/pkg/internal/database" jsoniter "github.com/json-iterator/go" "github.com/samber/lo" @@ -28,6 +29,8 @@ func (v *Server) NotifyUser(_ context.Context, in *proto.NotifyUserRequest) (*pr Subtitle: in.GetNotify().Subtitle, Body: in.GetNotify().GetBody(), Metadata: metadata, + Avatar: in.GetNotify().Avatar, + Picture: in.GetNotify().Picture, IsRealtime: in.GetNotify().GetIsRealtime(), IsForcePush: in.GetNotify().GetIsForcePush(), AccountID: user.ID, @@ -68,6 +71,8 @@ func (v *Server) NotifyUserBatch(_ context.Context, in *proto.NotifyUserBatchReq Subtitle: in.GetNotify().Subtitle, Body: in.GetNotify().GetBody(), Metadata: metadata, + Avatar: in.GetNotify().Avatar, + Picture: in.GetNotify().Picture, IsRealtime: in.GetNotify().GetIsRealtime(), IsForcePush: in.GetNotify().GetIsForcePush(), AccountID: user.ID, @@ -106,6 +111,8 @@ func (v *Server) NotifyAllUser(_ context.Context, in *proto.NotifyRequest) (*pro Subtitle: in.Subtitle, Body: in.GetBody(), Metadata: metadata, + Avatar: in.Avatar, + Picture: in.Picture, IsRealtime: in.GetIsRealtime(), IsForcePush: in.GetIsForcePush(), AccountID: user.ID, diff --git a/pkg/internal/server/admin/notify_api.go b/pkg/internal/server/admin/notify_api.go index 98e8e86..0c2794d 100644 --- a/pkg/internal/server/admin/notify_api.go +++ b/pkg/internal/server/admin/notify_api.go @@ -16,6 +16,8 @@ func notifyAllUser(c *fiber.Ctx) error { Subtitle *string `json:"subtitle" validate:"max=1024"` Body string `json:"content" validate:"required,max=4096"` Metadata map[string]any `json:"metadata"` + Avatar *string `json:"avatar"` + Picture *string `json:"picture"` IsForcePush bool `json:"is_force_push"` IsRealtime bool `json:"is_realtime"` } @@ -45,6 +47,9 @@ func notifyAllUser(c *fiber.Ctx) error { Subtitle: data.Subtitle, Title: data.Title, Body: data.Body, + Metadata: data.Metadata, + Avatar: data.Avatar, + Picture: data.Picture, IsRealtime: data.IsRealtime, IsForcePush: data.IsForcePush, AccountID: user.ID, diff --git a/pkg/internal/server/api/notify_api.go b/pkg/internal/server/api/notify_api.go index 89a3d48..b4989c5 100644 --- a/pkg/internal/server/api/notify_api.go +++ b/pkg/internal/server/api/notify_api.go @@ -16,6 +16,8 @@ func notifyUser(c *fiber.Ctx) error { Subtitle *string `json:"subtitle" validate:"max=1024"` Body string `json:"content" validate:"required,max=4096"` Metadata map[string]any `json:"metadata"` + Avatar *string `json:"avatar"` + Picture *string `json:"picture"` IsForcePush bool `json:"is_force_push"` IsRealtime bool `json:"is_realtime"` UserID uint `json:"user_id" validate:"required"` @@ -40,6 +42,9 @@ func notifyUser(c *fiber.Ctx) error { Subtitle: data.Subtitle, Title: data.Title, Body: data.Body, + Metadata: data.Metadata, + Avatar: data.Avatar, + Picture: data.Picture, IsRealtime: data.IsRealtime, IsForcePush: data.IsForcePush, AccountID: user.ID,