fix: update message.

This commit is contained in:
Gordon 2024-04-19 16:25:41 +08:00
parent b35c9e4382
commit 7d8886a364
6 changed files with 5 additions and 75 deletions

View File

@ -10,7 +10,5 @@ prometheus:
#发消息是否需要好友验证 #发消息是否需要好友验证
friendVerify: false friendVerify: false
#
groupMessageHasReadReceiptEnable: true
singleMessageHasReadReceiptEnable: true

View File

@ -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
}

View File

@ -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:

View File

@ -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
@ -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
} }

View File

@ -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:

View File

@ -267,10 +267,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 {