在进行 socket 连接前先关闭之前连接。实现新建会话功能。

This commit is contained in:
RockYang
2023-04-19 15:18:13 +08:00
parent 50ff591dbb
commit 14a351b477
8 changed files with 158 additions and 22 deletions

View File

@@ -290,6 +290,17 @@ func (s *Server) RemoveUserHandle(c *gin.Context) {
// GetUserListHandle 获取用户列表
func (s *Server) GetUserListHandle(c *gin.Context) {
username := c.PostForm("username")
if username != "" {
user, err := GetUser(username)
if err != nil {
c.JSON(http.StatusOK, types.BizVo{Code: types.Failed, Message: "User not exists"})
} else {
c.JSON(http.StatusOK, types.BizVo{Code: types.Success, Message: types.OkMsg, Data: user})
}
return
}
c.JSON(http.StatusOK, types.BizVo{Code: types.Success, Message: types.OkMsg, Data: GetUsers()})
}

View File

@@ -129,7 +129,7 @@ func (s *Server) Run(webRoot embed.FS, path string, debug bool) {
for {
for key, ctx := range s.ChatContexts {
// 清理超过 60min 没有更新,则表示为过期会话
if time.Now().Unix()-ctx.LastAccessTime > int64(s.Config.Chat.ChatContextExpireTime) {
if time.Now().Unix()-ctx.LastAccessTime >= int64(s.Config.Chat.ChatContextExpireTime) {
logger.Infof("清理会话上下文: %s", key)
delete(s.ChatContexts, key)
}