Merge branch 'refs/heads/feature-im'
This commit is contained in:
commit
1e559ac29d
|
|
@ -244,7 +244,7 @@ func FindFriendsIDs(user_id int) []Friend {
|
||||||
|
|
||||||
func FindFriends(user_id int) []FriendRet {
|
func FindFriends(user_id int) []FriendRet {
|
||||||
var friends []FriendRet
|
var friends []FriendRet
|
||||||
DB.Debug().Raw("select users.id, users.name, users.email from users join friends on users.id = friends.friend_id where friends.user_id = ? and friends.deleted_at is null", user_id).Scan(&friends)
|
DB.Debug().Raw("select distinct users.id, users.name, users.email from users join friends on users.id = friends.friend_id where friends.user_id = ? and friends.deleted_at is null", user_id).Scan(&friends)
|
||||||
return friends
|
return friends
|
||||||
}
|
}
|
||||||
func GetGroups(user_id int) []Group {
|
func GetGroups(user_id int) []Group {
|
||||||
|
|
@ -289,6 +289,11 @@ func FindGroupUsers(group_id int) []GroupUser {
|
||||||
DB.Debug().Where("group_id = ?", group_id).Find(&groupUsers)
|
DB.Debug().Where("group_id = ?", group_id).Find(&groupUsers)
|
||||||
return groupUsers
|
return groupUsers
|
||||||
}
|
}
|
||||||
|
func FindGroupUsersInfo(group_id int) []FriendRet {
|
||||||
|
var groupUsers []FriendRet
|
||||||
|
DB.Debug().Raw("select distinct users.id, users.name, users.email from users join group_users on users.id = group_users.user_id where group_users.group_id = ?", group_id).Scan(&groupUsers)
|
||||||
|
return groupUsers
|
||||||
|
}
|
||||||
|
|
||||||
func FindGroupByNameLike(groupName string) []Group {
|
func FindGroupByNameLike(groupName string) []Group {
|
||||||
var groups []Group
|
var groups []Group
|
||||||
|
|
|
||||||
|
|
@ -77,6 +77,7 @@ func SetUpIMGroup(router *gin.Engine) {
|
||||||
//获取好友请求
|
//获取好友请求
|
||||||
imGroup.POST("/get_friend_request", GetFriendRequest)
|
imGroup.POST("/get_friend_request", GetFriendRequest)
|
||||||
imGroup.POST("/del_friend_or_group", DelFriendOrGroup)
|
imGroup.POST("/del_friend_or_group", DelFriendOrGroup)
|
||||||
|
imGroup.POST("/get_group_users_info", GetGroupUsersInfo)
|
||||||
}
|
}
|
||||||
func generateRandomHexString(length int) (string, error) {
|
func generateRandomHexString(length int) (string, error) {
|
||||||
bytes := make([]byte, length/2) // 16字节的字符串需要32个十六进制字符,即16个字节
|
bytes := make([]byte, length/2) // 16字节的字符串需要32个十六进制字符,即16个字节
|
||||||
|
|
@ -86,6 +87,31 @@ func generateRandomHexString(length int) (string, error) {
|
||||||
return hex.EncodeToString(bytes), nil
|
return hex.EncodeToString(bytes), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func GetGroupUsersInfo(c *gin.Context) {
|
||||||
|
var req Message
|
||||||
|
id, _ := c.Get("id")
|
||||||
|
user_id := int(id.(float64))
|
||||||
|
if err := c.ShouldBind(&req); err == nil {
|
||||||
|
if req.GroupID == 0 {
|
||||||
|
c.JSON(http.StatusOK, gin.H{"error": "parameter error", "code": proto.ParameterError, "message": "failed"})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
group := dao.FindGroupByID(req.GroupID)
|
||||||
|
if len(group) == 0 {
|
||||||
|
c.JSON(http.StatusOK, gin.H{"error": "parameter error", "code": proto.ParameterError, "message": "failed"})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if group[0].AuthID != user_id {
|
||||||
|
c.JSON(http.StatusOK, gin.H{"error": "no permission", "code": proto.ParameterError, "message": "不是群主"})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
data := dao.FindGroupUsersInfo(req.GroupID)
|
||||||
|
c.JSON(http.StatusOK, gin.H{"code": proto.SuccessCode, "data": data, "message": "success"})
|
||||||
|
} else {
|
||||||
|
c.JSON(http.StatusOK, gin.H{"error": err.Error(), "code": proto.ParameterError, "message": "failed"})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func GetGroups(c *gin.Context) {
|
func GetGroups(c *gin.Context) {
|
||||||
id, _ := c.Get("id")
|
id, _ := c.Get("id")
|
||||||
user_id := int(id.(float64))
|
user_id := int(id.(float64))
|
||||||
|
|
@ -137,6 +163,29 @@ func DelFriendOrGroup(c *gin.Context) {
|
||||||
} else {
|
} else {
|
||||||
c.JSON(http.StatusOK, gin.H{"error": "parameter error", "code": proto.ParameterError, "message": "failed"})
|
c.JSON(http.StatusOK, gin.H{"error": "parameter error", "code": proto.ParameterError, "message": "failed"})
|
||||||
}
|
}
|
||||||
|
} else if req.Type == 4 {
|
||||||
|
//群管理员删除群成员
|
||||||
|
if req.GroupID == 0 {
|
||||||
|
c.JSON(http.StatusOK, gin.H{"error": "parameter error", "code": proto.ParameterError, "message": "failed"})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
//获取群
|
||||||
|
group := dao.FindGroupByID(req.GroupID)
|
||||||
|
if len(group) == 0 {
|
||||||
|
c.JSON(http.StatusOK, gin.H{"error": "parameter error", "code": proto.ParameterError, "message": "failed"})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
//判断是否是群主
|
||||||
|
if group[0].AuthID != cid {
|
||||||
|
c.JSON(http.StatusOK, gin.H{"error": "no permission", "code": proto.ParameterError, "message": "不是群主"})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
err2 := service.QuitGroupService(req.To_user_id, req.GroupID)
|
||||||
|
if err2 == nil {
|
||||||
|
c.JSON(http.StatusOK, gin.H{"code": proto.SuccessCode, "message": "success"})
|
||||||
|
} else {
|
||||||
|
c.JSON(http.StatusOK, gin.H{"error": err2.Error(), "code": proto.OperationFailed, "message": "failed"})
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
c.JSON(http.StatusOK, gin.H{"error": err.Error(), "code": proto.ParameterError, "message": "failed"})
|
c.JSON(http.StatusOK, gin.H{"error": err.Error(), "code": proto.ParameterError, "message": "failed"})
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue