mirror of
https://github.com/openimsdk/open-im-server.git
synced 2026-04-28 14:29:19 +08:00
style: add format
Signed-off-by: Xinwei Xiong(cubxxw-openim) <3293172751nss@gmail.com>
This commit is contained in:
@@ -3,6 +3,8 @@ package conversation
|
||||
import (
|
||||
"context"
|
||||
|
||||
"google.golang.org/grpc"
|
||||
|
||||
"github.com/OpenIMSDK/Open-IM-Server/pkg/common/constant"
|
||||
"github.com/OpenIMSDK/Open-IM-Server/pkg/common/convert"
|
||||
"github.com/OpenIMSDK/Open-IM-Server/pkg/common/db/cache"
|
||||
@@ -17,7 +19,6 @@ import (
|
||||
"github.com/OpenIMSDK/Open-IM-Server/pkg/rpcclient"
|
||||
"github.com/OpenIMSDK/Open-IM-Server/pkg/rpcclient/notification"
|
||||
"github.com/OpenIMSDK/Open-IM-Server/pkg/utils"
|
||||
"google.golang.org/grpc"
|
||||
)
|
||||
|
||||
type conversationServer struct {
|
||||
@@ -44,12 +45,19 @@ func Start(client discoveryregistry.SvcDiscoveryRegistry, server *grpc.Server) e
|
||||
pbConversation.RegisterConversationServer(server, &conversationServer{
|
||||
conversationNotificationSender: notification.NewConversationNotificationSender(&msgRpcClient),
|
||||
groupRpcClient: &groupRpcClient,
|
||||
conversationDatabase: controller.NewConversationDatabase(conversationDB, cache.NewConversationRedis(rdb, cache.GetDefaultOpt(), conversationDB), tx.NewGorm(db)),
|
||||
conversationDatabase: controller.NewConversationDatabase(
|
||||
conversationDB,
|
||||
cache.NewConversationRedis(rdb, cache.GetDefaultOpt(), conversationDB),
|
||||
tx.NewGorm(db),
|
||||
),
|
||||
})
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c *conversationServer) GetConversation(ctx context.Context, req *pbConversation.GetConversationReq) (*pbConversation.GetConversationResp, error) {
|
||||
func (c *conversationServer) GetConversation(
|
||||
ctx context.Context,
|
||||
req *pbConversation.GetConversationReq,
|
||||
) (*pbConversation.GetConversationResp, error) {
|
||||
conversations, err := c.conversationDatabase.FindConversations(ctx, req.OwnerUserID, []string{req.ConversationID})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -62,7 +70,10 @@ func (c *conversationServer) GetConversation(ctx context.Context, req *pbConvers
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
func (c *conversationServer) GetAllConversations(ctx context.Context, req *pbConversation.GetAllConversationsReq) (*pbConversation.GetAllConversationsResp, error) {
|
||||
func (c *conversationServer) GetAllConversations(
|
||||
ctx context.Context,
|
||||
req *pbConversation.GetAllConversationsReq,
|
||||
) (*pbConversation.GetAllConversationsResp, error) {
|
||||
conversations, err := c.conversationDatabase.GetUserAllConversation(ctx, req.OwnerUserID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -72,7 +83,10 @@ func (c *conversationServer) GetAllConversations(ctx context.Context, req *pbCon
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
func (c *conversationServer) GetConversations(ctx context.Context, req *pbConversation.GetConversationsReq) (*pbConversation.GetConversationsResp, error) {
|
||||
func (c *conversationServer) GetConversations(
|
||||
ctx context.Context,
|
||||
req *pbConversation.GetConversationsReq,
|
||||
) (*pbConversation.GetConversationsResp, error) {
|
||||
conversations, err := c.conversationDatabase.FindConversations(ctx, req.OwnerUserID, req.ConversationIDs)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -82,7 +96,10 @@ func (c *conversationServer) GetConversations(ctx context.Context, req *pbConver
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
func (c *conversationServer) BatchSetConversations(ctx context.Context, req *pbConversation.BatchSetConversationsReq) (*pbConversation.BatchSetConversationsResp, error) {
|
||||
func (c *conversationServer) BatchSetConversations(
|
||||
ctx context.Context,
|
||||
req *pbConversation.BatchSetConversationsReq,
|
||||
) (*pbConversation.BatchSetConversationsResp, error) {
|
||||
conversations := convert.ConversationsPb2DB(req.Conversations)
|
||||
err := c.conversationDatabase.SetUserConversations(ctx, req.OwnerUserID, conversations)
|
||||
if err != nil {
|
||||
@@ -92,12 +109,19 @@ func (c *conversationServer) BatchSetConversations(ctx context.Context, req *pbC
|
||||
return &pbConversation.BatchSetConversationsResp{}, nil
|
||||
}
|
||||
|
||||
func (c *conversationServer) SetConversation(ctx context.Context, req *pbConversation.SetConversationReq) (*pbConversation.SetConversationResp, error) {
|
||||
func (c *conversationServer) SetConversation(
|
||||
ctx context.Context,
|
||||
req *pbConversation.SetConversationReq,
|
||||
) (*pbConversation.SetConversationResp, error) {
|
||||
var conversation tableRelation.ConversationModel
|
||||
if err := utils.CopyStructFields(&conversation, req.Conversation); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
err := c.conversationDatabase.SetUserConversations(ctx, req.Conversation.OwnerUserID, []*tableRelation.ConversationModel{&conversation})
|
||||
err := c.conversationDatabase.SetUserConversations(
|
||||
ctx,
|
||||
req.Conversation.OwnerUserID,
|
||||
[]*tableRelation.ConversationModel{&conversation},
|
||||
)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -106,7 +130,10 @@ func (c *conversationServer) SetConversation(ctx context.Context, req *pbConvers
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
func (c *conversationServer) SetRecvMsgOpt(ctx context.Context, req *pbConversation.SetRecvMsgOptReq) (*pbConversation.SetRecvMsgOptResp, error) {
|
||||
func (c *conversationServer) SetRecvMsgOpt(
|
||||
ctx context.Context,
|
||||
req *pbConversation.SetRecvMsgOptReq,
|
||||
) (*pbConversation.SetRecvMsgOptResp, error) {
|
||||
if err := c.conversationDatabase.SetUsersConversationFiledTx(ctx, []string{req.OwnerUserID}, &tableRelation.ConversationModel{OwnerUserID: req.OwnerUserID, ConversationID: req.ConversationID, RecvMsgOpt: req.RecvMsgOpt}, map[string]interface{}{"recv_msg_opt": req.RecvMsgOpt}); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -115,7 +142,10 @@ func (c *conversationServer) SetRecvMsgOpt(ctx context.Context, req *pbConversat
|
||||
}
|
||||
|
||||
// deprecated
|
||||
func (c *conversationServer) ModifyConversationField(ctx context.Context, req *pbConversation.ModifyConversationFieldReq) (*pbConversation.ModifyConversationFieldResp, error) {
|
||||
func (c *conversationServer) ModifyConversationField(
|
||||
ctx context.Context,
|
||||
req *pbConversation.ModifyConversationFieldReq,
|
||||
) (*pbConversation.ModifyConversationFieldResp, error) {
|
||||
resp := &pbConversation.ModifyConversationFieldResp{}
|
||||
var err error
|
||||
if req.Conversation.ConversationType == constant.GroupChatType {
|
||||
@@ -129,11 +159,19 @@ func (c *conversationServer) ModifyConversationField(ctx context.Context, req *p
|
||||
}
|
||||
conversation := convert.ConversationPb2DB(req.Conversation)
|
||||
if req.FieldType == constant.FieldIsPrivateChat {
|
||||
err := c.conversationDatabase.SyncPeerUserPrivateConversationTx(ctx, []*tableRelation.ConversationModel{conversation})
|
||||
err := c.conversationDatabase.SyncPeerUserPrivateConversationTx(
|
||||
ctx,
|
||||
[]*tableRelation.ConversationModel{conversation},
|
||||
)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
c.conversationNotificationSender.ConversationSetPrivateNotification(ctx, req.Conversation.OwnerUserID, req.Conversation.UserID, req.Conversation.IsPrivateChat)
|
||||
c.conversationNotificationSender.ConversationSetPrivateNotification(
|
||||
ctx,
|
||||
req.Conversation.OwnerUserID,
|
||||
req.Conversation.UserID,
|
||||
req.Conversation.IsPrivateChat,
|
||||
)
|
||||
return resp, nil
|
||||
}
|
||||
filedMap := make(map[string]interface{})
|
||||
@@ -161,7 +199,10 @@ func (c *conversationServer) ModifyConversationField(ctx context.Context, req *p
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
func (c *conversationServer) SetConversations(ctx context.Context, req *pbConversation.SetConversationsReq) (*pbConversation.SetConversationsResp, error) {
|
||||
func (c *conversationServer) SetConversations(
|
||||
ctx context.Context,
|
||||
req *pbConversation.SetConversationsReq,
|
||||
) (*pbConversation.SetConversationsResp, error) {
|
||||
if req.Conversation == nil {
|
||||
return nil, errs.ErrArgs.Wrap("conversation must not be nil")
|
||||
}
|
||||
@@ -207,7 +248,12 @@ func (c *conversationServer) SetConversations(ctx context.Context, req *pbConver
|
||||
return nil, err
|
||||
}
|
||||
for _, ownerUserID := range req.UserIDs {
|
||||
c.conversationNotificationSender.ConversationSetPrivateNotification(ctx, ownerUserID, req.Conversation.UserID, req.Conversation.IsPrivateChat.Value)
|
||||
c.conversationNotificationSender.ConversationSetPrivateNotification(
|
||||
ctx,
|
||||
ownerUserID,
|
||||
req.Conversation.UserID,
|
||||
req.Conversation.IsPrivateChat.Value,
|
||||
)
|
||||
}
|
||||
}
|
||||
if req.Conversation.BurnDuration != nil {
|
||||
@@ -224,7 +270,10 @@ func (c *conversationServer) SetConversations(ctx context.Context, req *pbConver
|
||||
}
|
||||
|
||||
// 获取超级大群开启免打扰的用户ID
|
||||
func (c *conversationServer) GetRecvMsgNotNotifyUserIDs(ctx context.Context, req *pbConversation.GetRecvMsgNotNotifyUserIDsReq) (*pbConversation.GetRecvMsgNotNotifyUserIDsResp, error) {
|
||||
func (c *conversationServer) GetRecvMsgNotNotifyUserIDs(
|
||||
ctx context.Context,
|
||||
req *pbConversation.GetRecvMsgNotNotifyUserIDsReq,
|
||||
) (*pbConversation.GetRecvMsgNotNotifyUserIDsResp, error) {
|
||||
userIDs, err := c.conversationDatabase.FindRecvMsgNotNotifyUserIDs(ctx, req.GroupID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -233,7 +282,10 @@ func (c *conversationServer) GetRecvMsgNotNotifyUserIDs(ctx context.Context, req
|
||||
}
|
||||
|
||||
// create conversation without notification for msg redis transfer
|
||||
func (c *conversationServer) CreateSingleChatConversations(ctx context.Context, req *pbConversation.CreateSingleChatConversationsReq) (*pbConversation.CreateSingleChatConversationsResp, error) {
|
||||
func (c *conversationServer) CreateSingleChatConversations(
|
||||
ctx context.Context,
|
||||
req *pbConversation.CreateSingleChatConversationsReq,
|
||||
) (*pbConversation.CreateSingleChatConversationsResp, error) {
|
||||
var conversation tableRelation.ConversationModel
|
||||
conversation.ConversationID = utils.GetConversationIDBySessionType(constant.SingleChatType, req.RecvID, req.SendID)
|
||||
conversation.ConversationType = constant.SingleChatType
|
||||
@@ -254,7 +306,10 @@ func (c *conversationServer) CreateSingleChatConversations(ctx context.Context,
|
||||
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) {
|
||||
err := c.conversationDatabase.CreateGroupChatConversation(ctx, req.GroupID, req.UserIDs)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -262,7 +317,10 @@ func (c *conversationServer) CreateGroupChatConversations(ctx context.Context, r
|
||||
return &pbConversation.CreateGroupChatConversationsResp{}, nil
|
||||
}
|
||||
|
||||
func (c *conversationServer) SetConversationMaxSeq(ctx context.Context, req *pbConversation.SetConversationMaxSeqReq) (*pbConversation.SetConversationMaxSeqResp, error) {
|
||||
func (c *conversationServer) SetConversationMaxSeq(
|
||||
ctx context.Context,
|
||||
req *pbConversation.SetConversationMaxSeqReq,
|
||||
) (*pbConversation.SetConversationMaxSeqResp, error) {
|
||||
if err := c.conversationDatabase.UpdateUsersConversationFiled(ctx, req.OwnerUserID, req.ConversationID,
|
||||
map[string]interface{}{"max_seq": req.MaxSeq}); err != nil {
|
||||
return nil, err
|
||||
@@ -270,7 +328,10 @@ func (c *conversationServer) SetConversationMaxSeq(ctx context.Context, req *pbC
|
||||
return &pbConversation.SetConversationMaxSeqResp{}, nil
|
||||
}
|
||||
|
||||
func (c *conversationServer) GetConversationIDs(ctx context.Context, req *pbConversation.GetConversationIDsReq) (*pbConversation.GetConversationIDsResp, error) {
|
||||
func (c *conversationServer) GetConversationIDs(
|
||||
ctx context.Context,
|
||||
req *pbConversation.GetConversationIDsReq,
|
||||
) (*pbConversation.GetConversationIDsResp, error) {
|
||||
conversationIDs, err := c.conversationDatabase.GetConversationIDs(ctx, req.UserID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -278,7 +339,10 @@ func (c *conversationServer) GetConversationIDs(ctx context.Context, req *pbConv
|
||||
return &pbConversation.GetConversationIDsResp{ConversationIDs: conversationIDs}, nil
|
||||
}
|
||||
|
||||
func (c *conversationServer) GetUserConversationIDsHash(ctx context.Context, req *pbConversation.GetUserConversationIDsHashReq) (*pbConversation.GetUserConversationIDsHashResp, error) {
|
||||
func (c *conversationServer) GetUserConversationIDsHash(
|
||||
ctx context.Context,
|
||||
req *pbConversation.GetUserConversationIDsHashReq,
|
||||
) (*pbConversation.GetUserConversationIDsHashResp, error) {
|
||||
hash, err := c.conversationDatabase.GetUserConversationIDsHash(ctx, req.OwnerUserID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -286,10 +350,15 @@ func (c *conversationServer) GetUserConversationIDsHash(ctx context.Context, req
|
||||
return &pbConversation.GetUserConversationIDsHashResp{Hash: hash}, nil
|
||||
}
|
||||
|
||||
func (c *conversationServer) GetConversationsByConversationID(ctx context.Context, req *pbConversation.GetConversationsByConversationIDReq) (*pbConversation.GetConversationsByConversationIDResp, error) {
|
||||
func (c *conversationServer) GetConversationsByConversationID(
|
||||
ctx context.Context,
|
||||
req *pbConversation.GetConversationsByConversationIDReq,
|
||||
) (*pbConversation.GetConversationsByConversationIDResp, error) {
|
||||
conversations, err := c.conversationDatabase.GetConversationsByConversationID(ctx, req.ConversationIDs)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &pbConversation.GetConversationsByConversationIDResp{Conversations: convert.ConversationsDB2Pb(conversations)}, nil
|
||||
return &pbConversation.GetConversationsByConversationIDResp{
|
||||
Conversations: convert.ConversationsDB2Pb(conversations),
|
||||
}, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user