mirror of
https://github.com/openimsdk/open-im-server.git
synced 2026-04-28 06:19:20 +08:00
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:
+11
-6
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user