refactor: change sendNotification to sendMessage to avoid ambiguity regarding message sending behavior. (#3173)

* 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.

* refactor: change sendNotification to sendMessage to avoid ambiguity regarding message sending behavior.

---------

Co-authored-by: Monet Lee <monet_lee@163.com>
This commit is contained in:
OpenIM-Gordon
2025-02-28 16:59:04 +08:00
committed by withchao
parent 744f481b9c
commit 4890487429
6 changed files with 34 additions and 25 deletions
+5 -2
View File
@@ -58,10 +58,13 @@ func GetProjectRoot() (string, error) {
return projectRoot, nil
}
func GetOptionsByNotification(cfg NotificationConfig) msgprocessor.Options {
func GetOptionsByNotification(cfg NotificationConfig, sendMessage *bool) msgprocessor.Options {
opts := msgprocessor.NewOptions()
if cfg.UnreadCount {
if sendMessage != nil {
cfg.IsSendMsg = *sendMessage
}
if cfg.IsSendMsg {
opts = msgprocessor.WithOptions(opts, msgprocessor.WithUnreadCount(true))
}
if cfg.OfflinePush.Enable {
+9 -3
View File
@@ -179,14 +179,20 @@ func NewNotificationSender(conf *config.Notification, opts ...NotificationSender
}
type notificationOpt struct {
WithRpcGetUsername bool
RpcGetUsername bool
SendMessage *bool
}
type NotificationOptions func(*notificationOpt)
func WithRpcGetUserName() NotificationOptions {
return func(opt *notificationOpt) {
opt.WithRpcGetUsername = true
opt.RpcGetUsername = true
}
}
func WithSendMessage(sendMessage *bool) NotificationOptions {
return func(opt *notificationOpt) {
opt.SendMessage = sendMessage
}
}
@@ -233,7 +239,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.SendMessage)
s.SetOptionsByContentType(ctx, options, contentType)
msg.Options = options
// fill Notification OfflinePush by config