添加加入群组请求
This commit is contained in:
parent
61eb0db82b
commit
ea6a87bb33
12
dao/im.go
12
dao/im.go
|
|
@ -78,6 +78,18 @@ func GetMsgGroupByIndex(group_id, index int) ([]GroupMessage, error) {
|
|||
|
||||
}
|
||||
|
||||
func GetGroupRequestUsers(user_id int) []FriendRequest {
|
||||
var users []FriendRequest
|
||||
DB.Debug().Raw("select id,im_id,name,email FROM (SELECT im_id,from_user_id,group_id FROM (( SELECT id as im_id,from_user_id,group_id FROM messages WHERE type=? and status=? ) as m JOIN groups as g on g.id=m.group_id ) where g.auth_id=? ) as e JOIN users as u ON e.from_user_id=u.id", proto.MSG_TYPE_GROUP_INVI, 0, user_id).Scan(&users)
|
||||
return users
|
||||
}
|
||||
|
||||
func GetMsgUserGroupReq(from_user_id, group_id int) ([]Message, error) {
|
||||
var msgs []Message
|
||||
res := DB.Debug().Where("from_user_id = ? and group_id = ? and type = ? and status = ?", from_user_id, group_id, 5, 0).Find(&msgs)
|
||||
return msgs, res.Error
|
||||
}
|
||||
|
||||
// 获取邀请消息
|
||||
func GetFriendGroupReq(user_id int) ([]Message, error) {
|
||||
var msgs []Message
|
||||
|
|
|
|||
|
|
@ -68,6 +68,7 @@ func SetUpIMGroup(router *gin.Engine) {
|
|||
imGroup.POST("/accept_invite", AcceptInvite)
|
||||
imGroup.POST("/create_group", CreateGroup)
|
||||
imGroup.POST("/get_group", GetGroups)
|
||||
imGroup.POST("/get_group_req_user", GetFriendRequest)
|
||||
imGroup.GET("/sse_msg", ServerSendMsg)
|
||||
imGroup.GET("/ws_v2", ServerSsendMsgV2)
|
||||
imGroup.POST("/get_friend_list", GetFriendList) //获取好友列表,包括群聊
|
||||
|
|
@ -175,10 +176,22 @@ func GetMessage(c *gin.Context) {
|
|||
}
|
||||
|
||||
func GetFriendRequest(c *gin.Context) {
|
||||
var req Message
|
||||
id, _ := c.Get("id")
|
||||
user_id := int(id.(float64))
|
||||
data := service.GetFriendRequest(user_id)
|
||||
c.JSON(http.StatusOK, gin.H{"code": proto.SuccessCode, "data": data, "message": "success"})
|
||||
|
||||
if err := c.ShouldBind(&req); err == nil {
|
||||
if req.Type == 1 {
|
||||
data := service.GetGroupRequestUsers(user_id)
|
||||
c.JSON(http.StatusOK, gin.H{"code": proto.SuccessCode, "data": data, "message": "success"})
|
||||
} else {
|
||||
data := service.GetFriendRequest(user_id)
|
||||
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 CreateGroup(c *gin.Context) {
|
||||
|
|
|
|||
|
|
@ -71,6 +71,11 @@ func CreateGeneralMessageService(from_id, to_id, msg_type, group_id int, content
|
|||
if len(groupUser) > 0 {
|
||||
return errors.New("已在群里"), 0
|
||||
}
|
||||
//查看是否已经发送过请求
|
||||
res, _ := dao.GetMsgUserGroupReq(from_id, group_id)
|
||||
if len(res) > 0 {
|
||||
return errors.New("已发送请求"), res[0].ID
|
||||
}
|
||||
err, id = dao.CreateGeneralMessage(from_id, to_id, msg_type, 0, group_id, content)
|
||||
|
||||
case proto.MSG_TYPE_GROUP_INVI:
|
||||
|
|
@ -116,6 +121,9 @@ func GetMsgUserByIndexService(from_id, to_id, index, msq_type, from_user_id, gro
|
|||
func AddFriendService(id, from_user_id, to_user_id int) error {
|
||||
// 业务逻辑
|
||||
res := dao.FindMessageByID(uint(id))
|
||||
if len(res) == 0 {
|
||||
return errors.New("no such message")
|
||||
}
|
||||
if res[0].FromUserID == to_user_id && res[0].ToUserID == from_user_id {
|
||||
friend := dao.FindFriend(from_user_id, to_user_id)
|
||||
if len(friend) > 0 {
|
||||
|
|
@ -217,3 +225,9 @@ func GetGroupByNameLike(name string) []dao.Group {
|
|||
groups := dao.FindGroupByNameLike(name)
|
||||
return groups
|
||||
}
|
||||
|
||||
func GetGroupRequestUsers(user_id int) []dao.FriendRequest {
|
||||
//获取群聊请求
|
||||
users := dao.GetGroupRequestUsers(user_id)
|
||||
return users
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue