This commit is contained in:
wangchuxiao 2023-01-04 11:28:52 +08:00
parent 89a4fe96b5
commit cbe7dcebea
7 changed files with 1580 additions and 2449 deletions

View File

@ -0,0 +1,32 @@
package friend
import (
common "Open_IM/internal/api_to_rpc"
api "Open_IM/pkg/base_info"
"Open_IM/pkg/common/config"
"Open_IM/pkg/common/token_verify"
rpc "Open_IM/pkg/proto/friend"
"Open_IM/pkg/utils"
"github.com/gin-gonic/gin"
)
// 不一致
func AddBlacklist(c *gin.Context) {
common.ApiToRpc(c, &api.AddBlacklistReq{}, &api.AddBlacklistResp{},
config.Config.RpcRegisterName.OpenImFriendName, rpc.NewFriendClient, utils.GetSelfFuncName(), token_verify.ParseUserIDFromToken)
}
func ImportFriend1(c *gin.Context) {
common.ApiToRpc(c, &api.ImportFriendReq{}, &api.ImportFriendResp{},
config.Config.RpcRegisterName.OpenImFriendName, rpc.NewFriendClient, utils.GetSelfFuncName(), token_verify.ParseUserIDFromToken)
}
func AddFriend1(c *gin.Context) {
common.ApiToRpc(c, &api.AddFriendReq{}, &api.AddFriendResp{},
config.Config.RpcRegisterName.OpenImFriendName, rpc.NewFriendClient, utils.GetSelfFuncName(), token_verify.ParseUserIDFromToken)
}
func AddFriendResponse1(c *gin.Context) {
common.ApiToRpc(c, &api.AddFriendResponseReq{}, &api.AddFriendResponseResp{},
config.Config.RpcRegisterName.OpenImFriendName, rpc.NewFriendClient, utils.GetSelfFuncName(), token_verify.ParseUserIDFromToken)
}

View File

@ -17,6 +17,8 @@ import (
sdkws "Open_IM/pkg/proto/sdk_ws"
"Open_IM/pkg/utils"
"context"
"errors"
"fmt"
"net"
"strconv"
"strings"
@ -102,15 +104,16 @@ func (s *friendServer) AddBlacklist(ctx context.Context, req *pbFriend.AddBlackl
log.NewInfo(req.CommID.OperationID, "AddBlacklist args ", req.String())
ok := token_verify.CheckAccess(req.CommID.OpUserID, req.CommID.FromUserID)
if !ok {
log.NewError(req.CommID.OperationID, "CheckAccess false ", req.CommID.OpUserID, req.CommID.FromUserID)
return &pbFriend.AddBlacklistResp{CommonResp: &pbFriend.CommonResp{ErrCode: constant.ErrAccess.ErrCode, ErrMsg: constant.ErrAccess.ErrMsg}}, nil
err := errors.New("CheckAccess false")
log.NewError(req.CommID.OperationID, err.Error(), req.CommID.OpUserID, req.CommID.FromUserID)
return &pbFriend.AddBlacklistResp{CommonResp: constant.Error2CommResp(constant.ErrNoPermission, err)}, nil
}
black := db.Black{OwnerUserID: req.CommID.FromUserID, BlockUserID: req.CommID.ToUserID, OperatorUserID: req.CommID.OpUserID}
err := imdb.InsertInToUserBlackList(black)
if err != nil {
log.NewError(req.CommID.OperationID, "InsertInToUserBlackList failed ", err.Error())
return &pbFriend.AddBlacklistResp{CommonResp: &pbFriend.CommonResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: err.Error()}}, nil
return &pbFriend.AddBlacklistResp{CommonResp: constant.Error2CommResp(constant.ErrDatabase, err)}, nil
}
log.NewInfo(req.CommID.OperationID, "AddBlacklist rpc ok ", req.CommID.FromUserID, req.CommID.ToUserID)
@ -118,21 +121,22 @@ func (s *friendServer) AddBlacklist(ctx context.Context, req *pbFriend.AddBlackl
if etcdConn == nil {
errMsg := req.CommID.OperationID + "getcdv3.GetDefaultConn == nil"
log.NewError(req.CommID.OperationID, errMsg)
return &pbFriend.AddBlacklistResp{CommonResp: &pbFriend.CommonResp{ErrCode: constant.ErrInternal.ErrCode, ErrMsg: errMsg}}, nil
return &pbFriend.AddBlacklistResp{CommonResp: constant.Error2CommResp(constant.ErrInternalServer, err)}, nil
}
cacheClient := pbCache.NewCacheClient(etcdConn)
cacheResp, err := cacheClient.DelBlackIDListFromCache(context.Background(), &pbCache.DelBlackIDListFromCacheReq{UserID: req.CommID.FromUserID, OperationID: req.CommID.OperationID})
if err != nil {
log.NewError(req.CommID.OperationID, "DelBlackIDListFromCache rpc call failed ", err.Error())
return &pbFriend.AddBlacklistResp{CommonResp: &pbFriend.CommonResp{ErrCode: 500, ErrMsg: "AddBlackUserToCache rpc call failed"}}, nil
return &pbFriend.AddBlacklistResp{CommonResp: constant.Error2CommResp(constant.ErrInternalServer, err)}, nil
}
if cacheResp.CommonResp.ErrCode != 0 {
err = errors.New(fmt.Sprintf("call DelBlackIDListFromCache rpc failed code is %d, err is %s, args is %s", cacheResp.CommonResp.ErrCode, cacheResp.CommonResp.ErrMsg, req.CommID.FromUserID))
log.NewError(req.CommID.OperationID, "DelBlackIDListFromCache rpc logic call failed ", cacheResp.String())
return &pbFriend.AddBlacklistResp{CommonResp: &pbFriend.CommonResp{ErrCode: cacheResp.CommonResp.ErrCode, ErrMsg: cacheResp.CommonResp.ErrMsg}}, nil
return &pbFriend.AddBlacklistResp{CommonResp: constant.Error2CommResp(constant.ErrInternalServer, err)}, nil
}
chat.BlackAddedNotification(req)
return &pbFriend.AddBlacklistResp{CommonResp: &pbFriend.CommonResp{}}, nil
return &pbFriend.AddBlacklistResp{CommonResp: &sdkws.CommonResp{}}, nil
}
func (s *friendServer) AddFriend(ctx context.Context, req *pbFriend.AddFriendReq) (*pbFriend.AddFriendResp, error) {

View File

@ -1,6 +1,7 @@
package constant
import (
sdkws "Open_IM/pkg/proto/sdk_ws"
"errors"
"gorm.io/gorm"
)
@ -76,6 +77,17 @@ func ToAPIErrWithErr(err error) ErrInfo {
return ErrDefaultOther
}
func Error2CommResp(info ErrInfo, detailErr error) *sdkws.CommonResp {
err := &sdkws.CommonResp{
ErrCode: info.ErrCode,
ErrMsg: info.ErrMsg,
}
if detailErr != nil {
err.DetailErrMsg = detailErr.Error()
}
return err
}
const (
FormattingError = 10001
HasRegistered = 10002

File diff suppressed because it is too large Load Diff

View File

@ -76,7 +76,7 @@ message AddBlacklistReq{
CommID CommID = 1;
}
message AddBlacklistResp{
CommonResp CommonResp = 1;
server_api_params.CommonResp commonResp = 1;
}

File diff suppressed because it is too large Load Diff

View File

@ -5,7 +5,11 @@ package server_api_params;
////////////////////////////////base///////////////////////////////
message CommonResp{
int32 errCode = 1;
string errMsg = 2;
string detailErrMsg =3;
}
message GroupInfo{
string groupID = 1;