feat: add a field to specify whether to send a notification message w… (#3163)

* feat: add a field to specify whether to send a notification message when creating a group.

* feat: add a field to specify whether to send a notification message when creating a group.

---------

Co-authored-by: Monet Lee <monet_lee@163.com>
This commit is contained in:
OpenIM-Gordon
2025-02-28 16:38:57 +08:00
committed by GitHub
parent b7f88138bd
commit 4d2fce0e52
12 changed files with 61 additions and 46 deletions
+6 -2
View File
@@ -18,11 +18,12 @@ import (
"os"
"path/filepath"
"gopkg.in/yaml.v3"
"github.com/openimsdk/open-im-server/v3/pkg/msgprocessor"
"github.com/openimsdk/protocol/constant"
"github.com/openimsdk/tools/errs"
"github.com/openimsdk/tools/field"
"gopkg.in/yaml.v3"
)
const (
@@ -56,9 +57,12 @@ func GetProjectRoot() (string, error) {
return projectRoot, nil
}
func GetOptionsByNotification(cfg NotificationConfig) msgprocessor.Options {
func GetOptionsByNotification(cfg NotificationConfig, sendNotification *bool) msgprocessor.Options {
opts := msgprocessor.NewOptions()
if sendNotification != nil {
cfg.IsSendMsg = *sendNotification
}
if cfg.IsSendMsg {
opts = msgprocessor.WithOptions(opts, msgprocessor.WithUnreadCount(true))
}
+11 -6
View File
@@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.
package rpcclient
package notification
import (
"context"
@@ -179,19 +179,24 @@ func NewNotificationSender(conf *config.Notification, opts ...NotificationSender
}
type notificationOpt struct {
WithRpcGetUsername bool
RpcGetUsername bool
SendNotification *bool
}
type NotificationOptions func(*notificationOpt)
func WithRpcGetUserName() NotificationOptions {
return func(opt *notificationOpt) {
opt.WithRpcGetUsername = true
opt.RpcGetUsername = true
}
}
func WithSendNotification(send *bool) NotificationOptions {
return func(opt *notificationOpt) {
opt.SendNotification = send
}
}
func (s *NotificationSender) send(ctx context.Context, sendID, recvID string, contentType, sessionType int32, m proto.Message, opts ...NotificationOptions) {
//ctx = mcontext.WithMustInfoCtx([]string{mcontext.GetOperationID(ctx), mcontext.GetOpUserID(ctx), mcontext.GetOpUserPlatform(ctx), mcontext.GetConnID(ctx)})
ctx = context.WithoutCancel(ctx)
ctx, cancel := context.WithTimeout(ctx, time.Second*time.Duration(5))
defer cancel()
@@ -208,7 +213,7 @@ func (s *NotificationSender) send(ctx context.Context, sendID, recvID string, co
var req msg.SendMsgReq
var msg sdkws.MsgData
var userInfo *sdkws.UserInfo
if notificationOpt.WithRpcGetUsername && s.getUserInfo != nil {
if notificationOpt.RpcGetUsername && s.getUserInfo != nil {
userInfo, err = s.getUserInfo(ctx, sendID)
if err != nil {
log.ZWarn(ctx, "getUserInfo failed", err, "sendID", sendID)
@@ -233,7 +238,7 @@ func (s *NotificationSender) send(ctx context.Context, sendID, recvID string, co
if sendID == recvID && contentType == constant.HasReadReceipt {
optionsConfig.ReliabilityLevel = constant.UnreliableNotification
}
options := config.GetOptionsByNotification(optionsConfig)
options := config.GetOptionsByNotification(optionsConfig, notificationOpt.SendNotification)
s.SetOptionsByContentType(ctx, options, contentType)
msg.Options = options
// fill Notification OfflinePush by config