Skip to content

An open-source, privacy-first, self-hosted knowledge workspace where humans and AI agents work together 开源、隐私优先、自托管的知识工作空间,让人与智能体在此协作

:art: Support sending notifications on Android https://github.com/siyuan-note/siyuan/issues/17114

Danielf07ae1fc752a
diff --git a/kernel/api/notification.go b/kernel/api/notification.go
index 704107680e..8dad637d8c 100644
--- a/kernel/api/notification.go
+++ b/kernel/api/notification.go
@@ -25,6 +25,29 @@ import (
"github.com/siyuan-note/siyuan/kernel/util"
)
+func sendDeviceNotification(c *gin.Context) {
+ ret := gulu.Ret.NewResult()
+ defer c.JSON(http.StatusOK, ret)
+
+ arg, ok := util.JsonArg(c, ret)
+ if !ok {
+ return
+ }
+
+ if util.ContainerAndroid != util.Container {
+ ret.Code = -1
+ ret.Msg = "Just support Android"
+ return
+ }
+
+ payload := arg["payload"].(string)
+ evt := util.NewCmdResult("sendDeviceNotification", 0, util.PushModeSingleSelf)
+ evt.Data = map[string]interface{}{
+ "payload": payload,
+ }
+ util.PushEvent(evt)
+}
+
func pushMsg(c *gin.Context) {
ret := gulu.Ret.NewResult()
defer c.JSON(http.StatusOK, ret)
diff --git a/kernel/api/router.go b/kernel/api/router.go
index ffa717939d..f3d031f935 100644
--- a/kernel/api/router.go
+++ b/kernel/api/router.go
@@ -458,6 +458,7 @@ func ServeAPI(ginServer *gin.Engine) {
ginServer.Handle("POST", "/api/notification/pushMsg", model.CheckAuth, model.CheckAdminRole, pushMsg)
ginServer.Handle("POST", "/api/notification/pushErrMsg", model.CheckAuth, model.CheckAdminRole, pushErrMsg)
+ ginServer.Handle("POST", "/api/notification/sendDeviceNotification", model.CheckAuth, model.CheckAdminRole, sendDeviceNotification)
ginServer.Handle("POST", "/api/snippet/getSnippet", model.CheckAuth, getSnippet)
ginServer.Handle("POST", "/api/snippet/setSnippet", model.CheckAuth, model.CheckAdminRole, model.CheckReadonly, setSnippet)