mirror of
https://github.com/openimsdk/open-im-server.git
synced 2026-05-08 11:05:59 +08:00
config path
This commit is contained in:
@@ -19,10 +19,10 @@ var Terminal = []int{constant.IOSPlatformID, constant.AndroidPlatformID, constan
|
||||
|
||||
type Fcm struct {
|
||||
fcmMsgCli *messaging.Client
|
||||
cache cache.MsgCache
|
||||
cache cache.Cache
|
||||
}
|
||||
|
||||
func NewClient(cache cache.MsgCache) *Fcm {
|
||||
func NewClient(cache cache.Cache) *Fcm {
|
||||
opt := option.WithCredentialsFile(filepath.Join(config.Root, "config", config.Config.Push.Fcm.ServiceAccount))
|
||||
fcmApp, err := firebase.NewApp(context.Background(), nil, opt)
|
||||
if err != nil {
|
||||
|
||||
@@ -9,7 +9,7 @@ import (
|
||||
)
|
||||
|
||||
func Test_Push(t *testing.T) {
|
||||
var redis cache.MsgCache
|
||||
var redis cache.Cache
|
||||
offlinePusher := NewClient(redis)
|
||||
err := offlinePusher.Push(context.Background(), []string{"userID1"}, "test", "test", &push.Opts{})
|
||||
assert.Nil(t, err)
|
||||
|
||||
@@ -38,12 +38,12 @@ const (
|
||||
)
|
||||
|
||||
type Client struct {
|
||||
cache cache.MsgCache
|
||||
cache cache.Cache
|
||||
tokenExpireTime int64
|
||||
taskIDTTL int64
|
||||
}
|
||||
|
||||
func NewClient(cache cache.MsgCache) *Client {
|
||||
func NewClient(cache cache.Cache) *Client {
|
||||
return &Client{cache: cache, tokenExpireTime: tokenExpireTime, taskIDTTL: taskIDTTL}
|
||||
}
|
||||
|
||||
|
||||
@@ -25,7 +25,7 @@ type RPCServer struct {
|
||||
pusher Pusher
|
||||
}
|
||||
|
||||
func (r *RPCServer) Init(rpcPort int, cache cache.MsgCache) {
|
||||
func (r *RPCServer) Init(rpcPort int, cache cache.Cache) {
|
||||
r.rpcPort = rpcPort
|
||||
r.rpcRegisterName = config.Config.RpcRegisterName.OpenImPushName
|
||||
}
|
||||
|
||||
@@ -25,7 +25,7 @@ import (
|
||||
)
|
||||
|
||||
type Pusher struct {
|
||||
cache cache.MsgCache
|
||||
cache cache.Cache
|
||||
client discoveryregistry.SvcDiscoveryRegistry
|
||||
offlinePusher OfflinePusher
|
||||
groupLocalCache localcache.GroupLocalCache
|
||||
@@ -33,7 +33,7 @@ type Pusher struct {
|
||||
successCount int
|
||||
}
|
||||
|
||||
func NewPusher(cache cache.MsgCache, client discoveryregistry.SvcDiscoveryRegistry, offlinePusher OfflinePusher) *Pusher {
|
||||
func NewPusher(cache cache.Cache, client discoveryregistry.SvcDiscoveryRegistry, offlinePusher OfflinePusher) *Pusher {
|
||||
return &Pusher{
|
||||
cache: cache,
|
||||
client: client,
|
||||
|
||||
@@ -3,12 +3,12 @@ package conversation
|
||||
import (
|
||||
"OpenIM/internal/common/check"
|
||||
"OpenIM/internal/common/notification"
|
||||
"OpenIM/internal/tx"
|
||||
"OpenIM/pkg/common/constant"
|
||||
"OpenIM/pkg/common/db/cache"
|
||||
"OpenIM/pkg/common/db/controller"
|
||||
"OpenIM/pkg/common/db/relation"
|
||||
tableRelation "OpenIM/pkg/common/db/table/relation"
|
||||
"OpenIM/pkg/common/db/tx"
|
||||
pbConversation "OpenIM/pkg/proto/conversation"
|
||||
"OpenIM/pkg/utils"
|
||||
"context"
|
||||
|
||||
@@ -4,11 +4,11 @@ import (
|
||||
"OpenIM/internal/common/check"
|
||||
"OpenIM/internal/common/convert"
|
||||
"OpenIM/internal/common/notification"
|
||||
"OpenIM/internal/tx"
|
||||
"OpenIM/pkg/common/constant"
|
||||
"OpenIM/pkg/common/db/controller"
|
||||
"OpenIM/pkg/common/db/relation"
|
||||
tablerelation "OpenIM/pkg/common/db/table/relation"
|
||||
"OpenIM/pkg/common/db/tx"
|
||||
"OpenIM/pkg/common/tokenverify"
|
||||
"OpenIM/pkg/common/tracelog"
|
||||
registry "OpenIM/pkg/discoveryregistry"
|
||||
|
||||
@@ -3,12 +3,12 @@ package group
|
||||
import (
|
||||
"OpenIM/internal/common/check"
|
||||
"OpenIM/internal/common/notification"
|
||||
"OpenIM/internal/tx"
|
||||
"OpenIM/pkg/common/constant"
|
||||
"OpenIM/pkg/common/db/cache"
|
||||
"OpenIM/pkg/common/db/controller"
|
||||
"OpenIM/pkg/common/db/relation"
|
||||
relationTb "OpenIM/pkg/common/db/table/relation"
|
||||
"OpenIM/pkg/common/db/tx"
|
||||
"OpenIM/pkg/common/db/unrelation"
|
||||
"OpenIM/pkg/common/tokenverify"
|
||||
"OpenIM/pkg/common/tracelog"
|
||||
|
||||
@@ -9,7 +9,7 @@ import (
|
||||
|
||||
func (m *msgServer) DelMsgList(ctx context.Context, req *sdkws.DelMsgListReq) (*sdkws.DelMsgListResp, error) {
|
||||
resp := &sdkws.DelMsgListResp{}
|
||||
if _, err := m.MsgInterface.DelMsgBySeqs(ctx, req.UserID, req.SeqList); err != nil {
|
||||
if _, err := m.MsgDatabase.DelMsgBySeqs(ctx, req.UserID, req.SeqList); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
DeleteMessageNotification(ctx, req.UserID, req.SeqList)
|
||||
@@ -21,14 +21,14 @@ func (m *msgServer) DelSuperGroupMsg(ctx context.Context, req *msg.DelSuperGroup
|
||||
if err := tokenverify.CheckAdmin(ctx); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
//maxSeq, err := m.MsgInterface.GetGroupMaxSeq(ctx, req.GroupID)
|
||||
//maxSeq, err := m.MsgDatabase.GetGroupMaxSeq(ctx, req.GroupID)
|
||||
//if err != nil {
|
||||
// return nil, err
|
||||
//}
|
||||
//if err := m.MsgInterface.SetGroupUserMinSeq(ctx, req.GroupID, maxSeq); err != nil {
|
||||
//if err := m.MsgDatabase.SetGroupUserMinSeq(ctx, req.GroupID, maxSeq); err != nil {
|
||||
// return nil, err
|
||||
//}
|
||||
if err := m.MsgInterface.DeleteUserSuperGroupMsgsAndSetMinSeq(ctx, req.GroupID, []string{req.UserID}, 0); err != nil {
|
||||
if err := m.MsgDatabase.DeleteUserSuperGroupMsgsAndSetMinSeq(ctx, req.GroupID, []string{req.UserID}, 0); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return resp, nil
|
||||
@@ -39,10 +39,10 @@ func (m *msgServer) ClearMsg(ctx context.Context, req *msg.ClearMsgReq) (*msg.Cl
|
||||
if err := tokenverify.CheckAccessV3(ctx, req.UserID); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if err := m.MsgInterface.CleanUpUserMsg(ctx, req.UserID); err != nil {
|
||||
if err := m.MsgDatabase.CleanUpUserMsg(ctx, req.UserID); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
//if err := m.MsgInterface.DelUserAllSeq(ctx, req.UserID); err != nil {
|
||||
//if err := m.MsgDatabase.DelUserAllSeq(ctx, req.UserID); err != nil {
|
||||
// return nil, err
|
||||
//}
|
||||
return resp, nil
|
||||
|
||||
@@ -27,7 +27,7 @@ func (m *msgServer) SetMessageReactionExtensions(ctx context.Context, req *msg.S
|
||||
notification.ExtendMessageUpdatedNotification(req.OperationID, req.OpUserID, req.SourceID, req.SessionType, req, &resp, !req.IsReact, false)
|
||||
return resp, nil
|
||||
}
|
||||
isExists, err := m.MsgInterface.JudgeMessageReactionEXISTS(ctx, req.ClientMsgID, req.SessionType)
|
||||
isExists, err := m.MsgDatabase.JudgeMessageReactionEXISTS(ctx, req.ClientMsgID, req.SessionType)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -41,12 +41,12 @@ func (m *msgServer) SetMessageReactionExtensions(ctx context.Context, req *msg.S
|
||||
return nil, err
|
||||
}
|
||||
v.LatestUpdateTime = utils.GetCurrentTimestampByMill()
|
||||
if err := m.MsgInterface.SetMessageTypeKeyValue(ctx, req.ClientMsgID, req.SessionType, k, utils.StructToJsonString(v)); err != nil {
|
||||
if err := m.MsgDatabase.SetMessageTypeKeyValue(ctx, req.ClientMsgID, req.SessionType, k, utils.StructToJsonString(v)); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
resp.IsReact = true
|
||||
_, err := m.MsgInterface.SetMessageReactionExpire(ctx, req.ClientMsgID, req.SessionType, time.Duration(24*3)*time.Hour)
|
||||
_, err := m.MsgDatabase.SetMessageReactionExpire(ctx, req.ClientMsgID, req.SessionType, time.Duration(24*3)*time.Hour)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -55,7 +55,7 @@ func (m *msgServer) SetMessageReactionExtensions(ctx context.Context, req *msg.S
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
mongoValue, err := m.MsgInterface.GetExtendMsg(ctx, req.SourceID, req.SessionType, req.ClientMsgID, req.MsgFirstModifyTime)
|
||||
mongoValue, err := m.MsgDatabase.GetExtendMsg(ctx, req.SourceID, req.SessionType, req.ClientMsgID, req.MsgFirstModifyTime)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@@ -9,7 +9,7 @@ import (
|
||||
|
||||
func (m *msgServer) SetSendMsgStatus(ctx context.Context, req *pbMsg.SetSendMsgStatusReq) (*pbMsg.SetSendMsgStatusResp, error) {
|
||||
resp := &pbMsg.SetSendMsgStatusResp{}
|
||||
if err := m.MsgInterface.SetSendMsgStatus(ctx, tracelog.GetOperationID(ctx), req.Status); err != nil {
|
||||
if err := m.MsgDatabase.SetSendMsgStatus(ctx, tracelog.GetOperationID(ctx), req.Status); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return resp, nil
|
||||
@@ -17,7 +17,7 @@ func (m *msgServer) SetSendMsgStatus(ctx context.Context, req *pbMsg.SetSendMsgS
|
||||
|
||||
func (m *msgServer) GetSendMsgStatus(ctx context.Context, req *pbMsg.GetSendMsgStatusReq) (*pbMsg.GetSendMsgStatusResp, error) {
|
||||
resp := &pbMsg.GetSendMsgStatusResp{}
|
||||
status, err := m.MsgInterface.GetSendMsgStatus(ctx, tracelog.GetOperationID(ctx))
|
||||
status, err := m.MsgDatabase.GetSendMsgStatus(ctx, tracelog.GetOperationID(ctx))
|
||||
if IsNotFound(err) {
|
||||
resp.Status = constant.MsgStatusNotExist
|
||||
return resp, nil
|
||||
|
||||
@@ -165,7 +165,7 @@ func (m *msgServer) messageVerification(ctx context.Context, data *msg.SendMsgRe
|
||||
}
|
||||
|
||||
if revokeMessage.RevokerID != revokeMessage.SourceMessageSendID {
|
||||
resp, err := m.MsgInterface.GetSuperGroupMsgBySeqs(ctx, data.MsgData.GroupID, []int64{int64(revokeMessage.Seq)})
|
||||
resp, err := m.MsgDatabase.GetSuperGroupMsgBySeqs(ctx, data.MsgData.GroupID, []int64{int64(revokeMessage.Seq)})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -352,7 +352,7 @@ func (m *msgServer) sendMsgToGroupOptimization(ctx context.Context, list []strin
|
||||
if v == "" || groupPB.MsgData.SendID == "" {
|
||||
return constant.ErrArgs.Wrap("userID or groupPB.MsgData.SendID is empty")
|
||||
}
|
||||
err := m.MsgInterface.MsgToMQ(ctx, v, &msgToMQGroup)
|
||||
err := m.MsgDatabase.MsgToMQ(ctx, v, &msgToMQGroup)
|
||||
if err != nil {
|
||||
wg.Done()
|
||||
return err
|
||||
|
||||
@@ -25,7 +25,7 @@ func (m *msgServer) sendMsgSuperGroupChat(ctx context.Context, req *msg.SendMsgR
|
||||
return nil, err
|
||||
}
|
||||
msgToMQSingle := msg.MsgDataToMQ{MsgData: req.MsgData}
|
||||
err = m.MsgInterface.MsgToMQ(ctx, msgToMQSingle.MsgData.GroupID, &msgToMQSingle)
|
||||
err = m.MsgDatabase.MsgToMQ(ctx, msgToMQSingle.MsgData.GroupID, &msgToMQSingle)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -42,12 +42,12 @@ func (m *msgServer) sendMsgSuperGroupChat(ctx context.Context, req *msg.SendMsgR
|
||||
}
|
||||
func (m *msgServer) sendMsgNotification(ctx context.Context, req *msg.SendMsgReq) (resp *msg.SendMsgResp, err error) {
|
||||
msgToMQSingle := msg.MsgDataToMQ{MsgData: req.MsgData}
|
||||
err = m.MsgInterface.MsgToMQ(ctx, msgToMQSingle.MsgData.RecvID, &msgToMQSingle)
|
||||
err = m.MsgDatabase.MsgToMQ(ctx, msgToMQSingle.MsgData.RecvID, &msgToMQSingle)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if msgToMQSingle.MsgData.SendID != msgToMQSingle.MsgData.RecvID { //Filter messages sent to yourself
|
||||
err = m.MsgInterface.MsgToMQ(ctx, msgToMQSingle.MsgData.SendID, &msgToMQSingle)
|
||||
err = m.MsgDatabase.MsgToMQ(ctx, msgToMQSingle.MsgData.SendID, &msgToMQSingle)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -74,13 +74,13 @@ func (m *msgServer) sendMsgSingleChat(ctx context.Context, req *msg.SendMsgReq)
|
||||
}
|
||||
msgToMQSingle := msg.MsgDataToMQ{MsgData: req.MsgData}
|
||||
if isSend {
|
||||
err = m.MsgInterface.MsgToMQ(ctx, req.MsgData.RecvID, &msgToMQSingle)
|
||||
err = m.MsgDatabase.MsgToMQ(ctx, req.MsgData.RecvID, &msgToMQSingle)
|
||||
if err != nil {
|
||||
return nil, constant.ErrInternalServer.Wrap("insert to mq")
|
||||
}
|
||||
}
|
||||
if msgToMQSingle.MsgData.SendID != msgToMQSingle.MsgData.RecvID { //Filter messages sent to yourself
|
||||
err = m.MsgInterface.MsgToMQ(ctx, req.MsgData.SendID, &msgToMQSingle)
|
||||
err = m.MsgDatabase.MsgToMQ(ctx, req.MsgData.SendID, &msgToMQSingle)
|
||||
if err != nil {
|
||||
return nil, constant.ErrInternalServer.Wrap("insert to mq")
|
||||
}
|
||||
@@ -255,11 +255,11 @@ func (m *msgServer) SendMsg(ctx context.Context, req *msg.SendMsgReq) (resp *msg
|
||||
func (m *msgServer) GetMaxAndMinSeq(ctx context.Context, req *sdkws.GetMaxAndMinSeqReq) (*sdkws.GetMaxAndMinSeqResp, error) {
|
||||
resp := new(sdkws.GetMaxAndMinSeqResp)
|
||||
m2 := make(map[string]*sdkws.MaxAndMinSeq)
|
||||
maxSeq, err := m.MsgInterface.GetUserMaxSeq(ctx, req.UserID)
|
||||
maxSeq, err := m.MsgDatabase.GetUserMaxSeq(ctx, req.UserID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
minSeq, err := m.MsgInterface.GetUserMinSeq(ctx, req.UserID)
|
||||
minSeq, err := m.MsgDatabase.GetUserMinSeq(ctx, req.UserID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -268,11 +268,11 @@ func (m *msgServer) GetMaxAndMinSeq(ctx context.Context, req *sdkws.GetMaxAndMin
|
||||
if len(req.GroupIDList) > 0 {
|
||||
resp.GroupMaxAndMinSeq = make(map[string]*sdkws.MaxAndMinSeq)
|
||||
for _, groupID := range req.GroupIDList {
|
||||
maxSeq, err := m.MsgInterface.GetGroupMaxSeq(ctx, groupID)
|
||||
maxSeq, err := m.MsgDatabase.GetGroupMaxSeq(ctx, groupID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
minSeq, err := m.MsgInterface.GetGroupMinSeq(ctx, groupID)
|
||||
minSeq, err := m.MsgDatabase.GetGroupMinSeq(ctx, groupID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -287,13 +287,13 @@ func (m *msgServer) GetMaxAndMinSeq(ctx context.Context, req *sdkws.GetMaxAndMin
|
||||
|
||||
func (m *msgServer) PullMessageBySeqList(ctx context.Context, req *sdkws.PullMessageBySeqListReq) (*sdkws.PullMessageBySeqListResp, error) {
|
||||
resp := &sdkws.PullMessageBySeqListResp{GroupMsgDataList: make(map[string]*sdkws.MsgDataList)}
|
||||
msgs, err := m.MsgInterface.GetMessagesBySeqs(ctx, req.UserID, req.Seqs)
|
||||
msgs, err := m.MsgDatabase.GetMsgBySeqs(ctx, req.UserID, req.Seqs)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
resp.List = msgs
|
||||
for userID, list := range req.GroupSeqList {
|
||||
msgs, err := m.MsgInterface.GetMessagesBySeq(ctx, userID, req.Seqs)
|
||||
msgs, err := m.MsgDatabase.GetMsgBySeqs(ctx, userID, req.Seqs)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@@ -16,7 +16,7 @@ import (
|
||||
|
||||
type msgServer struct {
|
||||
RegisterCenter discoveryRegistry.SvcDiscoveryRegistry
|
||||
MsgInterface controller.MsgDatabase
|
||||
MsgDatabase controller.MsgDatabase
|
||||
Group *check.GroupChecker
|
||||
User *check.UserCheck
|
||||
Conversation *check.ConversationChecker
|
||||
@@ -45,7 +45,7 @@ func Start(client *openKeeper.ZkClient, server *grpc.Server) error {
|
||||
Conversation: check.NewConversationChecker(client),
|
||||
User: check.NewUserCheck(client),
|
||||
Group: check.NewGroupChecker(client),
|
||||
//MsgInterface: controller.MsgInterface(),
|
||||
//MsgDatabase: controller.MsgDatabase(),
|
||||
RegisterCenter: client,
|
||||
GroupLocalCache: localcache.NewGroupMemberIDsLocalCache(client),
|
||||
black: check.NewBlackChecker(client),
|
||||
|
||||
@@ -1,19 +0,0 @@
|
||||
package tx
|
||||
|
||||
import (
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
func NewGorm(db *gorm.DB) Tx {
|
||||
return &_Gorm{tx: db}
|
||||
}
|
||||
|
||||
type _Gorm struct {
|
||||
tx *gorm.DB
|
||||
}
|
||||
|
||||
func (g *_Gorm) Transaction(fn func(tx any) error) error {
|
||||
return g.tx.Transaction(func(tx *gorm.DB) error {
|
||||
return fn(tx)
|
||||
})
|
||||
}
|
||||
@@ -1,31 +0,0 @@
|
||||
package tx
|
||||
|
||||
import (
|
||||
"OpenIM/pkg/utils"
|
||||
"context"
|
||||
"go.mongodb.org/mongo-driver/mongo"
|
||||
)
|
||||
|
||||
func NewMongo(client *mongo.Client) CtxTx {
|
||||
return &_Mongo{
|
||||
client: client,
|
||||
}
|
||||
}
|
||||
|
||||
type _Mongo struct {
|
||||
client *mongo.Client
|
||||
}
|
||||
|
||||
func (m *_Mongo) Transaction(ctx context.Context, fn func(ctx context.Context) error) error {
|
||||
sess, err := m.client.StartSession()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
sCtx := mongo.NewSessionContext(ctx, sess)
|
||||
defer sess.EndSession(sCtx)
|
||||
if err := fn(sCtx); err != nil {
|
||||
_ = sess.AbortTransaction(sCtx)
|
||||
return err
|
||||
}
|
||||
return utils.Wrap(sess.CommitTransaction(sCtx), "")
|
||||
}
|
||||
@@ -1,11 +0,0 @@
|
||||
package tx
|
||||
|
||||
import "context"
|
||||
|
||||
type Tx interface {
|
||||
Transaction(fn func(tx any) error) error
|
||||
}
|
||||
|
||||
type CtxTx interface {
|
||||
Transaction(ctx context.Context, fn func(ctx context.Context) error) error
|
||||
}
|
||||
Reference in New Issue
Block a user