fix: changing naming irregularities under pkg and internal packages (#520)

Signed-off-by: BanTanger <1290288968@qq.com>
pull/636/head
BanTanger 2 years ago
parent 94b4dcae3f
commit b369e43c05

@ -25,7 +25,6 @@ require (
github.com/robfig/cron/v3 v3.0.1
github.com/sirupsen/logrus v1.9.2 // indirect
github.com/stretchr/testify v1.8.3
github.com/tencentyun/qcloud-cos-sts-sdk v0.0.0-20210325043845-84a0811633ca
go.mongodb.org/mongo-driver v1.8.3
golang.org/x/image v0.3.0
google.golang.org/api v0.114.0

@ -426,8 +426,6 @@ github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.194/go.mod
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/kms v1.0.194/go.mod h1:yrBKWhChnDqNz1xuXdSbWXG56XawEq0G5j1lg4VwBD4=
github.com/tencentyun/cos-go-sdk-v5 v0.7.41 h1:iU0Li/Np78H4SBna0ECQoF3mpgi6ImLXU+doGzPFXGc=
github.com/tencentyun/cos-go-sdk-v5 v0.7.41/go.mod h1:4dCEtLHGh8QPxHEkgq+nFaky7yZxQuYwgSJM87icDaw=
github.com/tencentyun/qcloud-cos-sts-sdk v0.0.0-20210325043845-84a0811633ca h1:G/aIr3WiUesWHL2YGYgEqjM5tCAJ43Ml+0C18wDkWWs=
github.com/tencentyun/qcloud-cos-sts-sdk v0.0.0-20210325043845-84a0811633ca/go.mod h1:b18KQa4IxHbxeseW1GcZox53d7J0z39VNONTxvvlkXw=
github.com/tidwall/pretty v1.0.0 h1:HsD+QiTn7sK6flMKIvNmpqz1qrpP3Ps6jOKIKMooyg4=
github.com/tidwall/pretty v1.0.0/go.mod h1:XNkn88O1ChpSDQmQeStsy+sBenx6DDtFZJxhVysOjyk=
github.com/twitchyliquid64/golang-asm v0.15.1 h1:SU5vSMR7hnwNxj24w34ZyCi/FmDZTkS4MhqMhdFk5YI=

@ -0,0 +1,21 @@
#!/usr/bin/env bash
internet_ip=`curl ifconfig.me -s`
echo $internet_ip
source .env
echo $MINIO_ENDPOINT
if [ $MINIO_ENDPOINT == "http://127.0.0.1:10005" ]; then
sed -i "s/127.0.0.1/${internet_ip}/" .env
fi
cd scripts ;
chmod +x *.sh ;
./init_pwd.sh
./env_check.sh;
cd .. ;
docker-compose -f im-compose.yaml up -d
docker ps

@ -0,0 +1,43 @@
#!/usr/bin/env bash
# Get the public internet IP address
internet_ip=$(curl ifconfig.me -s)
echo $internet_ip
# Load environment variables from .env file
source .env
echo $MINIO_ENDPOINT
# Replace local IP address with the public IP address in .env file
if [ $API_URL == "http://127.0.0.1:10002/object/" ]; then
sed -i "s/127.0.0.1/${internet_ip}/" .env
fi
if [ $MINIO_ENDPOINT == "http://127.0.0.1:10005" ]; then
sed -i "s/127.0.0.1/${internet_ip}/" .env
fi
# Change directory to scripts folder
cd scripts
chmod +x *.sh
# Execute necessary scripts
./init_pwd.sh
./env_check.sh
# Go back to the previous directory
cd ..
# Check if docker-compose command is available
if command -v docker-compose &> /dev/null
then
docker-compose up -d
else
docker compose up -d
fi
# Change directory to scripts folder again
cd scripts
# Check docker services
./docker_check_service.sh

@ -86,7 +86,6 @@ func (u *UserApi) GetUsersOnlineStatus(c *gin.Context) {
log.ZWarn(c, "GetUsersOnlineStatus rpc err", err)
parseError := apiresp.ParseError(err)
log.ZDebug(c, "errcode bantanger", "errcode", parseError.ErrCode)
if parseError.ErrCode == errs.NoPermissionError {
apiresp.GinError(c, err)
return

@ -18,12 +18,12 @@ import (
"context"
)
// OfflinePusher Offline Pusher.
// OfflinePusher Offline Pusher
type OfflinePusher interface {
Push(ctx context.Context, userIDs []string, title, content string, opts *Opts) error
}
// Opts opts.
// Opts opts
type Opts struct {
Signal *Signal
IOSPushSound string
@ -31,7 +31,7 @@ type Opts struct {
Ex string
}
// Signal message id.
// Signal message id
type Signal struct {
ClientMsgID string
}

@ -38,6 +38,7 @@ import (
"github.com/OpenIMSDK/Open-IM-Server/pkg/proto/errinfo"
)
// rpcString
func rpcString(v interface{}) string {
if s, ok := v.(interface{ String() string }); ok {
return s.String()
@ -45,6 +46,7 @@ func rpcString(v interface{}) string {
return fmt.Sprintf("%+v", v)
}
// RpcServerInterceptor
func RpcServerInterceptor(
ctx context.Context,
req interface{},
@ -133,8 +135,8 @@ func RpcServerInterceptor(
var errInfo *errinfo.ErrorInfo
if config.Config.Log.WithStack {
if unwrap != err {
sti, ok := err.(interface{ StackTrace() errors.StackTrace })
if ok {
var sti interface{ StackTrace() errors.StackTrace }
if errors.As(err, &sti) {
log.ZWarn(
ctx,
"rpc server resp",
@ -173,9 +175,11 @@ func RpcServerInterceptor(
return nil, errs.Wrap(err)
}
log.ZWarn(ctx, "rpc server resp", err, "funcName", funcName)
return nil, details.Err()
}
// GrpcServer
func GrpcServer() grpc.ServerOption {
return grpc.ChainUnaryInterceptor(RpcServerInterceptor)
}

@ -14,10 +14,15 @@
package specialerror
import "github.com/OpenIMSDK/Open-IM-Server/pkg/errs"
import (
"errors"
"github.com/OpenIMSDK/Open-IM-Server/pkg/errs"
)
var handlers []func(err error) errs.CodeError
// AddErrHandler
func AddErrHandler(h func(err error) errs.CodeError) {
if h == nil {
panic("nil handler")
@ -27,13 +32,15 @@ func AddErrHandler(h func(err error) errs.CodeError) {
func AddReplace(target error, codeErr errs.CodeError) {
AddErrHandler(func(err error) errs.CodeError {
if err == target {
if errors.Is(err, target) {
return codeErr
}
return nil
})
}
// ErrCode
func ErrCode(err error) errs.CodeError {
if codeErr, ok := err.(errs.CodeError); ok {
return codeErr
@ -43,5 +50,6 @@ func ErrCode(err error) errs.CodeError {
return codeErr
}
}
return nil
}

@ -79,6 +79,7 @@ var (
ConversationCreateFailedCounter prometheus.Counter
)
// NewUserLoginCounter
func NewUserLoginCounter() {
if UserLoginCounter != nil {
return
@ -89,6 +90,7 @@ func NewUserLoginCounter() {
})
}
// NewUserRegisterCounter
func NewUserRegisterCounter() {
if UserRegisterCounter != nil {
return
@ -99,6 +101,7 @@ func NewUserRegisterCounter() {
})
}
// NewSeqGetSuccessCounter
func NewSeqGetSuccessCounter() {
if SeqGetSuccessCounter != nil {
return
@ -109,6 +112,7 @@ func NewSeqGetSuccessCounter() {
})
}
// NewSeqGetFailedCounter
func NewSeqGetFailedCounter() {
if SeqGetFailedCounter != nil {
return
@ -119,6 +123,7 @@ func NewSeqGetFailedCounter() {
})
}
// NewSeqSetSuccessCounter
func NewSeqSetSuccessCounter() {
if SeqSetSuccessCounter != nil {
return
@ -129,6 +134,7 @@ func NewSeqSetSuccessCounter() {
})
}
// NewSeqSetFailedCounter
func NewSeqSetFailedCounter() {
if SeqSetFailedCounter != nil {
return
@ -139,6 +145,7 @@ func NewSeqSetFailedCounter() {
})
}
// NewApiRequestCounter
func NewApiRequestCounter() {
if ApiRequestCounter != nil {
return
@ -149,6 +156,7 @@ func NewApiRequestCounter() {
})
}
// NewApiRequestSuccessCounter
func NewApiRequestSuccessCounter() {
if ApiRequestSuccessCounter != nil {
return
@ -159,6 +167,7 @@ func NewApiRequestSuccessCounter() {
})
}
// NewApiRequestFailedCounter
func NewApiRequestFailedCounter() {
if ApiRequestFailedCounter != nil {
return
@ -169,6 +178,7 @@ func NewApiRequestFailedCounter() {
})
}
// NewGrpcRequestCounter
func NewGrpcRequestCounter() {
if GrpcRequestCounter != nil {
return
@ -179,6 +189,7 @@ func NewGrpcRequestCounter() {
})
}
// NewGrpcRequestSuccessCounter
func NewGrpcRequestSuccessCounter() {
if GrpcRequestSuccessCounter != nil {
return
@ -189,6 +200,7 @@ func NewGrpcRequestSuccessCounter() {
})
}
// NewGrpcRequestFailedCounter
func NewGrpcRequestFailedCounter() {
if GrpcRequestFailedCounter != nil {
return
@ -199,6 +211,7 @@ func NewGrpcRequestFailedCounter() {
})
}
// NewSendMsgCount
func NewSendMsgCount() {
if SendMsgCounter != nil {
return
@ -209,6 +222,7 @@ func NewSendMsgCount() {
})
}
// NewMsgInsertRedisSuccessCounter
func NewMsgInsertRedisSuccessCounter() {
if MsgInsertRedisSuccessCounter != nil {
return
@ -219,6 +233,7 @@ func NewMsgInsertRedisSuccessCounter() {
})
}
// NewMsgInsertRedisFailedCounter
func NewMsgInsertRedisFailedCounter() {
if MsgInsertRedisFailedCounter != nil {
return
@ -229,6 +244,7 @@ func NewMsgInsertRedisFailedCounter() {
})
}
// NewMsgInsertMongoSuccessCounter
func NewMsgInsertMongoSuccessCounter() {
if MsgInsertMongoSuccessCounter != nil {
return
@ -239,6 +255,7 @@ func NewMsgInsertMongoSuccessCounter() {
})
}
// NewMsgInsertMongoFailedCounter
func NewMsgInsertMongoFailedCounter() {
if MsgInsertMongoFailedCounter != nil {
return
@ -249,6 +266,7 @@ func NewMsgInsertMongoFailedCounter() {
})
}
// NewMsgPullFromRedisSuccessCounter
func NewMsgPullFromRedisSuccessCounter() {
if MsgPullFromRedisSuccessCounter != nil {
return
@ -259,6 +277,7 @@ func NewMsgPullFromRedisSuccessCounter() {
})
}
// NewMsgPullFromRedisFailedCounter
func NewMsgPullFromRedisFailedCounter() {
if MsgPullFromRedisFailedCounter != nil {
return
@ -269,6 +288,7 @@ func NewMsgPullFromRedisFailedCounter() {
})
}
// NewMsgPullFromMongoSuccessCounter
func NewMsgPullFromMongoSuccessCounter() {
if MsgPullFromMongoSuccessCounter != nil {
return
@ -279,6 +299,7 @@ func NewMsgPullFromMongoSuccessCounter() {
})
}
// NewMsgPullFromMongoFailedCounter
func NewMsgPullFromMongoFailedCounter() {
if MsgPullFromMongoFailedCounter != nil {
return
@ -289,6 +310,7 @@ func NewMsgPullFromMongoFailedCounter() {
})
}
// NewMsgRecvTotalCounter
func NewMsgRecvTotalCounter() {
if MsgRecvTotalCounter != nil {
return
@ -299,6 +321,7 @@ func NewMsgRecvTotalCounter() {
})
}
// NewGetNewestSeqTotalCounter
func NewGetNewestSeqTotalCounter() {
if GetNewestSeqTotalCounter != nil {
return
@ -309,6 +332,7 @@ func NewGetNewestSeqTotalCounter() {
})
}
// NewPullMsgBySeqListTotalCounter
func NewPullMsgBySeqListTotalCounter() {
if PullMsgBySeqListTotalCounter != nil {
return
@ -319,6 +343,7 @@ func NewPullMsgBySeqListTotalCounter() {
})
}
// NewSingleChatMsgRecvSuccessCounter
func NewSingleChatMsgRecvSuccessCounter() {
if SingleChatMsgRecvSuccessCounter != nil {
return
@ -329,6 +354,7 @@ func NewSingleChatMsgRecvSuccessCounter() {
})
}
// NewGroupChatMsgRecvSuccessCounter
func NewGroupChatMsgRecvSuccessCounter() {
if GroupChatMsgRecvSuccessCounter != nil {
return
@ -339,6 +365,7 @@ func NewGroupChatMsgRecvSuccessCounter() {
})
}
// NewWorkSuperGroupChatMsgRecvSuccessCounter
func NewWorkSuperGroupChatMsgRecvSuccessCounter() {
if WorkSuperGroupChatMsgRecvSuccessCounter != nil {
return
@ -349,6 +376,7 @@ func NewWorkSuperGroupChatMsgRecvSuccessCounter() {
})
}
// NewOnlineUserGauges
func NewOnlineUserGauges() {
if OnlineUserGauge != nil {
return
@ -359,6 +387,7 @@ func NewOnlineUserGauges() {
})
}
// NewSingleChatMsgProcessSuccessCounter
func NewSingleChatMsgProcessSuccessCounter() {
if SingleChatMsgProcessSuccessCounter != nil {
return
@ -369,6 +398,7 @@ func NewSingleChatMsgProcessSuccessCounter() {
})
}
// NewSingleChatMsgProcessFailedCounter
func NewSingleChatMsgProcessFailedCounter() {
if SingleChatMsgProcessFailedCounter != nil {
return
@ -379,6 +409,7 @@ func NewSingleChatMsgProcessFailedCounter() {
})
}
// NewGroupChatMsgProcessSuccessCounter
func NewGroupChatMsgProcessSuccessCounter() {
if GroupChatMsgProcessSuccessCounter != nil {
return
@ -389,6 +420,7 @@ func NewGroupChatMsgProcessSuccessCounter() {
})
}
// NewGroupChatMsgProcessFailedCounter
func NewGroupChatMsgProcessFailedCounter() {
if GroupChatMsgProcessFailedCounter != nil {
return
@ -399,6 +431,7 @@ func NewGroupChatMsgProcessFailedCounter() {
})
}
// NewWorkSuperGroupChatMsgProcessSuccessCounter
func NewWorkSuperGroupChatMsgProcessSuccessCounter() {
if WorkSuperGroupChatMsgProcessSuccessCounter != nil {
return
@ -409,6 +442,7 @@ func NewWorkSuperGroupChatMsgProcessSuccessCounter() {
})
}
// NewWorkSuperGroupChatMsgProcessFailedCounter
func NewWorkSuperGroupChatMsgProcessFailedCounter() {
if WorkSuperGroupChatMsgProcessFailedCounter != nil {
return
@ -419,6 +453,7 @@ func NewWorkSuperGroupChatMsgProcessFailedCounter() {
})
}
// NewMsgOnlinePushSuccessCounter
func NewMsgOnlinePushSuccessCounter() {
if MsgOnlinePushSuccessCounter != nil {
return
@ -429,6 +464,7 @@ func NewMsgOnlinePushSuccessCounter() {
})
}
// NewMsgOfflinePushSuccessCounter
func NewMsgOfflinePushSuccessCounter() {
if MsgOfflinePushSuccessCounter != nil {
return
@ -439,6 +475,7 @@ func NewMsgOfflinePushSuccessCounter() {
})
}
// NewMsgOfflinePushFailedCounter
func NewMsgOfflinePushFailedCounter() {
if MsgOfflinePushFailedCounter != nil {
return
@ -449,6 +486,7 @@ func NewMsgOfflinePushFailedCounter() {
})
}
// NewConversationCreateSuccessCounter
func NewConversationCreateSuccessCounter() {
if ConversationCreateSuccessCounter != nil {
return
@ -459,6 +497,7 @@ func NewConversationCreateSuccessCounter() {
})
}
// NewConversationCreateFailedCounter
func NewConversationCreateFailedCounter() {
if ConversationCreateFailedCounter != nil {
return

@ -26,6 +26,7 @@ import (
"github.com/prometheus/client_golang/prometheus/promhttp"
)
// StartPrometheusSrv
func StartPrometheusSrv(prometheusPort int) error {
if config.Config.Prometheus.Enable {
http.Handle("/metrics", promhttp.Handler())
@ -35,6 +36,7 @@ func StartPrometheusSrv(prometheusPort int) error {
return nil
}
// PrometheusHandler
func PrometheusHandler() gin.HandlerFunc {
h := promhttp.Handler()
return func(c *gin.Context) {
@ -42,16 +44,19 @@ func PrometheusHandler() gin.HandlerFunc {
}
}
// responseBodyWriter
type responseBodyWriter struct {
gin.ResponseWriter
body *bytes.Buffer
}
// Write
func (r responseBodyWriter) Write(b []byte) (int, error) {
r.body.Write(b)
return r.ResponseWriter.Write(b)
}
// PrometheusMiddleware
func PrometheusMiddleware(c *gin.Context) {
Inc(ApiRequestCounter)
w := &responseBodyWriter{body: &bytes.Buffer{}, ResponseWriter: c.Writer}
@ -64,6 +69,7 @@ func PrometheusMiddleware(c *gin.Context) {
}
}
// Inc
func Inc(counter prometheus.Counter) {
if config.Config.Prometheus.Enable {
if counter != nil {
@ -72,6 +78,7 @@ func Inc(counter prometheus.Counter) {
}
}
// Add
func Add(counter prometheus.Counter, add int) {
if config.Config.Prometheus.Enable {
if counter != nil {
@ -80,6 +87,7 @@ func Add(counter prometheus.Counter, add int) {
}
}
// GaugeInc
func GaugeInc(gauges prometheus.Gauge) {
if config.Config.Prometheus.Enable {
if gauges != nil {
@ -88,6 +96,7 @@ func GaugeInc(gauges prometheus.Gauge) {
}
}
// GaugeDec
func GaugeDec(gauges prometheus.Gauge) {
if config.Config.Prometheus.Enable {
if gauges != nil {

@ -27,15 +27,18 @@ import (
"github.com/OpenIMSDK/Open-IM-Server/pkg/utils"
)
// Claims
type Claims struct {
UserID string
PlatformID int // login platform
jwt.RegisteredClaims
}
// BuildClaims
func BuildClaims(uid string, platformID int, ttl int64) Claims {
now := time.Now()
before := now.Add(-time.Minute * 5)
return Claims{
UserID: uid,
PlatformID: platformID,
@ -47,12 +50,14 @@ func BuildClaims(uid string, platformID int, ttl int64) Claims {
}
}
// secret
func secret() jwt.Keyfunc {
return func(token *jwt.Token) (interface{}, error) {
return []byte(config.Config.Secret), nil
}
}
// GetClaimFromToken
func GetClaimFromToken(tokensString string) (*Claims, error) {
token, err := jwt.ParseWithClaims(tokensString, &Claims{}, secret())
if err != nil {
@ -73,10 +78,12 @@ func GetClaimFromToken(tokensString string) (*Claims, error) {
if claims, ok := token.Claims.(*Claims); ok && token.Valid {
return claims, nil
}
return nil, utils.Wrap(errs.ErrTokenUnknown, "")
}
}
// CheckAccessV3
func CheckAccessV3(ctx context.Context, ownerUserID string) (err error) {
opUserID := mcontext.GetOpUserID(ctx)
if utils.IsContain(opUserID, config.Config.Manager.UserID) {
@ -85,28 +92,35 @@ func CheckAccessV3(ctx context.Context, ownerUserID string) (err error) {
if opUserID == ownerUserID {
return nil
}
return errs.ErrNoPermission.Wrap(utils.GetSelfFuncName())
}
// IsAppManagerUid
func IsAppManagerUid(ctx context.Context) bool {
return utils.IsContain(mcontext.GetOpUserID(ctx), config.Config.Manager.UserID)
}
// CheckAdmin
func CheckAdmin(ctx context.Context) error {
if utils.IsContain(mcontext.GetOpUserID(ctx), config.Config.Manager.UserID) {
return nil
}
return errs.ErrNoPermission.Wrap(fmt.Sprintf("user %s is not admin userID", mcontext.GetOpUserID(ctx)))
}
// ParseRedisInterfaceToken
func ParseRedisInterfaceToken(redisToken interface{}) (*Claims, error) {
return GetClaimFromToken(string(redisToken.([]uint8)))
}
// IsManagerUserID
func IsManagerUserID(opUserID string) bool {
return utils.IsContain(opUserID, config.Config.Manager.UserID)
}
// WsVerifyToken
func WsVerifyToken(token, userID string, platformID int) error {
claim, err := GetClaimFromToken(token)
if err != nil {
@ -118,5 +132,6 @@ func WsVerifyToken(token, userID string, platformID int) error {
if claim.PlatformID != platformID {
return errs.ErrTokenInvalid.Wrap(fmt.Sprintf("token platform %d != %d", claim.PlatformID, platformID))
}
return nil
}

@ -20,6 +20,7 @@ import (
"google.golang.org/grpc"
)
// Conn
type Conn interface {
GetConns(ctx context.Context, serviceName string, opts ...grpc.DialOption) ([]grpc.ClientConnInterface, error)
GetConn(ctx context.Context, serviceName string, opts ...grpc.DialOption) (grpc.ClientConnInterface, error)
@ -29,6 +30,7 @@ type Conn interface {
GetClientLocalConns() map[string][]grpc.ClientConnInterface
}
// SvcDiscoveryRegistry
type SvcDiscoveryRegistry interface {
Conn
Register(serviceName, host string, port int, opts ...grpc.DialOption) error

@ -18,6 +18,7 @@ import (
"github.com/go-zookeeper/zk"
)
// RegisterConf2Registry
func (s *ZkClient) RegisterConf2Registry(key string, conf []byte) error {
exists, _, err := s.conn.Exists(s.getPath(key))
if err != nil {
@ -32,10 +33,13 @@ func (s *ZkClient) RegisterConf2Registry(key string, conf []byte) error {
if err != zk.ErrNodeExists {
return err
}
return nil
}
// GetConfFromRegistry
func (s *ZkClient) GetConfFromRegistry(key string) ([]byte, error) {
bytes, _, err := s.conn.Get(s.getPath(key))
return bytes, err
}

@ -35,6 +35,7 @@ var (
ErrConnIsNilButLocalNotNil = errors.New("conn is nil, but local is not nil")
)
// watch
func (s *ZkClient) watch() {
for {
event := <-s.eventChan
@ -69,6 +70,7 @@ func (s *ZkClient) watch() {
}
}
// GetConnsRemote
func (s *ZkClient) GetConnsRemote(serviceName string) (conns []resolver.Address, err error) {
path := s.getPath(serviceName)
_, _, _, err = s.conn.ChildrenW(path)
@ -86,15 +88,18 @@ func (s *ZkClient) GetConnsRemote(serviceName string) (conns []resolver.Address,
if err == zk.ErrNoNode {
return nil, errors.Wrap(err, "this is zk ErrNoNode")
}
return nil, errors.Wrap(err, "get children error")
}
log.ZDebug(context.Background(), "get addrs from remote", "conn", string(data))
conns = append(conns, resolver.Address{Addr: string(data), ServerName: serviceName})
}
}
return conns, nil
}
// GetConns
func (s *ZkClient) GetConns(ctx context.Context, serviceName string, opts ...grpc.DialOption) ([]grpc.ClientConnInterface, error) {
s.logger.Printf("get conns from client, serviceName: %s", serviceName)
s.lock.Lock()
@ -114,21 +119,26 @@ func (s *ZkClient) GetConns(ctx context.Context, serviceName string, opts ...grp
cc, err := grpc.DialContext(ctx, addr.Addr, append(s.options, opts...)...)
if err != nil {
log.ZError(context.Background(), "dialContext failed", err, "addr", addr.Addr, "opts", append(s.options, opts...))
return nil, errs.Wrap(err)
}
conns = append(conns, cc)
}
s.localConns[serviceName] = conns
}
return conns, nil
}
// GetConn
func (s *ZkClient) GetConn(ctx context.Context, serviceName string, opts ...grpc.DialOption) (grpc.ClientConnInterface, error) {
newOpts := append(s.options, grpc.WithDefaultServiceConfig(fmt.Sprintf(`{"LoadBalancingPolicy": "%s"}`, s.balancerName)))
s.logger.Printf("get conn from client, serviceName: %s", serviceName)
return grpc.DialContext(ctx, fmt.Sprintf("%s:///%s", s.scheme, serviceName), append(newOpts, opts...)...)
}
// CloseConn
func (s *ZkClient) CloseConn(conn grpc.ClientConnInterface) {
if closer, ok := conn.(io.Closer); ok {
closer.Close()

@ -21,16 +21,20 @@ import (
"google.golang.org/grpc"
)
// CreateRpcRootNodes
func (s *ZkClient) CreateRpcRootNodes(serviceNames []string) error {
for _, serviceName := range serviceNames {
if err := s.ensureName(serviceName); err != nil && err != zk.ErrNodeExists {
return err
}
}
return nil
}
// CreateTempNode
func (s *ZkClient) CreateTempNode(rpcRegisterName, addr string) (node string, err error) {
return s.conn.CreateProtectedEphemeralSequential(
s.getPath(rpcRegisterName)+"/"+addr+"_",
[]byte(addr),
@ -38,6 +42,7 @@ func (s *ZkClient) CreateTempNode(rpcRegisterName, addr string) (node string, er
)
}
// Register
func (s *ZkClient) Register(rpcRegisterName, host string, port int, opts ...grpc.DialOption) error {
if err := s.ensureName(rpcRegisterName); err != nil {
return err
@ -55,9 +60,11 @@ func (s *ZkClient) Register(rpcRegisterName, host string, port int, opts ...grpc
s.rpcRegisterAddr = addr
s.node = node
s.isRegistered = true
return nil
}
// UnRegister
func (s *ZkClient) UnRegister() error {
s.lock.Lock()
defer s.lock.Unlock()
@ -72,5 +79,6 @@ func (s *ZkClient) UnRegister() error {
s.isRegistered = false
s.localConns = make(map[string][]grpc.ClientConnInterface)
s.resolvers = make(map[string]*Resolver)
return nil
}

@ -23,6 +23,7 @@ import (
"google.golang.org/grpc/resolver"
)
// Resolver
type Resolver struct {
target resolver.Target
cc resolver.ClientConn
@ -31,6 +32,7 @@ type Resolver struct {
getConnsRemote func(serviceName string) (conns []resolver.Address, err error)
}
// ResolveNowZK
func (r *Resolver) ResolveNowZK(o resolver.ResolveNowOptions) {
log.ZDebug(
context.Background(),
@ -45,6 +47,7 @@ func (r *Resolver) ResolveNowZK(o resolver.ResolveNowOptions) {
newConns, err := r.getConnsRemote(strings.TrimLeft(r.target.URL.Path, "/"))
if err != nil {
log.ZError(context.Background(), "resolve now error", err, "target", r.target)
return
}
r.addrs = newConns
@ -58,15 +61,19 @@ func (r *Resolver) ResolveNowZK(o resolver.ResolveNowOptions) {
"zk path",
r.target.URL.Path,
)
return
}
log.ZDebug(context.Background(), "resolve now finished", "target", r.target, "conns", r.addrs)
}
// ResolveNow
func (r *Resolver) ResolveNow(o resolver.ResolveNowOptions) {}
// Close
func (s *Resolver) Close() {}
// Build
func (s *ZkClient) Build(
target resolver.Target,
cc resolver.ClientConn,
@ -76,6 +83,7 @@ func (s *ZkClient) Build(
serviceName := strings.TrimLeft(target.URL.Path, "/")
if oldResolver, ok := s.resolvers[serviceName]; ok {
s.logger.Printf("rpc resolver exist: %+v, cc: %+v, key: %s", target, cc.UpdateState, serviceName)
return oldResolver, nil
}
r := &Resolver{}
@ -87,7 +95,9 @@ func (s *ZkClient) Build(
defer s.lock.Unlock()
s.resolvers[serviceName] = r
s.logger.Printf("build resolver finished: %+v, cc: %+v, key: %s", target, cc.UpdateState, serviceName)
return r, nil
}
// Scheme
func (s *ZkClient) Scheme() string { return s.scheme }

@ -30,10 +30,12 @@ const (
timeout = 5
)
// Logger
type Logger interface {
Printf(string, ...interface{})
}
// ZkClient
type ZkClient struct {
zkServers []string
zkRoot string
@ -62,14 +64,17 @@ type ZkClient struct {
logger Logger
}
// ZkOption
type ZkOption func(*ZkClient)
// WithRoundRobin
func WithRoundRobin() ZkOption {
return func(client *ZkClient) {
client.balancerName = "round_robin"
}
}
// WithUserNameAndPassword
func WithUserNameAndPassword(userName, password string) ZkOption {
return func(client *ZkClient) {
client.userName = userName
@ -83,24 +88,28 @@ func WithOptions(opts ...grpc.DialOption) ZkOption {
}
}
// WithFreq
func WithFreq(freq time.Duration) ZkOption {
return func(client *ZkClient) {
client.ticker = time.NewTicker(freq)
}
}
// WithTimeout
func WithTimeout(timeout int) ZkOption {
return func(client *ZkClient) {
client.timeout = timeout
}
}
// WithLogger
func WithLogger(logger Logger) ZkOption {
return func(client *ZkClient) {
client.logger = logger
}
}
// NewClient
func NewClient(zkServers []string, zkRoot string, options ...ZkOption) (*ZkClient, error) {
client := &ZkClient{
zkServers: zkServers,
@ -134,15 +143,18 @@ func NewClient(zkServers []string, zkRoot string, options ...ZkOption) (*ZkClien
client.conn = conn
if err := client.ensureRoot(); err != nil {
client.CloseZK()
return nil, err
}
resolver.Register(client)
go client.refresh()
go client.watch()
time.Sleep(time.Millisecond * 50)
return client, nil
}
// CloseZK
func (s *ZkClient) CloseZK() {
s.conn.Close()
}
@ -158,6 +170,7 @@ func (s *ZkClient) ensureAndCreate(node string) error {
return err
}
}
return nil
}
@ -189,14 +202,17 @@ func (s *ZkClient) flushResolver(serviceName string) {
}
}
// GetZkConn
func (s *ZkClient) GetZkConn() *zk.Conn {
return s.conn
}
// GetRootPath
func (s *ZkClient) GetRootPath() string {
return s.zkRoot
}
// GetNode
func (s *ZkClient) GetNode() string {
return s.node
}
@ -217,10 +233,12 @@ func (s *ZkClient) getAddr(host string, port int) string {
return net.JoinHostPort(host, strconv.Itoa(port))
}
// AddOption
func (s *ZkClient) AddOption(opts ...grpc.DialOption) {
s.options = append(s.options, opts...)
}
// GetClientLocalConns
func (s *ZkClient) GetClientLocalConns() map[string][]grpc.ClientConnInterface {
return s.localConns
}

@ -15,12 +15,12 @@
package errs
import (
"fmt"
"strings"
"github.com/pkg/errors"
)
// CodeError
type CodeError interface {
Code() int
Msg() string
@ -32,6 +32,7 @@ type CodeError interface {
error
}
// NewCodeError
func NewCodeError(code int, msg string) CodeError {
return &codeError{
code: code,
@ -64,6 +65,7 @@ func (e *codeError) WithDetail(detail string) CodeError {
} else {
d = e.detail + ", " + detail
}
return &codeError{
code: e.code,
msg: e.msg,
@ -93,13 +95,15 @@ func (e *codeError) Is(err error, loose ...bool) bool {
return codeErr.Code() == e.code
}
}
return false
}
func (e *codeError) Error() string {
return fmt.Sprintf("%s", e.msg)
return e.msg
}
// Unwrap
func Unwrap(err error) error {
for err != nil {
unwrap, ok := err.(interface {
@ -110,9 +114,11 @@ func Unwrap(err error) error {
}
err = unwrap.Unwrap()
}
return err
}
// Wrap
func Wrap(err error, msg ...string) error {
if err == nil {
return nil
@ -120,5 +126,6 @@ func Wrap(err error, msg ...string) error {
if len(msg) == 0 {
return errors.WithStack(err)
}
return errors.Wrap(err, strings.Join(msg, ", "))
}

@ -14,6 +14,7 @@
package errs
// Relation
var Relation = &relation{m: make(map[int]map[int]struct{})}
func init() {
@ -52,5 +53,6 @@ func (r *relation) Is(parent, child int) bool {
return false
}
_, ok = s[child]
return ok
}

@ -19,6 +19,7 @@ import (
"github.com/OpenIMSDK/Open-IM-Server/pkg/errs"
)
// Check
func (x *UserTokenReq) Check() error {
if x.UserID == "" {
return errs.ErrArgs.Wrap("userID is empty")
@ -26,9 +27,11 @@ func (x *UserTokenReq) Check() error {
if x.PlatformID > constant.AdminPlatformID || x.PlatformID < constant.IOSPlatformID {
return errs.ErrArgs.Wrap("platform is invalidate")
}
return nil
}
// Check
func (x *ForceLogoutReq) Check() error {
if x.UserID == "" {
return errs.ErrArgs.Wrap("userID is empty")
@ -36,12 +39,15 @@ func (x *ForceLogoutReq) Check() error {
if x.PlatformID > constant.AdminPlatformID || x.PlatformID < constant.IOSPlatformID {
return errs.ErrArgs.Wrap("platformID is invalidate")
}
return nil
}
// Check
func (x *ParseTokenReq) Check() error {
if x.Token == "" {
return errs.ErrArgs.Wrap("userID is empty")
}
return nil
}

@ -22,13 +22,14 @@ package auth
import (
context "context"
reflect "reflect"
sync "sync"
grpc "google.golang.org/grpc"
codes "google.golang.org/grpc/codes"
status "google.golang.org/grpc/status"
protoreflect "google.golang.org/protobuf/reflect/protoreflect"
protoimpl "google.golang.org/protobuf/runtime/protoimpl"
reflect "reflect"
sync "sync"
)
const (

@ -16,13 +16,16 @@ package conversation
import "github.com/OpenIMSDK/Open-IM-Server/pkg/errs"
// Check
func (x *ConversationReq) Check() error {
if x.ConversationID == "" {
return errs.ErrArgs.Wrap("conversation is empty")
}
return nil
}
// Check
func (x *Conversation) Check() error {
if x.OwnerUserID == "" {
return errs.ErrArgs.Wrap("OwnerUserID is empty")
@ -36,9 +39,11 @@ func (x *Conversation) Check() error {
if x.RecvMsgOpt < 0 || x.RecvMsgOpt > 2 {
return errs.ErrArgs.Wrap("RecvMsgOpt is invalid")
}
return nil
}
// // Check
// func (x *ModifyConversationFieldReq) Check() error {
// if x.UserIDList == nil {
// return errs.ErrArgs.Wrap("userIDList is empty")
@ -46,9 +51,11 @@ func (x *Conversation) Check() error {
// if x.Conversation == nil {
// return errs.ErrArgs.Wrap("conversation is empty")
// }
//
// return nil
// }
// Check
func (x *SetConversationReq) Check() error {
if x.Conversation == nil {
return errs.ErrArgs.Wrap("Conversation is empty")
@ -56,9 +63,11 @@ func (x *SetConversationReq) Check() error {
if x.Conversation.ConversationID == "" {
return errs.ErrArgs.Wrap("conversationID is empty")
}
return nil
}
// // Check
// func (x *SetRecvMsgOptReq) Check() error {
// if x.OwnerUserID == "" {
// return errs.ErrArgs.Wrap("ownerUserID is empty")
@ -69,9 +78,11 @@ func (x *SetConversationReq) Check() error {
// if x.RecvMsgOpt > 2 || x.RecvMsgOpt < 0 {
// return errs.ErrArgs.Wrap("MsgReceiveOpt is invalid")
// }
//
// return nil
// }
// Check
func (x *GetConversationReq) Check() error {
if x.OwnerUserID == "" {
return errs.ErrArgs.Wrap("ownerUserID is empty")
@ -79,9 +90,11 @@ func (x *GetConversationReq) Check() error {
if x.ConversationID == "" {
return errs.ErrArgs.Wrap("conversationID is empty")
}
return nil
}
// Check
func (x *GetConversationsReq) Check() error {
if x.OwnerUserID == "" {
return errs.ErrArgs.Wrap("ownerUserID is empty")
@ -89,17 +102,21 @@ func (x *GetConversationsReq) Check() error {
if x.ConversationIDs == nil {
return errs.ErrArgs.Wrap("conversationIDs is empty")
}
return nil
}
// Check
func (x *GetAllConversationsReq) Check() error {
if x.OwnerUserID == "" {
return errs.ErrArgs.Wrap("ownerUserID is empty")
}
return nil
}
//
// // Check
// func (x *BatchSetConversationsReq) Check() error {
// if x.Conversations == nil {
// return errs.ErrArgs.Wrap("conversations is empty")
@ -107,23 +124,29 @@ func (x *GetAllConversationsReq) Check() error {
// if x.OwnerUserID == "" {
// return errs.ErrArgs.Wrap("conversation is empty")
// }
//
// return nil
// }
// Check
func (x *GetRecvMsgNotNotifyUserIDsReq) Check() error {
if x.GroupID == "" {
return errs.ErrArgs.Wrap("groupID is empty")
}
return nil
}
// Check
func (x *CreateGroupChatConversationsReq) Check() error {
if x.GroupID == "" {
return errs.ErrArgs.Wrap("groupID is empty")
}
return nil
}
// Check
func (x *SetConversationMaxSeqReq) Check() error {
if x.ConversationID == "" {
return errs.ErrArgs.Wrap("conversationID is empty")
@ -134,9 +157,11 @@ func (x *SetConversationMaxSeqReq) Check() error {
if x.MaxSeq <= 0 {
return errs.ErrArgs.Wrap("maxSeq is invalid")
}
return nil
}
// Check
func (x *SetConversationsReq) Check() error {
if x.UserIDs == nil {
return errs.ErrArgs.Wrap("userID is empty")
@ -144,19 +169,24 @@ func (x *SetConversationsReq) Check() error {
if x.Conversation == nil {
return errs.ErrArgs.Wrap("conversation is empty")
}
return nil
}
// Check
func (x *GetUserConversationIDsHashReq) Check() error {
if x.OwnerUserID == "" {
return errs.ErrArgs.Wrap("ownerUserID is empty")
}
return nil
}
// Check
func (x *GetConversationsByConversationIDReq) Check() error {
if x.ConversationIDs == nil {
return errs.ErrArgs.Wrap("conversationIDs is empty")
}
return nil
}

@ -22,14 +22,16 @@ package conversation
import (
context "context"
wrapperspb "github.com/OpenIMSDK/Open-IM-Server/pkg/proto/wrapperspb"
reflect "reflect"
sync "sync"
grpc "google.golang.org/grpc"
codes "google.golang.org/grpc/codes"
status "google.golang.org/grpc/status"
protoreflect "google.golang.org/protobuf/reflect/protoreflect"
protoimpl "google.golang.org/protobuf/runtime/protoimpl"
reflect "reflect"
sync "sync"
wrapperspb "github.com/OpenIMSDK/Open-IM-Server/pkg/proto/wrapperspb"
)
const (

@ -21,10 +21,11 @@
package errinfo
import (
protoreflect "google.golang.org/protobuf/reflect/protoreflect"
protoimpl "google.golang.org/protobuf/runtime/protoimpl"
reflect "reflect"
sync "sync"
protoreflect "google.golang.org/protobuf/reflect/protoreflect"
protoimpl "google.golang.org/protobuf/runtime/protoimpl"
)
const (

@ -16,6 +16,7 @@ package friend
import "github.com/OpenIMSDK/Open-IM-Server/pkg/errs"
// Check
func (x *GetPaginationFriendsReq) Check() error {
if x.Pagination == nil {
return errs.ErrArgs.Wrap("pagination is empty")
@ -26,9 +27,11 @@ func (x *GetPaginationFriendsReq) Check() error {
if x.UserID == "" {
return errs.ErrArgs.Wrap("userID is empty")
}
return nil
}
// Check
func (x *ApplyToAddFriendReq) Check() error {
if x.ToUserID == "" {
return errs.ErrArgs.Wrap("toUserID is empty")
@ -36,9 +39,11 @@ func (x *ApplyToAddFriendReq) Check() error {
if x.FromUserID == "" {
return errs.ErrArgs.Wrap("fromUserID is empty")
}
return nil
}
// Check
func (x *ImportFriendReq) Check() error {
if x.OwnerUserID == "" {
return errs.ErrArgs.Wrap("ownerUserID is empty")
@ -46,9 +51,11 @@ func (x *ImportFriendReq) Check() error {
if x.FriendUserIDs == nil {
return errs.ErrArgs.Wrap("friendUserIDS is empty")
}
return nil
}
// Check
func (x *GetPaginationFriendsApplyToReq) Check() error {
if x.UserID == "" {
return errs.ErrArgs.Wrap("userID is empty")
@ -59,9 +66,11 @@ func (x *GetPaginationFriendsApplyToReq) Check() error {
if x.Pagination.PageNumber < 1 {
return errs.ErrArgs.Wrap("pageNumber is invalid")
}
return nil
}
// Check
func (x *GetDesignatedFriendsReq) Check() error {
if x.OwnerUserID == "" {
return errs.ErrArgs.Wrap("ownerUserID is empty")
@ -69,9 +78,11 @@ func (x *GetDesignatedFriendsReq) Check() error {
if x.FriendUserIDs == nil {
return errs.ErrArgs.Wrap("friendUserIDS is empty")
}
return nil
}
// Check
func (x *AddBlackReq) Check() error {
if x.OwnerUserID == "" {
return errs.ErrArgs.Wrap("ownerUserID is empty")
@ -79,9 +90,11 @@ func (x *AddBlackReq) Check() error {
if x.BlackUserID == "" {
return errs.ErrArgs.Wrap("BlackUserID is empty")
}
return nil
}
// Check
func (x *RemoveBlackReq) Check() error {
if x.OwnerUserID == "" {
return errs.ErrArgs.Wrap("ownerUserID is empty")
@ -89,9 +102,11 @@ func (x *RemoveBlackReq) Check() error {
if x.BlackUserID == "" {
return errs.ErrArgs.Wrap("BlackUserID is empty")
}
return nil
}
// Check
func (x *GetPaginationBlacksReq) Check() error {
if x.UserID == "" {
return errs.ErrArgs.Wrap("userID is empty")
@ -102,9 +117,11 @@ func (x *GetPaginationBlacksReq) Check() error {
if x.Pagination.PageNumber < 1 {
return errs.ErrArgs.Wrap("pageNumber is invalid")
}
return nil
}
// Check
func (x *IsFriendReq) Check() error {
if x.UserID1 == "" {
return errs.ErrArgs.Wrap("userID1 is empty")
@ -112,9 +129,11 @@ func (x *IsFriendReq) Check() error {
if x.UserID2 == "" {
return errs.ErrArgs.Wrap("userID2 is empty")
}
return nil
}
// Check
func (x *IsBlackReq) Check() error {
if x.UserID1 == "" {
return errs.ErrArgs.Wrap("userID1 is empty")
@ -122,9 +141,11 @@ func (x *IsBlackReq) Check() error {
if x.UserID2 == "" {
return errs.ErrArgs.Wrap("userID2 is empty")
}
return nil
}
// Check
func (x *DeleteFriendReq) Check() error {
if x.OwnerUserID == "" {
return errs.ErrArgs.Wrap("userID1 is empty")
@ -132,9 +153,11 @@ func (x *DeleteFriendReq) Check() error {
if x.FriendUserID == "" {
return errs.ErrArgs.Wrap("userID2 is empty")
}
return nil
}
// Check
func (x *RespondFriendApplyReq) Check() error {
if x.ToUserID == "" {
return errs.ErrArgs.Wrap("toUserID is empty")
@ -142,9 +165,11 @@ func (x *RespondFriendApplyReq) Check() error {
if x.FromUserID == "" {
return errs.ErrArgs.Wrap("fromUserID is empty")
}
return nil
}
// Check
func (x *SetFriendRemarkReq) Check() error {
if x.OwnerUserID == "" {
return errs.ErrArgs.Wrap("ownerUserID is empty")
@ -152,9 +177,11 @@ func (x *SetFriendRemarkReq) Check() error {
if x.FriendUserID == "" {
return errs.ErrArgs.Wrap("fromUserID is empty")
}
return nil
}
// Check
func (x *GetPaginationFriendsApplyFromReq) Check() error {
if x.UserID == "" {
return errs.ErrArgs.Wrap("userID is empty")
@ -165,12 +192,15 @@ func (x *GetPaginationFriendsApplyFromReq) Check() error {
if x.Pagination.PageNumber < 1 {
return errs.ErrArgs.Wrap("pageNumber is invalid")
}
return nil
}
// Check
func (x *GetFriendIDsReq) Check() error {
if x.UserID == "" {
return errs.ErrArgs.Wrap("userID is empty")
}
return nil
}

@ -22,14 +22,16 @@ package friend
import (
context "context"
sdkws "github.com/OpenIMSDK/Open-IM-Server/pkg/proto/sdkws"
reflect "reflect"
sync "sync"
grpc "google.golang.org/grpc"
codes "google.golang.org/grpc/codes"
status "google.golang.org/grpc/status"
protoreflect "google.golang.org/protobuf/reflect/protoreflect"
protoimpl "google.golang.org/protobuf/runtime/protoimpl"
reflect "reflect"
sync "sync"
sdkws "github.com/OpenIMSDK/Open-IM-Server/pkg/proto/sdkws"
)
const (

@ -16,6 +16,7 @@ package group
import "github.com/OpenIMSDK/Open-IM-Server/pkg/errs"
// Check
func (x *CreateGroupReq) Check() error {
if x.MemberUserIDs == nil {
return errs.ErrArgs.Wrap("memberUserIDS is empty")
@ -29,16 +30,20 @@ func (x *CreateGroupReq) Check() error {
if x.OwnerUserID == "" {
return errs.ErrArgs.Wrap("ownerUserID")
}
return nil
}
// Check
func (x *GetGroupsInfoReq) Check() error {
if x.GroupIDs == nil {
return errs.ErrArgs.Wrap("GroupIDs")
}
return nil
}
// Check
func (x *SetGroupInfoReq) Check() error {
if x.GroupInfoForSet == nil {
return errs.ErrArgs.Wrap("GroupInfoForSets is empty")
@ -46,9 +51,11 @@ func (x *SetGroupInfoReq) Check() error {
if x.GroupInfoForSet.GroupID == "" {
return errs.ErrArgs.Wrap("GroupID is empty")
}
return nil
}
// Check
func (x *GetGroupApplicationListReq) Check() error {
if x.Pagination == nil {
return errs.ErrArgs.Wrap("pagination is empty")
@ -59,9 +66,11 @@ func (x *GetGroupApplicationListReq) Check() error {
if x.FromUserID == "" {
return errs.ErrArgs.Wrap("fromUserID is empty")
}
return nil
}
// Check
func (x *GetUserReqApplicationListReq) Check() error {
if x.UserID == "" {
return errs.ErrArgs.Wrap("UserID is empty")
@ -72,9 +81,11 @@ func (x *GetUserReqApplicationListReq) Check() error {
if x.Pagination.PageNumber < 1 {
return errs.ErrArgs.Wrap("pageNumber is invalid")
}
return nil
}
// Check
func (x *TransferGroupOwnerReq) Check() error {
if x.GroupID == "" {
return errs.ErrArgs.Wrap("groupID is empty")
@ -85,9 +96,11 @@ func (x *TransferGroupOwnerReq) Check() error {
if x.NewOwnerUserID == "" {
return errs.ErrArgs.Wrap("newOwnerUserID is empty")
}
return nil
}
// Check
func (x *JoinGroupReq) Check() error {
if x.GroupID == "" {
return errs.ErrArgs.Wrap("groupID is empty")
@ -100,9 +113,11 @@ func (x *JoinGroupReq) Check() error {
return errs.ErrArgs.Wrap("inviterUserID is empty")
}
}
return nil
}
// Check
func (x *GroupApplicationResponseReq) Check() error {
if x.GroupID == "" {
return errs.ErrArgs.Wrap("groupID is empty")
@ -113,16 +128,20 @@ func (x *GroupApplicationResponseReq) Check() error {
if x.HandleResult > 1 || x.HandleResult < -1 {
return errs.ErrArgs.Wrap("handleResult is invalid")
}
return nil
}
// Check
func (x *QuitGroupReq) Check() error {
if x.GroupID == "" {
return errs.ErrArgs.Wrap("groupID is empty")
}
return nil
}
// Check
func (x *GetGroupMemberListReq) Check() error {
if x.GroupID == "" {
return errs.ErrArgs.Wrap("groupID is empty")
@ -136,9 +155,11 @@ func (x *GetGroupMemberListReq) Check() error {
if x.Filter < 0 || x.Filter > 5 {
return errs.ErrArgs.Wrap("filter is invalid")
}
return nil
}
// Check
func (x *GetGroupMembersInfoReq) Check() error {
if x.GroupID == "" {
return errs.ErrArgs.Wrap("groupID is empty")
@ -146,9 +167,11 @@ func (x *GetGroupMembersInfoReq) Check() error {
if x.UserIDs == nil {
return errs.ErrArgs.Wrap("userIDs is empty")
}
return nil
}
// Check
func (x *KickGroupMemberReq) Check() error {
if x.GroupID == "" {
return errs.ErrArgs.Wrap("groupID is empty")
@ -156,9 +179,11 @@ func (x *KickGroupMemberReq) Check() error {
if x.KickedUserIDs == nil {
return errs.ErrArgs.Wrap("kickUserIDs is empty")
}
return nil
}
// Check
func (x *GetJoinedGroupListReq) Check() error {
if x.Pagination == nil {
return errs.ErrArgs.Wrap("pagination is empty")
@ -169,9 +194,11 @@ func (x *GetJoinedGroupListReq) Check() error {
if x.FromUserID == "" {
return errs.ErrArgs.Wrap("fromUserID is empty")
}
return nil
}
// Check
func (x *InviteUserToGroupReq) Check() error {
if x.GroupID == "" {
return errs.ErrArgs.Wrap("groupID is empty")
@ -179,9 +206,11 @@ func (x *InviteUserToGroupReq) Check() error {
if x.InvitedUserIDs == nil {
return errs.ErrArgs.Wrap("invitedUserIDs is empty")
}
return nil
}
// Check
func (x *GetGroupAllMemberReq) Check() error {
if x.GroupID == "" {
return errs.ErrArgs.Wrap("groupID is empty")
@ -192,9 +221,11 @@ func (x *GetGroupAllMemberReq) Check() error {
if x.Pagination.PageNumber < 1 {
return errs.ErrArgs.Wrap("pageNumber is invalid")
}
return nil
}
// Check
func (x *GetGroupsReq) Check() error {
if x.Pagination == nil {
return errs.ErrArgs.Wrap("pagination is empty")
@ -202,16 +233,20 @@ func (x *GetGroupsReq) Check() error {
if x.Pagination.PageNumber < 1 {
return errs.ErrArgs.Wrap("pageNumber is invalid")
}
return nil
}
// Check
func (x *GetGroupMemberReq) Check() error {
if x.GroupID == "" {
return errs.ErrArgs.Wrap("groupID is empty")
}
return nil
}
// Check
func (x *GetGroupMembersCMSReq) Check() error {
if x.GroupID == "" {
return errs.ErrArgs.Wrap("groupID is empty")
@ -222,16 +257,20 @@ func (x *GetGroupMembersCMSReq) Check() error {
if x.Pagination.PageNumber < 1 {
return errs.ErrArgs.Wrap("pageNumber is invalid")
}
return nil
}
// Check
func (x *DismissGroupReq) Check() error {
if x.GroupID == "" {
return errs.ErrArgs.Wrap("groupID is empty")
}
return nil
}
// Check
func (x *MuteGroupMemberReq) Check() error {
if x.GroupID == "" {
return errs.ErrArgs.Wrap("groupID is empty")
@ -242,9 +281,11 @@ func (x *MuteGroupMemberReq) Check() error {
if x.MutedSeconds <= 0 {
return errs.ErrArgs.Wrap("mutedSeconds is empty")
}
return nil
}
// Check
func (x *CancelMuteGroupMemberReq) Check() error {
if x.GroupID == "" {
return errs.ErrArgs.Wrap("groupID is empty")
@ -252,37 +293,47 @@ func (x *CancelMuteGroupMemberReq) Check() error {
if x.UserID == "" {
return errs.ErrArgs.Wrap("userID is empty")
}
return nil
}
// Check
func (x *MuteGroupReq) Check() error {
if x.GroupID == "" {
return errs.ErrArgs.Wrap("groupID is empty")
}
return nil
}
// Check
func (x *CancelMuteGroupReq) Check() error {
if x.GroupID == "" {
return errs.ErrArgs.Wrap("groupID is empty")
}
return nil
}
// Check
func (x *GetJoinedSuperGroupListReq) Check() error {
if x.UserID == "" {
return errs.ErrArgs.Wrap("userID is empty")
}
return nil
}
// Check
func (x *GetSuperGroupsInfoReq) Check() error {
if x.GroupIDs == nil {
return errs.ErrArgs.Wrap("GroupIDs is empty")
}
return nil
}
// Check
func (x *SetGroupMemberInfo) Check() error {
if x.GroupID == "" {
return errs.ErrArgs.Wrap("GroupID is empty")
@ -290,23 +341,29 @@ func (x *SetGroupMemberInfo) Check() error {
if x.UserID == "" {
return errs.ErrArgs.Wrap("userID is empty")
}
return nil
}
// Check
func (x *SetGroupMemberInfoReq) Check() error {
if x.Members == nil {
return errs.ErrArgs.Wrap("Members is empty")
}
return nil
}
// Check
func (x *GetGroupAbstractInfoReq) Check() error {
if x.GroupIDs == nil {
return errs.ErrArgs.Wrap("GroupID is empty")
}
return nil
}
// Check
func (x *GetUserInGroupMembersReq) Check() error {
if x.GroupIDs == nil {
return errs.ErrArgs.Wrap("GroupID is empty")
@ -314,16 +371,20 @@ func (x *GetUserInGroupMembersReq) Check() error {
if x.UserID == "" {
return errs.ErrArgs.Wrap("userID is empty")
}
return nil
}
// Check
func (x *GetGroupMemberUserIDsReq) Check() error {
if x.GroupID == "" {
return errs.ErrArgs.Wrap("GroupID is empty")
}
return nil
}
// Check
func (x *GetGroupMemberRoleLevelReq) Check() error {
if x.GroupID == "" {
return errs.ErrArgs.Wrap("GroupID is empty")
@ -331,16 +392,20 @@ func (x *GetGroupMemberRoleLevelReq) Check() error {
if x.RoleLevels == nil {
return errs.ErrArgs.Wrap("rolesLevel is empty")
}
return nil
}
// Check
func (x *GetGroupInfoCacheReq) Check() error {
if x.GroupID == "" {
return errs.ErrArgs.Wrap("GroupID is empty")
}
return nil
}
// Check
func (x *GetGroupMemberCacheReq) Check() error {
if x.GroupID == "" {
return errs.ErrArgs.Wrap("GroupID is empty")
@ -348,5 +413,6 @@ func (x *GetGroupMemberCacheReq) Check() error {
if x.GroupMemberID == "" {
return errs.ErrArgs.Wrap("GroupMemberID is empty")
}
return nil
}

@ -22,15 +22,17 @@ package group
import (
context "context"
sdkws "github.com/OpenIMSDK/Open-IM-Server/pkg/proto/sdkws"
wrapperspb "github.com/OpenIMSDK/Open-IM-Server/pkg/proto/wrapperspb"
reflect "reflect"
sync "sync"
grpc "google.golang.org/grpc"
codes "google.golang.org/grpc/codes"
status "google.golang.org/grpc/status"
protoreflect "google.golang.org/protobuf/reflect/protoreflect"
protoimpl "google.golang.org/protobuf/runtime/protoimpl"
reflect "reflect"
sync "sync"
sdkws "github.com/OpenIMSDK/Open-IM-Server/pkg/proto/sdkws"
wrapperspb "github.com/OpenIMSDK/Open-IM-Server/pkg/proto/wrapperspb"
)
const (

@ -16,13 +16,16 @@ package msg
import "github.com/OpenIMSDK/Open-IM-Server/pkg/errs"
// Check
func (x *GetMaxAndMinSeqReq) Check() error {
if x.UserID == "" {
return errs.ErrArgs.Wrap("userID is empty")
}
return nil
}
// Check
func (x *SendMsgReq) Check() error {
if x.MsgData == nil {
return errs.ErrArgs.Wrap("MsgData is empty")
@ -30,16 +33,20 @@ func (x *SendMsgReq) Check() error {
if err := x.MsgData.Check(); err != nil {
return err
}
return nil
}
// Check
func (x *SetSendMsgStatusReq) Check() error {
if x.Status < 0 || x.Status > 3 {
return errs.ErrArgs.Wrap("status is invalid")
}
return nil
}
// Check
func (x *GetSendMsgStatusReq) Check() error {
return nil
}
@ -99,10 +106,12 @@ func (x *GetSendMsgStatusReq) Check() error {
// return nil
// }
// Check
func (x *DelMsgsReq) Check() error {
return nil
}
// Check
func (x *RevokeMsgReq) Check() error {
if x.ConversationID == "" {
return errs.ErrArgs.Wrap("conversationID is empty")
@ -113,9 +122,11 @@ func (x *RevokeMsgReq) Check() error {
if x.UserID == "" {
return errs.ErrArgs.Wrap("userID is empty")
}
return nil
}
// Check
func (x *MarkMsgsAsReadReq) Check() error {
if x.ConversationID == "" {
return errs.ErrArgs.Wrap("conversationID is empty")
@ -131,9 +142,11 @@ func (x *MarkMsgsAsReadReq) Check() error {
return errs.ErrArgs.Wrap("seqs has 0 value is invalid")
}
}
return nil
}
// Check
func (x *MarkConversationAsReadReq) Check() error {
if x.ConversationID == "" {
return errs.ErrArgs.Wrap("conversationID is empty")
@ -149,9 +162,11 @@ func (x *MarkConversationAsReadReq) Check() error {
return errs.ErrArgs.Wrap("seqs has 0 value is invalid")
}
}
return nil
}
// Check
func (x *SetConversationHasReadSeqReq) Check() error {
if x.ConversationID == "" {
return errs.ErrArgs.Wrap("conversationID is empty")
@ -162,9 +177,11 @@ func (x *SetConversationHasReadSeqReq) Check() error {
if x.HasReadSeq < 1 {
return errs.ErrArgs.Wrap("hasReadSeq is invalid")
}
return nil
}
// Check
func (x *ClearConversationsMsgReq) Check() error {
if x.ConversationIDs == nil {
return errs.ErrArgs.Wrap("conversationIDs is empty")
@ -172,16 +189,20 @@ func (x *ClearConversationsMsgReq) Check() error {
if x.UserID == "" {
return errs.ErrArgs.Wrap("userID is empty")
}
return nil
}
// Check
func (x *UserClearAllMsgReq) Check() error {
if x.UserID == "" {
return errs.ErrArgs.Wrap("userID is empty")
}
return nil
}
// Check
func (x *DeleteMsgsReq) Check() error {
if x.ConversationID == "" {
return errs.ErrArgs.Wrap("conversationID is empty")
@ -192,26 +213,33 @@ func (x *DeleteMsgsReq) Check() error {
if x.Seqs == nil {
return errs.ErrArgs.Wrap("seqs is empty")
}
return nil
}
// Check
func (x *DeleteMsgPhysicalReq) Check() error {
if x.ConversationIDs == nil {
return errs.ErrArgs.Wrap("conversationIDs is empty")
}
return nil
}
// Check
func (x *GetConversationMaxSeqReq) Check() error {
if x.ConversationID == "" {
return errs.ErrArgs.Wrap("conversationID is empty")
}
return nil
}
// Check
func (x *GetConversationsHasReadAndMaxSeqReq) Check() error {
if x.UserID == "" {
return errs.ErrArgs.Wrap("userID is empty")
}
return nil
}

@ -22,14 +22,16 @@ package msg
import (
context "context"
sdkws "github.com/OpenIMSDK/Open-IM-Server/pkg/proto/sdkws"
reflect "reflect"
sync "sync"
grpc "google.golang.org/grpc"
codes "google.golang.org/grpc/codes"
status "google.golang.org/grpc/status"
protoreflect "google.golang.org/protobuf/reflect/protoreflect"
protoimpl "google.golang.org/protobuf/runtime/protoimpl"
reflect "reflect"
sync "sync"
sdkws "github.com/OpenIMSDK/Open-IM-Server/pkg/proto/sdkws"
)
const (

@ -16,6 +16,7 @@ package msggateway
import "github.com/OpenIMSDK/Open-IM-Server/pkg/errs"
// Check
func (x *OnlinePushMsgReq) Check() error {
if x.MsgData == nil {
return errs.ErrArgs.Wrap("MsgData is empty")
@ -26,9 +27,11 @@ func (x *OnlinePushMsgReq) Check() error {
if x.PushToUserID == "" {
return errs.ErrArgs.Wrap("PushToUserID is empty")
}
return nil
}
// Check
func (x *OnlineBatchPushOneMsgReq) Check() error {
if x.MsgData == nil {
return errs.ErrArgs.Wrap("MsgData is empty")
@ -39,16 +42,20 @@ func (x *OnlineBatchPushOneMsgReq) Check() error {
if x.PushToUserIDs == nil {
return errs.ErrArgs.Wrap("PushToUserIDs is empty")
}
return nil
}
// Check
func (x *GetUsersOnlineStatusReq) Check() error {
if x.UserIDs == nil {
return errs.ErrArgs.Wrap("UserIDs is empty")
}
return nil
}
// Check
func (x *KickUserOfflineReq) Check() error {
if x.PlatformID < 1 || x.PlatformID > 9 {
return errs.ErrArgs.Wrap("PlatformID is invalid")
@ -56,9 +63,11 @@ func (x *KickUserOfflineReq) Check() error {
if x.KickUserIDList == nil {
return errs.ErrArgs.Wrap("KickUserIDList is empty")
}
return nil
}
// Check
func (x *MultiTerminalLoginCheckReq) Check() error {
if x.PlatformID < 1 || x.PlatformID > 9 {
return errs.ErrArgs.Wrap("PlatformID is invalid")
@ -69,5 +78,6 @@ func (x *MultiTerminalLoginCheckReq) Check() error {
if x.Token == "" {
return errs.ErrArgs.Wrap("Token is empty")
}
return nil
}

@ -22,14 +22,16 @@ package msggateway
import (
context "context"
sdkws "github.com/OpenIMSDK/Open-IM-Server/pkg/proto/sdkws"
reflect "reflect"
sync "sync"
grpc "google.golang.org/grpc"
codes "google.golang.org/grpc/codes"
status "google.golang.org/grpc/status"
protoreflect "google.golang.org/protobuf/reflect/protoreflect"
protoimpl "google.golang.org/protobuf/runtime/protoimpl"
reflect "reflect"
sync "sync"
sdkws "github.com/OpenIMSDK/Open-IM-Server/pkg/proto/sdkws"
)
const (

@ -16,6 +16,7 @@ package push
import "github.com/OpenIMSDK/Open-IM-Server/pkg/errs"
// Check
func (x *PushMsgReq) Check() error {
if x.MsgData == nil {
return errs.ErrArgs.Wrap("MsgData is empty")
@ -26,9 +27,11 @@ func (x *PushMsgReq) Check() error {
if x.ConversationID == "" {
return errs.ErrArgs.Wrap("ConversationID is empty")
}
return nil
}
// Check
func (x *DelUserPushTokenReq) Check() error {
if x.UserID == "" {
return errs.ErrArgs.Wrap("UserID is empty")
@ -36,5 +39,6 @@ func (x *DelUserPushTokenReq) Check() error {
if x.PlatformID < 1 || x.PlatformID > 9 {
return errs.ErrArgs.Wrap("PlatformID is invalid")
}
return nil
}

@ -22,14 +22,16 @@ package push
import (
context "context"
sdkws "github.com/OpenIMSDK/Open-IM-Server/pkg/proto/sdkws"
reflect "reflect"
sync "sync"
grpc "google.golang.org/grpc"
codes "google.golang.org/grpc/codes"
status "google.golang.org/grpc/status"
protoreflect "google.golang.org/protobuf/reflect/protoreflect"
protoimpl "google.golang.org/protobuf/runtime/protoimpl"
reflect "reflect"
sync "sync"
sdkws "github.com/OpenIMSDK/Open-IM-Server/pkg/proto/sdkws"
)
const (

@ -19,6 +19,7 @@ import (
"github.com/OpenIMSDK/Open-IM-Server/pkg/errs"
)
// Check
func (x *MsgData) Check() error {
if x.SendID == "" {
return errs.ErrArgs.Wrap("sendID is empty")
@ -42,5 +43,6 @@ func (x *MsgData) Check() error {
return errs.ErrArgs.Wrap("GroupID is empty")
}
}
return nil
}

@ -21,11 +21,13 @@
package sdkws
import (
wrapperspb "github.com/OpenIMSDK/Open-IM-Server/pkg/proto/wrapperspb"
protoreflect "google.golang.org/protobuf/reflect/protoreflect"
protoimpl "google.golang.org/protobuf/runtime/protoimpl"
reflect "reflect"
sync "sync"
protoreflect "google.golang.org/protobuf/reflect/protoreflect"
protoimpl "google.golang.org/protobuf/runtime/protoimpl"
wrapperspb "github.com/OpenIMSDK/Open-IM-Server/pkg/proto/wrapperspb"
)
const (

@ -21,9 +21,10 @@
package statistics
import (
reflect "reflect"
protoreflect "google.golang.org/protobuf/reflect/protoreflect"
protoimpl "google.golang.org/protobuf/runtime/protoimpl"
reflect "reflect"
)
const (

@ -54,6 +54,7 @@ import "github.com/OpenIMSDK/Open-IM-Server/pkg/errs"
// return nil
// }
// Check
func (x *FcmUpdateTokenReq) Check() error {
if x.PlatformID < 1 || x.PlatformID > 9 {
return errs.ErrArgs.Wrap("PlatformID is invalid")
@ -64,12 +65,15 @@ func (x *FcmUpdateTokenReq) Check() error {
if x.Account == "" {
return errs.ErrArgs.Wrap("Account is empty")
}
return nil
}
// Check
func (x *SetAppBadgeReq) Check() error {
if x.UserID == "" {
return errs.ErrArgs.Wrap("UserID is empty")
}
return nil
}

@ -22,13 +22,14 @@ package third
import (
context "context"
reflect "reflect"
sync "sync"
grpc "google.golang.org/grpc"
codes "google.golang.org/grpc/codes"
status "google.golang.org/grpc/status"
protoreflect "google.golang.org/protobuf/reflect/protoreflect"
protoimpl "google.golang.org/protobuf/runtime/protoimpl"
reflect "reflect"
sync "sync"
)
const (

@ -16,6 +16,7 @@ package user
import "github.com/OpenIMSDK/Open-IM-Server/pkg/errs"
// Check
func (x *GetAllUserIDReq) Check() error {
if x.Pagination == nil {
return errs.ErrArgs.Wrap("pagination is empty")
@ -23,23 +24,29 @@ func (x *GetAllUserIDReq) Check() error {
if x.Pagination.PageNumber < 1 {
return errs.ErrArgs.Wrap("pageNumber is invalid")
}
return nil
}
// Check
func (x *AccountCheckReq) Check() error {
if x.CheckUserIDs == nil {
return errs.ErrArgs.Wrap("CheckUserIDs is empty")
}
return nil
}
// Check
func (x *GetDesignateUsersReq) Check() error {
if x.UserIDs == nil {
return errs.ErrArgs.Wrap("UserIDs is empty")
}
return nil
}
// Check
func (x *UpdateUserInfoReq) Check() error {
if x.UserInfo == nil {
return errs.ErrArgs.Wrap("UserInfo is empty")
@ -47,9 +54,11 @@ func (x *UpdateUserInfoReq) Check() error {
if x.UserInfo.UserID == "" {
return errs.ErrArgs.Wrap("UserID is empty")
}
return nil
}
// Check
func (x *SetGlobalRecvMessageOptReq) Check() error {
if x.GlobalRecvMsgOpt > 2 || x.GlobalRecvMsgOpt < 0 {
return errs.ErrArgs.Wrap("GlobalRecvMsgOpt is invalid")
@ -57,9 +66,11 @@ func (x *SetGlobalRecvMessageOptReq) Check() error {
if x.UserID == "" {
return errs.ErrArgs.Wrap("UserID is empty")
}
return nil
}
// Check
func (x *SetConversationReq) Check() error {
if err := x.Conversation.Check(); err != nil {
return err
@ -67,9 +78,11 @@ func (x *SetConversationReq) Check() error {
if x.NotificationType < 1 || x.NotificationType > 3 {
return errs.ErrArgs.Wrap("NotificationType is invalid")
}
return nil
}
// Check
func (x *SetRecvMsgOptReq) Check() error {
if x.OwnerUserID == "" {
return errs.ErrArgs.Wrap("OwnerUserID is empty")
@ -83,9 +96,11 @@ func (x *SetRecvMsgOptReq) Check() error {
if x.NotificationType < 1 || x.NotificationType > 3 {
return errs.ErrArgs.Wrap("NotificationType is invalid")
}
return nil
}
// Check
func (x *GetConversationReq) Check() error {
if x.OwnerUserID == "" {
return errs.ErrArgs.Wrap("OwnerUserID is empty")
@ -93,9 +108,11 @@ func (x *GetConversationReq) Check() error {
if x.ConversationID == "" {
return errs.ErrArgs.Wrap("ConversationID is empty")
}
return nil
}
// Check
func (x *GetConversationsReq) Check() error {
if x.OwnerUserID == "" {
return errs.ErrArgs.Wrap("OwnerUserID is empty")
@ -103,16 +120,20 @@ func (x *GetConversationsReq) Check() error {
if x.ConversationIDs == nil {
return errs.ErrArgs.Wrap("ConversationIDs is empty")
}
return nil
}
// Check
func (x *GetAllConversationsReq) Check() error {
if x.OwnerUserID == "" {
return errs.ErrArgs.Wrap("OwnerUserID is empty")
}
return nil
}
// Check
func (x *BatchSetConversationsReq) Check() error {
if x.OwnerUserID == "" {
return errs.ErrArgs.Wrap("OwnerUserID is empty")
@ -123,9 +144,11 @@ func (x *BatchSetConversationsReq) Check() error {
if x.NotificationType < 1 || x.NotificationType > 3 {
return errs.ErrArgs.Wrap("NotificationType is invalid")
}
return nil
}
// Check
func (x *GetPaginationUsersReq) Check() error {
if x.Pagination == nil {
return errs.ErrArgs.Wrap("pagination is empty")
@ -133,23 +156,29 @@ func (x *GetPaginationUsersReq) Check() error {
if x.Pagination.PageNumber < 1 {
return errs.ErrArgs.Wrap("pageNumber is invalid")
}
return nil
}
// Check
func (x *UserRegisterReq) Check() error {
if x.Users == nil {
return errs.ErrArgs.Wrap("Users is empty")
}
return nil
}
// Check
func (x *GetGlobalRecvMessageOptReq) Check() error {
if x.UserID == "" {
return errs.ErrArgs.Wrap("UserID is empty")
}
return nil
}
// Check
func (x *UserRegisterCountReq) Check() error {
if x.Start <= 0 {
return errs.ErrArgs.Wrap("start is invalid")
@ -157,5 +186,6 @@ func (x *UserRegisterCountReq) Check() error {
if x.End <= 0 {
return errs.ErrArgs.Wrap("end is invalid")
}
return nil
}

@ -22,15 +22,17 @@ package user
import (
context "context"
conversation "github.com/OpenIMSDK/Open-IM-Server/pkg/proto/conversation"
sdkws "github.com/OpenIMSDK/Open-IM-Server/pkg/proto/sdkws"
reflect "reflect"
sync "sync"
grpc "google.golang.org/grpc"
codes "google.golang.org/grpc/codes"
status "google.golang.org/grpc/status"
protoreflect "google.golang.org/protobuf/reflect/protoreflect"
protoimpl "google.golang.org/protobuf/runtime/protoimpl"
reflect "reflect"
sync "sync"
conversation "github.com/OpenIMSDK/Open-IM-Server/pkg/proto/conversation"
sdkws "github.com/OpenIMSDK/Open-IM-Server/pkg/proto/sdkws"
)
const (

@ -21,10 +21,11 @@
package wrapperspb
import (
protoreflect "google.golang.org/protobuf/reflect/protoreflect"
protoimpl "google.golang.org/protobuf/runtime/protoimpl"
reflect "reflect"
sync "sync"
protoreflect "google.golang.org/protobuf/reflect/protoreflect"
protoimpl "google.golang.org/protobuf/runtime/protoimpl"
)
const (

@ -24,15 +24,18 @@ import (
"github.com/OpenIMSDK/Open-IM-Server/pkg/proto/auth"
)
// NewAuth
func NewAuth(discov discoveryregistry.SvcDiscoveryRegistry) *Auth {
conn, err := discov.GetConn(context.Background(), config.Config.RpcRegisterName.OpenImAuthName)
if err != nil {
panic(err)
}
client := auth.NewAuthClient(conn)
return &Auth{discov: discov, conn: conn, Client: client}
}
// Auth
type Auth struct {
conn grpc.ClientConnInterface
Client auth.AuthClient

@ -26,27 +26,33 @@ import (
pbConversation "github.com/OpenIMSDK/Open-IM-Server/pkg/proto/conversation"
)
// Conversation
type Conversation struct {
Client pbConversation.ConversationClient
conn grpc.ClientConnInterface
discov discoveryregistry.SvcDiscoveryRegistry
}
// NewConversation
func NewConversation(discov discoveryregistry.SvcDiscoveryRegistry) *Conversation {
conn, err := discov.GetConn(context.Background(), config.Config.RpcRegisterName.OpenImConversationName)
if err != nil {
panic(err)
}
client := pbConversation.NewConversationClient(conn)
return &Conversation{discov: discov, conn: conn, Client: client}
}
// ConversationRpcClient
type ConversationRpcClient Conversation
// NewConversationRpcClient
func NewConversationRpcClient(discov discoveryregistry.SvcDiscoveryRegistry) ConversationRpcClient {
return ConversationRpcClient(*NewConversation(discov))
}
// GetSingleConversationRecvMsgOpt
func (c *ConversationRpcClient) GetSingleConversationRecvMsgOpt(ctx context.Context, userID, conversationID string) (int32, error) {
var req pbConversation.GetConversationReq
req.OwnerUserID = userID
@ -55,45 +61,59 @@ func (c *ConversationRpcClient) GetSingleConversationRecvMsgOpt(ctx context.Cont
if err != nil {
return 0, err
}
return conversation.GetConversation().RecvMsgOpt, err
}
// SingleChatFirstCreateConversation
func (c *ConversationRpcClient) SingleChatFirstCreateConversation(ctx context.Context, recvID, sendID string) error {
_, err := c.Client.CreateSingleChatConversations(ctx, &pbConversation.CreateSingleChatConversationsReq{RecvID: recvID, SendID: sendID})
return err
}
// GroupChatFirstCreateConversation
func (c *ConversationRpcClient) GroupChatFirstCreateConversation(ctx context.Context, groupID string, userIDs []string) error {
_, err := c.Client.CreateGroupChatConversations(ctx, &pbConversation.CreateGroupChatConversationsReq{UserIDs: userIDs, GroupID: groupID})
return err
}
// SetConversationMaxSeq
func (c *ConversationRpcClient) SetConversationMaxSeq(ctx context.Context, ownerUserIDs []string, conversationID string, maxSeq int64) error {
_, err := c.Client.SetConversationMaxSeq(ctx, &pbConversation.SetConversationMaxSeqReq{OwnerUserID: ownerUserIDs, ConversationID: conversationID, MaxSeq: maxSeq})
return err
}
// SetConversations
func (c *ConversationRpcClient) SetConversations(ctx context.Context, userIDs []string, conversation *pbConversation.ConversationReq) error {
_, err := c.Client.SetConversations(ctx, &pbConversation.SetConversationsReq{UserIDs: userIDs, Conversation: conversation})
return err
}
// GetConversationIDs
func (c *ConversationRpcClient) GetConversationIDs(ctx context.Context, ownerUserID string) ([]string, error) {
resp, err := c.Client.GetConversationIDs(ctx, &pbConversation.GetConversationIDsReq{UserID: ownerUserID})
if err != nil {
return nil, err
}
return resp.ConversationIDs, nil
}
// GetConversation
func (c *ConversationRpcClient) GetConversation(ctx context.Context, ownerUserID, conversationID string) (*pbConversation.Conversation, error) {
resp, err := c.Client.GetConversation(ctx, &pbConversation.GetConversationReq{OwnerUserID: ownerUserID, ConversationID: conversationID})
if err != nil {
return nil, err
}
return resp.Conversation, nil
}
// GetConversationsByConversationID
func (c *ConversationRpcClient) GetConversationsByConversationID(ctx context.Context, conversationIDs []string) ([]*pbConversation.Conversation, error) {
if len(conversationIDs) == 0 {
return nil, nil
@ -105,9 +125,11 @@ func (c *ConversationRpcClient) GetConversationsByConversationID(ctx context.Con
if len(resp.Conversations) == 0 {
return nil, errs.ErrRecordNotFound.Wrap(fmt.Sprintf("conversationIDs: %v not found", conversationIDs))
}
return resp.Conversations, nil
}
// GetConversations
func (c *ConversationRpcClient) GetConversations(
ctx context.Context,
ownerUserID string,
@ -123,5 +145,6 @@ func (c *ConversationRpcClient) GetConversations(
if err != nil {
return nil, err
}
return resp.Conversations, nil
}

@ -25,27 +25,33 @@ import (
sdkws "github.com/OpenIMSDK/Open-IM-Server/pkg/proto/sdkws"
)
// Friend
type Friend struct {
conn grpc.ClientConnInterface
Client friend.FriendClient
discov discoveryregistry.SvcDiscoveryRegistry
}
// NewFriend
func NewFriend(discov discoveryregistry.SvcDiscoveryRegistry) *Friend {
conn, err := discov.GetConn(context.Background(), config.Config.RpcRegisterName.OpenImFriendName)
if err != nil {
panic(err)
}
client := friend.NewFriendClient(conn)
return &Friend{discov: discov, conn: conn, Client: client}
}
// FriendRpcClient
type FriendRpcClient Friend
// NewFriendRpcClient
func NewFriendRpcClient(discov discoveryregistry.SvcDiscoveryRegistry) FriendRpcClient {
return FriendRpcClient(*NewFriend(discov))
}
// GetFriendsInfo
func (f *FriendRpcClient) GetFriendsInfo(
ctx context.Context,
ownerUserID, friendUserID string,
@ -58,31 +64,37 @@ func (f *FriendRpcClient) GetFriendsInfo(
return nil, err
}
resp = r.FriendsInfo[0]
return
}
// possibleFriendUserID是否在userID的好友中.
// IsFriend possibleFriendUserID是否在userID的好友中.
func (f *FriendRpcClient) IsFriend(ctx context.Context, possibleFriendUserID, userID string) (bool, error) {
resp, err := f.Client.IsFriend(ctx, &friend.IsFriendReq{UserID1: userID, UserID2: possibleFriendUserID})
if err != nil {
return false, err
}
return resp.InUser1Friends, nil
}
// GetFriendIDs
func (f *FriendRpcClient) GetFriendIDs(ctx context.Context, ownerUserID string) (friendIDs []string, err error) {
req := friend.GetFriendIDsReq{UserID: ownerUserID}
resp, err := f.Client.GetFriendIDs(ctx, &req)
if err != nil {
return nil, err
}
return resp.FriendIDs, nil
}
// IsBlocked
func (b *FriendRpcClient) IsBlocked(ctx context.Context, possibleBlackUserID, userID string) (bool, error) {
r, err := b.Client.IsBlack(ctx, &friend.IsBlackReq{UserID1: possibleBlackUserID, UserID2: userID})
if err != nil {
return false, err
}
return r.InUser2Blacks, nil
}

@ -29,27 +29,33 @@ import (
"github.com/OpenIMSDK/Open-IM-Server/pkg/utils"
)
// Group
type Group struct {
conn grpc.ClientConnInterface
Client group.GroupClient
discov discoveryregistry.SvcDiscoveryRegistry
}
// NewGroup
func NewGroup(discov discoveryregistry.SvcDiscoveryRegistry) *Group {
conn, err := discov.GetConn(context.Background(), config.Config.RpcRegisterName.OpenImGroupName)
if err != nil {
panic(err)
}
client := group.NewGroupClient(conn)
return &Group{discov: discov, conn: conn, Client: client}
}
// GroupRpcClient
type GroupRpcClient Group
// NewGroupRpcClient
func NewGroupRpcClient(discov discoveryregistry.SvcDiscoveryRegistry) GroupRpcClient {
return GroupRpcClient(*NewGroup(discov))
}
// GetGroupInfos
func (g *GroupRpcClient) GetGroupInfos(
ctx context.Context,
groupIDs []string,
@ -71,14 +77,17 @@ func (g *GroupRpcClient) GetGroupInfos(
return resp.GroupInfos, nil
}
// GetGroupInfo
func (g *GroupRpcClient) GetGroupInfo(ctx context.Context, groupID string) (*sdkws.GroupInfo, error) {
groups, err := g.GetGroupInfos(ctx, []string{groupID}, true)
if err != nil {
return nil, err
}
return groups[0], nil
}
// GetGroupInfoMap
func (g *GroupRpcClient) GetGroupInfoMap(
ctx context.Context,
groupIDs []string,
@ -88,11 +97,13 @@ func (g *GroupRpcClient) GetGroupInfoMap(
if err != nil {
return nil, err
}
return utils.SliceToMap(groups, func(e *sdkws.GroupInfo) string {
return e.GroupID
}), nil
}
// GetGroupMemberInfos
func (g *GroupRpcClient) GetGroupMemberInfos(
ctx context.Context,
groupID string,
@ -113,9 +124,11 @@ func (g *GroupRpcClient) GetGroupMemberInfos(
return nil, errs.ErrNotInGroupYet.Wrap(strings.Join(ids, ","))
}
}
return resp.Members, nil
}
// GetGroupMemberInfo
func (g *GroupRpcClient) GetGroupMemberInfo(
ctx context.Context,
groupID string,
@ -125,9 +138,11 @@ func (g *GroupRpcClient) GetGroupMemberInfo(
if err != nil {
return nil, err
}
return members[0], nil
}
// GetGroupMemberInfoMap
func (g *GroupRpcClient) GetGroupMemberInfoMap(
ctx context.Context,
groupID string,
@ -138,11 +153,13 @@ func (g *GroupRpcClient) GetGroupMemberInfoMap(
if err != nil {
return nil, err
}
return utils.SliceToMap(members, func(e *sdkws.GroupMemberFullInfo) string {
return e.UserID
}), nil
}
// GetOwnerAndAdminInfos
func (g *GroupRpcClient) GetOwnerAndAdminInfos(
ctx context.Context,
groupID string,
@ -154,17 +171,21 @@ func (g *GroupRpcClient) GetOwnerAndAdminInfos(
if err != nil {
return nil, err
}
return resp.Members, nil
}
// GetOwnerInfo
func (g *GroupRpcClient) GetOwnerInfo(ctx context.Context, groupID string) (*sdkws.GroupMemberFullInfo, error) {
resp, err := g.Client.GetGroupMemberRoleLevel(ctx, &group.GetGroupMemberRoleLevelReq{
GroupID: groupID,
RoleLevels: []int32{constant.GroupOwner},
})
return resp.Members[0], err
}
// GetGroupMemberIDs
func (g *GroupRpcClient) GetGroupMemberIDs(ctx context.Context, groupID string) ([]string, error) {
resp, err := g.Client.GetGroupMemberUserIDs(ctx, &group.GetGroupMemberUserIDsReq{
GroupID: groupID,
@ -172,9 +193,11 @@ func (g *GroupRpcClient) GetGroupMemberIDs(ctx context.Context, groupID string)
if err != nil {
return nil, err
}
return resp.UserIDs, nil
}
// GetGroupInfoCache
func (g *GroupRpcClient) GetGroupInfoCache(ctx context.Context, groupID string) (*sdkws.GroupInfo, error) {
resp, err := g.Client.GetGroupInfoCache(ctx, &group.GetGroupInfoCacheReq{
GroupID: groupID,
@ -182,9 +205,11 @@ func (g *GroupRpcClient) GetGroupInfoCache(ctx context.Context, groupID string)
if err != nil {
return nil, err
}
return resp.GroupInfo, nil
}
// GetGroupMemberCache
func (g *GroupRpcClient) GetGroupMemberCache(
ctx context.Context,
groupID string,
@ -197,13 +222,16 @@ func (g *GroupRpcClient) GetGroupMemberCache(
if err != nil {
return nil, err
}
return resp.Member, nil
}
// DismissGroup
func (g *GroupRpcClient) DismissGroup(ctx context.Context, groupID string) error {
_, err := g.Client.DismissGroup(ctx, &group.DismissGroupReq{
GroupID: groupID,
DeleteMember: true,
})
return err
}

@ -121,29 +121,36 @@ func newSessionTypeConf() map[int32]int32 {
}
}
// Message
type Message struct {
conn grpc.ClientConnInterface
Client msg.MsgClient
discov discoveryregistry.SvcDiscoveryRegistry
}
// NewMessage
func NewMessage(discov discoveryregistry.SvcDiscoveryRegistry) *Message {
conn, err := discov.GetConn(context.Background(), config.Config.RpcRegisterName.OpenImMsgName)
if err != nil {
panic(err)
}
client := msg.NewMsgClient(conn)
return &Message{discov: discov, conn: conn, Client: client}
}
// MessageRpcClient
type MessageRpcClient Message
// NewMessageRpcClient
func NewMessageRpcClient(discov discoveryregistry.SvcDiscoveryRegistry) MessageRpcClient {
return MessageRpcClient(*NewMessage(discov))
}
// SendMsg
func (m *MessageRpcClient) SendMsg(ctx context.Context, req *msg.SendMsgReq) (*msg.SendMsgResp, error) {
resp, err := m.Client.SendMsg(ctx, req)
return resp, err
}
@ -154,17 +161,21 @@ func (m *MessageRpcClient) GetMaxSeq(ctx context.Context, req *sdkws.GetMaxSeqRe
func (m *MessageRpcClient) PullMessageBySeqList(ctx context.Context, req *sdkws.PullMessageBySeqsReq) (*sdkws.PullMessageBySeqsResp, error) {
resp, err := m.Client.PullMessageBySeqs(ctx, req)
return resp, err
}
// GetConversationMaxSeq
func (m *MessageRpcClient) GetConversationMaxSeq(ctx context.Context, conversationID string) (int64, error) {
resp, err := m.Client.GetConversationMaxSeq(ctx, &msg.GetConversationMaxSeqReq{ConversationID: conversationID})
if err != nil {
return 0, err
}
return resp.MaxSeq, nil
}
// NotificationSender
type NotificationSender struct {
contentTypeConf map[int32]config.NotificationConf
sessionTypeConf map[int32]int32
@ -172,31 +183,37 @@ type NotificationSender struct {
getUserInfo func(ctx context.Context, userID string) (*sdkws.UserInfo, error)
}
// NotificationSenderOptions
type NotificationSenderOptions func(*NotificationSender)
// WithLocalSendMsg
func WithLocalSendMsg(sendMsg func(ctx context.Context, req *msg.SendMsgReq) (*msg.SendMsgResp, error)) NotificationSenderOptions {
return func(s *NotificationSender) {
s.sendMsg = sendMsg
}
}
// WithRpcClient
func WithRpcClient(msgRpcClient *MessageRpcClient) NotificationSenderOptions {
return func(s *NotificationSender) {
s.sendMsg = msgRpcClient.SendMsg
}
}
// WithUserRpcClient
func WithUserRpcClient(userRpcClient *UserRpcClient) NotificationSenderOptions {
return func(s *NotificationSender) {
s.getUserInfo = userRpcClient.GetUserInfo
}
}
// NewNotificationSender
func NewNotificationSender(opts ...NotificationSenderOptions) *NotificationSender {
notificationSender := &NotificationSender{contentTypeConf: newContentTypeConf(), sessionTypeConf: newSessionTypeConf()}
for _, opt := range opts {
opt(notificationSender)
}
return notificationSender
}
@ -204,19 +221,23 @@ type notificationOpt struct {
WithRpcGetUsername bool
}
// NotificationOptions
type NotificationOptions func(*notificationOpt)
// WithRpcGetUserName
func WithRpcGetUserName() NotificationOptions {
return func(opt *notificationOpt) {
opt.WithRpcGetUsername = true
}
}
// NotificationWithSesstionType
func (s *NotificationSender) NotificationWithSesstionType(ctx context.Context, sendID, recvID string, contentType, sesstionType int32, m proto.Message, opts ...NotificationOptions) (err error) {
n := sdkws.NotificationElem{Detail: utils.StructToJsonString(m)}
content, err := json.Marshal(&n)
if err != nil {
log.ZError(ctx, "MsgClient Notification json.Marshal failed", err, "sendID", sendID, "recvID", recvID, "contentType", contentType, "msg", m)
return err
}
notificationOpt := &notificationOpt{}
@ -260,9 +281,11 @@ func (s *NotificationSender) NotificationWithSesstionType(ctx context.Context, s
} else {
log.ZError(ctx, "MsgClient Notification SendMsg failed", err, "req", &req)
}
return err
}
// Notification
func (s *NotificationSender) Notification(ctx context.Context, sendID, recvID string, contentType int32, m proto.Message, opts ...NotificationOptions) error {
return s.NotificationWithSesstionType(ctx, sendID, recvID, contentType, s.sessionTypeConf[contentType], m, opts...)
}

@ -14,6 +14,7 @@
package notification
// CommonUser
type CommonUser interface {
GetNickname() string
GetFaceURL() string
@ -21,6 +22,7 @@ type CommonUser interface {
GetEx() string
}
// CommonGroup
type CommonGroup interface {
GetNickname() string
GetFaceURL() string

@ -22,15 +22,17 @@ import (
"github.com/OpenIMSDK/Open-IM-Server/pkg/rpcclient"
)
// ConversationNotificationSender
type ConversationNotificationSender struct {
*rpcclient.NotificationSender
}
// NewConversationNotificationSender
func NewConversationNotificationSender(msgRpcClient *rpcclient.MessageRpcClient) *ConversationNotificationSender {
return &ConversationNotificationSender{rpcclient.NewNotificationSender(rpcclient.WithRpcClient(msgRpcClient))}
}
// SetPrivate调用.
// ConversationSetPrivateNotification
func (c *ConversationNotificationSender) ConversationSetPrivateNotification(
ctx context.Context,
sendID, recvID string,
@ -41,18 +43,20 @@ func (c *ConversationNotificationSender) ConversationSetPrivateNotification(
SendID: sendID,
IsPrivate: isPrivateChat,
}
return c.Notification(ctx, sendID, recvID, constant.ConversationPrivateChatNotification, tips)
}
// 会话改变.
// ConversationChangeNotification
func (c *ConversationNotificationSender) ConversationChangeNotification(ctx context.Context, userID string) error {
tips := &sdkws.ConversationUpdateTips{
UserID: userID,
}
return c.Notification(ctx, userID, userID, constant.ConversationChangeNotification, tips)
}
// 会话未读数同步.
// ConversationUnreadChangeNotification
func (c *ConversationNotificationSender) ConversationUnreadChangeNotification(
ctx context.Context,
userID, conversationID string,
@ -64,5 +68,6 @@ func (c *ConversationNotificationSender) ConversationUnreadChangeNotification(
HasReadSeq: hasReadSeq,
UnreadCountTime: unreadCountTime,
}
return c.Notification(ctx, userID, userID, constant.ConversationUnreadNotification, tips)
}

@ -28,9 +28,10 @@ import (
"github.com/OpenIMSDK/Open-IM-Server/pkg/rpcclient"
)
// FriendNotificationSender
type FriendNotificationSender struct {
*rpcclient.NotificationSender
// 找不到报错
// if not finded, return err
getUsersInfo func(ctx context.Context, userIDs []string) ([]CommonUser, error)
// db controller
db controller.FriendDatabase
@ -38,12 +39,14 @@ type FriendNotificationSender struct {
type friendNotificationSenderOptions func(*FriendNotificationSender)
// WithFriendDB
func WithFriendDB(db controller.FriendDatabase) friendNotificationSenderOptions {
return func(s *FriendNotificationSender) {
s.db = db
}
}
// WithDBFunc
func WithDBFunc(
fn func(ctx context.Context, userIDs []string) (users []*relationTb.UserModel, err error),
) friendNotificationSenderOptions {
@ -56,12 +59,14 @@ func WithDBFunc(
for _, user := range users {
result = append(result, user)
}
return result, nil
}
s.getUsersInfo = f
}
}
// WithRpcFunc
func WithRpcFunc(
fn func(ctx context.Context, userIDs []string) ([]*sdkws.UserInfo, error),
) friendNotificationSenderOptions {
@ -74,12 +79,14 @@ func WithRpcFunc(
for _, user := range users {
result = append(result, user)
}
return result, err
}
s.getUsersInfo = f
}
}
// NewFriendNotificationSender
func NewFriendNotificationSender(
msgRpcClient *rpcclient.MessageRpcClient,
opts ...friendNotificationSenderOptions,
@ -90,6 +97,7 @@ func NewFriendNotificationSender(
for _, opt := range opts {
opt(f)
}
return f
}
@ -105,6 +113,7 @@ func (f *FriendNotificationSender) getUsersInfoMap(
for _, user := range users {
result[user.GetUserID()] = user.(*sdkws.UserInfo)
}
return result, nil
}
@ -114,16 +123,20 @@ func (f *FriendNotificationSender) getFromToUserNickname(
) (string, string, error) {
users, err := f.getUsersInfoMap(ctx, []string{fromUserID, toUserID})
if err != nil {
return "", "", nil
return "", "", err
}
return users[fromUserID].Nickname, users[toUserID].Nickname, nil
}
// UserInfoUpdatedNotification
func (f *FriendNotificationSender) UserInfoUpdatedNotification(ctx context.Context, changedUserID string) error {
tips := sdkws.UserInfoUpdatedTips{UserID: changedUserID}
return f.Notification(ctx, mcontext.GetOpUserID(ctx), changedUserID, constant.UserInfoUpdatedNotification, &tips)
}
// FriendApplicationAddNotification
func (f *FriendNotificationSender) FriendApplicationAddNotification(
ctx context.Context,
req *pbFriend.ApplyToAddFriendReq,
@ -132,9 +145,11 @@ func (f *FriendNotificationSender) FriendApplicationAddNotification(
FromUserID: req.FromUserID,
ToUserID: req.ToUserID,
}}
return f.Notification(ctx, req.FromUserID, req.ToUserID, constant.FriendApplicationNotification, &tips)
}
// FriendApplicationAgreedNotification
func (c *FriendNotificationSender) FriendApplicationAgreedNotification(
ctx context.Context,
req *pbFriend.RespondFriendApplyReq,
@ -143,6 +158,7 @@ func (c *FriendNotificationSender) FriendApplicationAgreedNotification(
FromUserID: req.FromUserID,
ToUserID: req.ToUserID,
}, HandleMsg: req.HandleMsg}
return c.Notification(ctx, req.ToUserID, req.FromUserID, constant.FriendApplicationApprovedNotification, &tips)
}
@ -154,9 +170,11 @@ func (c *FriendNotificationSender) FriendApplicationRefusedNotification(
FromUserID: req.FromUserID,
ToUserID: req.ToUserID,
}, HandleMsg: req.HandleMsg}
return c.Notification(ctx, req.ToUserID, req.FromUserID, constant.FriendApplicationRejectedNotification, &tips)
}
// FriendAddedNotification
func (c *FriendNotificationSender) FriendAddedNotification(
ctx context.Context,
operationID, opUserID, fromUserID, toUserID string,
@ -178,31 +196,39 @@ func (c *FriendNotificationSender) FriendAddedNotification(
if err != nil {
return err
}
return c.Notification(ctx, fromUserID, toUserID, constant.FriendAddedNotification, &tips)
}
// FriendDeletedNotification
func (c *FriendNotificationSender) FriendDeletedNotification(ctx context.Context, req *pbFriend.DeleteFriendReq) error {
tips := sdkws.FriendDeletedTips{FromToUserID: &sdkws.FromToUserID{
FromUserID: req.OwnerUserID,
ToUserID: req.FriendUserID,
}}
return c.Notification(ctx, req.OwnerUserID, req.FriendUserID, constant.FriendDeletedNotification, &tips)
}
// FriendRemarkSetNotification
func (c *FriendNotificationSender) FriendRemarkSetNotification(ctx context.Context, fromUserID, toUserID string) error {
tips := sdkws.FriendInfoChangedTips{FromToUserID: &sdkws.FromToUserID{}}
tips.FromToUserID.FromUserID = fromUserID
tips.FromToUserID.ToUserID = toUserID
return c.Notification(ctx, fromUserID, toUserID, constant.FriendRemarkSetNotification, &tips)
}
// BlackAddedNotification
func (c *FriendNotificationSender) BlackAddedNotification(ctx context.Context, req *pbFriend.AddBlackReq) error {
tips := sdkws.BlackAddedTips{FromToUserID: &sdkws.FromToUserID{}}
tips.FromToUserID.FromUserID = req.OwnerUserID
tips.FromToUserID.ToUserID = req.BlackUserID
return c.Notification(ctx, req.OwnerUserID, req.BlackUserID, constant.BlackAddedNotification, &tips)
}
// BlackDeletedNotification
func (c *FriendNotificationSender) BlackDeletedNotification(ctx context.Context, req *pbFriend.RemoveBlackReq) {
blackDeletedTips := sdkws.BlackDeletedTips{FromToUserID: &sdkws.FromToUserID{
FromUserID: req.OwnerUserID,
@ -211,6 +237,7 @@ func (c *FriendNotificationSender) BlackDeletedNotification(ctx context.Context,
c.Notification(ctx, req.OwnerUserID, req.BlackUserID, constant.BlackDeletedNotification, &blackDeletedTips)
}
// FriendInfoUpdatedNotification
func (c *FriendNotificationSender) FriendInfoUpdatedNotification(
ctx context.Context,
changedUserID string,

@ -30,6 +30,7 @@ import (
"github.com/OpenIMSDK/Open-IM-Server/pkg/utils"
)
// NewGroupNotificationSender
func NewGroupNotificationSender(
db controller.GroupDatabase,
msgRpcClient *rpcclient.MessageRpcClient,
@ -43,6 +44,7 @@ func NewGroupNotificationSender(
}
}
// GroupNotificationSender
type GroupNotificationSender struct {
*rpcclient.NotificationSender
getUsersInfo func(ctx context.Context, userIDs []string) ([]CommonUser, error)
@ -57,6 +59,7 @@ func (g *GroupNotificationSender) getUser(ctx context.Context, userID string) (*
if len(users) == 0 {
return nil, errs.ErrUserIDNotFound.Wrap(fmt.Sprintf("user %s not found", userID))
}
return &sdkws.PublicUserInfo{
UserID: users[0].GetUserID(),
Nickname: users[0].GetNickname(),
@ -78,6 +81,7 @@ func (g *GroupNotificationSender) getGroupInfo(ctx context.Context, groupID stri
if err != nil {
return nil, err
}
return &sdkws.GroupInfo{
GroupID: gm.GroupID,
GroupName: gm.GroupName,
@ -145,6 +149,7 @@ func (g *GroupNotificationSender) getGroupMemberMap(ctx context.Context, groupID
for i, member := range members {
m[member.UserID] = members[i]
}
return m, nil
}
@ -156,6 +161,7 @@ func (g *GroupNotificationSender) getGroupMember(ctx context.Context, groupID st
if len(members) == 0 {
return nil, errs.ErrInternalServer.Wrap(fmt.Sprintf("group %s member %s not found", groupID, userID))
}
return members[0], nil
}
@ -165,6 +171,7 @@ func (g *GroupNotificationSender) getGroupOwnerAndAdminUserID(ctx context.Contex
return nil, err
}
fn := func(e *relation.GroupMemberModel) string { return e.UserID }
return utils.Slice(members, fn), nil
}
@ -216,6 +223,7 @@ func (g *GroupNotificationSender) getUsersInfoMap(ctx context.Context, userIDs [
for _, user := range users {
result[user.GetUserID()] = user.(*sdkws.UserInfo)
}
return result, nil
}
@ -255,37 +263,47 @@ func (g *GroupNotificationSender) fillOpUser(ctx context.Context, opUser **sdkws
(*opUser).FaceURL = user.FaceURL
}
}
return nil
}
// GroupCreatedNotification
func (g *GroupNotificationSender) GroupCreatedNotification(ctx context.Context, tips *sdkws.GroupCreatedTips) (err error) {
if err := g.fillOpUser(ctx, &tips.OpUser, tips.Group.GroupID); err != nil {
return err
}
return g.Notification(ctx, mcontext.GetOpUserID(ctx), tips.Group.GroupID, constant.GroupCreatedNotification, tips)
}
// GroupInfoSetNotification
func (g *GroupNotificationSender) GroupInfoSetNotification(ctx context.Context, tips *sdkws.GroupInfoSetTips) (err error) {
if err := g.fillOpUser(ctx, &tips.OpUser, tips.Group.GroupID); err != nil {
return err
}
return g.Notification(ctx, mcontext.GetOpUserID(ctx), tips.Group.GroupID, constant.GroupInfoSetNotification, tips, rpcclient.WithRpcGetUserName())
}
// GroupInfoSetNameNotification
func (g *GroupNotificationSender) GroupInfoSetNameNotification(ctx context.Context, tips *sdkws.GroupInfoSetNameTips) (err error) {
if err := g.fillOpUser(ctx, &tips.OpUser, tips.Group.GroupID); err != nil {
return err
}
return g.Notification(ctx, mcontext.GetOpUserID(ctx), tips.Group.GroupID, constant.GroupInfoSetNameNotification, tips)
}
// GroupInfoSetAnnouncementNotification
func (g *GroupNotificationSender) GroupInfoSetAnnouncementNotification(ctx context.Context, tips *sdkws.GroupInfoSetAnnouncementTips) (err error) {
if err := g.fillOpUser(ctx, &tips.OpUser, tips.Group.GroupID); err != nil {
return err
}
return g.Notification(ctx, mcontext.GetOpUserID(ctx), tips.Group.GroupID, constant.GroupInfoSetAnnouncementNotification, tips, rpcclient.WithRpcGetUserName())
}
// JoinGroupApplicationNotification
func (g *GroupNotificationSender) JoinGroupApplicationNotification(ctx context.Context, req *pbGroup.JoinGroupReq) (err error) {
group, err := g.getGroupInfo(ctx, req.GroupID)
if err != nil {
@ -307,9 +325,11 @@ func (g *GroupNotificationSender) JoinGroupApplicationNotification(ctx context.C
log.ZError(ctx, "JoinGroupApplicationNotification failed", err, "group", req.GroupID, "userID", userID)
}
}
return nil
}
// MemberQuitNotification
func (g *GroupNotificationSender) MemberQuitNotification(ctx context.Context, member *sdkws.GroupMemberFullInfo) (err error) {
defer log.ZDebug(ctx, "return")
defer func() {
@ -322,9 +342,11 @@ func (g *GroupNotificationSender) MemberQuitNotification(ctx context.Context, me
return err
}
tips := &sdkws.MemberQuitTips{Group: group, QuitUser: member}
return g.Notification(ctx, mcontext.GetOpUserID(ctx), member.GroupID, constant.MemberQuitNotification, tips)
}
// GroupApplicationAcceptedNotification
func (g *GroupNotificationSender) GroupApplicationAcceptedNotification(ctx context.Context, req *pbGroup.GroupApplicationResponseReq) (err error) {
defer log.ZDebug(ctx, "return")
defer func() {
@ -350,9 +372,11 @@ func (g *GroupNotificationSender) GroupApplicationAcceptedNotification(ctx conte
log.ZError(ctx, "failed", err)
}
}
return nil
}
// GroupApplicationRejectedNotification
func (g *GroupNotificationSender) GroupApplicationRejectedNotification(ctx context.Context, req *pbGroup.GroupApplicationResponseReq) (err error) {
group, err := g.getGroupInfo(ctx, req.GroupID)
if err != nil {
@ -372,9 +396,11 @@ func (g *GroupNotificationSender) GroupApplicationRejectedNotification(ctx conte
log.ZError(ctx, "failed", err)
}
}
return nil
}
// GroupOwnerTransferredNotification
func (g *GroupNotificationSender) GroupOwnerTransferredNotification(ctx context.Context, req *pbGroup.TransferGroupOwnerReq) (err error) {
group, err := g.getGroupInfo(ctx, req.GroupID)
if err != nil {
@ -389,16 +415,20 @@ func (g *GroupNotificationSender) GroupOwnerTransferredNotification(ctx context.
if err := g.fillOpUser(ctx, &tips.OpUser, tips.Group.GroupID); err != nil {
return err
}
return g.Notification(ctx, mcontext.GetOpUserID(ctx), group.GroupID, constant.GroupOwnerTransferredNotification, tips)
}
// MemberKickedNotification
func (g *GroupNotificationSender) MemberKickedNotification(ctx context.Context, tips *sdkws.MemberKickedTips) (err error) {
if err := g.fillOpUser(ctx, &tips.OpUser, tips.Group.GroupID); err != nil {
return err
}
return g.Notification(ctx, mcontext.GetOpUserID(ctx), tips.Group.GroupID, constant.MemberKickedNotification, tips)
}
// MemberInvitedNotification
func (g *GroupNotificationSender) MemberInvitedNotification(ctx context.Context, groupID, reason string, invitedUserIDList []string) (err error) {
group, err := g.getGroupInfo(ctx, groupID)
if err != nil {
@ -415,9 +445,11 @@ func (g *GroupNotificationSender) MemberInvitedNotification(ctx context.Context,
if err := g.fillOpUser(ctx, &tips.OpUser, tips.Group.GroupID); err != nil {
return err
}
return g.Notification(ctx, mcontext.GetOpUserID(ctx), group.GroupID, constant.MemberInvitedNotification, tips)
}
// MemberEnterNotification
func (g *GroupNotificationSender) MemberEnterNotification(ctx context.Context, req *pbGroup.GroupApplicationResponseReq) (err error) {
group, err := g.getGroupInfo(ctx, req.GroupID)
if err != nil {
@ -435,9 +467,11 @@ func (g *GroupNotificationSender) GroupDismissedNotification(ctx context.Context
if err := g.fillOpUser(ctx, &tips.OpUser, tips.Group.GroupID); err != nil {
return err
}
return g.Notification(ctx, mcontext.GetOpUserID(ctx), tips.Group.GroupID, constant.GroupDismissedNotification, tips)
}
// GroupMemberMutedNotification
func (g *GroupNotificationSender) GroupMemberMutedNotification(ctx context.Context, groupID, groupMemberUserID string, mutedSeconds uint32) (err error) {
group, err := g.getGroupInfo(ctx, groupID)
if err != nil {
@ -454,6 +488,7 @@ func (g *GroupNotificationSender) GroupMemberMutedNotification(ctx context.Conte
if err := g.fillOpUser(ctx, &tips.OpUser, tips.Group.GroupID); err != nil {
return err
}
return g.Notification(ctx, mcontext.GetOpUserID(ctx), group.GroupID, constant.GroupMemberMutedNotification, tips)
}
@ -470,6 +505,7 @@ func (g *GroupNotificationSender) GroupMemberCancelMutedNotification(ctx context
if err := g.fillOpUser(ctx, &tips.OpUser, tips.Group.GroupID); err != nil {
return err
}
return g.Notification(ctx, mcontext.GetOpUserID(ctx), group.GroupID, constant.GroupMemberCancelMutedNotification, tips)
}
@ -489,6 +525,7 @@ func (g *GroupNotificationSender) GroupMutedNotification(ctx context.Context, gr
if err := g.fillOpUser(ctx, &tips.OpUser, tips.Group.GroupID); err != nil {
return err
}
return g.Notification(ctx, mcontext.GetOpUserID(ctx), group.GroupID, constant.GroupMutedNotification, tips)
}
@ -508,9 +545,11 @@ func (g *GroupNotificationSender) GroupCancelMutedNotification(ctx context.Conte
if err := g.fillOpUser(ctx, &tips.OpUser, tips.Group.GroupID); err != nil {
return err
}
return g.Notification(ctx, mcontext.GetOpUserID(ctx), group.GroupID, constant.GroupCancelMutedNotification, tips)
}
// GroupMemberInfoSetNotification
func (g *GroupNotificationSender) GroupMemberInfoSetNotification(ctx context.Context, groupID, groupMemberUserID string) (err error) {
group, err := g.getGroupInfo(ctx, groupID)
if err != nil {
@ -524,6 +563,7 @@ func (g *GroupNotificationSender) GroupMemberInfoSetNotification(ctx context.Con
if err := g.fillOpUser(ctx, &tips.OpUser, tips.Group.GroupID); err != nil {
return err
}
return g.Notification(ctx, mcontext.GetOpUserID(ctx), group.GroupID, constant.GroupMemberInfoSetNotification, tips)
}
@ -540,6 +580,7 @@ func (g *GroupNotificationSender) GroupMemberSetToAdminNotification(ctx context.
if err := g.fillOpUser(ctx, &tips.OpUser, tips.Group.GroupID); err != nil {
return err
}
return g.Notification(ctx, mcontext.GetOpUserID(ctx), group.GroupID, constant.GroupMemberSetToAdminNotification, tips)
}
@ -556,9 +597,11 @@ func (g *GroupNotificationSender) GroupMemberSetToOrdinaryUserNotification(ctx c
if err := g.fillOpUser(ctx, &tips.OpUser, tips.Group.GroupID); err != nil {
return err
}
return g.Notification(ctx, mcontext.GetOpUserID(ctx), group.GroupID, constant.GroupMemberSetToOrdinaryUserNotification, tips)
}
// MemberEnterDirectlyNotification
func (g *GroupNotificationSender) MemberEnterDirectlyNotification(ctx context.Context, groupID string, entrantUserID string) (err error) {
defer log.ZDebug(ctx, "return")
defer func() {
@ -575,9 +618,11 @@ func (g *GroupNotificationSender) MemberEnterDirectlyNotification(ctx context.Co
return err
}
tips := &sdkws.MemberEnterTips{Group: group, EntrantUser: user}
return g.Notification(ctx, mcontext.GetOpUserID(ctx), group.GroupID, constant.MemberEnterNotification, tips)
}
// SuperGroupNotification
func (g *GroupNotificationSender) SuperGroupNotification(ctx context.Context, sendID, recvID string) (err error) {
defer log.ZDebug(ctx, "return")
defer func() {
@ -586,5 +631,6 @@ func (g *GroupNotificationSender) SuperGroupNotification(ctx context.Context, se
}
}()
err = g.Notification(ctx, sendID, recvID, constant.SuperGroupUpdateNotification, nil)
return err
}

@ -22,23 +22,28 @@ import (
"github.com/OpenIMSDK/Open-IM-Server/pkg/rpcclient"
)
// MsgNotificationSender
type MsgNotificationSender struct {
*rpcclient.NotificationSender
}
// NewMsgNotificationSender
func NewMsgNotificationSender(opts ...rpcclient.NotificationSenderOptions) *MsgNotificationSender {
return &MsgNotificationSender{rpcclient.NewNotificationSender(opts...)}
}
// UserDeleteMsgsNotification
func (m *MsgNotificationSender) UserDeleteMsgsNotification(ctx context.Context, userID, conversationID string, seqs []int64) error {
tips := sdkws.DeleteMsgsTips{
UserID: userID,
ConversationID: conversationID,
Seqs: seqs,
}
return m.Notification(ctx, userID, userID, constant.DeleteMsgsNotification, &tips)
}
// MarkAsReadNotification
func (m *MsgNotificationSender) MarkAsReadNotification(ctx context.Context, conversationID string, sesstionType int32, sendID, recvID string, seqs []int64, hasReadSeq int64) error {
tips := &sdkws.MarkAsReadTips{
MarkAsReadUserID: sendID,
@ -46,5 +51,6 @@ func (m *MsgNotificationSender) MarkAsReadNotification(ctx context.Context, conv
Seqs: seqs,
HasReadSeq: hasReadSeq,
}
return m.NotificationWithSesstionType(ctx, sendID, recvID, constant.HasReadReceipt, sesstionType, tips)
}

@ -24,17 +24,20 @@ import (
"github.com/OpenIMSDK/Open-IM-Server/pkg/proto/push"
)
// Push
type Push struct {
conn grpc.ClientConnInterface
Client push.PushMsgServiceClient
discov discoveryregistry.SvcDiscoveryRegistry
}
// NewPush
func NewPush(discov discoveryregistry.SvcDiscoveryRegistry) *Push {
conn, err := discov.GetConn(context.Background(), config.Config.RpcRegisterName.OpenImPushName)
if err != nil {
panic(err)
}
return &Push{
discov: discov,
conn: conn,
@ -42,12 +45,15 @@ func NewPush(discov discoveryregistry.SvcDiscoveryRegistry) *Push {
}
}
// PushRpcClient
type PushRpcClient Push
// NewPushRpcClient
func NewPushRpcClient(discov discoveryregistry.SvcDiscoveryRegistry) PushRpcClient {
return PushRpcClient(*NewPush(discov))
}
// DelUserPushToken
func (p *PushRpcClient) DelUserPushToken(
ctx context.Context,
req *push.DelUserPushTokenReq,

@ -28,6 +28,7 @@ import (
"github.com/OpenIMSDK/Open-IM-Server/pkg/proto/third"
)
// Third
type Third struct {
conn grpc.ClientConnInterface
Client third.ThirdClient
@ -35,20 +36,22 @@ type Third struct {
MinioClient *minio.Client
}
// NewThird
func NewThird(discov discoveryregistry.SvcDiscoveryRegistry) *Third {
var minioClient *minio.Client
conn, err := discov.GetConn(context.Background(), config.Config.RpcRegisterName.OpenImThirdName)
if err != nil {
panic(err)
}
client := third.NewThirdClient(conn)
minioClient, err := minioInit()
minioClient, err = minioInit()
return &Third{discov: discov, Client: client, conn: conn, MinioClient: minioClient}
}
func minioInit() (*minio.Client, error) {
minioClient := &minio.Client{}
var initUrl string
initUrl = config.Config.Object.Minio.Endpoint
var minioClient *minio.Client
initUrl := config.Config.Object.Minio.Endpoint
minioUrl, err := url.Parse(initUrl)
if err != nil {
return nil, err
@ -66,5 +69,6 @@ func minioInit() (*minio.Client, error) {
if err != nil {
return nil, err
}
return minioClient, nil
}

@ -29,32 +29,39 @@ import (
"github.com/OpenIMSDK/Open-IM-Server/pkg/utils"
)
// User
type User struct {
conn grpc.ClientConnInterface
Client user.UserClient
Discov discoveryregistry.SvcDiscoveryRegistry
}
// NewUser
func NewUser(discov discoveryregistry.SvcDiscoveryRegistry) *User {
conn, err := discov.GetConn(context.Background(), config.Config.RpcRegisterName.OpenImUserName)
if err != nil {
panic(err)
}
client := user.NewUserClient(conn)
return &User{Discov: discov, Client: client, conn: conn}
}
type UserRpcClient User
// NewUserRpcClientByUser
func NewUserRpcClientByUser(user *User) *UserRpcClient {
rpc := UserRpcClient(*user)
return &rpc
}
// NewUserRpcClient
func NewUserRpcClient(client discoveryregistry.SvcDiscoveryRegistry) UserRpcClient {
return UserRpcClient(*NewUser(client))
}
// GetUsersInfo
func (u *UserRpcClient) GetUsersInfo(ctx context.Context, userIDs []string) ([]*sdkws.UserInfo, error) {
resp, err := u.Client.GetDesignateUsers(ctx, &user.GetDesignateUsersReq{
UserIDs: userIDs,
@ -67,27 +74,33 @@ func (u *UserRpcClient) GetUsersInfo(ctx context.Context, userIDs []string) ([]*
})); len(ids) > 0 {
return nil, errs.ErrUserIDNotFound.Wrap(strings.Join(ids, ","))
}
return resp.UsersInfo, nil
}
// GetUserInfo
func (u *UserRpcClient) GetUserInfo(ctx context.Context, userID string) (*sdkws.UserInfo, error) {
users, err := u.GetUsersInfo(ctx, []string{userID})
if err != nil {
return nil, err
}
return users[0], nil
}
// GetUsersInfoMap
func (u *UserRpcClient) GetUsersInfoMap(ctx context.Context, userIDs []string) (map[string]*sdkws.UserInfo, error) {
users, err := u.GetUsersInfo(ctx, userIDs)
if err != nil {
return nil, err
}
return utils.SliceToMap(users, func(e *sdkws.UserInfo) string {
return e.UserID
}), nil
}
// GetPublicUserInfos
func (u *UserRpcClient) GetPublicUserInfos(
ctx context.Context,
userIDs []string,
@ -97,6 +110,7 @@ func (u *UserRpcClient) GetPublicUserInfos(
if err != nil {
return nil, err
}
return utils.Slice(users, func(e *sdkws.UserInfo) *sdkws.PublicUserInfo {
return &sdkws.PublicUserInfo{
UserID: e.UserID,
@ -107,14 +121,17 @@ func (u *UserRpcClient) GetPublicUserInfos(
}), nil
}
// GetPublicUserInfo
func (u *UserRpcClient) GetPublicUserInfo(ctx context.Context, userID string) (*sdkws.PublicUserInfo, error) {
users, err := u.GetPublicUserInfos(ctx, []string{userID}, true)
if err != nil {
return nil, err
}
return users[0], nil
}
// GetPublicUserInfoMap
func (u *UserRpcClient) GetPublicUserInfoMap(
ctx context.Context,
userIDs []string,
@ -124,11 +141,13 @@ func (u *UserRpcClient) GetPublicUserInfoMap(
if err != nil {
return nil, err
}
return utils.SliceToMap(users, func(e *sdkws.PublicUserInfo) string {
return e.UserID
}), nil
}
// GetUserGlobalMsgRecvOpt
func (u *UserRpcClient) GetUserGlobalMsgRecvOpt(ctx context.Context, userID string) (int32, error) {
resp, err := u.Client.GetGlobalRecvMessageOpt(ctx, &user.GetGlobalRecvMessageOptReq{
UserID: userID,
@ -136,21 +155,26 @@ func (u *UserRpcClient) GetUserGlobalMsgRecvOpt(ctx context.Context, userID stri
if err != nil {
return 0, err
}
return resp.GlobalRecvMsgOpt, err
}
// Access
func (u *UserRpcClient) Access(ctx context.Context, ownerUserID string) error {
_, err := u.GetUserInfo(ctx, ownerUserID)
if err != nil {
return err
}
return tokenverify.CheckAccessV3(ctx, ownerUserID)
}
// GetAllUserIDs
func (u *UserRpcClient) GetAllUserIDs(ctx context.Context, pageNumber, showNumber int32) ([]string, error) {
resp, err := u.Client.GetAllUserID(ctx, &user.GetAllUserIDReq{Pagination: &sdkws.RequestPagination{PageNumber: pageNumber, ShowNumber: showNumber}})
if err != nil {
return nil, err
}
return resp.UserIDs, nil
}

@ -34,6 +34,7 @@ import (
"github.com/OpenIMSDK/Open-IM-Server/pkg/utils"
)
// Start
func Start(
rpcPort int,
rpcRegisterName string,
@ -108,5 +109,6 @@ func Start(
}
}
}()
return utils.Wrap1(srv.Serve(listener))
}

@ -21,6 +21,7 @@ import (
"github.com/OpenIMSDK/Open-IM-Server/pkg/common/log"
)
// Statistics num
type Statistics struct {
AllCount *uint64
ModuleName string
@ -63,8 +64,10 @@ func (s *Statistics) output() {
}
}
// NewStatistics
func NewStatistics(allCount *uint64, moduleName, printArgs string, sleepTime int) *Statistics {
p := &Statistics{AllCount: allCount, ModuleName: moduleName, SleepTime: uint64(sleepTime), PrintArgs: printArgs}
go p.output()
return p
}

Loading…
Cancel
Save