mirror of
https://github.com/openimsdk/open-im-server.git
synced 2025-11-05 20:54:18 +08:00
Merge remote-tracking branch 'origin/3.6.1-code-conventions' into 3.6.1-code-conventions
# Conflicts: # pkg/rpcclient/group.go # pkg/rpcclient/third.go
This commit is contained in:
commit
261367242a
@ -20,6 +20,7 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"github.com/openimsdk/open-im-server/v3/pkg/common/servererrs"
|
"github.com/openimsdk/open-im-server/v3/pkg/common/servererrs"
|
||||||
"github.com/openimsdk/tools/discovery"
|
"github.com/openimsdk/tools/discovery"
|
||||||
|
"github.com/openimsdk/tools/system/program"
|
||||||
"net"
|
"net"
|
||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
@ -41,7 +42,6 @@ import (
|
|||||||
ginprom "github.com/openimsdk/open-im-server/v3/pkg/common/ginprometheus"
|
ginprom "github.com/openimsdk/open-im-server/v3/pkg/common/ginprometheus"
|
||||||
"github.com/openimsdk/open-im-server/v3/pkg/common/prommetrics"
|
"github.com/openimsdk/open-im-server/v3/pkg/common/prommetrics"
|
||||||
"github.com/openimsdk/open-im-server/v3/pkg/rpcclient"
|
"github.com/openimsdk/open-im-server/v3/pkg/rpcclient"
|
||||||
util "github.com/openimsdk/open-im-server/v3/pkg/util/genutil"
|
|
||||||
"github.com/openimsdk/protocol/constant"
|
"github.com/openimsdk/protocol/constant"
|
||||||
"github.com/openimsdk/tools/apiresp"
|
"github.com/openimsdk/tools/apiresp"
|
||||||
"github.com/openimsdk/tools/errs"
|
"github.com/openimsdk/tools/errs"
|
||||||
@ -122,7 +122,7 @@ func Start(ctx context.Context, config *config.GlobalConfig, port int, proPort i
|
|||||||
defer cancel()
|
defer cancel()
|
||||||
select {
|
select {
|
||||||
case <-sigs:
|
case <-sigs:
|
||||||
util.SIGTERMExit()
|
program.SIGTERMExit()
|
||||||
err := server.Shutdown(ctx)
|
err := server.Shutdown(ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return errs.WrapMsg(err, "shutdown err")
|
return errs.WrapMsg(err, "shutdown err")
|
||||||
|
|||||||
@ -16,9 +16,8 @@ package msggateway
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"sync"
|
|
||||||
|
|
||||||
"github.com/openimsdk/tools/utils/datautil"
|
"github.com/openimsdk/tools/utils/datautil"
|
||||||
|
"sync"
|
||||||
|
|
||||||
"github.com/openimsdk/tools/log"
|
"github.com/openimsdk/tools/log"
|
||||||
)
|
)
|
||||||
@ -66,6 +65,7 @@ func (u *UserMap) Set(key string, v *Client) {
|
|||||||
u.m.Store(key, oldClients)
|
u.m.Store(key, oldClients)
|
||||||
} else {
|
} else {
|
||||||
log.ZDebug(context.Background(), "Set not existed", "user_id", key, "client_user_id", v.UserID)
|
log.ZDebug(context.Background(), "Set not existed", "user_id", key, "client_user_id", v.UserID)
|
||||||
|
|
||||||
var clients []*Client
|
var clients []*Client
|
||||||
clients = append(clients, v)
|
clients = append(clients, v)
|
||||||
u.m.Store(key, clients)
|
u.m.Store(key, clients)
|
||||||
@ -115,7 +115,7 @@ func (u *UserMap) deleteClients(key string, clients []*Client) (isDeleteUser boo
|
|||||||
oldClients := allClients.([]*Client)
|
oldClients := allClients.([]*Client)
|
||||||
var remainingClients []*Client
|
var remainingClients []*Client
|
||||||
for _, client := range oldClients {
|
for _, client := range oldClients {
|
||||||
if _, shouldBeDeleted := deleteMap[client.ctx.GetRemoteAddr()]; !shouldBeDeleted {
|
if _, shouldBeDeleted := m[client.ctx.GetRemoteAddr()]; !shouldBeDeleted {
|
||||||
remainingClients = append(remainingClients, client)
|
remainingClients = append(remainingClients, client)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -18,8 +18,8 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
"github.com/openimsdk/open-im-server/v3/internal/api"
|
"github.com/openimsdk/open-im-server/v3/internal/api"
|
||||||
config2 "github.com/openimsdk/open-im-server/v3/pkg/common/config"
|
config2 "github.com/openimsdk/open-im-server/v3/pkg/common/config"
|
||||||
"github.com/openimsdk/open-im-server/v3/pkg/util/genutil"
|
|
||||||
"github.com/openimsdk/protocol/constant"
|
"github.com/openimsdk/protocol/constant"
|
||||||
|
"github.com/openimsdk/tools/system/program"
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -29,7 +29,7 @@ type ApiCmd struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func NewApiCmd(name string) *ApiCmd {
|
func NewApiCmd(name string) *ApiCmd {
|
||||||
ret := &ApiCmd{RootCmd: NewRootCmd(genutil.GetProcessName(), name)}
|
ret := &ApiCmd{RootCmd: NewRootCmd(program.GetProcessName(), name)}
|
||||||
ret.ctx = context.WithValue(context.Background(), "version", config2.Version)
|
ret.ctx = context.WithValue(context.Background(), "version", config2.Version)
|
||||||
ret.SetRootCmdPt(ret)
|
ret.SetRootCmdPt(ret)
|
||||||
ret.addPreRun()
|
ret.addPreRun()
|
||||||
|
|||||||
@ -18,7 +18,7 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
"github.com/openimsdk/open-im-server/v3/internal/tools"
|
"github.com/openimsdk/open-im-server/v3/internal/tools"
|
||||||
"github.com/openimsdk/open-im-server/v3/pkg/common/config"
|
"github.com/openimsdk/open-im-server/v3/pkg/common/config"
|
||||||
"github.com/openimsdk/open-im-server/v3/pkg/util/genutil"
|
"github.com/openimsdk/tools/system/program"
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -29,7 +29,7 @@ type CronTaskCmd struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func NewCronTaskCmd(name string) *CronTaskCmd {
|
func NewCronTaskCmd(name string) *CronTaskCmd {
|
||||||
ret := &CronTaskCmd{RootCmd: NewRootCmd(genutil.GetProcessName(), name, WithCronTaskLogName()),
|
ret := &CronTaskCmd{RootCmd: NewRootCmd(program.GetProcessName(), name, WithCronTaskLogName()),
|
||||||
initFunc: tools.StartTask}
|
initFunc: tools.StartTask}
|
||||||
ret.ctx = context.WithValue(context.Background(), "version", config.Version)
|
ret.ctx = context.WithValue(context.Background(), "version", config.Version)
|
||||||
ret.addRunE()
|
ret.addRunE()
|
||||||
|
|||||||
@ -17,10 +17,10 @@ package cmd
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
config2 "github.com/openimsdk/open-im-server/v3/pkg/common/config"
|
config2 "github.com/openimsdk/open-im-server/v3/pkg/common/config"
|
||||||
|
"github.com/openimsdk/tools/system/program"
|
||||||
"log"
|
"log"
|
||||||
|
|
||||||
"github.com/openimsdk/open-im-server/v3/internal/msggateway"
|
"github.com/openimsdk/open-im-server/v3/internal/msggateway"
|
||||||
"github.com/openimsdk/open-im-server/v3/pkg/util/genutil"
|
|
||||||
"github.com/openimsdk/protocol/constant"
|
"github.com/openimsdk/protocol/constant"
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
)
|
)
|
||||||
@ -31,7 +31,7 @@ type MsgGatewayCmd struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func NewMsgGatewayCmd(name string) *MsgGatewayCmd {
|
func NewMsgGatewayCmd(name string) *MsgGatewayCmd {
|
||||||
ret := &MsgGatewayCmd{RootCmd: NewRootCmd(genutil.GetProcessName(), name)}
|
ret := &MsgGatewayCmd{RootCmd: NewRootCmd(program.GetProcessName(), name)}
|
||||||
ret.ctx = context.WithValue(context.Background(), "version", config2.Version)
|
ret.ctx = context.WithValue(context.Background(), "version", config2.Version)
|
||||||
ret.addRunE()
|
ret.addRunE()
|
||||||
ret.SetRootCmdPt(ret)
|
ret.SetRootCmdPt(ret)
|
||||||
|
|||||||
@ -17,9 +17,9 @@ package cmd
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
config2 "github.com/openimsdk/open-im-server/v3/pkg/common/config"
|
config2 "github.com/openimsdk/open-im-server/v3/pkg/common/config"
|
||||||
|
"github.com/openimsdk/tools/system/program"
|
||||||
|
|
||||||
"github.com/openimsdk/open-im-server/v3/internal/msgtransfer"
|
"github.com/openimsdk/open-im-server/v3/internal/msgtransfer"
|
||||||
"github.com/openimsdk/open-im-server/v3/pkg/util/genutil"
|
|
||||||
"github.com/openimsdk/protocol/constant"
|
"github.com/openimsdk/protocol/constant"
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
)
|
)
|
||||||
@ -30,7 +30,7 @@ type MsgTransferCmd struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func NewMsgTransferCmd(name string) *MsgTransferCmd {
|
func NewMsgTransferCmd(name string) *MsgTransferCmd {
|
||||||
ret := &MsgTransferCmd{RootCmd: NewRootCmd(genutil.GetProcessName(), name)}
|
ret := &MsgTransferCmd{RootCmd: NewRootCmd(program.GetProcessName(), name)}
|
||||||
ret.ctx = context.WithValue(context.Background(), "version", config2.Version)
|
ret.ctx = context.WithValue(context.Background(), "version", config2.Version)
|
||||||
ret.addRunE()
|
ret.addRunE()
|
||||||
ret.SetRootCmdPt(ret)
|
ret.SetRootCmdPt(ret)
|
||||||
|
|||||||
@ -17,7 +17,7 @@ package cmd
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"github.com/openimsdk/open-im-server/v3/internal/tools"
|
"github.com/openimsdk/open-im-server/v3/internal/tools"
|
||||||
util "github.com/openimsdk/open-im-server/v3/pkg/util/genutil"
|
"github.com/openimsdk/tools/system/program"
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -139,7 +139,7 @@ func (s *SeqCmd) GetSeqCmd() *cobra.Command {
|
|||||||
s.Command.Run = func(cmdLines *cobra.Command, args []string) {
|
s.Command.Run = func(cmdLines *cobra.Command, args []string) {
|
||||||
_, err := tools.InitMsgTool(context.Background(), s.MsgTool.Config)
|
_, err := tools.InitMsgTool(context.Background(), s.MsgTool.Config)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
util.ExitWithError(err)
|
program.ExitWithError(err)
|
||||||
}
|
}
|
||||||
userID := s.getUserIDFlag(cmdLines)
|
userID := s.getUserIDFlag(cmdLines)
|
||||||
superGroupID := s.getSuperGroupIDFlag(cmdLines)
|
superGroupID := s.getSuperGroupIDFlag(cmdLines)
|
||||||
|
|||||||
@ -17,10 +17,10 @@ package cmd
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"errors"
|
"errors"
|
||||||
|
"github.com/openimsdk/tools/system/program"
|
||||||
|
|
||||||
config2 "github.com/openimsdk/open-im-server/v3/pkg/common/config"
|
config2 "github.com/openimsdk/open-im-server/v3/pkg/common/config"
|
||||||
"github.com/openimsdk/open-im-server/v3/pkg/common/startrpc"
|
"github.com/openimsdk/open-im-server/v3/pkg/common/startrpc"
|
||||||
"github.com/openimsdk/open-im-server/v3/pkg/util/genutil"
|
|
||||||
"github.com/openimsdk/protocol/constant"
|
"github.com/openimsdk/protocol/constant"
|
||||||
"github.com/openimsdk/tools/discovery"
|
"github.com/openimsdk/tools/discovery"
|
||||||
"github.com/openimsdk/tools/errs"
|
"github.com/openimsdk/tools/errs"
|
||||||
@ -38,7 +38,7 @@ type RpcCmd struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func NewRpcCmd(name string, initFunc rpcInitFuc) *RpcCmd {
|
func NewRpcCmd(name string, initFunc rpcInitFuc) *RpcCmd {
|
||||||
ret := &RpcCmd{RootCmd: NewRootCmd(genutil.GetProcessName(), name), initFunc: initFunc}
|
ret := &RpcCmd{RootCmd: NewRootCmd(program.GetProcessName(), name), initFunc: initFunc}
|
||||||
ret.ctx = context.WithValue(context.Background(), "version", config2.Version)
|
ret.ctx = context.WithValue(context.Background(), "version", config2.Version)
|
||||||
ret.addPreRun()
|
ret.addPreRun()
|
||||||
ret.addRunE()
|
ret.addRunE()
|
||||||
|
|||||||
@ -16,12 +16,12 @@ package config
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
_ "embed"
|
_ "embed"
|
||||||
|
"github.com/openimsdk/tools/field"
|
||||||
"gopkg.in/yaml.v3"
|
"gopkg.in/yaml.v3"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
|
||||||
"github.com/openimsdk/open-im-server/v3/pkg/msgprocessor"
|
"github.com/openimsdk/open-im-server/v3/pkg/msgprocessor"
|
||||||
"github.com/openimsdk/open-im-server/v3/pkg/util/genutil"
|
|
||||||
"github.com/openimsdk/protocol/constant"
|
"github.com/openimsdk/protocol/constant"
|
||||||
"github.com/openimsdk/tools/errs"
|
"github.com/openimsdk/tools/errs"
|
||||||
)
|
)
|
||||||
@ -42,7 +42,7 @@ func GetDefaultConfigPath() (string, error) {
|
|||||||
return "", errs.WrapMsg(err, "failed to get executable path")
|
return "", errs.WrapMsg(err, "failed to get executable path")
|
||||||
}
|
}
|
||||||
|
|
||||||
configPath, err := genutil.OutDir(filepath.Join(filepath.Dir(executablePath), "../config/"))
|
configPath, err := field.OutDir(filepath.Join(filepath.Dir(executablePath), "../config/"))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", errs.WrapMsg(err, "failed to get output directory", "outDir", filepath.Join(filepath.Dir(executablePath), "../config/"))
|
return "", errs.WrapMsg(err, "failed to get output directory", "outDir", filepath.Join(filepath.Dir(executablePath), "../config/"))
|
||||||
}
|
}
|
||||||
@ -55,7 +55,7 @@ func GetProjectRoot() (string, error) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return "", errs.Wrap(err)
|
return "", errs.Wrap(err)
|
||||||
}
|
}
|
||||||
projectRoot, err := genutil.OutDir(filepath.Join(filepath.Dir(executablePath), "../../../../.."))
|
projectRoot, err := field.OutDir(filepath.Join(filepath.Dir(executablePath), "../../../../.."))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", errs.Wrap(err)
|
return "", errs.Wrap(err)
|
||||||
}
|
}
|
||||||
|
|||||||
@ -19,6 +19,7 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"github.com/openimsdk/open-im-server/v3/pkg/common/servererrs"
|
||||||
"image"
|
"image"
|
||||||
"image/gif"
|
"image/gif"
|
||||||
"image/jpeg"
|
"image/jpeg"
|
||||||
@ -31,7 +32,6 @@ import (
|
|||||||
"github.com/minio/minio-go/v7"
|
"github.com/minio/minio-go/v7"
|
||||||
"github.com/openimsdk/open-im-server/v3/pkg/common/db/cache"
|
"github.com/openimsdk/open-im-server/v3/pkg/common/db/cache"
|
||||||
"github.com/openimsdk/open-im-server/v3/pkg/common/db/s3"
|
"github.com/openimsdk/open-im-server/v3/pkg/common/db/s3"
|
||||||
"github.com/openimsdk/tools/errs"
|
|
||||||
"github.com/openimsdk/tools/log"
|
"github.com/openimsdk/tools/log"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -45,7 +45,7 @@ func (m *Minio) getImageThumbnailURL(ctx context.Context, name string, expire ti
|
|||||||
return "", err
|
return "", err
|
||||||
}
|
}
|
||||||
if !info.IsImg {
|
if !info.IsImg {
|
||||||
return "", errs.ErrData.WrapMsg("object not image")
|
return "", servererrs.ErrData.WrapMsg("object not image")
|
||||||
}
|
}
|
||||||
if opt.Width > info.Width || opt.Width <= 0 {
|
if opt.Width > info.Width || opt.Width <= 0 {
|
||||||
opt.Width = info.Width
|
opt.Width = info.Width
|
||||||
|
|||||||
@ -18,7 +18,7 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/openimsdk/tools/pagination"
|
"github.com/openimsdk/tools/db/pagination"
|
||||||
)
|
)
|
||||||
|
|
||||||
type BlackModel struct {
|
type BlackModel struct {
|
||||||
|
|||||||
@ -18,7 +18,7 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/openimsdk/tools/pagination"
|
"github.com/openimsdk/tools/db/pagination"
|
||||||
)
|
)
|
||||||
|
|
||||||
type ConversationModel struct {
|
type ConversationModel struct {
|
||||||
|
|||||||
@ -18,7 +18,7 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/openimsdk/tools/pagination"
|
"github.com/openimsdk/tools/db/pagination"
|
||||||
)
|
)
|
||||||
|
|
||||||
// FriendModel represents the data structure for a friend relationship in MongoDB.
|
// FriendModel represents the data structure for a friend relationship in MongoDB.
|
||||||
|
|||||||
@ -18,7 +18,7 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/openimsdk/tools/pagination"
|
"github.com/openimsdk/tools/db/pagination"
|
||||||
)
|
)
|
||||||
|
|
||||||
type FriendRequestModel struct {
|
type FriendRequestModel struct {
|
||||||
|
|||||||
@ -18,7 +18,7 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/openimsdk/tools/pagination"
|
"github.com/openimsdk/tools/db/pagination"
|
||||||
)
|
)
|
||||||
|
|
||||||
type GroupModel struct {
|
type GroupModel struct {
|
||||||
|
|||||||
@ -18,7 +18,7 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/openimsdk/tools/pagination"
|
"github.com/openimsdk/tools/db/pagination"
|
||||||
)
|
)
|
||||||
|
|
||||||
type GroupMemberModel struct {
|
type GroupMemberModel struct {
|
||||||
|
|||||||
@ -18,7 +18,7 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/openimsdk/tools/pagination"
|
"github.com/openimsdk/tools/db/pagination"
|
||||||
)
|
)
|
||||||
|
|
||||||
type GroupRequestModel struct {
|
type GroupRequestModel struct {
|
||||||
|
|||||||
@ -18,7 +18,7 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/openimsdk/tools/pagination"
|
"github.com/openimsdk/tools/db/pagination"
|
||||||
)
|
)
|
||||||
|
|
||||||
type LogModel struct {
|
type LogModel struct {
|
||||||
|
|||||||
@ -19,7 +19,7 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/openimsdk/protocol/user"
|
"github.com/openimsdk/protocol/user"
|
||||||
"github.com/openimsdk/tools/pagination"
|
"github.com/openimsdk/tools/db/pagination"
|
||||||
)
|
)
|
||||||
|
|
||||||
type UserModel struct {
|
type UserModel struct {
|
||||||
|
|||||||
@ -15,7 +15,7 @@
|
|||||||
package relation
|
package relation
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/openimsdk/tools/utils"
|
"github.com/openimsdk/tools/errs"
|
||||||
"go.mongodb.org/mongo-driver/mongo"
|
"go.mongodb.org/mongo-driver/mongo"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -31,5 +31,5 @@ type GroupSimpleUserID struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func IsNotFound(err error) bool {
|
func IsNotFound(err error) bool {
|
||||||
return utils.Unwrap(err) == mongo.ErrNoDocuments
|
return errs.Unwrap(err) == mongo.ErrNoDocuments
|
||||||
}
|
}
|
||||||
|
|||||||
@ -15,12 +15,12 @@
|
|||||||
package discoveryregister
|
package discoveryregister
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"github.com/openimsdk/tools/discovery"
|
||||||
"os"
|
"os"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/openimsdk/open-im-server/v3/pkg/common/config"
|
"github.com/openimsdk/open-im-server/v3/pkg/common/config"
|
||||||
|
|
||||||
"github.com/openimsdk/tools/discoveryregistry"
|
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -57,7 +57,7 @@ func TestNewDiscoveryRegister(t *testing.T) {
|
|||||||
} else {
|
} else {
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
if test.expectedResult {
|
if test.expectedResult {
|
||||||
assert.Implements(t, (*discoveryregistry.SvcDiscoveryRegistry)(nil), client)
|
assert.Implements(t, (*discovery.SvcDiscoveryRegistry)(nil), client)
|
||||||
} else {
|
} else {
|
||||||
assert.Nil(t, client)
|
assert.Nil(t, client)
|
||||||
}
|
}
|
||||||
|
|||||||
@ -22,7 +22,7 @@ import (
|
|||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/openimsdk/tools/discoveryregistry"
|
"github.com/openimsdk/tools/discovery"
|
||||||
"github.com/openimsdk/tools/log"
|
"github.com/openimsdk/tools/log"
|
||||||
"github.com/stathat/consistent"
|
"github.com/stathat/consistent"
|
||||||
"google.golang.org/grpc"
|
"google.golang.org/grpc"
|
||||||
@ -36,7 +36,7 @@ type K8sDR struct {
|
|||||||
gatewayName string
|
gatewayName string
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewK8sDiscoveryRegister(gatewayName string) (discoveryregistry.SvcDiscoveryRegistry, error) {
|
func NewK8sDiscoveryRegister(gatewayName string) (discovery.SvcDiscoveryRegistry, error) {
|
||||||
gatewayConsistent := consistent.New()
|
gatewayConsistent := consistent.New()
|
||||||
gatewayHosts := getMsgGatewayHost(context.Background(), gatewayName)
|
gatewayHosts := getMsgGatewayHost(context.Background(), gatewayName)
|
||||||
for _, v := range gatewayHosts {
|
for _, v := range gatewayHosts {
|
||||||
|
|||||||
@ -15,30 +15,29 @@
|
|||||||
package zookeeper
|
package zookeeper
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"github.com/openimsdk/tools/discovery"
|
||||||
"os"
|
"os"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/openimsdk/open-im-server/v3/pkg/common/config"
|
"github.com/openimsdk/open-im-server/v3/pkg/common/config"
|
||||||
"github.com/openimsdk/tools/discoveryregistry"
|
"github.com/openimsdk/tools/discovery/zookeeper"
|
||||||
openkeeper "github.com/openimsdk/tools/discoveryregistry/zookeeper"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// NewZookeeperDiscoveryRegister creates a new instance of ZookeeperDR for Zookeeper service discovery and registration.
|
// NewZookeeperDiscoveryRegister creates a new instance of ZookeeperDR for Zookeeper service discovery and registration.
|
||||||
func NewZookeeperDiscoveryRegister(zkConf *config.Zookeeper) (discoveryregistry.SvcDiscoveryRegistry, error) {
|
func NewZookeeperDiscoveryRegister(zkConf *config.Zookeeper) (discovery.SvcDiscoveryRegistry, error) {
|
||||||
schema := getEnv("ZOOKEEPER_SCHEMA", zkConf.Schema)
|
schema := getEnv("ZOOKEEPER_SCHEMA", zkConf.Schema)
|
||||||
zkAddr := getZkAddrFromEnv(zkConf.ZkAddr)
|
zkAddr := getZkAddrFromEnv(zkConf.ZkAddr)
|
||||||
username := getEnv("ZOOKEEPER_USERNAME", zkConf.Username)
|
username := getEnv("ZOOKEEPER_USERNAME", zkConf.Username)
|
||||||
password := getEnv("ZOOKEEPER_PASSWORD", zkConf.Password)
|
password := getEnv("ZOOKEEPER_PASSWORD", zkConf.Password)
|
||||||
|
|
||||||
zk, err := openkeeper.NewClient(
|
zk, err := zookeeper.NewZkClient(
|
||||||
zkAddr,
|
zkAddr,
|
||||||
schema,
|
schema,
|
||||||
openkeeper.WithFreq(time.Hour),
|
zookeeper.WithFreq(time.Hour),
|
||||||
openkeeper.WithUserNameAndPassword(username, password),
|
zookeeper.WithUserNameAndPassword(username, password),
|
||||||
openkeeper.WithRoundRobin(),
|
zookeeper.WithRoundRobin(),
|
||||||
openkeeper.WithTimeout(10),
|
zookeeper.WithTimeout(10),
|
||||||
// openkeeper.WithLogger(log.NewZkLogger()),
|
|
||||||
)
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
|||||||
@ -16,17 +16,16 @@ package rpcclient
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
|
||||||
util "github.com/openimsdk/open-im-server/v3/pkg/util/genutil"
|
|
||||||
"github.com/openimsdk/protocol/auth"
|
"github.com/openimsdk/protocol/auth"
|
||||||
"github.com/openimsdk/tools/discoveryregistry"
|
"github.com/openimsdk/tools/discovery"
|
||||||
|
"github.com/openimsdk/tools/system/program"
|
||||||
"google.golang.org/grpc"
|
"google.golang.org/grpc"
|
||||||
)
|
)
|
||||||
|
|
||||||
func NewAuth(discov discoveryregistry.SvcDiscoveryRegistry, rpcRegisterName string) *Auth {
|
func NewAuth(discov discovery.SvcDiscoveryRegistry, rpcRegisterName string) *Auth {
|
||||||
conn, err := discov.GetConn(context.Background(), rpcRegisterName)
|
conn, err := discov.GetConn(context.Background(), rpcRegisterName)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
util.ExitWithError(err)
|
program.ExitWithError(err)
|
||||||
}
|
}
|
||||||
client := auth.NewAuthClient(conn)
|
client := auth.NewAuthClient(conn)
|
||||||
return &Auth{discov: discov, conn: conn, Client: client}
|
return &Auth{discov: discov, conn: conn, Client: client}
|
||||||
@ -35,5 +34,5 @@ func NewAuth(discov discoveryregistry.SvcDiscoveryRegistry, rpcRegisterName stri
|
|||||||
type Auth struct {
|
type Auth struct {
|
||||||
conn grpc.ClientConnInterface
|
conn grpc.ClientConnInterface
|
||||||
Client auth.AuthClient
|
Client auth.AuthClient
|
||||||
discov discoveryregistry.SvcDiscoveryRegistry
|
discov discovery.SvcDiscoveryRegistry
|
||||||
}
|
}
|
||||||
|
|||||||
@ -17,11 +17,11 @@ package rpcclient
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"github.com/openimsdk/tools/system/program"
|
||||||
|
|
||||||
"github.com/openimsdk/open-im-server/v3/pkg/common/config"
|
"github.com/openimsdk/open-im-server/v3/pkg/common/config"
|
||||||
util "github.com/openimsdk/open-im-server/v3/pkg/util/genutil"
|
|
||||||
pbconversation "github.com/openimsdk/protocol/conversation"
|
pbconversation "github.com/openimsdk/protocol/conversation"
|
||||||
"github.com/openimsdk/tools/discoveryregistry"
|
"github.com/openimsdk/tools/discovery"
|
||||||
"github.com/openimsdk/tools/errs"
|
"github.com/openimsdk/tools/errs"
|
||||||
"google.golang.org/grpc"
|
"google.golang.org/grpc"
|
||||||
)
|
)
|
||||||
@ -29,14 +29,14 @@ import (
|
|||||||
type Conversation struct {
|
type Conversation struct {
|
||||||
Client pbconversation.ConversationClient
|
Client pbconversation.ConversationClient
|
||||||
conn grpc.ClientConnInterface
|
conn grpc.ClientConnInterface
|
||||||
discov discoveryregistry.SvcDiscoveryRegistry
|
discov discovery.SvcDiscoveryRegistry
|
||||||
Config *config.GlobalConfig
|
Config *config.GlobalConfig
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewConversation(discov discoveryregistry.SvcDiscoveryRegistry, rpcRegisterName string) *Conversation {
|
func NewConversation(discov discovery.SvcDiscoveryRegistry, rpcRegisterName string) *Conversation {
|
||||||
conn, err := discov.GetConn(context.Background(), rpcRegisterName)
|
conn, err := discov.GetConn(context.Background(), rpcRegisterName)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
util.ExitWithError(err)
|
program.ExitWithError(err)
|
||||||
}
|
}
|
||||||
client := pbconversation.NewConversationClient(conn)
|
client := pbconversation.NewConversationClient(conn)
|
||||||
return &Conversation{discov: discov, conn: conn, Client: client}
|
return &Conversation{discov: discov, conn: conn, Client: client}
|
||||||
@ -44,7 +44,7 @@ func NewConversation(discov discoveryregistry.SvcDiscoveryRegistry, rpcRegisterN
|
|||||||
|
|
||||||
type ConversationRpcClient Conversation
|
type ConversationRpcClient Conversation
|
||||||
|
|
||||||
func NewConversationRpcClient(discov discoveryregistry.SvcDiscoveryRegistry, rpcRegisterName string) ConversationRpcClient {
|
func NewConversationRpcClient(discov discovery.SvcDiscoveryRegistry, rpcRegisterName string) ConversationRpcClient {
|
||||||
return ConversationRpcClient(*NewConversation(discov, rpcRegisterName))
|
return ConversationRpcClient(*NewConversation(discov, rpcRegisterName))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -16,24 +16,24 @@ package rpcclient
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"github.com/openimsdk/tools/system/program"
|
||||||
|
|
||||||
util "github.com/openimsdk/open-im-server/v3/pkg/util/genutil"
|
|
||||||
"github.com/openimsdk/protocol/friend"
|
"github.com/openimsdk/protocol/friend"
|
||||||
sdkws "github.com/openimsdk/protocol/sdkws"
|
sdkws "github.com/openimsdk/protocol/sdkws"
|
||||||
"github.com/openimsdk/tools/discoveryregistry"
|
"github.com/openimsdk/tools/discovery"
|
||||||
"google.golang.org/grpc"
|
"google.golang.org/grpc"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Friend struct {
|
type Friend struct {
|
||||||
conn grpc.ClientConnInterface
|
conn grpc.ClientConnInterface
|
||||||
Client friend.FriendClient
|
Client friend.FriendClient
|
||||||
discov discoveryregistry.SvcDiscoveryRegistry
|
discov discovery.SvcDiscoveryRegistry
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewFriend(discov discoveryregistry.SvcDiscoveryRegistry, rpcRegisterName string) *Friend {
|
func NewFriend(discov discovery.SvcDiscoveryRegistry, rpcRegisterName string) *Friend {
|
||||||
conn, err := discov.GetConn(context.Background(), rpcRegisterName)
|
conn, err := discov.GetConn(context.Background(), rpcRegisterName)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
util.ExitWithError(err)
|
program.ExitWithError(err)
|
||||||
}
|
}
|
||||||
client := friend.NewFriendClient(conn)
|
client := friend.NewFriendClient(conn)
|
||||||
return &Friend{discov: discov, conn: conn, Client: client}
|
return &Friend{discov: discov, conn: conn, Client: client}
|
||||||
@ -41,7 +41,7 @@ func NewFriend(discov discoveryregistry.SvcDiscoveryRegistry, rpcRegisterName st
|
|||||||
|
|
||||||
type FriendRpcClient Friend
|
type FriendRpcClient Friend
|
||||||
|
|
||||||
func NewFriendRpcClient(discov discoveryregistry.SvcDiscoveryRegistry, rpcRegisterName string) FriendRpcClient {
|
func NewFriendRpcClient(discov discovery.SvcDiscoveryRegistry, rpcRegisterName string) FriendRpcClient {
|
||||||
return FriendRpcClient(*NewFriend(discov, rpcRegisterName))
|
return FriendRpcClient(*NewFriend(discov, rpcRegisterName))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -17,7 +17,6 @@ package rpcclient
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"github.com/openimsdk/open-im-server/v3/pkg/common/servererrs"
|
"github.com/openimsdk/open-im-server/v3/pkg/common/servererrs"
|
||||||
"github.com/openimsdk/tools/discovery"
|
|
||||||
"github.com/openimsdk/tools/system/program"
|
"github.com/openimsdk/tools/system/program"
|
||||||
"github.com/openimsdk/tools/utils/datautil"
|
"github.com/openimsdk/tools/utils/datautil"
|
||||||
"strings"
|
"strings"
|
||||||
@ -25,6 +24,7 @@ import (
|
|||||||
"github.com/openimsdk/protocol/constant"
|
"github.com/openimsdk/protocol/constant"
|
||||||
"github.com/openimsdk/protocol/group"
|
"github.com/openimsdk/protocol/group"
|
||||||
"github.com/openimsdk/protocol/sdkws"
|
"github.com/openimsdk/protocol/sdkws"
|
||||||
|
"github.com/openimsdk/tools/discovery"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Group struct {
|
type Group struct {
|
||||||
|
|||||||
@ -19,10 +19,10 @@ import (
|
|||||||
"crypto/md5"
|
"crypto/md5"
|
||||||
"encoding/binary"
|
"encoding/binary"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
|
"github.com/openimsdk/tools/utils/datautil"
|
||||||
|
|
||||||
"github.com/openimsdk/protocol/group"
|
"github.com/openimsdk/protocol/group"
|
||||||
"github.com/openimsdk/protocol/sdkws"
|
"github.com/openimsdk/protocol/sdkws"
|
||||||
"github.com/openimsdk/tools/utils"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func NewGroupHashFromGroupClient(x group.GroupClient) *GroupHash {
|
func NewGroupHashFromGroupClient(x group.GroupClient) *GroupHash {
|
||||||
@ -79,9 +79,9 @@ func (gh *GroupHash) GetGroupHash(ctx context.Context, groupID string) (uint64,
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return 0, err
|
return 0, err
|
||||||
}
|
}
|
||||||
utils.Sort(userIDs, true)
|
datautil.Sort(userIDs, true)
|
||||||
}
|
}
|
||||||
memberMap := utils.SliceToMap(members, func(e *sdkws.GroupMemberFullInfo) string {
|
memberMap := datautil.SliceToMap(members, func(e *sdkws.GroupMemberFullInfo) string {
|
||||||
return e.UserID
|
return e.UserID
|
||||||
})
|
})
|
||||||
res := make([]*sdkws.GroupMemberFullInfo, 0, len(members))
|
res := make([]*sdkws.GroupMemberFullInfo, 0, len(members))
|
||||||
|
|||||||
@ -18,16 +18,18 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"github.com/openimsdk/tools/system/program"
|
||||||
|
"github.com/openimsdk/tools/utils/idutil"
|
||||||
|
"github.com/openimsdk/tools/utils/jsonutil"
|
||||||
|
"github.com/openimsdk/tools/utils/timeutil"
|
||||||
|
|
||||||
"github.com/openimsdk/open-im-server/v3/pkg/common/config"
|
"github.com/openimsdk/open-im-server/v3/pkg/common/config"
|
||||||
util "github.com/openimsdk/open-im-server/v3/pkg/util/genutil"
|
|
||||||
"github.com/openimsdk/protocol/constant"
|
"github.com/openimsdk/protocol/constant"
|
||||||
"github.com/openimsdk/protocol/msg"
|
"github.com/openimsdk/protocol/msg"
|
||||||
"github.com/openimsdk/protocol/sdkws"
|
"github.com/openimsdk/protocol/sdkws"
|
||||||
"github.com/openimsdk/tools/discoveryregistry"
|
"github.com/openimsdk/tools/discovery"
|
||||||
"github.com/openimsdk/tools/errs"
|
"github.com/openimsdk/tools/errs"
|
||||||
"github.com/openimsdk/tools/log"
|
"github.com/openimsdk/tools/log"
|
||||||
"github.com/openimsdk/tools/utils"
|
|
||||||
"google.golang.org/grpc"
|
"google.golang.org/grpc"
|
||||||
"google.golang.org/protobuf/proto"
|
"google.golang.org/protobuf/proto"
|
||||||
)
|
)
|
||||||
@ -129,13 +131,13 @@ func newSessionTypeConf() map[int32]int32 {
|
|||||||
type Message struct {
|
type Message struct {
|
||||||
conn grpc.ClientConnInterface
|
conn grpc.ClientConnInterface
|
||||||
Client msg.MsgClient
|
Client msg.MsgClient
|
||||||
discov discoveryregistry.SvcDiscoveryRegistry
|
discov discovery.SvcDiscoveryRegistry
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewMessage(discov discoveryregistry.SvcDiscoveryRegistry, rpcRegisterName string) *Message {
|
func NewMessage(discov discovery.SvcDiscoveryRegistry, rpcRegisterName string) *Message {
|
||||||
conn, err := discov.GetConn(context.Background(), rpcRegisterName)
|
conn, err := discov.GetConn(context.Background(), rpcRegisterName)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
util.ExitWithError(err)
|
program.ExitWithError(err)
|
||||||
}
|
}
|
||||||
client := msg.NewMsgClient(conn)
|
client := msg.NewMsgClient(conn)
|
||||||
return &Message{discov: discov, conn: conn, Client: client}
|
return &Message{discov: discov, conn: conn, Client: client}
|
||||||
@ -143,7 +145,7 @@ func NewMessage(discov discoveryregistry.SvcDiscoveryRegistry, rpcRegisterName s
|
|||||||
|
|
||||||
type MessageRpcClient Message
|
type MessageRpcClient Message
|
||||||
|
|
||||||
func NewMessageRpcClient(discov discoveryregistry.SvcDiscoveryRegistry, rpcRegisterName string) MessageRpcClient {
|
func NewMessageRpcClient(discov discovery.SvcDiscoveryRegistry, rpcRegisterName string) MessageRpcClient {
|
||||||
return MessageRpcClient(*NewMessage(discov, rpcRegisterName))
|
return MessageRpcClient(*NewMessage(discov, rpcRegisterName))
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -258,10 +260,10 @@ func WithRpcGetUserName() NotificationOptions {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (s *NotificationSender) NotificationWithSesstionType(ctx context.Context, sendID, recvID string, contentType, sesstionType int32, m proto.Message, opts ...NotificationOptions) (err error) {
|
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)}
|
n := sdkws.NotificationElem{Detail: jsonutil.StructToJsonString(m)}
|
||||||
content, err := json.Marshal(&n)
|
content, err := json.Marshal(&n)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return errs.WrapMsg(err, "json.Marshal failed", "sendID", sendID, "recvID", recvID, "contentType", contentType, "msg", utils.StructToJsonString(m))
|
return errs.WrapMsg(err, "json.Marshal failed", "sendID", sendID, "recvID", recvID, "contentType", contentType, "msg", jsonutil.StructToJsonString(m))
|
||||||
}
|
}
|
||||||
notificationOpt := ¬ificationOpt{}
|
notificationOpt := ¬ificationOpt{}
|
||||||
for _, opt := range opts {
|
for _, opt := range opts {
|
||||||
@ -288,8 +290,8 @@ func (s *NotificationSender) NotificationWithSesstionType(ctx context.Context, s
|
|||||||
if msg.SessionType == constant.SuperGroupChatType {
|
if msg.SessionType == constant.SuperGroupChatType {
|
||||||
msg.GroupID = recvID
|
msg.GroupID = recvID
|
||||||
}
|
}
|
||||||
msg.CreateTime = utils.GetCurrentTimestampByMill()
|
msg.CreateTime = timeutil.GetCurrentTimestampByMill()
|
||||||
msg.ClientMsgID = utils.GetMsgID(sendID)
|
msg.ClientMsgID = idutil.GetMsgIDByMD5(sendID)
|
||||||
optionsConfig := s.contentTypeConf[contentType]
|
optionsConfig := s.contentTypeConf[contentType]
|
||||||
if sendID == recvID && contentType == constant.HasReadReceipt {
|
if sendID == recvID && contentType == constant.HasReadReceipt {
|
||||||
optionsConfig.ReliabilityLevel = constant.UnreliableNotification
|
optionsConfig.ReliabilityLevel = constant.UnreliableNotification
|
||||||
|
|||||||
@ -17,6 +17,9 @@ package notification
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"github.com/openimsdk/open-im-server/v3/pkg/common/servererrs"
|
||||||
|
"github.com/openimsdk/tools/utils/datautil"
|
||||||
|
"github.com/openimsdk/tools/utils/stringutil"
|
||||||
|
|
||||||
"github.com/openimsdk/open-im-server/v3/pkg/authverify"
|
"github.com/openimsdk/open-im-server/v3/pkg/authverify"
|
||||||
"github.com/openimsdk/open-im-server/v3/pkg/common/config"
|
"github.com/openimsdk/open-im-server/v3/pkg/common/config"
|
||||||
@ -29,7 +32,6 @@ import (
|
|||||||
"github.com/openimsdk/tools/errs"
|
"github.com/openimsdk/tools/errs"
|
||||||
"github.com/openimsdk/tools/log"
|
"github.com/openimsdk/tools/log"
|
||||||
"github.com/openimsdk/tools/mcontext"
|
"github.com/openimsdk/tools/mcontext"
|
||||||
"github.com/openimsdk/tools/utils"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func NewGroupNotificationSender(db controller.GroupDatabase, msgRpcClient *rpcclient.MessageRpcClient, userRpcClient *rpcclient.UserRpcClient, config *config.GlobalConfig, fn func(ctx context.Context, userIDs []string) ([]CommonUser, error)) *GroupNotificationSender {
|
func NewGroupNotificationSender(db controller.GroupDatabase, msgRpcClient *rpcclient.MessageRpcClient, userRpcClient *rpcclient.UserRpcClient, config *config.GlobalConfig, fn func(ctx context.Context, userIDs []string) ([]CommonUser, error)) *GroupNotificationSender {
|
||||||
@ -59,7 +61,7 @@ func (g *GroupNotificationSender) PopulateGroupMember(ctx context.Context, membe
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if len(emptyUserIDs) > 0 {
|
if len(emptyUserIDs) > 0 {
|
||||||
users, err := g.getUsersInfo(ctx, utils.Keys(emptyUserIDs))
|
users, err := g.getUsersInfo(ctx, datautil.Keys(emptyUserIDs))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -89,7 +91,7 @@ func (g *GroupNotificationSender) getUser(ctx context.Context, userID string) (*
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
if len(users) == 0 {
|
if len(users) == 0 {
|
||||||
return nil, errs.ErrUserIDNotFound.WrapMsg(fmt.Sprintf("user %s not found", userID))
|
return nil, servererrs.ErrUserIDNotFound.WrapMsg(fmt.Sprintf("user %s not found", userID))
|
||||||
}
|
}
|
||||||
return &sdkws.PublicUserInfo{
|
return &sdkws.PublicUserInfo{
|
||||||
UserID: users[0].GetUserID(),
|
UserID: users[0].GetUserID(),
|
||||||
@ -185,7 +187,7 @@ func (g *GroupNotificationSender) getGroupOwnerAndAdminUserID(ctx context.Contex
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
fn := func(e *relation.GroupMemberModel) string { return e.UserID }
|
fn := func(e *relation.GroupMemberModel) string { return e.UserID }
|
||||||
return utils.Slice(members, fn), nil
|
return datautil.Slice(members, fn), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
//nolint:unused
|
//nolint:unused
|
||||||
@ -289,7 +291,7 @@ func (g *GroupNotificationSender) GroupCreatedNotification(ctx context.Context,
|
|||||||
defer log.ZDebug(ctx, "return")
|
defer log.ZDebug(ctx, "return")
|
||||||
defer func() {
|
defer func() {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.ZError(ctx, utils.GetFuncName(1)+" failed", err)
|
log.ZError(ctx, stringutil.GetFuncName(1)+" failed", err)
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
if err := g.fillOpUser(ctx, &tips.OpUser, tips.Group.GroupID); err != nil {
|
if err := g.fillOpUser(ctx, &tips.OpUser, tips.Group.GroupID); err != nil {
|
||||||
@ -302,7 +304,7 @@ func (g *GroupNotificationSender) GroupInfoSetNotification(ctx context.Context,
|
|||||||
defer log.ZDebug(ctx, "return")
|
defer log.ZDebug(ctx, "return")
|
||||||
defer func() {
|
defer func() {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.ZError(ctx, utils.GetFuncName(1)+" failed", err)
|
log.ZError(ctx, stringutil.GetFuncName(1)+" failed", err)
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
if err := g.fillOpUser(ctx, &tips.OpUser, tips.Group.GroupID); err != nil {
|
if err := g.fillOpUser(ctx, &tips.OpUser, tips.Group.GroupID); err != nil {
|
||||||
@ -315,7 +317,7 @@ func (g *GroupNotificationSender) GroupInfoSetNameNotification(ctx context.Conte
|
|||||||
defer log.ZDebug(ctx, "return")
|
defer log.ZDebug(ctx, "return")
|
||||||
defer func() {
|
defer func() {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.ZError(ctx, utils.GetFuncName(1)+" failed", err)
|
log.ZError(ctx, stringutil.GetFuncName(1)+" failed", err)
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
if err := g.fillOpUser(ctx, &tips.OpUser, tips.Group.GroupID); err != nil {
|
if err := g.fillOpUser(ctx, &tips.OpUser, tips.Group.GroupID); err != nil {
|
||||||
@ -328,7 +330,7 @@ func (g *GroupNotificationSender) GroupInfoSetAnnouncementNotification(ctx conte
|
|||||||
defer log.ZDebug(ctx, "return")
|
defer log.ZDebug(ctx, "return")
|
||||||
defer func() {
|
defer func() {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.ZError(ctx, utils.GetFuncName(1)+" failed", err)
|
log.ZError(ctx, stringutil.GetFuncName(1)+" failed", err)
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
if err := g.fillOpUser(ctx, &tips.OpUser, tips.Group.GroupID); err != nil {
|
if err := g.fillOpUser(ctx, &tips.OpUser, tips.Group.GroupID); err != nil {
|
||||||
@ -341,7 +343,7 @@ func (g *GroupNotificationSender) JoinGroupApplicationNotification(ctx context.C
|
|||||||
defer log.ZDebug(ctx, "return")
|
defer log.ZDebug(ctx, "return")
|
||||||
defer func() {
|
defer func() {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.ZError(ctx, utils.GetFuncName(1)+" failed", err)
|
log.ZError(ctx, stringutil.GetFuncName(1)+" failed", err)
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
group, err := g.getGroupInfo(ctx, req.GroupID)
|
group, err := g.getGroupInfo(ctx, req.GroupID)
|
||||||
@ -358,7 +360,7 @@ func (g *GroupNotificationSender) JoinGroupApplicationNotification(ctx context.C
|
|||||||
}
|
}
|
||||||
userIDs = append(userIDs, req.InviterUserID, mcontext.GetOpUserID(ctx))
|
userIDs = append(userIDs, req.InviterUserID, mcontext.GetOpUserID(ctx))
|
||||||
tips := &sdkws.JoinGroupApplicationTips{Group: group, Applicant: user, ReqMsg: req.ReqMessage}
|
tips := &sdkws.JoinGroupApplicationTips{Group: group, Applicant: user, ReqMsg: req.ReqMessage}
|
||||||
for _, userID := range utils.Distinct(userIDs) {
|
for _, userID := range datautil.Distinct(userIDs) {
|
||||||
err = g.Notification(ctx, mcontext.GetOpUserID(ctx), userID, constant.JoinGroupApplicationNotification, tips)
|
err = g.Notification(ctx, mcontext.GetOpUserID(ctx), userID, constant.JoinGroupApplicationNotification, tips)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.ZError(ctx, "JoinGroupApplicationNotification failed", err, "group", req.GroupID, "userID", userID)
|
log.ZError(ctx, "JoinGroupApplicationNotification failed", err, "group", req.GroupID, "userID", userID)
|
||||||
@ -371,7 +373,7 @@ func (g *GroupNotificationSender) MemberQuitNotification(ctx context.Context, me
|
|||||||
defer log.ZDebug(ctx, "return")
|
defer log.ZDebug(ctx, "return")
|
||||||
defer func() {
|
defer func() {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.ZError(ctx, utils.GetFuncName(1)+" failed", err)
|
log.ZError(ctx, stringutil.GetFuncName(1)+" failed", err)
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
group, err := g.getGroupInfo(ctx, member.GroupID)
|
group, err := g.getGroupInfo(ctx, member.GroupID)
|
||||||
@ -386,7 +388,7 @@ func (g *GroupNotificationSender) GroupApplicationAcceptedNotification(ctx conte
|
|||||||
defer log.ZDebug(ctx, "return")
|
defer log.ZDebug(ctx, "return")
|
||||||
defer func() {
|
defer func() {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.ZError(ctx, utils.GetFuncName(1)+" failed", err)
|
log.ZError(ctx, stringutil.GetFuncName(1)+" failed", err)
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
group, err := g.getGroupInfo(ctx, req.GroupID)
|
group, err := g.getGroupInfo(ctx, req.GroupID)
|
||||||
@ -419,7 +421,7 @@ func (g *GroupNotificationSender) GroupApplicationRejectedNotification(ctx conte
|
|||||||
defer log.ZDebug(ctx, "return")
|
defer log.ZDebug(ctx, "return")
|
||||||
defer func() {
|
defer func() {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.ZError(ctx, utils.GetFuncName(1)+" failed", err)
|
log.ZError(ctx, stringutil.GetFuncName(1)+" failed", err)
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
group, err := g.getGroupInfo(ctx, req.GroupID)
|
group, err := g.getGroupInfo(ctx, req.GroupID)
|
||||||
@ -452,7 +454,7 @@ func (g *GroupNotificationSender) GroupOwnerTransferredNotification(ctx context.
|
|||||||
defer log.ZDebug(ctx, "return")
|
defer log.ZDebug(ctx, "return")
|
||||||
defer func() {
|
defer func() {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.ZError(ctx, utils.GetFuncName(1)+" failed", err)
|
log.ZError(ctx, stringutil.GetFuncName(1)+" failed", err)
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
group, err := g.getGroupInfo(ctx, req.GroupID)
|
group, err := g.getGroupInfo(ctx, req.GroupID)
|
||||||
@ -475,7 +477,7 @@ func (g *GroupNotificationSender) MemberKickedNotification(ctx context.Context,
|
|||||||
defer log.ZDebug(ctx, "return")
|
defer log.ZDebug(ctx, "return")
|
||||||
defer func() {
|
defer func() {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.ZError(ctx, utils.GetFuncName(1)+" failed", err)
|
log.ZError(ctx, stringutil.GetFuncName(1)+" failed", err)
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
if err := g.fillOpUser(ctx, &tips.OpUser, tips.Group.GroupID); err != nil {
|
if err := g.fillOpUser(ctx, &tips.OpUser, tips.Group.GroupID); err != nil {
|
||||||
@ -488,7 +490,7 @@ func (g *GroupNotificationSender) MemberInvitedNotification(ctx context.Context,
|
|||||||
defer log.ZDebug(ctx, "return")
|
defer log.ZDebug(ctx, "return")
|
||||||
defer func() {
|
defer func() {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.ZError(ctx, utils.GetFuncName(1)+" failed", err)
|
log.ZError(ctx, stringutil.GetFuncName(1)+" failed", err)
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
group, err := g.getGroupInfo(ctx, groupID)
|
group, err := g.getGroupInfo(ctx, groupID)
|
||||||
@ -513,7 +515,7 @@ func (g *GroupNotificationSender) MemberEnterNotification(ctx context.Context, g
|
|||||||
defer log.ZDebug(ctx, "return")
|
defer log.ZDebug(ctx, "return")
|
||||||
defer func() {
|
defer func() {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.ZError(ctx, utils.GetFuncName(1)+" failed", err)
|
log.ZError(ctx, stringutil.GetFuncName(1)+" failed", err)
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
group, err := g.getGroupInfo(ctx, groupID)
|
group, err := g.getGroupInfo(ctx, groupID)
|
||||||
@ -532,7 +534,7 @@ func (g *GroupNotificationSender) GroupDismissedNotification(ctx context.Context
|
|||||||
defer log.ZDebug(ctx, "return")
|
defer log.ZDebug(ctx, "return")
|
||||||
defer func() {
|
defer func() {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.ZError(ctx, utils.GetFuncName(1)+" failed", err)
|
log.ZError(ctx, stringutil.GetFuncName(1)+" failed", err)
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
if err := g.fillOpUser(ctx, &tips.OpUser, tips.Group.GroupID); err != nil {
|
if err := g.fillOpUser(ctx, &tips.OpUser, tips.Group.GroupID); err != nil {
|
||||||
@ -545,7 +547,7 @@ func (g *GroupNotificationSender) GroupMemberMutedNotification(ctx context.Conte
|
|||||||
defer log.ZDebug(ctx, "return")
|
defer log.ZDebug(ctx, "return")
|
||||||
defer func() {
|
defer func() {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.ZError(ctx, utils.GetFuncName(1)+" failed", err)
|
log.ZError(ctx, stringutil.GetFuncName(1)+" failed", err)
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
group, err := g.getGroupInfo(ctx, groupID)
|
group, err := g.getGroupInfo(ctx, groupID)
|
||||||
@ -570,7 +572,7 @@ func (g *GroupNotificationSender) GroupMemberCancelMutedNotification(ctx context
|
|||||||
defer log.ZDebug(ctx, "return")
|
defer log.ZDebug(ctx, "return")
|
||||||
defer func() {
|
defer func() {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.ZError(ctx, utils.GetFuncName(1)+" failed", err)
|
log.ZError(ctx, stringutil.GetFuncName(1)+" failed", err)
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
group, err := g.getGroupInfo(ctx, groupID)
|
group, err := g.getGroupInfo(ctx, groupID)
|
||||||
@ -592,7 +594,7 @@ func (g *GroupNotificationSender) GroupMutedNotification(ctx context.Context, gr
|
|||||||
defer log.ZDebug(ctx, "return")
|
defer log.ZDebug(ctx, "return")
|
||||||
defer func() {
|
defer func() {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.ZError(ctx, utils.GetFuncName(1)+" failed", err)
|
log.ZError(ctx, stringutil.GetFuncName(1)+" failed", err)
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
group, err := g.getGroupInfo(ctx, groupID)
|
group, err := g.getGroupInfo(ctx, groupID)
|
||||||
@ -617,7 +619,7 @@ func (g *GroupNotificationSender) GroupCancelMutedNotification(ctx context.Conte
|
|||||||
defer log.ZDebug(ctx, "return")
|
defer log.ZDebug(ctx, "return")
|
||||||
defer func() {
|
defer func() {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.ZError(ctx, utils.GetFuncName(1)+" failed", err)
|
log.ZError(ctx, stringutil.GetFuncName(1)+" failed", err)
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
group, err := g.getGroupInfo(ctx, groupID)
|
group, err := g.getGroupInfo(ctx, groupID)
|
||||||
@ -674,7 +676,7 @@ func (g *GroupNotificationSender) GroupMemberSetToOrdinaryUserNotification(ctx c
|
|||||||
defer log.ZDebug(ctx, "return")
|
defer log.ZDebug(ctx, "return")
|
||||||
defer func() {
|
defer func() {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.ZError(ctx, utils.GetFuncName(1)+" failed", err)
|
log.ZError(ctx, stringutil.GetFuncName(1)+" failed", err)
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
group, err := g.getGroupInfo(ctx, groupID)
|
group, err := g.getGroupInfo(ctx, groupID)
|
||||||
@ -696,7 +698,7 @@ func (g *GroupNotificationSender) SuperGroupNotification(ctx context.Context, se
|
|||||||
defer log.ZDebug(ctx, "return")
|
defer log.ZDebug(ctx, "return")
|
||||||
defer func() {
|
defer func() {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.ZError(ctx, utils.GetFuncName(1)+" failed", err)
|
log.ZError(ctx, stringutil.GetFuncName(1)+" failed", err)
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
err = g.Notification(ctx, sendID, recvID, constant.SuperGroupUpdateNotification, nil)
|
err = g.Notification(ctx, sendID, recvID, constant.SuperGroupUpdateNotification, nil)
|
||||||
|
|||||||
@ -16,23 +16,23 @@ package rpcclient
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"github.com/openimsdk/tools/discovery"
|
||||||
|
"github.com/openimsdk/tools/system/program"
|
||||||
|
|
||||||
util "github.com/openimsdk/open-im-server/v3/pkg/util/genutil"
|
|
||||||
"github.com/openimsdk/protocol/push"
|
"github.com/openimsdk/protocol/push"
|
||||||
"github.com/openimsdk/tools/discoveryregistry"
|
|
||||||
"google.golang.org/grpc"
|
"google.golang.org/grpc"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Push struct {
|
type Push struct {
|
||||||
conn grpc.ClientConnInterface
|
conn grpc.ClientConnInterface
|
||||||
Client push.PushMsgServiceClient
|
Client push.PushMsgServiceClient
|
||||||
discov discoveryregistry.SvcDiscoveryRegistry
|
discov discovery.SvcDiscoveryRegistry
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewPush(discov discoveryregistry.SvcDiscoveryRegistry, rpcRegisterName string) *Push {
|
func NewPush(discov discovery.SvcDiscoveryRegistry, rpcRegisterName string) *Push {
|
||||||
conn, err := discov.GetConn(context.Background(), rpcRegisterName)
|
conn, err := discov.GetConn(context.Background(), rpcRegisterName)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
util.ExitWithError(err)
|
program.ExitWithError(err)
|
||||||
}
|
}
|
||||||
return &Push{
|
return &Push{
|
||||||
discov: discov,
|
discov: discov,
|
||||||
@ -43,7 +43,7 @@ func NewPush(discov discoveryregistry.SvcDiscoveryRegistry, rpcRegisterName stri
|
|||||||
|
|
||||||
type PushRpcClient Push
|
type PushRpcClient Push
|
||||||
|
|
||||||
func NewPushRpcClient(discov discoveryregistry.SvcDiscoveryRegistry, rpcRegisterName string) PushRpcClient {
|
func NewPushRpcClient(discov discovery.SvcDiscoveryRegistry, rpcRegisterName string) PushRpcClient {
|
||||||
return PushRpcClient(*NewPush(discov, rpcRegisterName))
|
return PushRpcClient(*NewPush(discov, rpcRegisterName))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -16,6 +16,7 @@ package rpcclient
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
|
||||||
"github.com/openimsdk/tools/system/program"
|
"github.com/openimsdk/tools/system/program"
|
||||||
|
|
||||||
"github.com/openimsdk/protocol/third"
|
"github.com/openimsdk/protocol/third"
|
||||||
|
|||||||
@ -17,12 +17,12 @@ package rpcclient
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"github.com/openimsdk/open-im-server/v3/pkg/common/servererrs"
|
"github.com/openimsdk/open-im-server/v3/pkg/common/servererrs"
|
||||||
|
"github.com/openimsdk/tools/system/program"
|
||||||
"github.com/openimsdk/tools/utils/datautil"
|
"github.com/openimsdk/tools/utils/datautil"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/openimsdk/open-im-server/v3/pkg/authverify"
|
"github.com/openimsdk/open-im-server/v3/pkg/authverify"
|
||||||
"github.com/openimsdk/open-im-server/v3/pkg/common/config"
|
"github.com/openimsdk/open-im-server/v3/pkg/common/config"
|
||||||
util "github.com/openimsdk/open-im-server/v3/pkg/util/genutil"
|
|
||||||
"github.com/openimsdk/protocol/sdkws"
|
"github.com/openimsdk/protocol/sdkws"
|
||||||
"github.com/openimsdk/protocol/user"
|
"github.com/openimsdk/protocol/user"
|
||||||
"github.com/openimsdk/tools/discovery"
|
"github.com/openimsdk/tools/discovery"
|
||||||
@ -44,7 +44,7 @@ func NewUser(discov discovery.SvcDiscoveryRegistry, rpcRegisterName, messageGate
|
|||||||
manager *config.Manager, imAdmin *config.IMAdmin) *User {
|
manager *config.Manager, imAdmin *config.IMAdmin) *User {
|
||||||
conn, err := discov.GetConn(context.Background(), rpcRegisterName)
|
conn, err := discov.GetConn(context.Background(), rpcRegisterName)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
util.ExitWithError(err)
|
program.ExitWithError(err)
|
||||||
}
|
}
|
||||||
client := user.NewUserClient(conn)
|
client := user.NewUserClient(conn)
|
||||||
return &User{Discov: discov, Client: client,
|
return &User{Discov: discov, Client: client,
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user