diff --git a/dao/im.go b/dao/im.go index bec4973..5cb5fa2 100644 --- a/dao/im.go +++ b/dao/im.go @@ -49,12 +49,12 @@ func FindSessionByID(id int) Session { } // 获取用户最新的创建时间会话列表 50个 -func FindSessionByUserID(userID int) []Session { +func FindSessionByUserID(userID, sessionType int) []Session { var sessions []Session if proto.Config.SERVER_SQL_LOG { - DB.Debug().Where("user_id = ?", userID).Order("created_at DESC").Limit(50).Find(&sessions) + DB.Debug().Where("user_id = ? and type = ?", userID, sessionType).Order("created_at DESC").Limit(50).Find(&sessions) } else { - DB.Where("user_id = ?", userID).Order("created_at DESC").Limit(50).Find(&sessions) + DB.Where("user_id = ? and type = ?", userID, sessionType).Order("created_at DESC").Limit(50).Find(&sessions) } return sessions } diff --git a/handler/session.go b/handler/session.go index a83ab59..3d93b8b 100644 --- a/handler/session.go +++ b/handler/session.go @@ -16,10 +16,11 @@ func SetUpSessionGroup(router *gin.Engine) { } type Session struct { - ID int `json:"id" form:"id"` - UserID int `json:"user_id" form:"user_id"` - Name string `json:"name" form:"name"` - Type string `json:"type" form:"type"` + ID int `json:"id" form:"id"` + UserID int `json:"user_id" form:"user_id"` + Name string `json:"name" form:"name"` + Type string `json:"type" form:"type"` + SessionType int `json:"session_type" form:"session_type"` } func CreateSession(c *gin.Context) { @@ -46,14 +47,14 @@ func FindSession(c *gin.Context) { if err := c.ShouldBind(&req); err == nil { // 查找会话 if req.Type == "ID" { - err2, session := service.FindSessionByID(req.ID, userID) + err2, session := service.FindSessionByID(req.ID, userID, req.SessionType) if err2 != nil { c.JSON(http.StatusOK, gin.H{"error": err2.Error(), "code": proto.SessionSearchFailed, "message": "failed"}) return } c.JSON(http.StatusOK, gin.H{"code": proto.SuccessCode, "message": "success", "data": session}) } else if req.Type == "UserID" { - sessions := service.FindSessionByUserID(userID) + sessions := service.FindSessionByUserID(userID, req.SessionType) c.JSON(http.StatusOK, gin.H{"code": proto.SuccessCode, "message": "success", "data": sessions}) } else { c.JSON(http.StatusOK, gin.H{"error": "type error", "code": proto.SessionSearchFailed, "message": "failed"}) diff --git a/service/imService.go b/service/imService.go index a22a1f3..f1b5a11 100644 --- a/service/imService.go +++ b/service/imService.go @@ -19,8 +19,8 @@ func CreateSession(userID, Type int, name string) (error, uint) { } // 查找用户的会话列表 -func FindSessionByUserID(userID int) []proto.SessionResponse { - sessions := dao.FindSessionByUserID(userID) +func FindSessionByUserID(userID, sessionType int) []proto.SessionResponse { + sessions := dao.FindSessionByUserID(userID, sessionType) sessionsMsgCounts := dao.FindSessionMessageCountByUserID(userID) sessionsTokens := dao.FindModelTotalTokensBySessionID(userID) smap := make(map[int]int) @@ -45,7 +45,7 @@ func FindSessionByUserID(userID int) []proto.SessionResponse { } return res } -func FindSessionByID(id, userID int) (error, []dao.Session) { +func FindSessionByID(id, userID, sessionType int) (error, []dao.Session) { session := dao.FindSessionByID(id) var res []dao.Session if session.UserID != userID {