mirror of
				https://github.com/openimsdk/open-im-server.git
				synced 2025-10-26 21:22:16 +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:
		
							parent
							
								
									b7f88138bd
								
							
						
					
					
						commit
						4d2fce0e52
					
				
							
								
								
									
										2
									
								
								go.mod
									
									
									
									
									
								
							
							
						
						
									
										2
									
								
								go.mod
									
									
									
									
									
								
							| @ -12,7 +12,7 @@ require ( | |||||||
| 	github.com/gorilla/websocket v1.5.1 | 	github.com/gorilla/websocket v1.5.1 | ||||||
| 	github.com/grpc-ecosystem/go-grpc-prometheus v1.2.0 | 	github.com/grpc-ecosystem/go-grpc-prometheus v1.2.0 | ||||||
| 	github.com/mitchellh/mapstructure v1.5.0 | 	github.com/mitchellh/mapstructure v1.5.0 | ||||||
| 	github.com/openimsdk/protocol v0.0.72-alpha.75 | 	github.com/openimsdk/protocol v0.0.72-alpha.77 | ||||||
| 	github.com/openimsdk/tools v0.0.50-alpha.74 | 	github.com/openimsdk/tools v0.0.50-alpha.74 | ||||||
| 	github.com/pkg/errors v0.9.1 // indirect | 	github.com/pkg/errors v0.9.1 // indirect | ||||||
| 	github.com/prometheus/client_golang v1.18.0 | 	github.com/prometheus/client_golang v1.18.0 | ||||||
|  | |||||||
							
								
								
									
										4
									
								
								go.sum
									
									
									
									
									
								
							
							
						
						
									
										4
									
								
								go.sum
									
									
									
									
									
								
							| @ -347,8 +347,8 @@ github.com/onsi/gomega v1.25.0 h1:Vw7br2PCDYijJHSfBOWhov+8cAnUf8MfMaIOV323l6Y= | |||||||
| github.com/onsi/gomega v1.25.0/go.mod h1:r+zV744Re+DiYCIPRlYOTxn0YkOLcAnW8k1xXdMPGhM= | github.com/onsi/gomega v1.25.0/go.mod h1:r+zV744Re+DiYCIPRlYOTxn0YkOLcAnW8k1xXdMPGhM= | ||||||
| github.com/openimsdk/gomake v0.0.15-alpha.2 h1:5Q8yl8ezy2yx+q8/ucU/t4kJnDfCzNOrkXcDACCqtyM= | github.com/openimsdk/gomake v0.0.15-alpha.2 h1:5Q8yl8ezy2yx+q8/ucU/t4kJnDfCzNOrkXcDACCqtyM= | ||||||
| github.com/openimsdk/gomake v0.0.15-alpha.2/go.mod h1:PndCozNc2IsQIciyn9mvEblYWZwJmAI+06z94EY+csI= | github.com/openimsdk/gomake v0.0.15-alpha.2/go.mod h1:PndCozNc2IsQIciyn9mvEblYWZwJmAI+06z94EY+csI= | ||||||
| github.com/openimsdk/protocol v0.0.72-alpha.75 h1:WlmBn8g2Fvv21g8TEFVbolmbw2rU0sN9kj6sQaDK7cA= | github.com/openimsdk/protocol v0.0.72-alpha.77 h1:ka7TeOpNKKqYTz8aWR8nZnz2rnzgsO9mw6xOQcVXwbE= | ||||||
| github.com/openimsdk/protocol v0.0.72-alpha.75/go.mod h1:WF7EuE55vQvpyUAzDXcqg+B+446xQyEba0X35lTINmw= | github.com/openimsdk/protocol v0.0.72-alpha.77/go.mod h1:WF7EuE55vQvpyUAzDXcqg+B+446xQyEba0X35lTINmw= | ||||||
| github.com/openimsdk/tools v0.0.50-alpha.74 h1:yh10SiMiivMEjicEQg+QAsH4pvaO+4noMPdlw+ew0Kc= | github.com/openimsdk/tools v0.0.50-alpha.74 h1:yh10SiMiivMEjicEQg+QAsH4pvaO+4noMPdlw+ew0Kc= | ||||||
| github.com/openimsdk/tools v0.0.50-alpha.74/go.mod h1:n2poR3asX1e1XZce4O+MOWAp+X02QJRFvhcLCXZdzRo= | github.com/openimsdk/tools v0.0.50-alpha.74/go.mod h1:n2poR3asX1e1XZce4O+MOWAp+X02QJRFvhcLCXZdzRo= | ||||||
| github.com/pelletier/go-toml/v2 v2.2.2 h1:aYUidT7k73Pcl9nb2gScu7NSrKCSHIDE89b3+6Wq+LM= | github.com/pelletier/go-toml/v2 v2.2.2 h1:aYUidT7k73Pcl9nb2gScu7NSrKCSHIDE89b3+6Wq+LM= | ||||||
|  | |||||||
| @ -308,7 +308,7 @@ func (m *MessageApi) SendBusinessNotification(c *gin.Context) { | |||||||
| 				IsSendMsg:        req.SendMsg, | 				IsSendMsg:        req.SendMsg, | ||||||
| 				ReliabilityLevel: *req.ReliabilityLevel, | 				ReliabilityLevel: *req.ReliabilityLevel, | ||||||
| 				UnreadCount:      false, | 				UnreadCount:      false, | ||||||
| 			}), | 			}, nil), | ||||||
| 		}, | 		}, | ||||||
| 	} | 	} | ||||||
| 	respPb, err := m.Client.SendMsg(c, &sendMsgReq) | 	respPb, err := m.Client.SendMsg(c, &sendMsgReq) | ||||||
|  | |||||||
| @ -16,6 +16,7 @@ package conversation | |||||||
| 
 | 
 | ||||||
| import ( | import ( | ||||||
| 	"context" | 	"context" | ||||||
|  | 
 | ||||||
| 	"github.com/openimsdk/open-im-server/v3/pkg/rpcli" | 	"github.com/openimsdk/open-im-server/v3/pkg/rpcli" | ||||||
| 	"github.com/openimsdk/protocol/msg" | 	"github.com/openimsdk/protocol/msg" | ||||||
| 
 | 
 | ||||||
| @ -26,11 +27,11 @@ import ( | |||||||
| ) | ) | ||||||
| 
 | 
 | ||||||
| type ConversationNotificationSender struct { | type ConversationNotificationSender struct { | ||||||
| 	*rpcclient.NotificationSender | 	*notification.NotificationSender | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| func NewConversationNotificationSender(conf *config.Notification, msgClient *rpcli.MsgClient) *ConversationNotificationSender { | func NewConversationNotificationSender(conf *config.Notification, msgClient *rpcli.MsgClient) *ConversationNotificationSender { | ||||||
| 	return &ConversationNotificationSender{rpcclient.NewNotificationSender(conf, rpcclient.WithRpcClient(func(ctx context.Context, req *msg.SendMsgReq) (*msg.SendMsgResp, error) { | 	return &ConversationNotificationSender{notification.NewNotificationSender(conf, notification.WithRpcClient(func(ctx context.Context, req *msg.SendMsgReq) (*msg.SendMsgResp, error) { | ||||||
| 		return msgClient.SendMsg(ctx, req) | 		return msgClient.SendMsg(ctx, req) | ||||||
| 	}))} | 	}))} | ||||||
| } | } | ||||||
|  | |||||||
| @ -26,6 +26,8 @@ import ( | |||||||
| 	"github.com/openimsdk/open-im-server/v3/pkg/dbbuild" | 	"github.com/openimsdk/open-im-server/v3/pkg/dbbuild" | ||||||
| 	"github.com/openimsdk/open-im-server/v3/pkg/rpcli" | 	"github.com/openimsdk/open-im-server/v3/pkg/rpcli" | ||||||
| 
 | 
 | ||||||
|  | 	"google.golang.org/grpc" | ||||||
|  | 
 | ||||||
| 	"github.com/openimsdk/open-im-server/v3/pkg/authverify" | 	"github.com/openimsdk/open-im-server/v3/pkg/authverify" | ||||||
| 	"github.com/openimsdk/open-im-server/v3/pkg/callbackstruct" | 	"github.com/openimsdk/open-im-server/v3/pkg/callbackstruct" | ||||||
| 	"github.com/openimsdk/open-im-server/v3/pkg/common/config" | 	"github.com/openimsdk/open-im-server/v3/pkg/common/config" | ||||||
| @ -51,7 +53,6 @@ import ( | |||||||
| 	"github.com/openimsdk/tools/mw/specialerror" | 	"github.com/openimsdk/tools/mw/specialerror" | ||||||
| 	"github.com/openimsdk/tools/utils/datautil" | 	"github.com/openimsdk/tools/utils/datautil" | ||||||
| 	"github.com/openimsdk/tools/utils/encrypt" | 	"github.com/openimsdk/tools/utils/encrypt" | ||||||
| 	"google.golang.org/grpc" |  | ||||||
| ) | ) | ||||||
| 
 | 
 | ||||||
| type groupServer struct { | type groupServer struct { | ||||||
| @ -284,7 +285,7 @@ func (g *groupServer) CreateGroup(ctx context.Context, req *pbgroup.CreateGroupR | |||||||
| 			break | 			break | ||||||
| 		} | 		} | ||||||
| 	} | 	} | ||||||
| 	g.notification.GroupCreatedNotification(ctx, tips) | 	g.notification.GroupCreatedNotification(ctx, tips, req.SendNotification) | ||||||
| 
 | 
 | ||||||
| 	if req.GroupInfo.Notification != "" { | 	if req.GroupInfo.Notification != "" { | ||||||
| 		g.notification.GroupInfoSetAnnouncementNotification(ctx, &sdkws.GroupInfoSetAnnouncementTips{ | 		g.notification.GroupInfoSetAnnouncementNotification(ctx, &sdkws.GroupInfoSetAnnouncementTips{ | ||||||
| @ -447,7 +448,7 @@ func (g *groupServer) InviteUserToGroup(ctx context.Context, req *pbgroup.Invite | |||||||
| 		return nil, err | 		return nil, err | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	if err = g.notification.GroupApplicationAgreeMemberEnterNotification(ctx, req.GroupID, opUserID, req.InvitedUserIDs...); err != nil { | 	if err = g.notification.GroupApplicationAgreeMemberEnterNotification(ctx, req.GroupID, req.SendNotification, opUserID, req.InvitedUserIDs...); err != nil { | ||||||
| 		return nil, err | 		return nil, err | ||||||
| 	} | 	} | ||||||
| 	return &pbgroup.InviteUserToGroupResp{}, nil | 	return &pbgroup.InviteUserToGroupResp{}, nil | ||||||
| @ -613,7 +614,7 @@ func (g *groupServer) KickGroupMember(ctx context.Context, req *pbgroup.KickGrou | |||||||
| 	for _, userID := range req.KickedUserIDs { | 	for _, userID := range req.KickedUserIDs { | ||||||
| 		tips.KickedUserList = append(tips.KickedUserList, convert.Db2PbGroupMember(memberMap[userID])) | 		tips.KickedUserList = append(tips.KickedUserList, convert.Db2PbGroupMember(memberMap[userID])) | ||||||
| 	} | 	} | ||||||
| 	g.notification.MemberKickedNotification(ctx, tips) | 	g.notification.MemberKickedNotification(ctx, tips, req.SendNotification) | ||||||
| 	if err := g.deleteMemberAndSetConversationSeq(ctx, req.GroupID, req.KickedUserIDs); err != nil { | 	if err := g.deleteMemberAndSetConversationSeq(ctx, req.GroupID, req.KickedUserIDs); err != nil { | ||||||
| 		return nil, err | 		return nil, err | ||||||
| 	} | 	} | ||||||
| @ -822,7 +823,7 @@ func (g *groupServer) GroupApplicationResponse(ctx context.Context, req *pbgroup | |||||||
| 		if member == nil { | 		if member == nil { | ||||||
| 			log.ZDebug(ctx, "GroupApplicationResponse", "member is nil") | 			log.ZDebug(ctx, "GroupApplicationResponse", "member is nil") | ||||||
| 		} else { | 		} else { | ||||||
| 			if err = g.notification.GroupApplicationAgreeMemberEnterNotification(ctx, req.GroupID, groupRequest.InviterUserID, req.FromUserID); err != nil { | 			if err = g.notification.GroupApplicationAgreeMemberEnterNotification(ctx, req.GroupID, nil, groupRequest.InviterUserID, req.FromUserID); err != nil { | ||||||
| 				return nil, err | 				return nil, err | ||||||
| 			} | 			} | ||||||
| 		} | 		} | ||||||
| @ -1368,7 +1369,7 @@ func (g *groupServer) DismissGroup(ctx context.Context, req *pbgroup.DismissGrou | |||||||
| 		if mcontext.GetOpUserID(ctx) == owner.UserID { | 		if mcontext.GetOpUserID(ctx) == owner.UserID { | ||||||
| 			tips.OpUser = g.groupMemberDB2PB(owner, 0) | 			tips.OpUser = g.groupMemberDB2PB(owner, 0) | ||||||
| 		} | 		} | ||||||
| 		g.notification.GroupDismissedNotification(ctx, tips) | 		g.notification.GroupDismissedNotification(ctx, tips, req.SendNotification) | ||||||
| 	} | 	} | ||||||
| 	membersID, err := g.db.FindGroupMemberUserID(ctx, group.GroupID) | 	membersID, err := g.db.FindGroupMemberUserID(ctx, group.GroupID) | ||||||
| 	if err != nil { | 	if err != nil { | ||||||
|  | |||||||
| @ -22,6 +22,8 @@ import ( | |||||||
| 
 | 
 | ||||||
| 	"github.com/openimsdk/open-im-server/v3/pkg/rpcli" | 	"github.com/openimsdk/open-im-server/v3/pkg/rpcli" | ||||||
| 
 | 
 | ||||||
|  | 	"go.mongodb.org/mongo-driver/mongo" | ||||||
|  | 
 | ||||||
| 	"github.com/openimsdk/open-im-server/v3/pkg/authverify" | 	"github.com/openimsdk/open-im-server/v3/pkg/authverify" | ||||||
| 	"github.com/openimsdk/open-im-server/v3/pkg/common/convert" | 	"github.com/openimsdk/open-im-server/v3/pkg/common/convert" | ||||||
| 	"github.com/openimsdk/open-im-server/v3/pkg/common/servererrs" | 	"github.com/openimsdk/open-im-server/v3/pkg/common/servererrs" | ||||||
| @ -41,7 +43,6 @@ import ( | |||||||
| 	"github.com/openimsdk/tools/mcontext" | 	"github.com/openimsdk/tools/mcontext" | ||||||
| 	"github.com/openimsdk/tools/utils/datautil" | 	"github.com/openimsdk/tools/utils/datautil" | ||||||
| 	"github.com/openimsdk/tools/utils/stringutil" | 	"github.com/openimsdk/tools/utils/stringutil" | ||||||
| 	"go.mongodb.org/mongo-driver/mongo" |  | ||||||
| ) | ) | ||||||
| 
 | 
 | ||||||
| // GroupApplicationReceiver | // GroupApplicationReceiver | ||||||
| @ -52,11 +53,11 @@ const ( | |||||||
| 
 | 
 | ||||||
| func NewNotificationSender(db controller.GroupDatabase, config *Config, userClient *rpcli.UserClient, msgClient *rpcli.MsgClient, conversationClient *rpcli.ConversationClient) *NotificationSender { | func NewNotificationSender(db controller.GroupDatabase, config *Config, userClient *rpcli.UserClient, msgClient *rpcli.MsgClient, conversationClient *rpcli.ConversationClient) *NotificationSender { | ||||||
| 	return &NotificationSender{ | 	return &NotificationSender{ | ||||||
| 		NotificationSender: rpcclient.NewNotificationSender(&config.NotificationConfig, | 		NotificationSender: notification.NewNotificationSender(&config.NotificationConfig, | ||||||
| 			rpcclient.WithRpcClient(func(ctx context.Context, req *msg.SendMsgReq) (*msg.SendMsgResp, error) { | 			notification.WithRpcClient(func(ctx context.Context, req *msg.SendMsgReq) (*msg.SendMsgResp, error) { | ||||||
| 				return msgClient.SendMsg(ctx, req) | 				return msgClient.SendMsg(ctx, req) | ||||||
| 			}), | 			}), | ||||||
| 			rpcclient.WithUserRpcClient(userClient.GetUserInfo), | 			notification.WithUserRpcClient(userClient.GetUserInfo), | ||||||
| 		), | 		), | ||||||
| 		getUsersInfo: func(ctx context.Context, userIDs []string) ([]common_user.CommonUser, error) { | 		getUsersInfo: func(ctx context.Context, userIDs []string) ([]common_user.CommonUser, error) { | ||||||
| 			users, err := userClient.GetUsersInfo(ctx, userIDs) | 			users, err := userClient.GetUsersInfo(ctx, userIDs) | ||||||
| @ -73,7 +74,7 @@ func NewNotificationSender(db controller.GroupDatabase, config *Config, userClie | |||||||
| } | } | ||||||
| 
 | 
 | ||||||
| type NotificationSender struct { | type NotificationSender struct { | ||||||
| 	*rpcclient.NotificationSender | 	*notification.NotificationSender | ||||||
| 	getUsersInfo       func(ctx context.Context, userIDs []string) ([]common_user.CommonUser, error) | 	getUsersInfo       func(ctx context.Context, userIDs []string) ([]common_user.CommonUser, error) | ||||||
| 	db                 controller.GroupDatabase | 	db                 controller.GroupDatabase | ||||||
| 	config             *Config | 	config             *Config | ||||||
| @ -307,7 +308,7 @@ func (g *NotificationSender) setSortVersion(ctx context.Context, version *uint64 | |||||||
| 	} | 	} | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| func (g *NotificationSender) GroupCreatedNotification(ctx context.Context, tips *sdkws.GroupCreatedTips) { | func (g *NotificationSender) GroupCreatedNotification(ctx context.Context, tips *sdkws.GroupCreatedTips, sendNotification *bool) { | ||||||
| 	var err error | 	var err error | ||||||
| 	defer func() { | 	defer func() { | ||||||
| 		if err != nil { | 		if err != nil { | ||||||
| @ -318,7 +319,7 @@ func (g *NotificationSender) GroupCreatedNotification(ctx context.Context, tips | |||||||
| 		return | 		return | ||||||
| 	} | 	} | ||||||
| 	g.setVersion(ctx, &tips.GroupMemberVersion, &tips.GroupMemberVersionID, database.GroupMemberVersionName, tips.Group.GroupID) | 	g.setVersion(ctx, &tips.GroupMemberVersion, &tips.GroupMemberVersionID, database.GroupMemberVersionName, tips.Group.GroupID) | ||||||
| 	g.Notification(ctx, mcontext.GetOpUserID(ctx), tips.Group.GroupID, constant.GroupCreatedNotification, tips) | 	g.Notification(ctx, mcontext.GetOpUserID(ctx), tips.Group.GroupID, constant.GroupCreatedNotification, tips, notification.WithSendNotification(sendNotification)) | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| func (g *NotificationSender) GroupInfoSetNotification(ctx context.Context, tips *sdkws.GroupInfoSetTips) { | func (g *NotificationSender) GroupInfoSetNotification(ctx context.Context, tips *sdkws.GroupInfoSetTips) { | ||||||
| @ -332,7 +333,7 @@ func (g *NotificationSender) GroupInfoSetNotification(ctx context.Context, tips | |||||||
| 		return | 		return | ||||||
| 	} | 	} | ||||||
| 	g.setVersion(ctx, &tips.GroupMemberVersion, &tips.GroupMemberVersionID, database.GroupMemberVersionName, tips.Group.GroupID) | 	g.setVersion(ctx, &tips.GroupMemberVersion, &tips.GroupMemberVersionID, database.GroupMemberVersionName, tips.Group.GroupID) | ||||||
| 	g.Notification(ctx, mcontext.GetOpUserID(ctx), tips.Group.GroupID, constant.GroupInfoSetNotification, tips, rpcclient.WithRpcGetUserName()) | 	g.Notification(ctx, mcontext.GetOpUserID(ctx), tips.Group.GroupID, constant.GroupInfoSetNotification, tips, notification.WithRpcGetUserName()) | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| func (g *NotificationSender) GroupInfoSetNameNotification(ctx context.Context, tips *sdkws.GroupInfoSetNameTips) { | func (g *NotificationSender) GroupInfoSetNameNotification(ctx context.Context, tips *sdkws.GroupInfoSetNameTips) { | ||||||
| @ -360,7 +361,7 @@ func (g *NotificationSender) GroupInfoSetAnnouncementNotification(ctx context.Co | |||||||
| 		return | 		return | ||||||
| 	} | 	} | ||||||
| 	g.setVersion(ctx, &tips.GroupMemberVersion, &tips.GroupMemberVersionID, database.GroupMemberVersionName, tips.Group.GroupID) | 	g.setVersion(ctx, &tips.GroupMemberVersion, &tips.GroupMemberVersionID, database.GroupMemberVersionName, tips.Group.GroupID) | ||||||
| 	g.Notification(ctx, mcontext.GetOpUserID(ctx), tips.Group.GroupID, constant.GroupInfoSetAnnouncementNotification, tips, rpcclient.WithRpcGetUserName()) | 	g.Notification(ctx, mcontext.GetOpUserID(ctx), tips.Group.GroupID, constant.GroupInfoSetAnnouncementNotification, tips, notification.WithRpcGetUserName()) | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| func (g *NotificationSender) JoinGroupApplicationNotification(ctx context.Context, req *pbgroup.JoinGroupReq) { | func (g *NotificationSender) JoinGroupApplicationNotification(ctx context.Context, req *pbgroup.JoinGroupReq) { | ||||||
| @ -505,7 +506,7 @@ func (g *NotificationSender) GroupOwnerTransferredNotification(ctx context.Conte | |||||||
| 	g.Notification(ctx, mcontext.GetOpUserID(ctx), group.GroupID, constant.GroupOwnerTransferredNotification, tips) | 	g.Notification(ctx, mcontext.GetOpUserID(ctx), group.GroupID, constant.GroupOwnerTransferredNotification, tips) | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| func (g *NotificationSender) MemberKickedNotification(ctx context.Context, tips *sdkws.MemberKickedTips) { | func (g *NotificationSender) MemberKickedNotification(ctx context.Context, tips *sdkws.MemberKickedTips, sendNotification *bool) { | ||||||
| 	var err error | 	var err error | ||||||
| 	defer func() { | 	defer func() { | ||||||
| 		if err != nil { | 		if err != nil { | ||||||
| @ -516,10 +517,10 @@ func (g *NotificationSender) MemberKickedNotification(ctx context.Context, tips | |||||||
| 		return | 		return | ||||||
| 	} | 	} | ||||||
| 	g.setVersion(ctx, &tips.GroupMemberVersion, &tips.GroupMemberVersionID, database.GroupMemberVersionName, tips.Group.GroupID) | 	g.setVersion(ctx, &tips.GroupMemberVersion, &tips.GroupMemberVersionID, database.GroupMemberVersionName, tips.Group.GroupID) | ||||||
| 	g.Notification(ctx, mcontext.GetOpUserID(ctx), tips.Group.GroupID, constant.MemberKickedNotification, tips) | 	g.Notification(ctx, mcontext.GetOpUserID(ctx), tips.Group.GroupID, constant.MemberKickedNotification, tips, notification.WithSendNotification(sendNotification)) | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| func (g *NotificationSender) GroupApplicationAgreeMemberEnterNotification(ctx context.Context, groupID string, invitedOpUserID string, entrantUserID ...string) error { | func (g *NotificationSender) GroupApplicationAgreeMemberEnterNotification(ctx context.Context, groupID string, sendNotification *bool, invitedOpUserID string, entrantUserID ...string) error { | ||||||
| 	var err error | 	var err error | ||||||
| 	defer func() { | 	defer func() { | ||||||
| 		if err != nil { | 		if err != nil { | ||||||
| @ -569,7 +570,7 @@ func (g *NotificationSender) GroupApplicationAgreeMemberEnterNotification(ctx co | |||||||
| 		} | 		} | ||||||
| 	} | 	} | ||||||
| 	g.setVersion(ctx, &tips.GroupMemberVersion, &tips.GroupMemberVersionID, database.GroupMemberVersionName, tips.Group.GroupID) | 	g.setVersion(ctx, &tips.GroupMemberVersion, &tips.GroupMemberVersionID, database.GroupMemberVersionName, tips.Group.GroupID) | ||||||
| 	g.Notification(ctx, mcontext.GetOpUserID(ctx), group.GroupID, constant.MemberInvitedNotification, tips) | 	g.Notification(ctx, mcontext.GetOpUserID(ctx), group.GroupID, constant.MemberInvitedNotification, tips, notification.WithSendNotification(sendNotification)) | ||||||
| 	return nil | 	return nil | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| @ -614,7 +615,7 @@ func (g *NotificationSender) MemberEnterNotification(ctx context.Context, groupI | |||||||
| 	return nil | 	return nil | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| func (g *NotificationSender) GroupDismissedNotification(ctx context.Context, tips *sdkws.GroupDismissedTips) { | func (g *NotificationSender) GroupDismissedNotification(ctx context.Context, tips *sdkws.GroupDismissedTips, sendNotification *bool) { | ||||||
| 	var err error | 	var err error | ||||||
| 	defer func() { | 	defer func() { | ||||||
| 		if err != nil { | 		if err != nil { | ||||||
| @ -624,7 +625,7 @@ func (g *NotificationSender) GroupDismissedNotification(ctx context.Context, tip | |||||||
| 	if err = g.fillOpUser(ctx, &tips.OpUser, tips.Group.GroupID); err != nil { | 	if err = g.fillOpUser(ctx, &tips.OpUser, tips.Group.GroupID); err != nil { | ||||||
| 		return | 		return | ||||||
| 	} | 	} | ||||||
| 	g.Notification(ctx, mcontext.GetOpUserID(ctx), tips.Group.GroupID, constant.GroupDismissedNotification, tips) | 	g.Notification(ctx, mcontext.GetOpUserID(ctx), tips.Group.GroupID, constant.GroupDismissedNotification, tips, notification.WithSendNotification(sendNotification)) | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| func (g *NotificationSender) GroupMemberMutedNotification(ctx context.Context, groupID, groupMemberUserID string, mutedSeconds uint32) { | func (g *NotificationSender) GroupMemberMutedNotification(ctx context.Context, groupID, groupMemberUserID string, mutedSeconds uint32) { | ||||||
|  | |||||||
| @ -23,11 +23,11 @@ import ( | |||||||
| ) | ) | ||||||
| 
 | 
 | ||||||
| type MsgNotificationSender struct { | type MsgNotificationSender struct { | ||||||
| 	*rpcclient.NotificationSender | 	*notification.NotificationSender | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| func NewMsgNotificationSender(config *Config, opts ...rpcclient.NotificationSenderOptions) *MsgNotificationSender { | func NewMsgNotificationSender(config *Config, opts ...notification.NotificationSenderOptions) *MsgNotificationSender { | ||||||
| 	return &MsgNotificationSender{rpcclient.NewNotificationSender(&config.NotificationConfig, opts...)} | 	return &MsgNotificationSender{notification.NewNotificationSender(&config.NotificationConfig, opts...)} | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| func (m *MsgNotificationSender) UserDeleteMsgsNotification(ctx context.Context, userID, conversationID string, seqs []int64) { | func (m *MsgNotificationSender) UserDeleteMsgsNotification(ctx context.Context, userID, conversationID string, seqs []int64) { | ||||||
|  | |||||||
| @ -23,6 +23,8 @@ import ( | |||||||
| 	"github.com/openimsdk/open-im-server/v3/pkg/mqbuild" | 	"github.com/openimsdk/open-im-server/v3/pkg/mqbuild" | ||||||
| 	"github.com/openimsdk/open-im-server/v3/pkg/rpcli" | 	"github.com/openimsdk/open-im-server/v3/pkg/rpcli" | ||||||
| 
 | 
 | ||||||
|  | 	"google.golang.org/grpc" | ||||||
|  | 
 | ||||||
| 	"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/storage/cache/redis" | 	"github.com/openimsdk/open-im-server/v3/pkg/common/storage/cache/redis" | ||||||
| 	"github.com/openimsdk/open-im-server/v3/pkg/common/storage/controller" | 	"github.com/openimsdk/open-im-server/v3/pkg/common/storage/controller" | ||||||
| @ -35,7 +37,6 @@ import ( | |||||||
| 	"github.com/openimsdk/protocol/msg" | 	"github.com/openimsdk/protocol/msg" | ||||||
| 	"github.com/openimsdk/protocol/sdkws" | 	"github.com/openimsdk/protocol/sdkws" | ||||||
| 	"github.com/openimsdk/tools/discovery" | 	"github.com/openimsdk/tools/discovery" | ||||||
| 	"google.golang.org/grpc" |  | ||||||
| ) | ) | ||||||
| 
 | 
 | ||||||
| type MessageInterceptorFunc func(ctx context.Context, globalConfig *Config, req *msg.SendMsgReq) (*sdkws.MsgData, error) | type MessageInterceptorFunc func(ctx context.Context, globalConfig *Config, req *msg.SendMsgReq) (*sdkws.MsgData, error) | ||||||
| @ -66,7 +67,7 @@ type msgServer struct { | |||||||
| 	GroupLocalCache        *rpccache.GroupLocalCache        // Local cache for group data. | 	GroupLocalCache        *rpccache.GroupLocalCache        // Local cache for group data. | ||||||
| 	ConversationLocalCache *rpccache.ConversationLocalCache // Local cache for conversation data. | 	ConversationLocalCache *rpccache.ConversationLocalCache // Local cache for conversation data. | ||||||
| 	Handlers               MessageInterceptorChain          // Chain of handlers for processing messages. | 	Handlers               MessageInterceptorChain          // Chain of handlers for processing messages. | ||||||
| 	notificationSender     *rpcclient.NotificationSender    // RPC client for sending notifications. | 	notificationSender     *notification.NotificationSender // RPC client for sending notifications. | ||||||
| 	msgNotificationSender  *MsgNotificationSender           // RPC client for sending msg notifications. | 	msgNotificationSender  *MsgNotificationSender           // RPC client for sending msg notifications. | ||||||
| 	config                 *Config                          // Global configuration settings. | 	config                 *Config                          // Global configuration settings. | ||||||
| 	webhookClient          *webhook.Client | 	webhookClient          *webhook.Client | ||||||
| @ -152,8 +153,8 @@ func Start(ctx context.Context, config *Config, client discovery.Conn, server gr | |||||||
| 		conversationClient:     conversationClient, | 		conversationClient:     conversationClient, | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	s.notificationSender = rpcclient.NewNotificationSender(&config.NotificationConfig, rpcclient.WithLocalSendMsg(s.SendMsg)) | 	s.notificationSender = notification.NewNotificationSender(&config.NotificationConfig, notification.WithLocalSendMsg(s.SendMsg)) | ||||||
| 	s.msgNotificationSender = NewMsgNotificationSender(config, rpcclient.WithLocalSendMsg(s.SendMsg)) | 	s.msgNotificationSender = NewMsgNotificationSender(config, notification.WithLocalSendMsg(s.SendMsg)) | ||||||
| 
 | 
 | ||||||
| 	msg.RegisterMsgServer(server, s) | 	msg.RegisterMsgServer(server, s) | ||||||
| 
 | 
 | ||||||
|  | |||||||
| @ -16,6 +16,7 @@ package relation | |||||||
| 
 | 
 | ||||||
| import ( | import ( | ||||||
| 	"context" | 	"context" | ||||||
|  | 
 | ||||||
| 	"github.com/openimsdk/open-im-server/v3/pkg/rpcli" | 	"github.com/openimsdk/open-im-server/v3/pkg/rpcli" | ||||||
| 	"github.com/openimsdk/protocol/msg" | 	"github.com/openimsdk/protocol/msg" | ||||||
| 
 | 
 | ||||||
| @ -36,7 +37,7 @@ import ( | |||||||
| ) | ) | ||||||
| 
 | 
 | ||||||
| type FriendNotificationSender struct { | type FriendNotificationSender struct { | ||||||
| 	*rpcclient.NotificationSender | 	*notification.NotificationSender | ||||||
| 	// Target not found err | 	// Target not found err | ||||||
| 	getUsersInfo func(ctx context.Context, userIDs []string) ([]common_user.CommonUser, error) | 	getUsersInfo func(ctx context.Context, userIDs []string) ([]common_user.CommonUser, error) | ||||||
| 	// db controller | 	// db controller | ||||||
| @ -89,7 +90,7 @@ func WithRpcFunc( | |||||||
| 
 | 
 | ||||||
| func NewFriendNotificationSender(conf *config.Notification, msgClient *rpcli.MsgClient, opts ...friendNotificationSenderOptions) *FriendNotificationSender { | func NewFriendNotificationSender(conf *config.Notification, msgClient *rpcli.MsgClient, opts ...friendNotificationSenderOptions) *FriendNotificationSender { | ||||||
| 	f := &FriendNotificationSender{ | 	f := &FriendNotificationSender{ | ||||||
| 		NotificationSender: rpcclient.NewNotificationSender(conf, rpcclient.WithRpcClient(func(ctx context.Context, req *msg.SendMsgReq) (*msg.SendMsgResp, error) { | 		NotificationSender: notification.NewNotificationSender(conf, notification.WithRpcClient(func(ctx context.Context, req *msg.SendMsgReq) (*msg.SendMsgResp, error) { | ||||||
| 			return msgClient.SendMsg(ctx, req) | 			return msgClient.SendMsg(ctx, req) | ||||||
| 		})), | 		})), | ||||||
| 	} | 	} | ||||||
|  | |||||||
| @ -16,6 +16,7 @@ package user | |||||||
| 
 | 
 | ||||||
| import ( | import ( | ||||||
| 	"context" | 	"context" | ||||||
|  | 
 | ||||||
| 	"github.com/openimsdk/open-im-server/v3/pkg/rpcli" | 	"github.com/openimsdk/open-im-server/v3/pkg/rpcli" | ||||||
| 	"github.com/openimsdk/protocol/msg" | 	"github.com/openimsdk/protocol/msg" | ||||||
| 
 | 
 | ||||||
| @ -29,7 +30,7 @@ import ( | |||||||
| ) | ) | ||||||
| 
 | 
 | ||||||
| type UserNotificationSender struct { | type UserNotificationSender struct { | ||||||
| 	*rpcclient.NotificationSender | 	*notification.NotificationSender | ||||||
| 	getUsersInfo func(ctx context.Context, userIDs []string) ([]common_user.CommonUser, error) | 	getUsersInfo func(ctx context.Context, userIDs []string) ([]common_user.CommonUser, error) | ||||||
| 	// db controller | 	// db controller | ||||||
| 	db controller.UserDatabase | 	db controller.UserDatabase | ||||||
| @ -63,7 +64,7 @@ func WithUserFunc( | |||||||
| 
 | 
 | ||||||
| func NewUserNotificationSender(config *Config, msgClient *rpcli.MsgClient, opts ...userNotificationSenderOptions) *UserNotificationSender { | func NewUserNotificationSender(config *Config, msgClient *rpcli.MsgClient, opts ...userNotificationSenderOptions) *UserNotificationSender { | ||||||
| 	f := &UserNotificationSender{ | 	f := &UserNotificationSender{ | ||||||
| 		NotificationSender: rpcclient.NewNotificationSender(&config.NotificationConfig, rpcclient.WithRpcClient(func(ctx context.Context, req *msg.SendMsgReq) (*msg.SendMsgResp, error) { | 		NotificationSender: notification.NewNotificationSender(&config.NotificationConfig, notification.WithRpcClient(func(ctx context.Context, req *msg.SendMsgReq) (*msg.SendMsgResp, error) { | ||||||
| 			return msgClient.SendMsg(ctx, req) | 			return msgClient.SendMsg(ctx, req) | ||||||
| 		})), | 		})), | ||||||
| 	} | 	} | ||||||
|  | |||||||
| @ -18,11 +18,12 @@ import ( | |||||||
| 	"os" | 	"os" | ||||||
| 	"path/filepath" | 	"path/filepath" | ||||||
| 
 | 
 | ||||||
|  | 	"gopkg.in/yaml.v3" | ||||||
|  | 
 | ||||||
| 	"github.com/openimsdk/open-im-server/v3/pkg/msgprocessor" | 	"github.com/openimsdk/open-im-server/v3/pkg/msgprocessor" | ||||||
| 	"github.com/openimsdk/protocol/constant" | 	"github.com/openimsdk/protocol/constant" | ||||||
| 	"github.com/openimsdk/tools/errs" | 	"github.com/openimsdk/tools/errs" | ||||||
| 	"github.com/openimsdk/tools/field" | 	"github.com/openimsdk/tools/field" | ||||||
| 	"gopkg.in/yaml.v3" |  | ||||||
| ) | ) | ||||||
| 
 | 
 | ||||||
| const ( | const ( | ||||||
| @ -56,9 +57,12 @@ func GetProjectRoot() (string, error) { | |||||||
| 	return projectRoot, nil | 	return projectRoot, nil | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| func GetOptionsByNotification(cfg NotificationConfig) msgprocessor.Options { | func GetOptionsByNotification(cfg NotificationConfig, sendNotification *bool) msgprocessor.Options { | ||||||
| 	opts := msgprocessor.NewOptions() | 	opts := msgprocessor.NewOptions() | ||||||
| 
 | 
 | ||||||
|  | 	if sendNotification != nil { | ||||||
|  | 		cfg.IsSendMsg = *sendNotification | ||||||
|  | 	} | ||||||
| 	if cfg.IsSendMsg { | 	if cfg.IsSendMsg { | ||||||
| 		opts = msgprocessor.WithOptions(opts, msgprocessor.WithUnreadCount(true)) | 		opts = msgprocessor.WithOptions(opts, msgprocessor.WithUnreadCount(true)) | ||||||
| 	} | 	} | ||||||
|  | |||||||
| @ -12,7 +12,7 @@ | |||||||
| // See the License for the specific language governing permissions and | // See the License for the specific language governing permissions and | ||||||
| // limitations under the License. | // limitations under the License. | ||||||
| 
 | 
 | ||||||
| package rpcclient | package notification | ||||||
| 
 | 
 | ||||||
| import ( | import ( | ||||||
| 	"context" | 	"context" | ||||||
| @ -179,19 +179,24 @@ func NewNotificationSender(conf *config.Notification, opts ...NotificationSender | |||||||
| } | } | ||||||
| 
 | 
 | ||||||
| type notificationOpt struct { | type notificationOpt struct { | ||||||
| 	WithRpcGetUsername bool | 	RpcGetUsername   bool | ||||||
|  | 	SendNotification *bool | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| type NotificationOptions func(*notificationOpt) | type NotificationOptions func(*notificationOpt) | ||||||
| 
 | 
 | ||||||
| func WithRpcGetUserName() NotificationOptions { | func WithRpcGetUserName() NotificationOptions { | ||||||
| 	return func(opt *notificationOpt) { | 	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) { | 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 = context.WithoutCancel(ctx) | ||||||
| 	ctx, cancel := context.WithTimeout(ctx, time.Second*time.Duration(5)) | 	ctx, cancel := context.WithTimeout(ctx, time.Second*time.Duration(5)) | ||||||
| 	defer cancel() | 	defer cancel() | ||||||
| @ -208,7 +213,7 @@ func (s *NotificationSender) send(ctx context.Context, sendID, recvID string, co | |||||||
| 	var req msg.SendMsgReq | 	var req msg.SendMsgReq | ||||||
| 	var msg sdkws.MsgData | 	var msg sdkws.MsgData | ||||||
| 	var userInfo *sdkws.UserInfo | 	var userInfo *sdkws.UserInfo | ||||||
| 	if notificationOpt.WithRpcGetUsername && s.getUserInfo != nil { | 	if notificationOpt.RpcGetUsername && s.getUserInfo != nil { | ||||||
| 		userInfo, err = s.getUserInfo(ctx, sendID) | 		userInfo, err = s.getUserInfo(ctx, sendID) | ||||||
| 		if err != nil { | 		if err != nil { | ||||||
| 			log.ZWarn(ctx, "getUserInfo failed", err, "sendID", sendID) | 			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 { | 	if sendID == recvID && contentType == constant.HasReadReceipt { | ||||||
| 		optionsConfig.ReliabilityLevel = constant.UnreliableNotification | 		optionsConfig.ReliabilityLevel = constant.UnreliableNotification | ||||||
| 	} | 	} | ||||||
| 	options := config.GetOptionsByNotification(optionsConfig) | 	options := config.GetOptionsByNotification(optionsConfig, notificationOpt.SendNotification) | ||||||
| 	s.SetOptionsByContentType(ctx, options, contentType) | 	s.SetOptionsByContentType(ctx, options, contentType) | ||||||
| 	msg.Options = options | 	msg.Options = options | ||||||
| 	// fill Notification OfflinePush by config | 	// fill Notification OfflinePush by config | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user