diff --git a/app/src/layout/Model.ts b/app/src/layout/Model.ts index 8f5c3c861..ac220340b 100644 --- a/app/src/layout/Model.ts +++ b/app/src/layout/Model.ts @@ -14,6 +14,7 @@ export class Model { /// #else // @ts-ignore public parent: any; + /// #endif constructor(options: { id: string, type?: TWS, callback?: () => void, msgCallback?: (data: IWebSocketData) => void }) { @@ -79,8 +80,13 @@ export class Model { cmd, reqId: this.reqId, param, - // pushMode 0: 广播,1:单播(默认),2:广播(不包含自己) - // reloadPushMode 是否需要 reload 0: 广播,1:单播(默认),2:广播(不包含自己),3:不推送 + // pushMode + // 0: 所有应用所有会话广播 + // 1:自我应用会话单播 + // 2:非自我会话广播 + // 4:非自我应用所有会话广播 + // 5:单个应用内所有会话广播 + // 6:非自我应用主会话广播 })); } } diff --git a/kernel/api/block_op.go b/kernel/api/block_op.go index cfaec4af2..7a5b4fd69 100644 --- a/kernel/api/block_op.go +++ b/kernel/api/block_op.go @@ -288,7 +288,7 @@ func deleteBlock(c *gin.Context) { } func broadcastTransactions(transactions []*model.Transaction) { - evt := util.NewCmdResult("transactions", 0, util.PushModeBroadcast, util.PushModeBroadcast) + evt := util.NewCmdResult("transactions", 0, util.PushModeBroadcast) evt.Data = transactions util.PushEvent(evt) } diff --git a/kernel/api/filetree.go b/kernel/api/filetree.go index 70de4e69e..ca1909ec4 100644 --- a/kernel/api/filetree.go +++ b/kernel/api/filetree.go @@ -115,7 +115,7 @@ func heading2Doc(c *gin.Context) { name := path.Base(targetPath) box := model.Conf.Box(targetNotebook) files, _, _ := model.ListDocTree(targetNotebook, path.Dir(targetPath), model.Conf.FileTree.Sort) - evt := util.NewCmdResult("heading2doc", 0, util.PushModeBroadcast, util.PushModeNone) + evt := util.NewCmdResult("heading2doc", 0, util.PushModeBroadcast) evt.Data = map[string]interface{}{ "box": box, "path": targetPath, @@ -159,7 +159,7 @@ func li2Doc(c *gin.Context) { name := path.Base(targetPath) box := model.Conf.Box(targetNotebook) files, _, _ := model.ListDocTree(targetNotebook, path.Dir(targetPath), model.Conf.FileTree.Sort) - evt := util.NewCmdResult("li2doc", 0, util.PushModeBroadcast, util.PushModeNone) + evt := util.NewCmdResult("li2doc", 0, util.PushModeBroadcast) evt.Data = map[string]interface{}{ "box": box, "path": targetPath, @@ -465,7 +465,7 @@ func createDailyNote(c *gin.Context) { if existed && "" != app { pushMode = util.PushModeBroadcastApp } - evt := util.NewCmdResult("createdailynote", 0, pushMode, util.PushModeNone) + evt := util.NewCmdResult("createdailynote", 0, pushMode) evt.AppId = app name := path.Base(p) @@ -750,7 +750,7 @@ func getDoc(c *gin.Context) { } func pushCreate(box *model.Box, p, treeID string, arg map[string]interface{}) { - evt := util.NewCmdResult("create", 0, util.PushModeBroadcast, util.PushModeNone) + evt := util.NewCmdResult("create", 0, util.PushModeBroadcast) name := path.Base(p) files, _, _ := model.ListDocTree(box.ID, path.Dir(p), model.Conf.FileTree.Sort) evt.Data = map[string]interface{}{ diff --git a/kernel/api/notebook.go b/kernel/api/notebook.go index ef8d81f5b..8e8f8e1cf 100644 --- a/kernel/api/notebook.go +++ b/kernel/api/notebook.go @@ -76,7 +76,7 @@ func renameNotebook(c *gin.Context) { return } - evt := util.NewCmdResult("renamenotebook", 0, util.PushModeBroadcast, util.PushModeNone) + evt := util.NewCmdResult("renamenotebook", 0, util.PushModeBroadcast) evt.Data = map[string]interface{}{ "box": notebook, "name": name, @@ -101,7 +101,7 @@ func removeNotebook(c *gin.Context) { return } - evt := util.NewCmdResult("unmount", 0, util.PushModeBroadcast, 0) + evt := util.NewCmdResult("unmount", 0, util.PushModeBroadcast) evt.Data = map[string]interface{}{ "box": notebook, } @@ -137,7 +137,7 @@ func createNotebook(c *gin.Context) { "notebook": model.Conf.Box(id), } - evt := util.NewCmdResult("createnotebook", 0, util.PushModeBroadcast, util.PushModeNone) + evt := util.NewCmdResult("createnotebook", 0, util.PushModeBroadcast) evt.Data = map[string]interface{}{ "box": model.Conf.Box(id), "existed": existed, @@ -164,7 +164,7 @@ func openNotebook(c *gin.Context) { return } - evt := util.NewCmdResult("mount", 0, util.PushModeBroadcast, util.PushModeNone) + evt := util.NewCmdResult("mount", 0, util.PushModeBroadcast) evt.Data = map[string]interface{}{ "box": model.Conf.Box(notebook), "existed": existed, diff --git a/kernel/api/storage.go b/kernel/api/storage.go index 65f4f0e10..02d089620 100644 --- a/kernel/api/storage.go +++ b/kernel/api/storage.go @@ -196,7 +196,7 @@ func setLocalStorage(c *gin.Context) { } app := arg["app"].(string) - evt := util.NewCmdResult("setLocalStorage", 0, util.PushModeBroadcastMainExcludeSelfApp, util.PushModeBroadcastMainExcludeSelfApp) + evt := util.NewCmdResult("setLocalStorage", 0, util.PushModeBroadcastMainExcludeSelfApp) evt.AppId = app evt.Data = val util.PushEvent(evt) diff --git a/kernel/api/transaction.go b/kernel/api/transaction.go index 1b425b28a..d50a73fdd 100644 --- a/kernel/api/transaction.go +++ b/kernel/api/transaction.go @@ -93,7 +93,7 @@ func performTransactions(c *gin.Context) { } func pushTransactions(app, session string, transactions []*model.Transaction) { - evt := util.NewCmdResult("transactions", 0, util.PushModeBroadcastExcludeSelf, util.PushModeBroadcastExcludeSelf) + evt := util.NewCmdResult("transactions", 0, util.PushModeBroadcastExcludeSelf) evt.AppId = app evt.SessionId = session evt.Data = transactions diff --git a/kernel/cmd/cmd.go b/kernel/cmd/cmd.go index 5ddce241a..d14ce6ea5 100644 --- a/kernel/cmd/cmd.go +++ b/kernel/cmd/cmd.go @@ -64,11 +64,7 @@ func NewCommand(cmdStr string, cmdId float64, param map[string]interface{}, sess if pushModeParam := param["pushMode"]; nil != pushModeParam { pushMode = util.PushMode(pushModeParam.(float64)) } - reloadPushMode := util.PushModeSingleSelf - if reloadPushModeParam := param["reloadPushMode"]; nil != reloadPushModeParam { - reloadPushMode = util.PushMode(reloadPushModeParam.(float64)) - } - baseCmd.PushPayload = util.NewCmdResult(ret.Name(), cmdId, pushMode, reloadPushMode) + baseCmd.PushPayload = util.NewCmdResult(ret.Name(), cmdId, pushMode) appId, _ := baseCmd.session.Get("app") baseCmd.PushPayload.AppId = appId.(string) sid, _ := baseCmd.session.Get("id") diff --git a/kernel/model/blockial.go b/kernel/model/blockial.go index 7299bcaac..d09f566c6 100644 --- a/kernel/model/blockial.go +++ b/kernel/model/blockial.go @@ -148,7 +148,7 @@ func SetBlockAttrs(id string, nameValues map[string]string) (err error) { } func pushBroadcastAttrTransactions(transactions []*Transaction) { - evt := util.NewCmdResult("transactions", 0, util.PushModeBroadcast, util.PushModeBroadcast) + evt := util.NewCmdResult("transactions", 0, util.PushModeBroadcast) evt.Data = transactions util.PushEvent(evt) } diff --git a/kernel/model/file.go b/kernel/model/file.go index c50236e31..9c885effd 100644 --- a/kernel/model/file.go +++ b/kernel/model/file.go @@ -1172,7 +1172,7 @@ func moveDoc(fromBox *Box, fromPath string, toBox *Box, toPath string) (newPath moveSorts(tree.ID, fromBox.ID, toBox.ID) } - evt := util.NewCmdResult("moveDoc", 0, util.PushModeBroadcast, util.PushModeNone) + evt := util.NewCmdResult("moveDoc", 0, util.PushModeBroadcast) evt.Data = map[string]interface{}{ "fromNotebook": fromBox.ID, "fromPath": fromPath, @@ -1275,7 +1275,7 @@ func removeDoc(box *Box, p string) (err error) { cache.RemoveDocIAL(p) - evt := util.NewCmdResult("removeDoc", 0, util.PushModeBroadcast, util.PushModeNone) + evt := util.NewCmdResult("removeDoc", 0, util.PushModeBroadcast) evt.Data = map[string]interface{}{ "ids": removeIDs, } @@ -1321,7 +1321,7 @@ func RenameDoc(boxID, p, title string) (err error) { } refText := getNodeRefText(tree.Root) - evt := util.NewCmdResult("rename", 0, util.PushModeBroadcast, util.PushModeNone) + evt := util.NewCmdResult("rename", 0, util.PushModeBroadcast) evt.Data = map[string]interface{}{ "box": boxID, "id": tree.Root.ID, diff --git a/kernel/model/mount.go b/kernel/model/mount.go index a3c72b5e0..ec895d5f1 100644 --- a/kernel/model/mount.go +++ b/kernel/model/mount.go @@ -115,7 +115,7 @@ func Unmount(boxID string) { WaitForWritingFiles() unmount0(boxID) - evt := util.NewCmdResult("unmount", 0, util.PushModeBroadcast, 0) + evt := util.NewCmdResult("unmount", 0, util.PushModeBroadcast) evt.Data = map[string]interface{}{ "box": boxID, } diff --git a/kernel/util/result.go b/kernel/util/result.go index 7ea9bf55d..522ce476e 100644 --- a/kernel/util/result.go +++ b/kernel/util/result.go @@ -24,45 +24,41 @@ import ( type PushMode int const ( - PushModeBroadcast PushMode = 0 // 所有应用所有会话广播 - PushModeSingleSelf PushMode = 1 // 自我应用会话单播 - PushModeBroadcastExcludeSelf PushMode = 2 // 非自我会话广播 - PushModeBroadcastExcludeSelfApp PushMode = 4 // 非自我应用所有会话广播 - PushModeBroadcastApp PushMode = 5 // 单个应用内所有会话广播 - PushModeBroadcastMainExcludeSelfApp PushMode = 6 // 非自我应用主会话广播 - PushModeNone PushMode = 10 // 不进行 reload + PushModeBroadcast PushMode = 0 // 所有应用所有会话广播 + PushModeSingleSelf PushMode = 1 // 自我应用会话单播 + PushModeBroadcastExcludeSelf PushMode = 2 // 非自我会话广播 + PushModeBroadcastExcludeSelfApp PushMode = 4 // 非自我应用所有会话广播 + PushModeBroadcastApp PushMode = 5 // 单个应用内所有会话广播 + PushModeBroadcastMainExcludeSelfApp PushMode = 6 // 非自我应用主会话广播 ) type Result struct { - Cmd string `json:"cmd"` - ReqId float64 `json:"reqId"` - AppId string `json:"app"` - SessionId string `json:"sid"` - PushMode PushMode `json:"pushMode"` - ReloadPushMode PushMode `json:"reloadPushMode"` - Callback interface{} `json:"callback"` - Code int `json:"code"` - Msg string `json:"msg"` - Data interface{} `json:"data"` + Cmd string `json:"cmd"` + ReqId float64 `json:"reqId"` + AppId string `json:"app"` + SessionId string `json:"sid"` + PushMode PushMode `json:"pushMode"` + Callback interface{} `json:"callback"` + Code int `json:"code"` + Msg string `json:"msg"` + Data interface{} `json:"data"` } func NewResult() *Result { return &Result{Cmd: "", - ReqId: 0, - PushMode: 0, - ReloadPushMode: 0, - Callback: "", - Code: 0, - Msg: "", - Data: nil} + ReqId: 0, + PushMode: 0, + Callback: "", + Code: 0, + Msg: "", + Data: nil} } -func NewCmdResult(cmdName string, cmdId float64, pushMode, reloadPushMode PushMode) *Result { +func NewCmdResult(cmdName string, cmdId float64, pushMode PushMode) *Result { ret := NewResult() ret.Cmd = cmdName ret.ReqId = cmdId ret.PushMode = pushMode - ret.ReloadPushMode = reloadPushMode return ret } diff --git a/kernel/util/websocket.go b/kernel/util/websocket.go index 6e9b8a0dd..ef1f05691 100644 --- a/kernel/util/websocket.go +++ b/kernel/util/websocket.go @@ -121,7 +121,7 @@ func ClosePushChan(id string) { } func ReloadUI() { - evt := NewCmdResult("reloadui", 0, PushModeBroadcast, 0) + evt := NewCmdResult("reloadui", 0, PushModeBroadcast) PushEvent(evt) } @@ -208,7 +208,7 @@ func PushClearProgress() { } func PushDownloadProgress(id string, percent float32) { - evt := NewCmdResult("downloadProgress", 0, PushModeBroadcast, 0) + evt := NewCmdResult("downloadProgress", 0, PushModeBroadcast) evt.Data = map[string]interface{}{ "id": id, "percent": percent, @@ -219,9 +219,6 @@ func PushDownloadProgress(id string, percent float32) { func PushEvent(event *Result) { msg := event.Bytes() mode := event.PushMode - if "reload" == event.Cmd { - mode = event.ReloadPushMode - } switch mode { case PushModeBroadcast: Broadcast(msg) @@ -235,7 +232,6 @@ func PushEvent(event *Result) { broadcastApp(msg, event.AppId) case PushModeBroadcastMainExcludeSelfApp: broadcastOtherAppMains(msg, event.AppId) - case PushModeNone: } }