mirror of
				https://github.com/openimsdk/open-im-server.git
				synced 2025-10-26 21:22:16 +08:00 
			
		
		
		
	improve webhookCreateConversations Implement
This commit is contained in:
		
							parent
							
								
									6262eee0d1
								
							
						
					
					
						commit
						0885d5b43e
					
				| @ -5,19 +5,33 @@ import ( | |||||||
| 
 | 
 | ||||||
| 	"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" | ||||||
|  | 	dbModel "github.com/openimsdk/open-im-server/v3/pkg/common/storage/model" | ||||||
| 	"github.com/openimsdk/open-im-server/v3/pkg/common/webhook" | 	"github.com/openimsdk/open-im-server/v3/pkg/common/webhook" | ||||||
| 	pbconversation "github.com/openimsdk/protocol/conversation" |  | ||||||
| 	"github.com/openimsdk/tools/utils/datautil" | 	"github.com/openimsdk/tools/utils/datautil" | ||||||
| ) | ) | ||||||
| 
 | 
 | ||||||
| func (c *conversationServer) webhookBeforeCreateSingleChatConversations(ctx context.Context, before *config.BeforeConfig, req *pbconversation.CreateSingleChatConversationsReq) error { | func (c *conversationServer) webhookBeforeCreateSingleChatConversations(ctx context.Context, before *config.BeforeConfig, req *dbModel.Conversation) error { | ||||||
| 	return webhook.WithCondition(ctx, before, func(ctx context.Context) error { | 	return webhook.WithCondition(ctx, before, func(ctx context.Context) error { | ||||||
| 		cbReq := &callbackstruct.CallbackBeforeCreateSingleChatConversationsReq{ | 		cbReq := &callbackstruct.CallbackBeforeCreateSingleChatConversationsReq{ | ||||||
| 			CallbackCommand:       callbackstruct.CallbackBeforeCreateSingleChatConversationsCommand, | 			CallbackCommand:       callbackstruct.CallbackBeforeCreateSingleChatConversationsCommand, | ||||||
| 			RecvID:           req.RecvID, | 			OwnerUserID:           req.OwnerUserID, | ||||||
| 			SendID:           req.SendID, |  | ||||||
| 			ConversationID:        req.ConversationID, | 			ConversationID:        req.ConversationID, | ||||||
| 			ConversationType:      req.ConversationType, | 			ConversationType:      req.ConversationType, | ||||||
|  | 			UserID:                req.UserID, | ||||||
|  | 			GroupID:               req.GroupID, | ||||||
|  | 			RecvMsgOpt:            req.RecvMsgOpt, | ||||||
|  | 			IsPinned:              req.IsPinned, | ||||||
|  | 			IsPrivateChat:         req.IsPrivateChat, | ||||||
|  | 			BurnDuration:          req.BurnDuration, | ||||||
|  | 			GroupAtType:           req.GroupAtType, | ||||||
|  | 			AttachedInfo:          req.AttachedInfo, | ||||||
|  | 			Ex:                    req.Ex, | ||||||
|  | 			MaxSeq:                req.MaxSeq, | ||||||
|  | 			MinSeq:                req.MinSeq, | ||||||
|  | 			CreateTime:            req.CreateTime, | ||||||
|  | 			IsMsgDestruct:         req.IsMsgDestruct, | ||||||
|  | 			MsgDestructTime:       req.MsgDestructTime, | ||||||
|  | 			LatestMsgDestructTime: req.LatestMsgDestructTime, | ||||||
| 		} | 		} | ||||||
| 
 | 
 | ||||||
| 		resp := &callbackstruct.CallbackBeforeCreateSingleChatConversationsResp{} | 		resp := &callbackstruct.CallbackBeforeCreateSingleChatConversationsResp{} | ||||||
| @ -26,34 +40,76 @@ func (c *conversationServer) webhookBeforeCreateSingleChatConversations(ctx cont | |||||||
| 			return err | 			return err | ||||||
| 		} | 		} | ||||||
| 
 | 
 | ||||||
| 		datautil.NotNilReplace(&req.RecvID, resp.RecvID) | 		datautil.NotNilReplace(&req.OwnerUserID, resp.OwnerUserID) | ||||||
| 		datautil.NotNilReplace(&req.SendID, resp.SendID) |  | ||||||
| 		datautil.NotNilReplace(&req.ConversationID, resp.ConversationID) | 		datautil.NotNilReplace(&req.ConversationID, resp.ConversationID) | ||||||
| 		datautil.NotNilReplace(&req.ConversationType, resp.ConversationType) | 		datautil.NotNilReplace(&req.ConversationType, resp.ConversationType) | ||||||
|  | 		datautil.NotNilReplace(&req.UserID, resp.UserID) | ||||||
|  | 		datautil.NotNilReplace(&req.GroupID, resp.GroupID) | ||||||
|  | 		datautil.NotNilReplace(&req.RecvMsgOpt, resp.RecvMsgOpt) | ||||||
|  | 		datautil.NotNilReplace(&req.IsPinned, resp.IsPinned) | ||||||
|  | 		datautil.NotNilReplace(&req.IsPrivateChat, resp.IsPrivateChat) | ||||||
|  | 		datautil.NotNilReplace(&req.BurnDuration, resp.BurnDuration) | ||||||
|  | 		datautil.NotNilReplace(&req.GroupAtType, resp.GroupAtType) | ||||||
|  | 		datautil.NotNilReplace(&req.AttachedInfo, resp.AttachedInfo) | ||||||
|  | 		datautil.NotNilReplace(&req.Ex, resp.Ex) | ||||||
|  | 		datautil.NotNilReplace(&req.MaxSeq, resp.MaxSeq) | ||||||
|  | 		datautil.NotNilReplace(&req.MinSeq, resp.MinSeq) | ||||||
|  | 		datautil.NotNilReplace(&req.CreateTime, resp.CreateTime) | ||||||
|  | 		datautil.NotNilReplace(&req.IsMsgDestruct, resp.IsMsgDestruct) | ||||||
|  | 		datautil.NotNilReplace(&req.MsgDestructTime, resp.MsgDestructTime) | ||||||
|  | 		datautil.NotNilReplace(&req.LatestMsgDestructTime, resp.LatestMsgDestructTime) | ||||||
|  | 
 | ||||||
| 		return nil | 		return nil | ||||||
| 	}) | 	}) | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| func (c *conversationServer) webhookAfterCreateSingleChatConversations(ctx context.Context, after *config.AfterConfig, req *pbconversation.CreateSingleChatConversationsReq) error { | func (c *conversationServer) webhookAfterCreateSingleChatConversations(ctx context.Context, after *config.AfterConfig, req *dbModel.Conversation) error { | ||||||
| 	cbReq := &callbackstruct.CallbackAfterCreateSingleChatConversationsReq{ | 	cbReq := &callbackstruct.CallbackAfterCreateSingleChatConversationsReq{ | ||||||
| 		CallbackCommand:       callbackstruct.CallbackAfterCreateSingleChatConversationsCommand, | 		CallbackCommand:       callbackstruct.CallbackAfterCreateSingleChatConversationsCommand, | ||||||
| 		RecvID:           req.RecvID, | 		OwnerUserID:           req.OwnerUserID, | ||||||
| 		SendID:           req.SendID, |  | ||||||
| 		ConversationID:        req.ConversationID, | 		ConversationID:        req.ConversationID, | ||||||
| 		ConversationType:      req.ConversationType, | 		ConversationType:      req.ConversationType, | ||||||
|  | 		UserID:                req.UserID, | ||||||
|  | 		GroupID:               req.GroupID, | ||||||
|  | 		RecvMsgOpt:            req.RecvMsgOpt, | ||||||
|  | 		IsPinned:              req.IsPinned, | ||||||
|  | 		IsPrivateChat:         req.IsPrivateChat, | ||||||
|  | 		BurnDuration:          req.BurnDuration, | ||||||
|  | 		GroupAtType:           req.GroupAtType, | ||||||
|  | 		AttachedInfo:          req.AttachedInfo, | ||||||
|  | 		Ex:                    req.Ex, | ||||||
|  | 		MaxSeq:                req.MaxSeq, | ||||||
|  | 		MinSeq:                req.MinSeq, | ||||||
|  | 		CreateTime:            req.CreateTime, | ||||||
|  | 		IsMsgDestruct:         req.IsMsgDestruct, | ||||||
|  | 		MsgDestructTime:       req.MsgDestructTime, | ||||||
|  | 		LatestMsgDestructTime: req.LatestMsgDestructTime, | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	c.webhookClient.AsyncPost(ctx, cbReq.GetCallbackCommand(), cbReq, &callbackstruct.CallbackAfterCreateSingleChatConversationsResp{}, after) | 	c.webhookClient.AsyncPost(ctx, cbReq.GetCallbackCommand(), cbReq, &callbackstruct.CallbackAfterCreateSingleChatConversationsResp{}, after) | ||||||
| 	return nil | 	return nil | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| 
 | func (c *conversationServer) webhookBeforeCreateGroupChatConversations(ctx context.Context, before *config.BeforeConfig, req *dbModel.Conversation) error { | ||||||
| func (c *conversationServer) webhookBeforeCreateGroupChatConversations(ctx context.Context, before *config.BeforeConfig, req *pbconversation.CreateGroupChatConversationsReq) error { |  | ||||||
| 	return webhook.WithCondition(ctx, before, func(ctx context.Context) error { | 	return webhook.WithCondition(ctx, before, func(ctx context.Context) error { | ||||||
| 		cbReq := &callbackstruct.CallbackBeforeCreateGroupChatConversationsReq{ | 		cbReq := &callbackstruct.CallbackBeforeCreateGroupChatConversationsReq{ | ||||||
| 			CallbackCommand:       callbackstruct.CallbackBeforeCreateGroupChatConversationsCommand, | 			CallbackCommand:       callbackstruct.CallbackBeforeCreateGroupChatConversationsCommand, | ||||||
| 			UserIDs:         req.UserIDs, | 			ConversationID:        req.ConversationID, | ||||||
|  | 			ConversationType:      req.ConversationType, | ||||||
| 			GroupID:               req.GroupID, | 			GroupID:               req.GroupID, | ||||||
|  | 			RecvMsgOpt:            req.RecvMsgOpt, | ||||||
|  | 			IsPinned:              req.IsPinned, | ||||||
|  | 			IsPrivateChat:         req.IsPrivateChat, | ||||||
|  | 			BurnDuration:          req.BurnDuration, | ||||||
|  | 			GroupAtType:           req.GroupAtType, | ||||||
|  | 			AttachedInfo:          req.AttachedInfo, | ||||||
|  | 			Ex:                    req.Ex, | ||||||
|  | 			MaxSeq:                req.MaxSeq, | ||||||
|  | 			MinSeq:                req.MinSeq, | ||||||
|  | 			CreateTime:            req.CreateTime, | ||||||
|  | 			IsMsgDestruct:         req.IsMsgDestruct, | ||||||
|  | 			MsgDestructTime:       req.MsgDestructTime, | ||||||
|  | 			LatestMsgDestructTime: req.LatestMsgDestructTime, | ||||||
| 		} | 		} | ||||||
| 
 | 
 | ||||||
| 		resp := &callbackstruct.CallbackBeforeCreateGroupChatConversationsResp{} | 		resp := &callbackstruct.CallbackBeforeCreateGroupChatConversationsResp{} | ||||||
| @ -62,17 +118,45 @@ func (c *conversationServer) webhookBeforeCreateGroupChatConversations(ctx conte | |||||||
| 			return err | 			return err | ||||||
| 		} | 		} | ||||||
| 
 | 
 | ||||||
| 		datautil.NotNilReplace(&req.UserIDs, resp.UserIDs) | 		datautil.NotNilReplace(&req.ConversationID, resp.ConversationID) | ||||||
|  | 		datautil.NotNilReplace(&req.ConversationType, resp.ConversationType) | ||||||
| 		datautil.NotNilReplace(&req.GroupID, resp.GroupID) | 		datautil.NotNilReplace(&req.GroupID, resp.GroupID) | ||||||
|  | 		datautil.NotNilReplace(&req.RecvMsgOpt, resp.RecvMsgOpt) | ||||||
|  | 		datautil.NotNilReplace(&req.IsPinned, resp.IsPinned) | ||||||
|  | 		datautil.NotNilReplace(&req.IsPrivateChat, resp.IsPrivateChat) | ||||||
|  | 		datautil.NotNilReplace(&req.BurnDuration, resp.BurnDuration) | ||||||
|  | 		datautil.NotNilReplace(&req.GroupAtType, resp.GroupAtType) | ||||||
|  | 		datautil.NotNilReplace(&req.AttachedInfo, resp.AttachedInfo) | ||||||
|  | 		datautil.NotNilReplace(&req.Ex, resp.Ex) | ||||||
|  | 		datautil.NotNilReplace(&req.MaxSeq, resp.MaxSeq) | ||||||
|  | 		datautil.NotNilReplace(&req.MinSeq, resp.MinSeq) | ||||||
|  | 		datautil.NotNilReplace(&req.CreateTime, resp.CreateTime) | ||||||
|  | 		datautil.NotNilReplace(&req.IsMsgDestruct, resp.IsMsgDestruct) | ||||||
|  | 		datautil.NotNilReplace(&req.MsgDestructTime, resp.MsgDestructTime) | ||||||
|  | 		datautil.NotNilReplace(&req.LatestMsgDestructTime, resp.LatestMsgDestructTime) | ||||||
| 		return nil | 		return nil | ||||||
| 	}) | 	}) | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| func (c *conversationServer) webhookAfterCreateGroupChatConversations(ctx context.Context, after *config.AfterConfig, req *pbconversation.CreateGroupChatConversationsReq) error { | func (c *conversationServer) webhookAfterCreateGroupChatConversations(ctx context.Context, after *config.AfterConfig, req *dbModel.Conversation) error { | ||||||
| 	cbReq := &callbackstruct.CallbackAfterCreateGroupChatConversationsReq{ | 	cbReq := &callbackstruct.CallbackAfterCreateGroupChatConversationsReq{ | ||||||
| 		CallbackCommand:       callbackstruct.CallbackAfterCreateGroupChatConversationsCommand, | 		CallbackCommand:       callbackstruct.CallbackAfterCreateGroupChatConversationsCommand, | ||||||
| 		UserIDs:         req.UserIDs, | 		ConversationID:        req.ConversationID, | ||||||
|  | 		ConversationType:      req.ConversationType, | ||||||
| 		GroupID:               req.GroupID, | 		GroupID:               req.GroupID, | ||||||
|  | 		RecvMsgOpt:            req.RecvMsgOpt, | ||||||
|  | 		IsPinned:              req.IsPinned, | ||||||
|  | 		IsPrivateChat:         req.IsPrivateChat, | ||||||
|  | 		BurnDuration:          req.BurnDuration, | ||||||
|  | 		GroupAtType:           req.GroupAtType, | ||||||
|  | 		AttachedInfo:          req.AttachedInfo, | ||||||
|  | 		Ex:                    req.Ex, | ||||||
|  | 		MaxSeq:                req.MaxSeq, | ||||||
|  | 		MinSeq:                req.MinSeq, | ||||||
|  | 		CreateTime:            req.CreateTime, | ||||||
|  | 		IsMsgDestruct:         req.IsMsgDestruct, | ||||||
|  | 		MsgDestructTime:       req.MsgDestructTime, | ||||||
|  | 		LatestMsgDestructTime: req.LatestMsgDestructTime, | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	c.webhookClient.AsyncPost(ctx, cbReq.GetCallbackCommand(), cbReq, &callbackstruct.CallbackAfterCreateGroupChatConversationsResp{}, after) | 	c.webhookClient.AsyncPost(ctx, cbReq.GetCallbackCommand(), cbReq, &callbackstruct.CallbackAfterCreateGroupChatConversationsResp{}, after) | ||||||
|  | |||||||
| @ -338,73 +338,82 @@ func (c *conversationServer) GetRecvMsgNotNotifyUserIDs(ctx context.Context, req | |||||||
| func (c *conversationServer) CreateSingleChatConversations(ctx context.Context, | func (c *conversationServer) CreateSingleChatConversations(ctx context.Context, | ||||||
| 	req *pbconversation.CreateSingleChatConversationsReq, | 	req *pbconversation.CreateSingleChatConversationsReq, | ||||||
| ) (*pbconversation.CreateSingleChatConversationsResp, error) { | ) (*pbconversation.CreateSingleChatConversationsResp, error) { | ||||||
| 	if err := c.webhookBeforeCreateSingleChatConversations(ctx, &c.config.WebhooksConfig.BeforeCreateSingleChatConversations, req); err != nil && err != servererrs.ErrCallbackContinue { | 	log.ZWarn(ctx, "create Single Chat Conversations is start", nil, "req", req) | ||||||
| 		return nil, err | 	// if err := c.webhookBeforeCreateSingleChatConversations(ctx, &c.config.WebhooksConfig.BeforeCreateSingleChatConversations, req); err != nil && err != servererrs.ErrCallbackContinue { | ||||||
| 	} | 	// 	return nil, err | ||||||
|  | 	// } | ||||||
| 
 | 
 | ||||||
|  | 	var conversation dbModel.Conversation | ||||||
| 	switch req.ConversationType { | 	switch req.ConversationType { | ||||||
| 	case constant.SingleChatType: | 	case constant.SingleChatType: | ||||||
| 		var conversation dbModel.Conversation | 		// sendUser create | ||||||
| 		conversation.ConversationID = req.ConversationID | 		conversation.ConversationID = req.ConversationID | ||||||
| 		conversation.ConversationType = req.ConversationType | 		conversation.ConversationType = req.ConversationType | ||||||
| 		conversation.OwnerUserID = req.SendID | 		conversation.OwnerUserID = req.SendID | ||||||
| 		conversation.UserID = req.RecvID | 		conversation.UserID = req.RecvID | ||||||
|  | 		if err := c.webhookBeforeCreateSingleChatConversations(ctx, &c.config.WebhooksConfig.BeforeCreateSingleChatConversations, &conversation); err != nil && err != servererrs.ErrCallbackContinue { | ||||||
|  | 			return nil, err | ||||||
|  | 		} | ||||||
|  | 
 | ||||||
| 		err := c.conversationDatabase.CreateConversation(ctx, []*dbModel.Conversation{&conversation}) | 		err := c.conversationDatabase.CreateConversation(ctx, []*dbModel.Conversation{&conversation}) | ||||||
| 		if err != nil { | 		if err != nil { | ||||||
| 			log.ZWarn(ctx, "create conversation failed", err, "conversation", conversation) | 			log.ZWarn(ctx, "create conversation failed", err, "conversation", conversation) | ||||||
| 		} | 		} | ||||||
| 
 | 
 | ||||||
|  | 		c.webhookAfterCreateSingleChatConversations(ctx, &c.config.WebhooksConfig.AfterCreateSingleChatConversations, &conversation) | ||||||
|  | 
 | ||||||
|  | 		// recvUser create | ||||||
| 		conversation2 := conversation | 		conversation2 := conversation | ||||||
| 		conversation2.OwnerUserID = req.RecvID | 		conversation2.OwnerUserID = req.RecvID | ||||||
| 		conversation2.UserID = req.SendID | 		conversation2.UserID = req.SendID | ||||||
|  | 		if err := c.webhookBeforeCreateSingleChatConversations(ctx, &c.config.WebhooksConfig.BeforeCreateSingleChatConversations, &conversation); err != nil && err != servererrs.ErrCallbackContinue { | ||||||
|  | 			return nil, err | ||||||
|  | 		} | ||||||
|  | 
 | ||||||
| 		err = c.conversationDatabase.CreateConversation(ctx, []*dbModel.Conversation{&conversation2}) | 		err = c.conversationDatabase.CreateConversation(ctx, []*dbModel.Conversation{&conversation2}) | ||||||
| 		if err != nil { | 		if err != nil { | ||||||
| 			log.ZWarn(ctx, "create conversation failed", err, "conversation2", conversation) | 			log.ZWarn(ctx, "create conversation failed", err, "conversation2", conversation) | ||||||
| 		} | 		} | ||||||
|  | 
 | ||||||
|  | 		c.webhookAfterCreateSingleChatConversations(ctx, &c.config.WebhooksConfig.AfterCreateSingleChatConversations, &conversation2) | ||||||
| 	case constant.NotificationChatType: | 	case constant.NotificationChatType: | ||||||
| 		var conversation dbModel.Conversation |  | ||||||
| 		conversation.ConversationID = req.ConversationID | 		conversation.ConversationID = req.ConversationID | ||||||
| 		conversation.ConversationType = req.ConversationType | 		conversation.ConversationType = req.ConversationType | ||||||
| 		conversation.OwnerUserID = req.RecvID | 		conversation.OwnerUserID = req.RecvID | ||||||
| 		conversation.UserID = req.SendID | 		conversation.UserID = req.SendID | ||||||
|  | 		if err := c.webhookBeforeCreateSingleChatConversations(ctx, &c.config.WebhooksConfig.BeforeCreateSingleChatConversations, &conversation); err != nil && err != servererrs.ErrCallbackContinue { | ||||||
|  | 			return nil, err | ||||||
|  | 		} | ||||||
|  | 
 | ||||||
| 		err := c.conversationDatabase.CreateConversation(ctx, []*dbModel.Conversation{&conversation}) | 		err := c.conversationDatabase.CreateConversation(ctx, []*dbModel.Conversation{&conversation}) | ||||||
| 		if err != nil { | 		if err != nil { | ||||||
| 			log.ZWarn(ctx, "create conversation failed", err, "conversation2", conversation) | 			log.ZWarn(ctx, "create conversation failed", err, "conversation2", conversation) | ||||||
| 		} | 		} | ||||||
| 	} |  | ||||||
| 
 | 
 | ||||||
| 	reqCallbackAfter := &pbconversation.CreateSingleChatConversationsReq{ | 		c.webhookAfterCreateSingleChatConversations(ctx, &c.config.WebhooksConfig.AfterCreateSingleChatConversations, &conversation) | ||||||
| 		RecvID:           req.RecvID, |  | ||||||
| 		SendID:           req.SendID, |  | ||||||
| 		ConversationID:   req.ConversationID, |  | ||||||
| 		ConversationType: req.ConversationType, |  | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	c.webhookAfterCreateSingleChatConversations(ctx, &c.config.WebhooksConfig.AfterCreateSingleChatConversations, reqCallbackAfter) |  | ||||||
| 
 |  | ||||||
| 	return &pbconversation.CreateSingleChatConversationsResp{}, nil | 	return &pbconversation.CreateSingleChatConversationsResp{}, nil | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| func (c *conversationServer) CreateGroupChatConversations(ctx context.Context, req *pbconversation.CreateGroupChatConversationsReq) (*pbconversation.CreateGroupChatConversationsResp, error) { | func (c *conversationServer) CreateGroupChatConversations(ctx context.Context, req *pbconversation.CreateGroupChatConversationsReq) (*pbconversation.CreateGroupChatConversationsResp, error) { | ||||||
| 	if err := c.webhookBeforeCreateGroupChatConversations(ctx, &c.config.WebhooksConfig.BeforeCreateGroupChatConversations, req); err != nil { | 	var conversations dbModel.Conversation | ||||||
|  | 
 | ||||||
|  | 	conversations.ConversationID = msgprocessor.GetConversationIDBySessionType(constant.ReadGroupChatType, req.GroupID) | ||||||
|  | 	conversations.GroupID = req.GroupID | ||||||
|  | 	conversations.ConversationType = constant.ReadGroupChatType | ||||||
|  | 	// conversations.MaxSeq = 0 | ||||||
|  | 
 | ||||||
|  | 	if err := c.webhookBeforeCreateGroupChatConversations(ctx, &c.config.WebhooksConfig.BeforeCreateGroupChatConversations, &conversations); err != nil { | ||||||
| 		return nil, err | 		return nil, err | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	err := c.conversationDatabase.CreateGroupChatConversation(ctx, req.GroupID, req.UserIDs) | 	err := c.conversationDatabase.CreateGroupChatConversation(ctx, req.GroupID, req.UserIDs, &conversations) | ||||||
| 	if err != nil { | 	if err != nil { | ||||||
| 		return nil, err | 		return nil, err | ||||||
| 	} | 	} | ||||||
| 	conversationID := msgprocessor.GetConversationIDBySessionType(constant.ReadGroupChatType, req.GroupID) |  | ||||||
| 	if err := c.msgClient.SetUserConversationMaxSeq(ctx, conversationID, req.UserIDs, 0); err != nil { |  | ||||||
| 		return nil, err |  | ||||||
| 	} |  | ||||||
| 
 | 
 | ||||||
| 	reqCallBackAfter := &pbconversation.CreateGroupChatConversationsReq{ | 	c.webhookAfterCreateGroupChatConversations(ctx, &c.config.WebhooksConfig.AfterCreateGroupChatConversations, &conversations) | ||||||
| 		UserIDs: req.UserIDs, |  | ||||||
| 		GroupID: req.GroupID, |  | ||||||
| 	} |  | ||||||
| 
 |  | ||||||
| 	c.webhookAfterCreateGroupChatConversations(ctx, &c.config.WebhooksConfig.AfterCreateGroupChatConversations, reqCallBackAfter) |  | ||||||
| 	return &pbconversation.CreateGroupChatConversationsResp{}, nil | 	return &pbconversation.CreateGroupChatConversationsResp{}, nil | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | |||||||
| @ -1,27 +1,92 @@ | |||||||
| package callbackstruct | package callbackstruct | ||||||
| 
 | 
 | ||||||
|  | import "time" | ||||||
|  | 
 | ||||||
|  | type Conversation struct { | ||||||
|  | 	OwnerUserID           string    `json:"owner_user_id"` | ||||||
|  | 	ConversationID        string    `json:"conversation_id"` | ||||||
|  | 	ConversationType      int32     `json:"conversation_type"` | ||||||
|  | 	UserID                string    `json:"user_id"` | ||||||
|  | 	GroupID               string    `json:"group_id"` | ||||||
|  | 	RecvMsgOpt            int32     `json:"recv_msg_opt"` | ||||||
|  | 	IsPinned              bool      `json:"is_pinned"` | ||||||
|  | 	IsPrivateChat         bool      `json:"is_private_chat"` | ||||||
|  | 	BurnDuration          int32     `json:"burn_duration"` | ||||||
|  | 	GroupAtType           int32     `json:"group_at_type"` | ||||||
|  | 	AttachedInfo          string    `json:"attached_info"` | ||||||
|  | 	Ex                    string    `json:"ex"` | ||||||
|  | 	MaxSeq                int64     `json:"max_seq"` | ||||||
|  | 	MinSeq                int64     `json:"min_seq"` | ||||||
|  | 	CreateTime            time.Time `json:"create_time"` | ||||||
|  | 	IsMsgDestruct         bool      `json:"is_msg_destruct"` | ||||||
|  | 	MsgDestructTime       int64     `json:"msg_destruct_time"` | ||||||
|  | 	LatestMsgDestructTime time.Time `json:"latest_msg_destruct_time"` | ||||||
|  | } | ||||||
|  | 
 | ||||||
| type CallbackBeforeCreateSingleChatConversationsReq struct { | type CallbackBeforeCreateSingleChatConversationsReq struct { | ||||||
| 	CallbackCommand       `json:"callbackCommand"` | 	CallbackCommand       `json:"callbackCommand"` | ||||||
| 	RecvID           string `json:"recvID"` | 	OwnerUserID           string    `json:"owner_user_id"` | ||||||
| 	SendID           string `json:"sendID"` | 	ConversationID        string    `json:"conversation_id"` | ||||||
| 	ConversationID   string `json:"conversationID"` | 	ConversationType      int32     `json:"conversation_type"` | ||||||
| 	ConversationType int32  `json:"conversationType"` | 	UserID                string    `json:"user_id"` | ||||||
|  | 	GroupID               string    `json:"group_id"` | ||||||
|  | 	RecvMsgOpt            int32     `json:"recv_msg_opt"` | ||||||
|  | 	IsPinned              bool      `json:"is_pinned"` | ||||||
|  | 	IsPrivateChat         bool      `json:"is_private_chat"` | ||||||
|  | 	BurnDuration          int32     `json:"burn_duration"` | ||||||
|  | 	GroupAtType           int32     `json:"group_at_type"` | ||||||
|  | 	AttachedInfo          string    `json:"attached_info"` | ||||||
|  | 	Ex                    string    `json:"ex"` | ||||||
|  | 	MaxSeq                int64     `json:"max_seq"` | ||||||
|  | 	MinSeq                int64     `json:"min_seq"` | ||||||
|  | 	CreateTime            time.Time `json:"create_time"` | ||||||
|  | 	IsMsgDestruct         bool      `json:"is_msg_destruct"` | ||||||
|  | 	MsgDestructTime       int64     `json:"msg_destruct_time"` | ||||||
|  | 	LatestMsgDestructTime time.Time `json:"latest_msg_destruct_time"` | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| type CallbackBeforeCreateSingleChatConversationsResp struct { | type CallbackBeforeCreateSingleChatConversationsResp struct { | ||||||
| 	CommonCallbackResp | 	CommonCallbackResp | ||||||
| 	RecvID           *string `json:"recvID"` | 	OwnerUserID           *string    `json:"owner_user_id"` | ||||||
| 	SendID           *string `json:"sendID"` | 	ConversationID        *string    `json:"conversation_id"` | ||||||
| 	ConversationID   *string `json:"conversationID"` | 	ConversationType      *int32     `json:"conversation_type"` | ||||||
| 	ConversationType *int32  `json:"conversationType"` | 	UserID                *string    `json:"user_id"` | ||||||
|  | 	GroupID               *string    `json:"group_id"` | ||||||
|  | 	RecvMsgOpt            *int32     `json:"recv_msg_opt"` | ||||||
|  | 	IsPinned              *bool      `json:"is_pinned"` | ||||||
|  | 	IsPrivateChat         *bool      `json:"is_private_chat"` | ||||||
|  | 	BurnDuration          *int32     `json:"burn_duration"` | ||||||
|  | 	GroupAtType           *int32     `json:"group_at_type"` | ||||||
|  | 	AttachedInfo          *string    `json:"attached_info"` | ||||||
|  | 	Ex                    *string    `json:"ex"` | ||||||
|  | 	MaxSeq                *int64     `json:"max_seq"` | ||||||
|  | 	MinSeq                *int64     `json:"min_seq"` | ||||||
|  | 	CreateTime            *time.Time `json:"create_time"` | ||||||
|  | 	IsMsgDestruct         *bool      `json:"is_msg_destruct"` | ||||||
|  | 	MsgDestructTime       *int64     `json:"msg_destruct_time"` | ||||||
|  | 	LatestMsgDestructTime *time.Time `json:"latest_msg_destruct_time"` | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| type CallbackAfterCreateSingleChatConversationsReq struct { | type CallbackAfterCreateSingleChatConversationsReq struct { | ||||||
| 	CallbackCommand       `json:"callbackCommand"` | 	CallbackCommand       `json:"callbackCommand"` | ||||||
| 	RecvID           string `json:"recvID"` | 	OwnerUserID           string    `json:"owner_user_id"` | ||||||
| 	SendID           string `json:"sendID"` | 	ConversationID        string    `json:"conversation_id"` | ||||||
| 	ConversationID   string `json:"conversationID"` | 	ConversationType      int32     `json:"conversation_type"` | ||||||
| 	ConversationType int32  `json:"conversationType"` | 	UserID                string    `json:"user_id"` | ||||||
|  | 	GroupID               string    `json:"group_id"` | ||||||
|  | 	RecvMsgOpt            int32     `json:"recv_msg_opt"` | ||||||
|  | 	IsPinned              bool      `json:"is_pinned"` | ||||||
|  | 	IsPrivateChat         bool      `json:"is_private_chat"` | ||||||
|  | 	BurnDuration          int32     `json:"burn_duration"` | ||||||
|  | 	GroupAtType           int32     `json:"group_at_type"` | ||||||
|  | 	AttachedInfo          string    `json:"attached_info"` | ||||||
|  | 	Ex                    string    `json:"ex"` | ||||||
|  | 	MaxSeq                int64     `json:"max_seq"` | ||||||
|  | 	MinSeq                int64     `json:"min_seq"` | ||||||
|  | 	CreateTime            time.Time `json:"create_time"` | ||||||
|  | 	IsMsgDestruct         bool      `json:"is_msg_destruct"` | ||||||
|  | 	MsgDestructTime       int64     `json:"msg_destruct_time"` | ||||||
|  | 	LatestMsgDestructTime time.Time `json:"latest_msg_destruct_time"` | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| type CallbackAfterCreateSingleChatConversationsResp struct { | type CallbackAfterCreateSingleChatConversationsResp struct { | ||||||
| @ -30,20 +95,68 @@ type CallbackAfterCreateSingleChatConversationsResp struct { | |||||||
| 
 | 
 | ||||||
| type CallbackBeforeCreateGroupChatConversationsReq struct { | type CallbackBeforeCreateGroupChatConversationsReq struct { | ||||||
| 	CallbackCommand       `json:"callbackCommand"` | 	CallbackCommand       `json:"callbackCommand"` | ||||||
| 	UserIDs         []string `json:"userIDs"` | 	OwnerUserID           string    `json:"owner_user_id"` | ||||||
| 	GroupID         string   `json:"groupID"` | 	ConversationID        string    `json:"conversation_id"` | ||||||
|  | 	ConversationType      int32     `json:"conversation_type"` | ||||||
|  | 	UserID                string    `json:"user_id"` | ||||||
|  | 	GroupID               string    `json:"group_id"` | ||||||
|  | 	RecvMsgOpt            int32     `json:"recv_msg_opt"` | ||||||
|  | 	IsPinned              bool      `json:"is_pinned"` | ||||||
|  | 	IsPrivateChat         bool      `json:"is_private_chat"` | ||||||
|  | 	BurnDuration          int32     `json:"burn_duration"` | ||||||
|  | 	GroupAtType           int32     `json:"group_at_type"` | ||||||
|  | 	AttachedInfo          string    `json:"attached_info"` | ||||||
|  | 	Ex                    string    `json:"ex"` | ||||||
|  | 	MaxSeq                int64     `json:"max_seq"` | ||||||
|  | 	MinSeq                int64     `json:"min_seq"` | ||||||
|  | 	CreateTime            time.Time `json:"create_time"` | ||||||
|  | 	IsMsgDestruct         bool      `json:"is_msg_destruct"` | ||||||
|  | 	MsgDestructTime       int64     `json:"msg_destruct_time"` | ||||||
|  | 	LatestMsgDestructTime time.Time `json:"latest_msg_destruct_time"` | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| type CallbackBeforeCreateGroupChatConversationsResp struct { | type CallbackBeforeCreateGroupChatConversationsResp struct { | ||||||
| 	CommonCallbackResp | 	CommonCallbackResp | ||||||
| 	UserIDs *[]string `json:"userIDs"` | 	OwnerUserID           *string    `json:"owner_user_id"` | ||||||
| 	GroupID *string   `json:"groupID"` | 	ConversationID        *string    `json:"conversation_id"` | ||||||
|  | 	ConversationType      *int32     `json:"conversation_type"` | ||||||
|  | 	UserID                *string    `json:"user_id"` | ||||||
|  | 	GroupID               *string    `json:"group_id"` | ||||||
|  | 	RecvMsgOpt            *int32     `json:"recv_msg_opt"` | ||||||
|  | 	IsPinned              *bool      `json:"is_pinned"` | ||||||
|  | 	IsPrivateChat         *bool      `json:"is_private_chat"` | ||||||
|  | 	BurnDuration          *int32     `json:"burn_duration"` | ||||||
|  | 	GroupAtType           *int32     `json:"group_at_type"` | ||||||
|  | 	AttachedInfo          *string    `json:"attached_info"` | ||||||
|  | 	Ex                    *string    `json:"ex"` | ||||||
|  | 	MaxSeq                *int64     `json:"max_seq"` | ||||||
|  | 	MinSeq                *int64     `json:"min_seq"` | ||||||
|  | 	CreateTime            *time.Time `json:"create_time"` | ||||||
|  | 	IsMsgDestruct         *bool      `json:"is_msg_destruct"` | ||||||
|  | 	MsgDestructTime       *int64     `json:"msg_destruct_time"` | ||||||
|  | 	LatestMsgDestructTime *time.Time `json:"latest_msg_destruct_time"` | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| type CallbackAfterCreateGroupChatConversationsReq struct { | type CallbackAfterCreateGroupChatConversationsReq struct { | ||||||
| 	CallbackCommand       `json:"callbackCommand"` | 	CallbackCommand       `json:"callbackCommand"` | ||||||
| 	UserIDs         []string `json:"userIDs"` | 	OwnerUserID           string    `json:"owner_user_id"` | ||||||
| 	GroupID         string   `json:"groupID"` | 	ConversationID        string    `json:"conversation_id"` | ||||||
|  | 	ConversationType      int32     `json:"conversation_type"` | ||||||
|  | 	UserID                string    `json:"user_id"` | ||||||
|  | 	GroupID               string    `json:"group_id"` | ||||||
|  | 	RecvMsgOpt            int32     `json:"recv_msg_opt"` | ||||||
|  | 	IsPinned              bool      `json:"is_pinned"` | ||||||
|  | 	IsPrivateChat         bool      `json:"is_private_chat"` | ||||||
|  | 	BurnDuration          int32     `json:"burn_duration"` | ||||||
|  | 	GroupAtType           int32     `json:"group_at_type"` | ||||||
|  | 	AttachedInfo          string    `json:"attached_info"` | ||||||
|  | 	Ex                    string    `json:"ex"` | ||||||
|  | 	MaxSeq                int64     `json:"max_seq"` | ||||||
|  | 	MinSeq                int64     `json:"min_seq"` | ||||||
|  | 	CreateTime            time.Time `json:"create_time"` | ||||||
|  | 	IsMsgDestruct         bool      `json:"is_msg_destruct"` | ||||||
|  | 	MsgDestructTime       int64     `json:"msg_destruct_time"` | ||||||
|  | 	LatestMsgDestructTime time.Time `json:"latest_msg_destruct_time"` | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| type CallbackAfterCreateGroupChatConversationsResp struct { | type CallbackAfterCreateGroupChatConversationsResp struct { | ||||||
|  | |||||||
| @ -41,6 +41,7 @@ func NewConversationRpcCmd() *ConversationRpcCmd { | |||||||
| 		config.MongodbConfigFileName:            &conversationConfig.MongodbConfig, | 		config.MongodbConfigFileName:            &conversationConfig.MongodbConfig, | ||||||
| 		config.ShareFileName:                    &conversationConfig.Share, | 		config.ShareFileName:                    &conversationConfig.Share, | ||||||
| 		config.NotificationFileName:             &conversationConfig.NotificationConfig, | 		config.NotificationFileName:             &conversationConfig.NotificationConfig, | ||||||
|  | 		config.WebhooksConfigFileName:           &conversationConfig.WebhooksConfig, | ||||||
| 		config.LocalCacheConfigFileName:         &conversationConfig.LocalCacheConfig, | 		config.LocalCacheConfigFileName:         &conversationConfig.LocalCacheConfig, | ||||||
| 		config.DiscoveryConfigFilename:          &conversationConfig.Discovery, | 		config.DiscoveryConfigFilename:          &conversationConfig.Discovery, | ||||||
| 	} | 	} | ||||||
| @ -67,6 +68,7 @@ func (a *ConversationRpcCmd) runE() error { | |||||||
| 			a.conversationConfig.NotificationConfig.GetConfigFileName(), | 			a.conversationConfig.NotificationConfig.GetConfigFileName(), | ||||||
| 			a.conversationConfig.Share.GetConfigFileName(), | 			a.conversationConfig.Share.GetConfigFileName(), | ||||||
| 			a.conversationConfig.LocalCacheConfig.GetConfigFileName(), | 			a.conversationConfig.LocalCacheConfig.GetConfigFileName(), | ||||||
|  | 			a.conversationConfig.WebhooksConfig.GetConfigFileName(), | ||||||
| 			a.conversationConfig.Discovery.GetConfigFileName(), | 			a.conversationConfig.Discovery.GetConfigFileName(), | ||||||
| 		}, nil, | 		}, nil, | ||||||
| 		conversation.Start) | 		conversation.Start) | ||||||
|  | |||||||
| @ -22,7 +22,6 @@ import ( | |||||||
| 	relationtb "github.com/openimsdk/open-im-server/v3/pkg/common/storage/model" | 	relationtb "github.com/openimsdk/open-im-server/v3/pkg/common/storage/model" | ||||||
| 
 | 
 | ||||||
| 	"github.com/openimsdk/open-im-server/v3/pkg/common/storage/cache" | 	"github.com/openimsdk/open-im-server/v3/pkg/common/storage/cache" | ||||||
| 	"github.com/openimsdk/open-im-server/v3/pkg/msgprocessor" |  | ||||||
| 	"github.com/openimsdk/protocol/constant" | 	"github.com/openimsdk/protocol/constant" | ||||||
| 	"github.com/openimsdk/tools/db/pagination" | 	"github.com/openimsdk/tools/db/pagination" | ||||||
| 	"github.com/openimsdk/tools/db/tx" | 	"github.com/openimsdk/tools/db/tx" | ||||||
| @ -48,7 +47,7 @@ type ConversationDatabase interface { | |||||||
| 	// transactional. | 	// transactional. | ||||||
| 	SetUsersConversationFieldTx(ctx context.Context, userIDs []string, conversation *relationtb.Conversation, fieldMap map[string]any) error | 	SetUsersConversationFieldTx(ctx context.Context, userIDs []string, conversation *relationtb.Conversation, fieldMap map[string]any) error | ||||||
| 	// CreateGroupChatConversation creates a group chat conversation for the specified group ID and user IDs. | 	// CreateGroupChatConversation creates a group chat conversation for the specified group ID and user IDs. | ||||||
| 	CreateGroupChatConversation(ctx context.Context, groupID string, userIDs []string) error | 	CreateGroupChatConversation(ctx context.Context, groupID string, userIDs []string, conversations *relationtb.Conversation) error | ||||||
| 	// GetConversationIDs retrieves conversation IDs for a given user. | 	// GetConversationIDs retrieves conversation IDs for a given user. | ||||||
| 	GetConversationIDs(ctx context.Context, userID string) ([]string, error) | 	GetConversationIDs(ctx context.Context, userID string) ([]string, error) | ||||||
| 	// GetUserConversationIDsHash gets the hash of conversation IDs for a given user. | 	// GetUserConversationIDsHash gets the hash of conversation IDs for a given user. | ||||||
| @ -298,10 +297,10 @@ func (c *conversationDatabase) SetUserConversations(ctx context.Context, ownerUs | |||||||
| //	return c.cache.GetSuperGroupRecvMsgNotNotifyUserIDs(ctx, groupID) | //	return c.cache.GetSuperGroupRecvMsgNotNotifyUserIDs(ctx, groupID) | ||||||
| //} | //} | ||||||
| 
 | 
 | ||||||
| func (c *conversationDatabase) CreateGroupChatConversation(ctx context.Context, groupID string, userIDs []string) error { | func (c *conversationDatabase) CreateGroupChatConversation(ctx context.Context, groupID string, userIDs []string, conversation *relationtb.Conversation) error { | ||||||
| 	return c.tx.Transaction(ctx, func(ctx context.Context) error { | 	return c.tx.Transaction(ctx, func(ctx context.Context) error { | ||||||
| 		cache := c.cache.CloneConversationCache() | 		cache := c.cache.CloneConversationCache() | ||||||
| 		conversationID := msgprocessor.GetConversationIDBySessionType(constant.ReadGroupChatType, groupID) | 		conversationID := conversation.ConversationID | ||||||
| 		existConversationUserIDs, err := c.conversationDB.FindUserID(ctx, userIDs, []string{conversationID}) | 		existConversationUserIDs, err := c.conversationDB.FindUserID(ctx, userIDs, []string{conversationID}) | ||||||
| 		if err != nil { | 		if err != nil { | ||||||
| 			return err | 			return err | ||||||
| @ -309,7 +308,7 @@ func (c *conversationDatabase) CreateGroupChatConversation(ctx context.Context, | |||||||
| 		notExistUserIDs := stringutil.DifferenceString(userIDs, existConversationUserIDs) | 		notExistUserIDs := stringutil.DifferenceString(userIDs, existConversationUserIDs) | ||||||
| 		var conversations []*relationtb.Conversation | 		var conversations []*relationtb.Conversation | ||||||
| 		for _, v := range notExistUserIDs { | 		for _, v := range notExistUserIDs { | ||||||
| 			conversation := relationtb.Conversation{ConversationType: constant.ReadGroupChatType, GroupID: groupID, OwnerUserID: v, ConversationID: conversationID} | 			conversation := relationtb.Conversation{ConversationType: conversation.ConversationType, GroupID: groupID, OwnerUserID: v, ConversationID: conversationID} | ||||||
| 			conversations = append(conversations, &conversation) | 			conversations = append(conversations, &conversation) | ||||||
| 			cache = cache.DelConversations(v, conversationID).DelConversationNotReceiveMessageUserIDs(conversationID) | 			cache = cache.DelConversations(v, conversationID).DelConversationNotReceiveMessageUserIDs(conversationID) | ||||||
| 		} | 		} | ||||||
| @ -320,7 +319,7 @@ func (c *conversationDatabase) CreateGroupChatConversation(ctx context.Context, | |||||||
| 				return err | 				return err | ||||||
| 			} | 			} | ||||||
| 		} | 		} | ||||||
| 		_, err = c.conversationDB.UpdateByMap(ctx, existConversationUserIDs, conversationID, map[string]any{"max_seq": 0}) | 		_, err = c.conversationDB.UpdateByMap(ctx, existConversationUserIDs, conversationID, map[string]any{"max_seq": conversation.MaxSeq}) | ||||||
| 		if err != nil { | 		if err != nil { | ||||||
| 			return err | 			return err | ||||||
| 		} | 		} | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user