$.size 제거

This commit is contained in:
2024-02-16 14:58:24 +09:00
parent 1922b9152b
commit e821eb7433

View File

@ -1,6 +1,7 @@
package core
import (
"encoding/gob"
"encoding/json"
"fmt"
"net/http"
@ -38,6 +39,10 @@ type groupChat struct {
sendUpstreamMessage func(msg *wshandler.UpstreamMessage)
}
func init() {
gob.Register(map[string]string{})
}
func (gc *groupChat) Initialize(tv *Tavern, cfg configDocument) error {
rem, _ := json.Marshal(cfg)
if err := json.Unmarshal(rem, &gc.chatConfig); err != nil {
@ -122,7 +127,6 @@ func (gc *groupChat) ClientDisconnected(msg string, callby *wshandler.Sender) {
if typename == "public" {
cnt, err := gc.rh.JSONDel(chanid, "$.members."+callby.Alias)
if cnt > 0 {
gc.rh.JSONNumIncrBy(chanid, "$.size", -1)
if cfg, ok := gc.chatConfig.Channels[chanid]; ok {
cfg.inoutChan <- "-" + callby.Alias
}
@ -151,14 +155,13 @@ func (gc *groupChat) EnterPublicChannel(ctx wshandler.ApiCallContext) {
return
}
atomicsize, _ := gc.rh.JSONNumIncrBy(chanid, "$.size", 1)
atomicsize, _ := gc.rh.JSONObjLen(chanid, "$.members")
if len(atomicsize) == 0 {
return
}
if atomicsize[0] > cfg.Capacity {
logger.Println("chatting channel is full :", chanid, atomicsize[0]-1, cfg.Capacity)
gc.rh.JSONNumIncrBy(chanid, "$.size", -1)
if atomicsize[0] >= cfg.Capacity {
logger.Println("chatting channel is full :", chanid, atomicsize[0], cfg.Capacity)
return
}
@ -181,7 +184,6 @@ func (gc *groupChat) EnterPublicChannel(ctx wshandler.ApiCallContext) {
return
}
logger.Println("groupchat EnterPublicChannel JSONSet :", chanid, ctx.CallBy.Alias)
gc.enterRoom(chanid, ctx.CallBy.Accid)
cfg.inoutChan <- "+" + ctx.CallBy.Alias
@ -210,8 +212,6 @@ func (gc *groupChat) LeavePublicChannel(ctx wshandler.ApiCallContext) {
cnt, err := gc.rh.JSONDel(oldchan, "$.members."+ctx.CallBy.Alias)
if cnt > 0 {
gc.rh.JSONNumIncrBy(oldchan, "$.size", -1)
logger.Println("groupchat LeavePublicChannel JSONDel :", oldchan, ctx.CallBy.Alias)
gc.leaveRoom(oldchan, ctx.CallBy.Accid)
if cfg, ok := gc.chatConfig.Channels[oldchan]; ok {
cfg.inoutChan <- "-" + ctx.CallBy.Alias