mirror of
https://github.com/openimsdk/open-im-server.git
synced 2026-05-06 01:55:58 +08:00
Merge remote-tracking branch 'origin/errcode' into errcode
This commit is contained in:
@@ -3,6 +3,7 @@ package admin_cms
|
||||
import (
|
||||
"Open_IM/pkg/common/config"
|
||||
"Open_IM/pkg/common/constant"
|
||||
"Open_IM/pkg/common/db/cache"
|
||||
"Open_IM/pkg/common/db/controller"
|
||||
"Open_IM/pkg/common/db/relation"
|
||||
"Open_IM/pkg/common/log"
|
||||
@@ -36,16 +37,26 @@ type adminCMSServer struct {
|
||||
adminCMSInterface controller.AdminCMSInterface
|
||||
groupInterface controller.GroupInterface
|
||||
userInterface controller.UserInterface
|
||||
chatLogInterface controller.ChatLogInterface
|
||||
}
|
||||
|
||||
func NewAdminCMSServer(port int) *adminCMSServer {
|
||||
log.NewPrivateLog(constant.LogFileName)
|
||||
return &adminCMSServer{
|
||||
admin := &adminCMSServer{
|
||||
rpcPort: port,
|
||||
rpcRegisterName: config.Config.RpcRegisterName.OpenImAdminCMSName,
|
||||
etcdSchema: config.Config.Etcd.EtcdSchema,
|
||||
etcdAddr: config.Config.Etcd.EtcdAddr,
|
||||
}
|
||||
var mysql relation.Mysql
|
||||
var redis cache.RedisClient
|
||||
mysql.InitConn()
|
||||
redis.InitRedis()
|
||||
admin.userInterface = controller.NewUserController(mysql.GormConn())
|
||||
admin.groupInterface = controller.NewGroupController(mysql.GormConn(), redis.GetClient(), nil)
|
||||
admin.adminCMSInterface = controller.NewAdminCMSController(mysql.GormConn())
|
||||
admin.chatLogInterface = controller.NewChatLogController(mysql.GormConn())
|
||||
return admin
|
||||
}
|
||||
|
||||
func (s *adminCMSServer) Run() {
|
||||
@@ -125,18 +136,15 @@ func (s *adminCMSServer) AdminLogin(ctx context.Context, req *pbAdminCMS.AdminLo
|
||||
}
|
||||
resp.UserName = admin.Nickname
|
||||
resp.FaceURL = admin.FaceURL
|
||||
log.NewInfo(tracelog.GetOperationID(ctx), utils.GetSelfFuncName(), "resp: ", resp.String())
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
func (s *adminCMSServer) GetUserToken(ctx context.Context, req *pbAdminCMS.GetUserTokenReq) (*pbAdminCMS.GetUserTokenResp, error) {
|
||||
resp := &pbAdminCMS.GetUserTokenResp{}
|
||||
token, expTime, err := token_verify.CreateToken(req.UserID, int(req.PlatformID))
|
||||
if err != nil {
|
||||
return resp, nil
|
||||
return nil, err
|
||||
}
|
||||
resp.Token = token
|
||||
resp.ExpTime = expTime
|
||||
resp := &pbAdminCMS.GetUserTokenResp{Token: token, ExpTime: expTime}
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
@@ -156,8 +164,7 @@ func (s *adminCMSServer) GetChatLogs(ctx context.Context, req *pbAdminCMS.GetCha
|
||||
}
|
||||
chatLog.SendTime = sendTime
|
||||
}
|
||||
resp := &pbAdminCMS.GetChatLogsResp{}
|
||||
num, chatLogs, err := relation.GetChatLog(&chatLog, req.Pagination.PageNumber, req.Pagination.ShowNumber, []int32{
|
||||
num, chatLogs, err := s.chatLogInterface.GetChatLog(&chatLog, req.Pagination.PageNumber, req.Pagination.ShowNumber, []int32{
|
||||
constant.Text,
|
||||
constant.Picture,
|
||||
constant.Voice,
|
||||
@@ -177,6 +184,7 @@ func (s *adminCMSServer) GetChatLogs(ctx context.Context, req *pbAdminCMS.GetCha
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
resp := &pbAdminCMS.GetChatLogsResp{}
|
||||
resp.ChatLogsNum = int32(num)
|
||||
for _, chatLog := range chatLogs {
|
||||
pbChatLog := &pbAdminCMS.ChatLog{}
|
||||
|
||||
+64
-79
@@ -1,17 +1,18 @@
|
||||
package auth
|
||||
|
||||
import (
|
||||
"Open_IM/internal/common/check"
|
||||
"Open_IM/pkg/common/constant"
|
||||
imdb "Open_IM/pkg/common/db/mysql_model/im_mysql_model"
|
||||
"Open_IM/pkg/common/db/controller"
|
||||
"Open_IM/pkg/common/log"
|
||||
promePkg "Open_IM/pkg/common/prometheus"
|
||||
"Open_IM/pkg/common/token_verify"
|
||||
"Open_IM/pkg/common/tracelog"
|
||||
"Open_IM/pkg/getcdv3"
|
||||
pbAuth "Open_IM/pkg/proto/auth"
|
||||
pbRelay "Open_IM/pkg/proto/relay"
|
||||
"Open_IM/pkg/utils"
|
||||
"context"
|
||||
"errors"
|
||||
"net"
|
||||
"strconv"
|
||||
"strings"
|
||||
@@ -23,93 +24,76 @@ import (
|
||||
"google.golang.org/grpc"
|
||||
)
|
||||
|
||||
func (rpc *rpcAuth) UserRegister(_ context.Context, req *pbAuth.UserRegisterReq) (*pbAuth.UserRegisterResp, error) {
|
||||
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), " rpc args ", req.String())
|
||||
var user imdb.User
|
||||
utils.CopyStructFields(&user, req.UserInfo)
|
||||
if req.UserInfo.BirthStr != "" {
|
||||
time, err := utils.TimeStringToTime(req.UserInfo.BirthStr)
|
||||
if err != nil {
|
||||
log.NewError(req.OperationID, "TimeStringToTime failed ", err.Error(), req.UserInfo.BirthStr)
|
||||
return &pbAuth.UserRegisterResp{CommonResp: &pbAuth.CommonResp{ErrCode: constant.ErrArgs.ErrCode, ErrMsg: "TimeStringToTime failed:" + err.Error()}}, nil
|
||||
}
|
||||
user.Birth = time
|
||||
func (s *rpcAuth) UserToken(ctx context.Context, req *pbAuth.UserTokenReq) (*pbAuth.UserTokenResp, error) {
|
||||
resp := pbAuth.UserTokenResp{}
|
||||
if _, err := check.GetUsersInfo(ctx, req.UserID); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
log.Debug(req.OperationID, "copy ", user, req.UserInfo)
|
||||
err := imdb.UserRegister(user)
|
||||
token, err := s.CreateToken(ctx, req.UserID, int(req.PlatformID), config.Config.TokenPolicy.AccessExpire)
|
||||
if err != nil {
|
||||
errMsg := req.OperationID + " imdb.UserRegister failed " + err.Error() + user.UserID
|
||||
log.NewError(req.OperationID, errMsg, user)
|
||||
return &pbAuth.UserRegisterResp{CommonResp: &pbAuth.CommonResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: errMsg}}, nil
|
||||
return nil, err
|
||||
}
|
||||
promePkg.PromeInc(promePkg.UserRegisterCounter)
|
||||
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), " rpc return ", pbAuth.UserRegisterResp{CommonResp: &pbAuth.CommonResp{}})
|
||||
return &pbAuth.UserRegisterResp{CommonResp: &pbAuth.CommonResp{}}, nil
|
||||
}
|
||||
|
||||
func (rpc *rpcAuth) UserToken(_ context.Context, req *pbAuth.UserTokenReq) (*pbAuth.UserTokenResp, error) {
|
||||
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), " rpc args ", req.String())
|
||||
_, err := imdb.GetUserByUserID(req.FromUserID)
|
||||
if err != nil {
|
||||
log.NewError(req.OperationID, "not this user:", req.FromUserID, req.String())
|
||||
return &pbAuth.UserTokenResp{CommonResp: &pbAuth.CommonResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: err.Error()}}, nil
|
||||
}
|
||||
tokens, expTime, err := token_verify.CreateToken(req.FromUserID, int(req.Platform))
|
||||
if err != nil {
|
||||
errMsg := req.OperationID + " token_verify.CreateToken failed " + err.Error() + req.FromUserID + utils.Int32ToString(req.Platform)
|
||||
log.NewError(req.OperationID, errMsg)
|
||||
return &pbAuth.UserTokenResp{CommonResp: &pbAuth.CommonResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: errMsg}}, nil
|
||||
}
|
||||
promePkg.PromeInc(promePkg.UserLoginCounter)
|
||||
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), " rpc return ", pbAuth.UserTokenResp{CommonResp: &pbAuth.CommonResp{}, Token: tokens, ExpiredTime: expTime})
|
||||
return &pbAuth.UserTokenResp{CommonResp: &pbAuth.CommonResp{}, Token: tokens, ExpiredTime: expTime}, nil
|
||||
}
|
||||
|
||||
func (rpc *rpcAuth) ParseToken(_ context.Context, req *pbAuth.ParseTokenReq) (*pbAuth.ParseTokenResp, error) {
|
||||
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), " rpc args ", req.String())
|
||||
claims, err := token_verify.ParseToken(req.Token, req.OperationID)
|
||||
if err != nil {
|
||||
errMsg := "ParseToken failed " + err.Error() + req.OperationID + " token " + req.Token
|
||||
log.Error(req.OperationID, errMsg, "token:", req.Token)
|
||||
return &pbAuth.ParseTokenResp{CommonResp: &pbAuth.CommonResp{ErrCode: 4001, ErrMsg: errMsg}}, nil
|
||||
}
|
||||
resp := pbAuth.ParseTokenResp{CommonResp: &pbAuth.CommonResp{}, UserID: claims.UID, Platform: claims.Platform, ExpireTimeSeconds: uint32(claims.ExpiresAt.Unix())}
|
||||
log.Info(req.OperationID, utils.GetSelfFuncName(), " rpc return ", resp.String())
|
||||
resp.Token = token
|
||||
resp.ExpireTimeSeconds = config.Config.TokenPolicy.AccessExpire
|
||||
return &resp, nil
|
||||
}
|
||||
|
||||
func (rpc *rpcAuth) ForceLogout(_ context.Context, req *pbAuth.ForceLogoutReq) (*pbAuth.ForceLogoutResp, error) {
|
||||
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), " rpc args ", req.String())
|
||||
if !token_verify.IsManagerUserID(req.OpUserID) {
|
||||
errMsg := req.OperationID + " IsManagerUserID false " + req.OpUserID
|
||||
log.NewError(req.OperationID, errMsg)
|
||||
return &pbAuth.ForceLogoutResp{CommonResp: &pbAuth.CommonResp{ErrCode: constant.ErrAccess.ErrCode, ErrMsg: errMsg}}, nil
|
||||
func (s *rpcAuth) parseToken(ctx context.Context, tokensString, operationID string) (claims *token_verify.Claims, err error) {
|
||||
claims, err = token_verify.GetClaimFromToken(tokensString)
|
||||
if err != nil {
|
||||
return nil, utils.Wrap(err, "")
|
||||
}
|
||||
//if err := token_verify.DeleteToken(req.FromUserID, int(req.Platform)); err != nil {
|
||||
// errMsg := req.OperationID + " DeleteToken failed " + err.Error() + req.FromUserID + utils.Int32ToString(req.Platform)
|
||||
// log.NewError(req.OperationID, errMsg)
|
||||
// return &pbAuth.ForceLogoutResp{CommonResp: &pbAuth.CommonResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: errMsg}}, nil
|
||||
//}
|
||||
if err := rpc.forceKickOff(req.FromUserID, req.Platform, req.OperationID); err != nil {
|
||||
errMsg := req.OperationID + " forceKickOff failed " + err.Error() + req.FromUserID + utils.Int32ToString(req.Platform)
|
||||
log.NewError(req.OperationID, errMsg)
|
||||
return &pbAuth.ForceLogoutResp{CommonResp: &pbAuth.CommonResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: errMsg}}, nil
|
||||
m, err := s.GetTokens(ctx, claims.UID, claims.Platform)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), " rpc return ", pbAuth.UserTokenResp{CommonResp: &pbAuth.CommonResp{}})
|
||||
return &pbAuth.ForceLogoutResp{CommonResp: &pbAuth.CommonResp{}}, nil
|
||||
|
||||
if v, ok := m[tokensString]; ok {
|
||||
switch v {
|
||||
case constant.NormalToken:
|
||||
return claims, nil
|
||||
case constant.KickedToken:
|
||||
return nil, utils.Wrap(constant.ErrTokenKicked, "this token has been kicked by other same terminal ")
|
||||
default:
|
||||
return nil, utils.Wrap(constant.ErrTokenUnknown, "")
|
||||
}
|
||||
}
|
||||
return nil, utils.Wrap(constant.ErrTokenNotExist, "redis token map not find")
|
||||
}
|
||||
|
||||
func (rpc *rpcAuth) forceKickOff(userID string, platformID int32, operationID string) error {
|
||||
log.NewInfo(operationID, utils.GetSelfFuncName(), " args ", userID, platformID)
|
||||
func (s *rpcAuth) ParseToken(ctx context.Context, req *pbAuth.ParseTokenReq) (*pbAuth.ParseTokenResp, error) {
|
||||
resp := pbAuth.ParseTokenResp{}
|
||||
claims, err := s.parseToken(ctx, req.Token, req.OperationID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
resp.UserID = claims.UID
|
||||
resp.Platform = claims.Platform
|
||||
resp.ExpireTimeSeconds = claims.ExpiresAt.Unix()
|
||||
return &resp, nil
|
||||
}
|
||||
|
||||
func (s *rpcAuth) ForceLogout(ctx context.Context, req *pbAuth.ForceLogoutReq) (*pbAuth.ForceLogoutResp, error) {
|
||||
resp := pbAuth.ForceLogoutResp{}
|
||||
if err := token_verify.CheckAdmin(ctx); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if err := s.forceKickOff(ctx, req.UserID, req.PlatformID, tracelog.GetOperationID(ctx)); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &resp, nil
|
||||
}
|
||||
|
||||
func (s *rpcAuth) forceKickOff(ctx context.Context, userID string, platformID int32, operationID string) error {
|
||||
grpcCons := getcdv3.GetDefaultGatewayConn4Unique(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), operationID)
|
||||
for _, v := range grpcCons {
|
||||
client := pbRelay.NewRelayClient(v)
|
||||
kickReq := &pbRelay.KickUserOfflineReq{OperationID: operationID, KickUserIDList: []string{userID}, PlatformID: platformID}
|
||||
log.NewInfo(operationID, "KickUserOffline ", client, kickReq.String())
|
||||
_, err := client.KickUserOffline(context.Background(), kickReq)
|
||||
_, err := client.KickUserOffline(ctx, kickReq)
|
||||
return utils.Wrap(err, "")
|
||||
}
|
||||
return errors.New("no rpc node ")
|
||||
return constant.ErrInternalServer.Wrap()
|
||||
}
|
||||
|
||||
type rpcAuth struct {
|
||||
@@ -117,6 +101,7 @@ type rpcAuth struct {
|
||||
rpcRegisterName string
|
||||
etcdSchema string
|
||||
etcdAddr []string
|
||||
controller.AuthInterface
|
||||
}
|
||||
|
||||
func NewRpcAuthServer(port int) *rpcAuth {
|
||||
@@ -129,7 +114,7 @@ func NewRpcAuthServer(port int) *rpcAuth {
|
||||
}
|
||||
}
|
||||
|
||||
func (rpc *rpcAuth) Run() {
|
||||
func (s *rpcAuth) Run() {
|
||||
operationID := utils.OperationIDGenerator()
|
||||
log.NewInfo(operationID, "rpc auth start...")
|
||||
|
||||
@@ -139,10 +124,10 @@ func (rpc *rpcAuth) Run() {
|
||||
} else {
|
||||
listenIP = config.Config.ListenIP
|
||||
}
|
||||
address := listenIP + ":" + strconv.Itoa(rpc.rpcPort)
|
||||
address := listenIP + ":" + strconv.Itoa(s.rpcPort)
|
||||
listener, err := net.Listen("tcp", address)
|
||||
if err != nil {
|
||||
panic("listening err:" + err.Error() + rpc.rpcRegisterName)
|
||||
panic("listening err:" + err.Error() + s.rpcRegisterName)
|
||||
}
|
||||
log.NewInfo(operationID, "listen network success, ", address, listener)
|
||||
var grpcOpts []grpc.ServerOption
|
||||
@@ -162,7 +147,7 @@ func (rpc *rpcAuth) Run() {
|
||||
defer srv.GracefulStop()
|
||||
|
||||
//service registers with etcd
|
||||
pbAuth.RegisterAuthServer(srv, rpc)
|
||||
pbAuth.RegisterAuthServer(srv, s)
|
||||
rpcRegisterIP := config.Config.RpcRegisterIP
|
||||
if config.Config.RpcRegisterIP == "" {
|
||||
rpcRegisterIP, err = utils.GetLocalIP()
|
||||
@@ -172,14 +157,14 @@ func (rpc *rpcAuth) Run() {
|
||||
}
|
||||
log.NewInfo("", "rpcRegisterIP", rpcRegisterIP)
|
||||
|
||||
err = getcdv3.RegisterEtcd(rpc.etcdSchema, strings.Join(rpc.etcdAddr, ","), rpcRegisterIP, rpc.rpcPort, rpc.rpcRegisterName, 10)
|
||||
err = getcdv3.RegisterEtcd(s.etcdSchema, strings.Join(s.etcdAddr, ","), rpcRegisterIP, s.rpcPort, s.rpcRegisterName, 10, "")
|
||||
if err != nil {
|
||||
log.NewError(operationID, "RegisterEtcd failed ", err.Error(),
|
||||
rpc.etcdSchema, strings.Join(rpc.etcdAddr, ","), rpcRegisterIP, rpc.rpcPort, rpc.rpcRegisterName)
|
||||
s.etcdSchema, strings.Join(s.etcdAddr, ","), rpcRegisterIP, s.rpcPort, s.rpcRegisterName)
|
||||
panic(utils.Wrap(err, "register auth module rpc to etcd err"))
|
||||
|
||||
}
|
||||
log.NewInfo(operationID, "RegisterAuthServer ok ", rpc.etcdSchema, strings.Join(rpc.etcdAddr, ","), rpcRegisterIP, rpc.rpcPort, rpc.rpcRegisterName)
|
||||
log.NewInfo(operationID, "RegisterAuthServer ok ", s.etcdSchema, strings.Join(s.etcdAddr, ","), rpcRegisterIP, s.rpcPort, s.rpcRegisterName)
|
||||
err = srv.Serve(listener)
|
||||
if err != nil {
|
||||
log.NewError(operationID, "Serve failed ", err.Error())
|
||||
|
||||
@@ -16,7 +16,7 @@ func (s *friendServer) GetBlacks(ctx context.Context, req *pbFriend.GetBlacksReq
|
||||
if err := check.Access(ctx, req.UserID); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
blacks, err := s.BlackInterface.FindOwnerBlacks(ctx, req.UserID, req.Pagination.PageNumber, req.Pagination.ShowNumber)
|
||||
blacks, total, err := s.BlackInterface.FindOwnerBlacks(ctx, req.UserID, req.Pagination.PageNumber, req.Pagination.ShowNumber)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -29,6 +29,7 @@ func (s *friendServer) GetBlacks(ctx context.Context, req *pbFriend.GetBlacksReq
|
||||
resp.Blacks = append(resp.Blacks, b)
|
||||
blackIDList = append(blackIDList, black.BlockUserID)
|
||||
}
|
||||
resp.Total = int32(total)
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
@@ -64,6 +65,6 @@ func (s *friendServer) AddBlack(ctx context.Context, req *pbFriend.AddBlackReq)
|
||||
if err := s.BlackInterface.Create(ctx, []*relation.Black{&black}); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
chat.BlackAddedNotification(req)
|
||||
chat.BlackAddedNotification(tracelog.GetOperationID(ctx), req)
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
@@ -6,14 +6,17 @@ import (
|
||||
"Open_IM/pkg/common/constant"
|
||||
"Open_IM/pkg/common/http"
|
||||
"Open_IM/pkg/common/log"
|
||||
"Open_IM/pkg/common/tracelog"
|
||||
pbFriend "Open_IM/pkg/proto/friend"
|
||||
"context"
|
||||
|
||||
//"Open_IM/pkg/proto/msg"
|
||||
"Open_IM/pkg/utils"
|
||||
http2 "net/http"
|
||||
)
|
||||
|
||||
func callbackBeforeAddFriendV1(req *pbFriend.AddFriendReq) error {
|
||||
resp := callbackBeforeAddFriend(req)
|
||||
func callbackBeforeAddFriendV1(ctx context.Context, req *pbFriend.AddFriendReq) error {
|
||||
resp := callbackBeforeAddFriend(ctx, req)
|
||||
if resp.ErrCode != 0 {
|
||||
return (&constant.ErrInfo{
|
||||
ErrCode: resp.ErrCode,
|
||||
@@ -23,28 +26,28 @@ func callbackBeforeAddFriendV1(req *pbFriend.AddFriendReq) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func callbackBeforeAddFriend(req *pbFriend.AddFriendReq) cbApi.CommonCallbackResp {
|
||||
callbackResp := cbApi.CommonCallbackResp{OperationID: req.CommID.OperationID}
|
||||
func callbackBeforeAddFriend(ctx context.Context, req *pbFriend.AddFriendReq) cbApi.CommonCallbackResp {
|
||||
callbackResp := cbApi.CommonCallbackResp{OperationID: tracelog.GetOperationID(ctx)}
|
||||
if !config.Config.Callback.CallbackBeforeAddFriend.Enable {
|
||||
return callbackResp
|
||||
}
|
||||
log.NewDebug(req.CommID.OperationID, utils.GetSelfFuncName(), req.String())
|
||||
|
||||
commonCallbackReq := &cbApi.CallbackBeforeAddFriendReq{
|
||||
CallbackCommand: constant.CallbackBeforeAddFriendCommand,
|
||||
FromUserID: req.CommID.FromUserID,
|
||||
ToUserID: req.CommID.ToUserID,
|
||||
FromUserID: req.FromUserID,
|
||||
ToUserID: req.ToUserID,
|
||||
ReqMsg: req.ReqMsg,
|
||||
OperationID: req.CommID.OperationID,
|
||||
OperationID: tracelog.GetOperationID(ctx),
|
||||
}
|
||||
resp := &cbApi.CallbackBeforeAddFriendResp{
|
||||
CommonCallbackResp: &callbackResp,
|
||||
}
|
||||
//utils.CopyStructFields(req, msg.MsgData)
|
||||
defer log.NewDebug(req.CommID.OperationID, utils.GetSelfFuncName(), commonCallbackReq, *resp)
|
||||
if err := http.CallBackPostReturn(config.Config.Callback.CallbackUrl, constant.CallbackBeforeAddFriendCommand, commonCallbackReq, resp, config.Config.Callback.CallbackBeforeAddFriend.CallbackTimeOut); err != nil {
|
||||
defer log.NewDebug(tracelog.GetOperationID(ctx), utils.GetSelfFuncName(), commonCallbackReq, *resp)
|
||||
if err := http.CallBackPostReturn(config.Config.Callback.CallbackUrl, constant.CallbackBeforeAddFriendCommand, commonCallbackReq, resp, config.Config.Callback.CallbackBeforeAddFriend); err != nil {
|
||||
callbackResp.ErrCode = http2.StatusInternalServerError
|
||||
callbackResp.ErrMsg = err.Error()
|
||||
if !config.Config.Callback.CallbackBeforeAddFriend.CallbackFailedContinue {
|
||||
if !*config.Config.Callback.CallbackBeforeAddFriend.CallbackFailedContinue {
|
||||
callbackResp.ActionCode = constant.ActionForbidden
|
||||
return callbackResp
|
||||
} else {
|
||||
|
||||
@@ -120,7 +120,7 @@ func (s *friendServer) AddFriend(ctx context.Context, req *pbFriend.AddFriendReq
|
||||
if err := token_verify.CheckAccessV3(ctx, req.FromUserID); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if err := callbackBeforeAddFriendV1(req); err != nil {
|
||||
if err := callbackBeforeAddFriendV1(ctx, req); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@@ -140,7 +140,7 @@ func (s *friendServer) AddFriend(ctx context.Context, req *pbFriend.AddFriendReq
|
||||
if err = s.FriendInterface.AddFriendRequest(ctx, req.FromUserID, req.ToUserID, req.ReqMsg, req.Ex); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
chat.FriendApplicationNotification(req)
|
||||
chat.FriendApplicationNotification(ctx, req)
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
@@ -177,7 +177,7 @@ func (s *friendServer) RespondFriendApply(ctx context.Context, req *pbFriend.Res
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
chat.FriendApplicationApprovedNotification(req)
|
||||
chat.FriendApplicationApprovedNotification(ctx, req)
|
||||
return resp, nil
|
||||
}
|
||||
if req.HandleResult == constant.FriendResponseRefuse {
|
||||
@@ -185,7 +185,7 @@ func (s *friendServer) RespondFriendApply(ctx context.Context, req *pbFriend.Res
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
chat.FriendApplicationRejectedNotification(req)
|
||||
chat.FriendApplicationRejectedNotification(ctx, req)
|
||||
return resp, nil
|
||||
}
|
||||
return nil, constant.ErrArgs.Wrap("req.HandleResult != -1/1")
|
||||
@@ -199,7 +199,7 @@ func (s *friendServer) DeleteFriend(ctx context.Context, req *pbFriend.DeleteFri
|
||||
if err := s.FriendInterface.Delete(ctx, req.OwnerUserID, req.FriendUserID); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
chat.FriendDeletedNotification(req)
|
||||
chat.FriendDeletedNotification(ctx, req)
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
@@ -211,7 +211,7 @@ func (s *friendServer) SetFriendRemark(ctx context.Context, req *pbFriend.SetFri
|
||||
if err := s.FriendInterface.UpdateRemark(ctx, req.OwnerUserID, req.FriendUserID, req.Remark); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
chat.FriendRemarkSetNotification(tracelog.GetOperationID(ctx), tracelog.GetOpUserID(ctx), req.OwnerUserID, req.FriendUserID)
|
||||
chat.FriendRemarkSetNotification(ctx, req.OwnerUserID, req.FriendUserID)
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
|
||||
@@ -1,32 +1,33 @@
|
||||
package msg
|
||||
|
||||
import (
|
||||
"Open_IM/internal/common/check"
|
||||
"Open_IM/pkg/common/config"
|
||||
"Open_IM/pkg/common/constant"
|
||||
imdb "Open_IM/pkg/common/db/mysql_model/im_mysql_model"
|
||||
"Open_IM/pkg/common/log"
|
||||
utils2 "Open_IM/pkg/common/utils"
|
||||
"Open_IM/pkg/common/tracelog"
|
||||
pbFriend "Open_IM/pkg/proto/friend"
|
||||
open_im_sdk "Open_IM/pkg/proto/sdk_ws"
|
||||
"Open_IM/pkg/utils"
|
||||
"context"
|
||||
"github.com/golang/protobuf/jsonpb"
|
||||
"github.com/golang/protobuf/proto"
|
||||
)
|
||||
|
||||
func getFromToUserNickname(fromUserID, toUserID string) (string, string, error) {
|
||||
from, err := imdb.GetUserByUserID(fromUserID)
|
||||
users, err := check.GetUsersInfo(context.Background(), fromUserID, toUserID)
|
||||
if err != nil {
|
||||
return "", "", utils.Wrap(err, "")
|
||||
return "", "", nil
|
||||
}
|
||||
to, err := imdb.GetUserByUserID(toUserID)
|
||||
if err != nil {
|
||||
return "", "", utils.Wrap(err, "")
|
||||
if users[0].UserID == fromUserID {
|
||||
return users[0].Nickname, users[1].Nickname, nil
|
||||
}
|
||||
return from.Nickname, to.Nickname, nil
|
||||
return users[1].Nickname, users[0].Nickname, nil
|
||||
|
||||
}
|
||||
|
||||
func friendNotification(operationID, fromUserID, toUserID string, contentType int32, m proto.Message) {
|
||||
log.Info(operationID, utils.GetSelfFuncName(), "args: ", commID, contentType)
|
||||
log.Info(operationID, utils.GetSelfFuncName(), "args: ", contentType)
|
||||
var err error
|
||||
var tips open_im_sdk.TipsComm
|
||||
tips.Detail, err = proto.Marshal(m)
|
||||
@@ -90,84 +91,83 @@ func friendNotification(operationID, fromUserID, toUserID string, contentType in
|
||||
Notification(&n)
|
||||
}
|
||||
|
||||
func FriendApplicationNotification(req *pbFriend.AddFriendReq) {
|
||||
func FriendApplicationNotification(ctx context.Context, req *pbFriend.AddFriendReq) {
|
||||
FriendApplicationTips := open_im_sdk.FriendApplicationTips{FromToUserID: &open_im_sdk.FromToUserID{}}
|
||||
FriendApplicationTips.FromToUserID.FromUserID = req.CommID.FromUserID
|
||||
FriendApplicationTips.FromToUserID.ToUserID = req.CommID.ToUserID
|
||||
friendNotification(req.CommID, constant.FriendApplicationNotification, &FriendApplicationTips)
|
||||
FriendApplicationTips.FromToUserID.FromUserID = req.FromUserID
|
||||
FriendApplicationTips.FromToUserID.ToUserID = req.ToUserID
|
||||
friendNotification(tracelog.GetOperationID(ctx), req.FromUserID, req.ToUserID, constant.FriendApplicationNotification, &FriendApplicationTips)
|
||||
}
|
||||
|
||||
func FriendApplicationApprovedNotification(req *pbFriend.AddFriendResponseReq) {
|
||||
func FriendApplicationApprovedNotification(ctx context.Context, req *pbFriend.RespondFriendApplyReq) {
|
||||
FriendApplicationApprovedTips := open_im_sdk.FriendApplicationApprovedTips{FromToUserID: &open_im_sdk.FromToUserID{}}
|
||||
FriendApplicationApprovedTips.FromToUserID.FromUserID = req.CommID.FromUserID
|
||||
FriendApplicationApprovedTips.FromToUserID.ToUserID = req.CommID.ToUserID
|
||||
FriendApplicationApprovedTips.FromToUserID.FromUserID = req.FromUserID
|
||||
FriendApplicationApprovedTips.FromToUserID.ToUserID = req.ToUserID
|
||||
FriendApplicationApprovedTips.HandleMsg = req.HandleMsg
|
||||
friendNotification(req.CommID, constant.FriendApplicationApprovedNotification, &FriendApplicationApprovedTips)
|
||||
friendNotification(tracelog.GetOperationID(ctx), req.ToUserID, req.FromUserID, constant.FriendApplicationApprovedNotification, &FriendApplicationApprovedTips)
|
||||
}
|
||||
|
||||
func FriendApplicationRejectedNotification(req *pbFriend.AddFriendResponseReq) {
|
||||
func FriendApplicationRejectedNotification(ctx context.Context, req *pbFriend.RespondFriendApplyReq) {
|
||||
FriendApplicationApprovedTips := open_im_sdk.FriendApplicationApprovedTips{FromToUserID: &open_im_sdk.FromToUserID{}}
|
||||
FriendApplicationApprovedTips.FromToUserID.FromUserID = req.CommID.FromUserID
|
||||
FriendApplicationApprovedTips.FromToUserID.ToUserID = req.CommID.ToUserID
|
||||
FriendApplicationApprovedTips.FromToUserID.FromUserID = req.FromUserID
|
||||
FriendApplicationApprovedTips.FromToUserID.ToUserID = req.ToUserID
|
||||
FriendApplicationApprovedTips.HandleMsg = req.HandleMsg
|
||||
friendNotification(req.CommID, constant.FriendApplicationRejectedNotification, &FriendApplicationApprovedTips)
|
||||
friendNotification(tracelog.GetOperationID(ctx), req.ToUserID, req.FromUserID, constant.FriendApplicationRejectedNotification, &FriendApplicationApprovedTips)
|
||||
}
|
||||
|
||||
func FriendAddedNotification(operationID, opUserID, fromUserID, toUserID string) {
|
||||
func FriendAddedNotification(ctx context.Context, operationID, opUserID, fromUserID, toUserID string) {
|
||||
friendAddedTips := open_im_sdk.FriendAddedTips{Friend: &open_im_sdk.FriendInfo{}, OpUser: &open_im_sdk.PublicUserInfo{}}
|
||||
user, err := imdb.GetUserByUserID(opUserID)
|
||||
user, err := check.GetUsersInfo(context.Background(), opUserID)
|
||||
if err != nil {
|
||||
log.NewError(operationID, "GetUserByUserID failed ", err.Error(), opUserID)
|
||||
return
|
||||
}
|
||||
utils2.UserDBCopyOpenIMPublicUser(friendAddedTips.OpUser, user)
|
||||
friend, err := imdb.GetFriendRelationshipFromFriend(fromUserID, toUserID)
|
||||
friendAddedTips.OpUser.UserID = user[0].UserID
|
||||
friendAddedTips.OpUser.Ex = user[0].Ex
|
||||
friendAddedTips.OpUser.Nickname = user[0].Nickname
|
||||
friendAddedTips.OpUser.FaceURL = user[0].FaceURL
|
||||
|
||||
friend, err := check.GetFriendsInfo(ctx, fromUserID, toUserID)
|
||||
if err != nil {
|
||||
log.NewError(operationID, "GetFriendRelationshipFromFriend failed ", err.Error(), fromUserID, toUserID)
|
||||
return
|
||||
}
|
||||
utils2.FriendDBCopyOpenIM(friendAddedTips.Friend, friend)
|
||||
commID := pbFriend.CommID{FromUserID: fromUserID, ToUserID: toUserID, OpUserID: opUserID, OperationID: operationID}
|
||||
friendNotification(&commID, constant.FriendAddedNotification, &friendAddedTips)
|
||||
friendAddedTips.Friend = friend
|
||||
friendNotification(operationID, fromUserID, toUserID, constant.FriendAddedNotification, &friendAddedTips)
|
||||
}
|
||||
|
||||
func FriendDeletedNotification(req *pbFriend.DeleteFriendReq) {
|
||||
func FriendDeletedNotification(ctx context.Context, req *pbFriend.DeleteFriendReq) {
|
||||
friendDeletedTips := open_im_sdk.FriendDeletedTips{FromToUserID: &open_im_sdk.FromToUserID{}}
|
||||
friendDeletedTips.FromToUserID.FromUserID = req.CommID.FromUserID
|
||||
friendDeletedTips.FromToUserID.ToUserID = req.CommID.ToUserID
|
||||
friendNotification(req.CommID, constant.FriendDeletedNotification, &friendDeletedTips)
|
||||
friendDeletedTips.FromToUserID.FromUserID = req.OwnerUserID
|
||||
friendDeletedTips.FromToUserID.ToUserID = req.FriendUserID
|
||||
friendNotification(tracelog.GetOperationID(ctx), req.OwnerUserID, req.FriendUserID, constant.FriendDeletedNotification, &friendDeletedTips)
|
||||
}
|
||||
|
||||
func FriendRemarkSetNotification(operationID, opUserID, fromUserID, toUserID string) {
|
||||
func FriendRemarkSetNotification(ctx context.Context, fromUserID, toUserID string) {
|
||||
friendInfoChangedTips := open_im_sdk.FriendInfoChangedTips{FromToUserID: &open_im_sdk.FromToUserID{}}
|
||||
friendInfoChangedTips.FromToUserID.FromUserID = fromUserID
|
||||
friendInfoChangedTips.FromToUserID.ToUserID = toUserID
|
||||
commID := pbFriend.CommID{FromUserID: fromUserID, ToUserID: toUserID, OpUserID: opUserID, OperationID: operationID}
|
||||
friendNotification(&commID, constant.FriendRemarkSetNotification, &friendInfoChangedTips)
|
||||
friendNotification(tracelog.GetOperationID(ctx), fromUserID, toUserID, constant.FriendRemarkSetNotification, &friendInfoChangedTips)
|
||||
}
|
||||
|
||||
func BlackAddedNotification(req *pbFriend.AddBlacklistReq) {
|
||||
func BlackAddedNotification(ctx context.Context, req *pbFriend.AddBlackReq) {
|
||||
blackAddedTips := open_im_sdk.BlackAddedTips{FromToUserID: &open_im_sdk.FromToUserID{}}
|
||||
blackAddedTips.FromToUserID.FromUserID = req.CommID.FromUserID
|
||||
blackAddedTips.FromToUserID.ToUserID = req.CommID.ToUserID
|
||||
friendNotification(req.CommID, constant.BlackAddedNotification, &blackAddedTips)
|
||||
blackAddedTips.FromToUserID.FromUserID = req.OwnerUserID
|
||||
blackAddedTips.FromToUserID.ToUserID = req.BlackUserID
|
||||
friendNotification(tracelog.GetOperationID(ctx), req.OwnerUserID, req.BlackUserID, constant.BlackAddedNotification, &blackAddedTips)
|
||||
}
|
||||
|
||||
func BlackDeletedNotification(req *pbFriend.RemoveBlacklistReq) {
|
||||
func BlackDeletedNotification(ctx context.Context, req *pbFriend.RemoveBlackReq) {
|
||||
blackDeletedTips := open_im_sdk.BlackDeletedTips{FromToUserID: &open_im_sdk.FromToUserID{}}
|
||||
blackDeletedTips.FromToUserID.FromUserID = req.CommID.FromUserID
|
||||
blackDeletedTips.FromToUserID.ToUserID = req.CommID.ToUserID
|
||||
friendNotification(req.CommID, constant.BlackDeletedNotification, &blackDeletedTips)
|
||||
blackDeletedTips.FromToUserID.FromUserID = req.OwnerUserID
|
||||
blackDeletedTips.FromToUserID.ToUserID = req.BlackUserID
|
||||
friendNotification(tracelog.GetOperationID(ctx), req.OwnerUserID, req.BlackUserID, constant.BlackDeletedNotification, &blackDeletedTips)
|
||||
}
|
||||
|
||||
// send to myself
|
||||
func UserInfoUpdatedNotification(operationID, opUserID string, changedUserID string) {
|
||||
func UserInfoUpdatedNotification(ctx context.Context, opUserID string, changedUserID string) {
|
||||
selfInfoUpdatedTips := open_im_sdk.UserInfoUpdatedTips{UserID: changedUserID}
|
||||
commID := pbFriend.CommID{FromUserID: opUserID, ToUserID: changedUserID, OpUserID: opUserID, OperationID: operationID}
|
||||
friendNotification(&commID, constant.UserInfoUpdatedNotification, &selfInfoUpdatedTips)
|
||||
friendNotification(tracelog.GetOperationID(ctx), opUserID, changedUserID, constant.UserInfoUpdatedNotification, &selfInfoUpdatedTips)
|
||||
}
|
||||
|
||||
func FriendInfoUpdatedNotification(operationID, changedUserID string, needNotifiedUserID string, opUserID string) {
|
||||
func FriendInfoUpdatedNotification(ctx context.Context, changedUserID string, needNotifiedUserID string, opUserID string) {
|
||||
selfInfoUpdatedTips := open_im_sdk.UserInfoUpdatedTips{UserID: changedUserID}
|
||||
friendNotification(operationID, opUserID, needNotifiedUserID, constant.FriendInfoUpdatedNotification, &selfInfoUpdatedTips)
|
||||
friendNotification(tracelog.GetOperationID(ctx), opUserID, needNotifiedUserID, constant.FriendInfoUpdatedNotification, &selfInfoUpdatedTips)
|
||||
}
|
||||
|
||||
+48
-25
@@ -1,6 +1,7 @@
|
||||
package user
|
||||
|
||||
import (
|
||||
"Open_IM/internal/common/convert"
|
||||
chat "Open_IM/internal/rpc/msg"
|
||||
"Open_IM/pkg/common/config"
|
||||
"Open_IM/pkg/common/constant"
|
||||
@@ -9,6 +10,7 @@ import (
|
||||
"Open_IM/pkg/common/log"
|
||||
promePkg "Open_IM/pkg/common/prometheus"
|
||||
"Open_IM/pkg/common/token_verify"
|
||||
"Open_IM/pkg/common/tracelog"
|
||||
"Open_IM/pkg/getcdv3"
|
||||
pbFriend "Open_IM/pkg/proto/friend"
|
||||
pbGroup "Open_IM/pkg/proto/group"
|
||||
@@ -170,12 +172,9 @@ func (s *userServer) GetUsersInfo(ctx context.Context, req *pbUser.GetUsersInfoR
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
for _, v := range users {
|
||||
n, err := utils.NewDBUser(v).Convert()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
resp.UsersInfo = append(resp.UsersInfo, n)
|
||||
resp.UsersInfo, err = (*convert.DBUser)(nil).DB2PB(users)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return resp, nil
|
||||
}
|
||||
@@ -188,13 +187,13 @@ func (s *userServer) UpdateUserInfo(ctx context.Context, req *pbUser.UpdateUserI
|
||||
}
|
||||
oldNickname := ""
|
||||
if req.UserInfo.Nickname != "" {
|
||||
u, err := s.Take(ctx, req.UserInfo.UserID)
|
||||
u, err := s.Find(ctx, []string{req.UserInfo.UserID})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
oldNickname = u.Nickname
|
||||
oldNickname = u[0].Nickname
|
||||
}
|
||||
user, err := utils.NewPBUser(req.UserInfo).Convert()
|
||||
user, err := convert.NewPBUser(req.UserInfo).Convert()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -207,23 +206,23 @@ func (s *userServer) UpdateUserInfo(ctx context.Context, req *pbUser.UpdateUserI
|
||||
return nil, err
|
||||
}
|
||||
client := pbFriend.NewFriendClient(etcdConn)
|
||||
newReq := &pbFriend.GetFriendListReq{UserID: req.UserInfo.UserID}
|
||||
rpcResp, err := client.GetFriendList(context.Background(), newReq)
|
||||
newReq := &pbFriend.GetFriendsReq{UserID: req.UserInfo.UserID}
|
||||
rpcResp, err := client.GetFriends(context.Background(), newReq)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
go func() {
|
||||
for _, v := range rpcResp.FriendInfoList {
|
||||
chat.FriendInfoUpdatedNotification(utils.OperationID(ctx), req.UserInfo.UserID, v.FriendUser.UserID, utils.OpUserID(ctx))
|
||||
for _, v := range rpcResp.FriendsInfo {
|
||||
chat.FriendInfoUpdatedNotification(tracelog.GetOperationID(ctx), req.UserInfo.UserID, v.FriendUser.UserID, tracelog.GetOpUserID(ctx))
|
||||
}
|
||||
}()
|
||||
|
||||
chat.UserInfoUpdatedNotification(utils.OperationID(ctx), utils.OpUserID(ctx), req.UserInfo.UserID)
|
||||
chat.UserInfoUpdatedNotification(tracelog.GetOperationID(ctx), tracelog.GetOpUserID(ctx), req.UserInfo.UserID)
|
||||
if req.UserInfo.FaceURL != "" {
|
||||
s.SyncJoinedGroupMemberFaceURL(ctx, req.UserInfo.UserID, req.UserInfo.FaceURL, utils.OperationID(ctx), utils.OpUserID(ctx))
|
||||
s.SyncJoinedGroupMemberFaceURL(ctx, req.UserInfo.UserID, req.UserInfo.FaceURL, tracelog.GetOperationID(ctx), tracelog.GetOpUserID(ctx))
|
||||
}
|
||||
if req.UserInfo.Nickname != "" {
|
||||
s.SyncJoinedGroupMemberNickname(ctx, req.UserInfo.UserID, req.UserInfo.Nickname, oldNickname, utils.OperationID(ctx), utils.OpUserID(ctx))
|
||||
s.SyncJoinedGroupMemberNickname(ctx, req.UserInfo.UserID, req.UserInfo.Nickname, oldNickname, tracelog.GetOperationID(ctx), tracelog.GetOpUserID(ctx))
|
||||
}
|
||||
return &resp, nil
|
||||
}
|
||||
@@ -236,13 +235,13 @@ func (s *userServer) SetGlobalRecvMessageOpt(ctx context.Context, req *pbUser.Se
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
chat.UserInfoUpdatedNotification(utils.OperationID(ctx), req.UserID, req.UserID)
|
||||
chat.UserInfoUpdatedNotification(tracelog.GetOperationID(ctx), req.UserID, req.UserID)
|
||||
return &resp, nil
|
||||
}
|
||||
|
||||
func (s *userServer) AccountCheck(ctx context.Context, req *pbUser.AccountCheckReq) (*pbUser.AccountCheckResp, error) {
|
||||
resp := pbUser.AccountCheckResp{}
|
||||
err := token_verify.CheckManagerUserID(ctx, utils.OpUserID(ctx))
|
||||
err := token_verify.CheckManagerUserID(ctx, tracelog.GetOpUserID(ctx))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -254,9 +253,9 @@ func (s *userServer) AccountCheck(ctx context.Context, req *pbUser.AccountCheckR
|
||||
for _, v := range user {
|
||||
uidList = append(uidList, v.UserID)
|
||||
}
|
||||
var r []*pbUser.AccountCheckResp_SingleUserStatus
|
||||
var r []*pbUser.AccountCheckRespSingleUserStatus
|
||||
for _, v := range req.CheckUserIDs {
|
||||
temp := new(pbUser.AccountCheckResp_SingleUserStatus)
|
||||
temp := new(pbUser.AccountCheckRespSingleUserStatus)
|
||||
temp.UserID = v
|
||||
if utils.IsContain(v, uidList) {
|
||||
temp.AccountStatus = constant.Registered
|
||||
@@ -272,12 +271,12 @@ func (s *userServer) GetUsers(ctx context.Context, req *pbUser.GetUsersReq) (*pb
|
||||
resp := pbUser.GetUsersResp{}
|
||||
var err error
|
||||
if req.UserID != "" {
|
||||
u, err := s.Take(ctx, req.UserID)
|
||||
u, err := s.Find(ctx, []string{req.UserID})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
resp.Total = 1
|
||||
u1, err := utils.NewDBUser(u).Convert()
|
||||
u1, err := convert.NewDBUser(u[0]).Convert()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -292,7 +291,7 @@ func (s *userServer) GetUsers(ctx context.Context, req *pbUser.GetUsersReq) (*pb
|
||||
}
|
||||
resp.Total = int32(total)
|
||||
for _, v := range usersDB {
|
||||
u1, err := utils.NewDBUser(v).Convert()
|
||||
u1, err := convert.NewDBUser(v).Convert()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -306,7 +305,7 @@ func (s *userServer) GetUsers(ctx context.Context, req *pbUser.GetUsersReq) (*pb
|
||||
}
|
||||
resp.Total = int32(total)
|
||||
for _, v := range usersDB {
|
||||
u1, err := utils.NewDBUser(v).Convert()
|
||||
u1, err := convert.NewDBUser(v).Convert()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -323,7 +322,7 @@ func (s *userServer) GetUsers(ctx context.Context, req *pbUser.GetUsersReq) (*pb
|
||||
resp.Total = int32(total)
|
||||
|
||||
for _, userDB := range usersDB {
|
||||
u, err := utils.NewDBUser(userDB).Convert()
|
||||
u, err := convert.NewDBUser(userDB).Convert()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -331,3 +330,27 @@ func (s *userServer) GetUsers(ctx context.Context, req *pbUser.GetUsersReq) (*pb
|
||||
}
|
||||
return &resp, nil
|
||||
}
|
||||
|
||||
func (s *userServer) UserRegister(ctx context.Context, req *pbUser.UserRegisterReq) (*pbUser.UserRegisterResp, error) {
|
||||
resp := pbUser.UserRegisterResp{}
|
||||
userIDs := make([]string, 0)
|
||||
for _, v := range req.Users {
|
||||
userIDs = append(userIDs, v.UserID)
|
||||
}
|
||||
exist, err := s.IsExist(ctx, userIDs)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if exist {
|
||||
return nil, constant.ErrRegisteredAlready.Wrap("exist")
|
||||
}
|
||||
users, err := (*convert.PBUser)(nil).PB2DB(req.Users)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
err = s.Create(ctx, users)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &resp, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user