拒绝与同意用户加入群聊
This commit is contained in:
parent
e192954037
commit
6d45baa4bd
|
|
@ -203,7 +203,6 @@ func GetMessage(c *gin.Context) {
|
||||||
id := int(user_id.(float64))
|
id := int(user_id.(float64))
|
||||||
//解析参数
|
//解析参数
|
||||||
if err := c.ShouldBind(&req); err == nil {
|
if err := c.ShouldBind(&req); err == nil {
|
||||||
|
|
||||||
if req.Type == 2 {
|
if req.Type == 2 {
|
||||||
msgs, err2 := dao.GetMsgGroupByIndex(req.GroupID, req.Index)
|
msgs, err2 := dao.GetMsgGroupByIndex(req.GroupID, req.Index)
|
||||||
if err2 == nil {
|
if err2 == nil {
|
||||||
|
|
@ -266,27 +265,52 @@ func AcceptInvite(c *gin.Context) {
|
||||||
user_id, _ := c.Get("id")
|
user_id, _ := c.Get("id")
|
||||||
cid := int(user_id.(float64))
|
cid := int(user_id.(float64))
|
||||||
if err := c.ShouldBind(&req); err == nil {
|
if err := c.ShouldBind(&req); err == nil {
|
||||||
err2 := service.AddFriendService(req.ID, cid, req.To_user_id)
|
if req.Type == 1 {
|
||||||
if err2 == nil {
|
//同意添加好友
|
||||||
c.JSON(http.StatusOK, gin.H{"code": proto.SuccessCode, "message": "success"})
|
err2 := service.AddFriendService(req.ID, cid, req.To_user_id)
|
||||||
|
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 if req.Type == 2 {
|
||||||
|
//同意加入群聊
|
||||||
|
err3 := service.JoinGroupService(req.ID, cid, req.To_user_id, req.GroupID)
|
||||||
|
if err3 == nil {
|
||||||
|
c.JSON(http.StatusOK, gin.H{"code": proto.SuccessCode, "message": "success"})
|
||||||
|
} else {
|
||||||
|
c.JSON(http.StatusOK, gin.H{"error": err3.Error(), "code": proto.OperationFailed, "message": "failed"})
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
c.JSON(http.StatusOK, gin.H{"error": err2.Error(), "code": proto.OperationFailed, "message": "failed"})
|
c.JSON(http.StatusOK, gin.H{"error": err.Error(), "code": proto.ParameterError, "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"})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func RejectInvite(c *gin.Context) {
|
func RejectInvite(c *gin.Context) {
|
||||||
var req Message
|
var req Message
|
||||||
user_id, _ := c.Get("id")
|
user_id, _ := c.Get("id")
|
||||||
cid := int(user_id.(float64))
|
cid := int(user_id.(float64))
|
||||||
if err := c.ShouldBind(&req); err == nil {
|
if err := c.ShouldBind(&req); err == nil {
|
||||||
err2 := service.RejectFriendService(req.ID, cid, req.To_user_id)
|
if req.Type == 1 {
|
||||||
if err2 == nil {
|
//拒绝添加好友
|
||||||
c.JSON(http.StatusOK, gin.H{"code": proto.SuccessCode, "message": "success"})
|
err2 := service.RejectFriendService(req.ID, cid, req.To_user_id)
|
||||||
|
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 if req.Type == 2 {
|
||||||
|
//拒绝加入群聊
|
||||||
|
err3 := service.RejectGroupService(req.ID, cid, req.To_user_id, req.GroupID)
|
||||||
|
if err3 == nil {
|
||||||
|
c.JSON(http.StatusOK, gin.H{"code": proto.SuccessCode, "message": "success"})
|
||||||
|
} else {
|
||||||
|
c.JSON(http.StatusOK, gin.H{"error": err3.Error(), "code": proto.OperationFailed, "message": "failed"})
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
c.JSON(http.StatusOK, gin.H{"error": err2.Error(), "code": proto.OperationFailed, "message": "failed"})
|
c.JSON(http.StatusOK, gin.H{"error": "parameter error", "code": proto.ParameterError, "message": "failed type error"})
|
||||||
}
|
}
|
||||||
} 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"})
|
||||||
|
|
|
||||||
|
|
@ -340,3 +340,39 @@ func SetGroupCache(group_id int) bool {
|
||||||
res := worker.SetRedisSet("group_"+strconv.Itoa(group_id)+"_users", ids, time.Hour*12)
|
res := worker.SetRedisSet("group_"+strconv.Itoa(group_id)+"_users", ids, time.Hour*12)
|
||||||
return res
|
return res
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 同意用户加入群聊
|
||||||
|
func JoinGroupService(im_id, cid, user_id, group_id int) error {
|
||||||
|
|
||||||
|
group := dao.FindGroup(group_id)
|
||||||
|
if len(group) == 0 {
|
||||||
|
return errors.New("no such group")
|
||||||
|
}
|
||||||
|
if group[0].AuthID != cid {
|
||||||
|
return errors.New("no permission")
|
||||||
|
}
|
||||||
|
|
||||||
|
//判断是否在群里
|
||||||
|
groupUser := dao.FindGroupUser(user_id, group_id)
|
||||||
|
if len(groupUser) > 0 {
|
||||||
|
return errors.New("已在群里")
|
||||||
|
}
|
||||||
|
err, _ := dao.JoinGroup(group_id, user_id)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
err = dao.UpdateMessageStatus(uint(im_id), 1)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
func RejectGroupService(im_id, cid, user_id, group_id int) error {
|
||||||
|
group := dao.FindGroup(group_id)
|
||||||
|
if len(group) == 0 {
|
||||||
|
return errors.New("no such group")
|
||||||
|
}
|
||||||
|
if group[0].AuthID != cid {
|
||||||
|
return errors.New("no permission")
|
||||||
|
}
|
||||||
|
err := dao.UpdateMessageStatus(uint(im_id), 1) // 拒绝,设为已读
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue