mirror of
https://github.com/openimsdk/open-im-server.git
synced 2025-11-05 11:52:10 +08:00
Merge branch '3.6.1-code-conventions' of https://github.com/FGadvancer/Open-IM-Server into 3.6.1-code-conventions
This commit is contained in:
commit
ab841faa66
@ -1,5 +1,3 @@
|
|||||||
prometheus:
|
prometheus:
|
||||||
enable: true
|
enable: true
|
||||||
ports: [ 20108, 20109, 20110, 20111 ]
|
ports: [ 20108, 20109, 20110, 20111 ]
|
||||||
|
|
||||||
msgCacheTimeout: 86400
|
|
||||||
@ -10,7 +10,5 @@ prometheus:
|
|||||||
#发消息是否需要好友验证
|
#发消息是否需要好友验证
|
||||||
friendVerify: false
|
friendVerify: false
|
||||||
|
|
||||||
#
|
|
||||||
groupMessageHasReadReceiptEnable: true
|
|
||||||
singleMessageHasReadReceiptEnable: true
|
|
||||||
|
|
||||||
|
|||||||
@ -88,7 +88,7 @@ func Start(ctx context.Context, index int, config *Config) error {
|
|||||||
client.AddOption(mw.GrpcClient(), grpc.WithTransportCredentials(insecure.NewCredentials()),
|
client.AddOption(mw.GrpcClient(), grpc.WithTransportCredentials(insecure.NewCredentials()),
|
||||||
grpc.WithDefaultServiceConfig(fmt.Sprintf(`{"LoadBalancingPolicy": "%s"}`, "round_robin")))
|
grpc.WithDefaultServiceConfig(fmt.Sprintf(`{"LoadBalancingPolicy": "%s"}`, "round_robin")))
|
||||||
//todo MsgCacheTimeout
|
//todo MsgCacheTimeout
|
||||||
msgModel := cache.NewMsgCache(rdb, 86400, config.RedisConfig.EnablePipeline)
|
msgModel := cache.NewMsgCache(rdb, config.RedisConfig.EnablePipeline)
|
||||||
seqModel := cache.NewSeqCache(rdb)
|
seqModel := cache.NewSeqCache(rdb)
|
||||||
msgDocModel, err := mgo.NewMsgMongo(mgocli.GetDB())
|
msgDocModel, err := mgo.NewMsgMongo(mgocli.GetDB())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
@ -1,42 +0,0 @@
|
|||||||
// Copyright © 2023 OpenIM. All rights reserved.
|
|
||||||
//
|
|
||||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
// you may not use this file except in compliance with the License.
|
|
||||||
// You may obtain a copy of the License at
|
|
||||||
//
|
|
||||||
// http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
//
|
|
||||||
// Unless required by applicable law or agreed to in writing, software
|
|
||||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
// See the License for the specific language governing permissions and
|
|
||||||
// limitations under the License.
|
|
||||||
|
|
||||||
package msg
|
|
||||||
|
|
||||||
import (
|
|
||||||
"context"
|
|
||||||
"github.com/openimsdk/open-im-server/v3/pkg/common/servererrs"
|
|
||||||
|
|
||||||
"github.com/openimsdk/protocol/constant"
|
|
||||||
"github.com/openimsdk/protocol/msg"
|
|
||||||
"github.com/openimsdk/protocol/sdkws"
|
|
||||||
)
|
|
||||||
|
|
||||||
type MessageInterceptorFunc func(ctx context.Context, globalConfig *Config, req *msg.SendMsgReq) (*sdkws.MsgData, error)
|
|
||||||
|
|
||||||
func MessageHasReadEnabled(ctx context.Context, config *Config, req *msg.SendMsgReq) (*sdkws.MsgData, error) {
|
|
||||||
switch {
|
|
||||||
case req.MsgData.ContentType == constant.HasReadReceipt && req.MsgData.SessionType == constant.SingleChatType:
|
|
||||||
if !config.RpcConfig.SingleMessageHasReadReceiptEnable {
|
|
||||||
return nil, servererrs.ErrMessageHasReadDisable.Wrap()
|
|
||||||
}
|
|
||||||
return req.MsgData, nil
|
|
||||||
case req.MsgData.ContentType == constant.HasReadReceipt && req.MsgData.SessionType == constant.SuperGroupChatType:
|
|
||||||
if !config.RpcConfig.GroupMessageHasReadReceiptEnable {
|
|
||||||
return nil, servererrs.ErrMessageHasReadDisable.Wrap()
|
|
||||||
}
|
|
||||||
return req.MsgData, nil
|
|
||||||
}
|
|
||||||
return req.MsgData, nil
|
|
||||||
}
|
|
||||||
@ -18,7 +18,6 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
|
|
||||||
"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/common/servererrs"
|
|
||||||
"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/conversationutil"
|
"github.com/openimsdk/open-im-server/v3/pkg/util/conversationutil"
|
||||||
"github.com/openimsdk/protocol/constant"
|
"github.com/openimsdk/protocol/constant"
|
||||||
@ -35,10 +34,6 @@ import (
|
|||||||
|
|
||||||
func (m *msgServer) SendMsg(ctx context.Context, req *pbmsg.SendMsgReq) (*pbmsg.SendMsgResp, error) {
|
func (m *msgServer) SendMsg(ctx context.Context, req *pbmsg.SendMsgReq) (*pbmsg.SendMsgResp, error) {
|
||||||
if req.MsgData != nil {
|
if req.MsgData != nil {
|
||||||
flag := isMessageHasReadEnabled(req.MsgData, m.config)
|
|
||||||
if !flag {
|
|
||||||
return nil, servererrs.ErrMessageHasReadDisable.Wrap()
|
|
||||||
}
|
|
||||||
m.encapsulateMsgData(req.MsgData)
|
m.encapsulateMsgData(req.MsgData)
|
||||||
switch req.MsgData.SessionType {
|
switch req.MsgData.SessionType {
|
||||||
case constant.SingleChatType:
|
case constant.SingleChatType:
|
||||||
|
|||||||
@ -18,6 +18,7 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
"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/common/webhook"
|
"github.com/openimsdk/open-im-server/v3/pkg/common/webhook"
|
||||||
|
"github.com/openimsdk/protocol/sdkws"
|
||||||
"github.com/openimsdk/tools/db/mongoutil"
|
"github.com/openimsdk/tools/db/mongoutil"
|
||||||
"github.com/openimsdk/tools/db/redisutil"
|
"github.com/openimsdk/tools/db/redisutil"
|
||||||
|
|
||||||
@ -33,6 +34,7 @@ import (
|
|||||||
"google.golang.org/grpc"
|
"google.golang.org/grpc"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
type MessageInterceptorFunc func(ctx context.Context, globalConfig *Config, req *msg.SendMsgReq) (*sdkws.MsgData, error)
|
||||||
type (
|
type (
|
||||||
// MessageInterceptorChain defines a chain of message interceptor functions.
|
// MessageInterceptorChain defines a chain of message interceptor functions.
|
||||||
MessageInterceptorChain []MessageInterceptorFunc
|
MessageInterceptorChain []MessageInterceptorFunc
|
||||||
@ -84,7 +86,7 @@ func Start(ctx context.Context, config *Config, client discovery.SvcDiscoveryReg
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
//todo MsgCacheTimeout
|
//todo MsgCacheTimeout
|
||||||
msgModel := cache.NewMsgCache(rdb, 86400, config.RedisConfig.EnablePipeline)
|
msgModel := cache.NewMsgCache(rdb, config.RedisConfig.EnablePipeline)
|
||||||
seqModel := cache.NewSeqCache(rdb)
|
seqModel := cache.NewSeqCache(rdb)
|
||||||
conversationClient := rpcclient.NewConversationRpcClient(client, config.Share.RpcRegisterName.Conversation)
|
conversationClient := rpcclient.NewConversationRpcClient(client, config.Share.RpcRegisterName.Conversation)
|
||||||
userRpcClient := rpcclient.NewUserRpcClient(client, config.Share.RpcRegisterName.User, config.Share.IMAdminUserID)
|
userRpcClient := rpcclient.NewUserRpcClient(client, config.Share.RpcRegisterName.User, config.Share.IMAdminUserID)
|
||||||
@ -107,7 +109,6 @@ func Start(ctx context.Context, config *Config, client discovery.SvcDiscoveryReg
|
|||||||
}
|
}
|
||||||
|
|
||||||
s.notificationSender = rpcclient.NewNotificationSender(&config.NotificationConfig, rpcclient.WithLocalSendMsg(s.SendMsg))
|
s.notificationSender = rpcclient.NewNotificationSender(&config.NotificationConfig, rpcclient.WithLocalSendMsg(s.SendMsg))
|
||||||
s.addInterceptorHandler(MessageHasReadEnabled)
|
|
||||||
msg.RegisterMsgServer(server, s)
|
msg.RegisterMsgServer(server, s)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|||||||
@ -15,31 +15,11 @@
|
|||||||
package msg
|
package msg
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/openimsdk/protocol/constant"
|
|
||||||
"github.com/openimsdk/protocol/sdkws"
|
|
||||||
"github.com/openimsdk/tools/errs"
|
"github.com/openimsdk/tools/errs"
|
||||||
"github.com/redis/go-redis/v9"
|
"github.com/redis/go-redis/v9"
|
||||||
"go.mongodb.org/mongo-driver/mongo"
|
"go.mongodb.org/mongo-driver/mongo"
|
||||||
)
|
)
|
||||||
|
|
||||||
func isMessageHasReadEnabled(msgData *sdkws.MsgData, config *Config) bool {
|
|
||||||
switch {
|
|
||||||
case msgData.ContentType == constant.HasReadReceipt && msgData.SessionType == constant.SingleChatType:
|
|
||||||
if config.RpcConfig.SingleMessageHasReadReceiptEnable {
|
|
||||||
return true
|
|
||||||
} else {
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
case msgData.ContentType == constant.HasReadReceipt && msgData.SessionType == constant.SuperGroupChatType:
|
|
||||||
if config.RpcConfig.GroupMessageHasReadReceiptEnable {
|
|
||||||
return true
|
|
||||||
} else {
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
|
|
||||||
func IsNotFound(err error) bool {
|
func IsNotFound(err error) bool {
|
||||||
switch errs.Unwrap(err) {
|
switch errs.Unwrap(err) {
|
||||||
case redis.Nil, mongo.ErrNoDocuments:
|
case redis.Nil, mongo.ErrNoDocuments:
|
||||||
|
|||||||
@ -185,8 +185,7 @@ type MsgGateway struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type MsgTransfer struct {
|
type MsgTransfer struct {
|
||||||
Prometheus Prometheus `mapstructure:"prometheus"`
|
Prometheus Prometheus `mapstructure:"prometheus"`
|
||||||
MsgCacheTimeout int `mapstructure:"msgCacheTimeout"`
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type Push struct {
|
type Push struct {
|
||||||
@ -267,10 +266,8 @@ type Msg struct {
|
|||||||
ListenIP string `mapstructure:"listenIP"`
|
ListenIP string `mapstructure:"listenIP"`
|
||||||
Ports []int `mapstructure:"ports"`
|
Ports []int `mapstructure:"ports"`
|
||||||
} `mapstructure:"rpc"`
|
} `mapstructure:"rpc"`
|
||||||
Prometheus Prometheus `mapstructure:"prometheus"`
|
Prometheus Prometheus `mapstructure:"prometheus"`
|
||||||
FriendVerify bool `mapstructure:"friendVerify"`
|
FriendVerify bool `mapstructure:"friendVerify"`
|
||||||
GroupMessageHasReadReceiptEnable bool `mapstructure:"groupMessageHasReadReceiptEnable"`
|
|
||||||
SingleMessageHasReadReceiptEnable bool `mapstructure:"singleMessageHasReadReceiptEnable"`
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type Third struct {
|
type Third struct {
|
||||||
|
|||||||
4
pkg/common/db/cache/msg.go
vendored
4
pkg/common/db/cache/msg.go
vendored
@ -31,6 +31,8 @@ import (
|
|||||||
"golang.org/x/sync/errgroup"
|
"golang.org/x/sync/errgroup"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
const msgCacheTimeout = 86400
|
||||||
|
|
||||||
const (
|
const (
|
||||||
maxSeq = "MAX_SEQ:"
|
maxSeq = "MAX_SEQ:"
|
||||||
minSeq = "MIN_SEQ:"
|
minSeq = "MIN_SEQ:"
|
||||||
@ -82,7 +84,7 @@ type MsgCache interface {
|
|||||||
// return &msgCache{rdb: client, msgCacheTimeout: msgCacheTimeout, redisConf: redisConf}
|
// return &msgCache{rdb: client, msgCacheTimeout: msgCacheTimeout, redisConf: redisConf}
|
||||||
//}
|
//}
|
||||||
|
|
||||||
func NewMsgCache(client redis.UniversalClient, msgCacheTimeout time.Duration, redisEnablePipeline bool) MsgCache {
|
func NewMsgCache(client redis.UniversalClient, redisEnablePipeline bool) MsgCache {
|
||||||
return &msgCache{rdb: client, msgCacheTimeout: msgCacheTimeout, redisEnablePipeline: redisEnablePipeline}
|
return &msgCache{rdb: client, msgCacheTimeout: msgCacheTimeout, redisEnablePipeline: redisEnablePipeline}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user