Compare commits
No commits in common. "e7898bdd9b59c295be44c3d7a5050495c6c9ae28" and "c3d802c2d97e57525eadb05b43895f2dbb6cd324" have entirely different histories.
e7898bdd9b
...
c3d802c2d9
|
|
@ -203,6 +203,7 @@ 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 {
|
||||||
|
|
@ -265,53 +266,28 @@ 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 {
|
||||||
if req.Type == 1 {
|
|
||||||
//同意添加好友
|
|
||||||
err2 := service.AddFriendService(req.ID, cid, req.To_user_id)
|
err2 := service.AddFriendService(req.ID, cid, req.To_user_id)
|
||||||
if err2 == nil {
|
if err2 == nil {
|
||||||
c.JSON(http.StatusOK, gin.H{"code": proto.SuccessCode, "message": "success"})
|
c.JSON(http.StatusOK, gin.H{"code": proto.SuccessCode, "message": "success"})
|
||||||
} else {
|
} else {
|
||||||
c.JSON(http.StatusOK, gin.H{"error": err2.Error(), "code": proto.OperationFailed, "message": "failed"})
|
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 {
|
|
||||||
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 {
|
||||||
if req.Type == 1 {
|
|
||||||
//拒绝添加好友
|
|
||||||
err2 := service.RejectFriendService(req.ID, cid, req.To_user_id)
|
err2 := service.RejectFriendService(req.ID, cid, req.To_user_id)
|
||||||
if err2 == nil {
|
if err2 == nil {
|
||||||
c.JSON(http.StatusOK, gin.H{"code": proto.SuccessCode, "message": "success"})
|
c.JSON(http.StatusOK, gin.H{"code": proto.SuccessCode, "message": "success"})
|
||||||
} else {
|
} else {
|
||||||
c.JSON(http.StatusOK, gin.H{"error": err2.Error(), "code": proto.OperationFailed, "message": "failed"})
|
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 {
|
|
||||||
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"})
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -370,39 +370,3 @@ func SetRobotMsg(person_id, robot_id int, msg string) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 同意用户加入群聊
|
|
||||||
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