mirror of
https://github.com/openimsdk/open-im-server.git
synced 2025-08-12 22:46:06 +08:00
fix friend bug
This commit is contained in:
parent
c5d144bcc4
commit
1c528b0f04
@ -157,14 +157,35 @@ func (s *friendServer) AddFriend(ctx context.Context, req *pbFriend.AddFriendReq
|
||||
ErrMsg: callbackResp.ErrMsg,
|
||||
}}, nil
|
||||
}
|
||||
var isSend = true
|
||||
userIDList, err := rocksCache.GetFriendIDListFromCache(req.CommID.ToUserID)
|
||||
if err != nil {
|
||||
log.NewError(req.CommID.OperationID, "GetFriendIDListFromCache failed ", err.Error(), req.CommID.ToUserID)
|
||||
return &pbFriend.AddFriendResp{CommonResp: &pbFriend.CommonResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: err.Error()}}, nil
|
||||
}
|
||||
userIDList2, err := rocksCache.GetFriendIDListFromCache(req.CommID.FromUserID)
|
||||
if err != nil {
|
||||
log.NewError(req.CommID.OperationID, "GetUserByUserID failed ", err.Error(), req.CommID.FromUserID)
|
||||
return &pbFriend.AddFriendResp{CommonResp: &pbFriend.CommonResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: err.Error()}}, nil
|
||||
}
|
||||
|
||||
for _, v := range userIDList {
|
||||
if v == req.CommID.FromUserID {
|
||||
for _, v2 := range userIDList2 {
|
||||
if v2 == req.CommID.ToUserID {
|
||||
isSend = false
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//Cannot add non-existent users
|
||||
|
||||
if isSend {
|
||||
if _, err := imdb.GetUserByUserID(req.CommID.ToUserID); err != nil {
|
||||
log.NewError(req.CommID.OperationID, "GetUserByUserID failed ", err.Error(), req.CommID.ToUserID)
|
||||
return &pbFriend.AddFriendResp{CommonResp: &pbFriend.CommonResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: constant.ErrDB.ErrMsg}}, nil
|
||||
}
|
||||
|
||||
//Establish a latest relationship in the friend request table
|
||||
friendRequest := db.FriendRequest{
|
||||
HandleResult: 0, ReqMsg: req.ReqMsg, CreateTime: time.Now()}
|
||||
utils.CopyStructFields(&friendRequest, req.CommID)
|
||||
@ -180,6 +201,9 @@ func (s *friendServer) AddFriend(ctx context.Context, req *pbFriend.AddFriendReq
|
||||
}
|
||||
|
||||
chat.FriendApplicationNotification(req)
|
||||
}
|
||||
//Establish a latest relationship in the friend request table
|
||||
|
||||
return &pbFriend.AddFriendResp{CommonResp: &pbFriend.CommonResp{}}, nil
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user