|
|
@ -41,11 +41,12 @@ import (
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
type friendServer struct {
|
|
|
|
type friendServer struct {
|
|
|
|
friendDatabase controller.FriendDatabase
|
|
|
|
friendDatabase controller.FriendDatabase
|
|
|
|
blackDatabase controller.BlackDatabase
|
|
|
|
blackDatabase controller.BlackDatabase
|
|
|
|
userRpcClient *rpcclient.UserRpcClient
|
|
|
|
userRpcClient *rpcclient.UserRpcClient
|
|
|
|
notificationSender *notification.FriendNotificationSender
|
|
|
|
notificationSender *notification.FriendNotificationSender
|
|
|
|
RegisterCenter registry.SvcDiscoveryRegistry
|
|
|
|
conversationRpcClient rpcclient.ConversationRpcClient
|
|
|
|
|
|
|
|
RegisterCenter registry.SvcDiscoveryRegistry
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func Start(client registry.SvcDiscoveryRegistry, server *grpc.Server) error {
|
|
|
|
func Start(client registry.SvcDiscoveryRegistry, server *grpc.Server) error {
|
|
|
@ -79,9 +80,10 @@ func Start(client registry.SvcDiscoveryRegistry, server *grpc.Server) error {
|
|
|
|
blackDB,
|
|
|
|
blackDB,
|
|
|
|
cache.NewBlackCacheRedis(rdb, blackDB, cache.GetDefaultOpt()),
|
|
|
|
cache.NewBlackCacheRedis(rdb, blackDB, cache.GetDefaultOpt()),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
userRpcClient: &userRpcClient,
|
|
|
|
userRpcClient: &userRpcClient,
|
|
|
|
notificationSender: notificationSender,
|
|
|
|
notificationSender: notificationSender,
|
|
|
|
RegisterCenter: client,
|
|
|
|
RegisterCenter: client,
|
|
|
|
|
|
|
|
conversationRpcClient: rpcclient.NewConversationRpcClient(client),
|
|
|
|
})
|
|
|
|
})
|
|
|
|
return nil
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -131,17 +133,20 @@ func (s *friendServer) ImportFriends(
|
|
|
|
if _, err := s.userRpcClient.GetUsersInfo(ctx, append([]string{req.OwnerUserID}, req.FriendUserIDs...)); err != nil {
|
|
|
|
if _, err := s.userRpcClient.GetUsersInfo(ctx, append([]string{req.OwnerUserID}, req.FriendUserIDs...)); err != nil {
|
|
|
|
return nil, err
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if utils.Contain(req.OwnerUserID, req.FriendUserIDs...) {
|
|
|
|
if utils.Contain(req.OwnerUserID, req.FriendUserIDs...) {
|
|
|
|
return nil, errs.ErrCanNotAddYourself.Wrap()
|
|
|
|
return nil, errs.ErrCanNotAddYourself.Wrap()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if utils.Duplicate(req.FriendUserIDs) {
|
|
|
|
if utils.Duplicate(req.FriendUserIDs) {
|
|
|
|
return nil, errs.ErrArgs.Wrap("friend userID repeated")
|
|
|
|
return nil, errs.ErrArgs.Wrap("friend userID repeated")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if err := s.friendDatabase.BecomeFriends(ctx, req.OwnerUserID, req.FriendUserIDs, constant.BecomeFriendByImport); err != nil {
|
|
|
|
if err := s.friendDatabase.BecomeFriends(ctx, req.OwnerUserID, req.FriendUserIDs, constant.BecomeFriendByImport); err != nil {
|
|
|
|
return nil, err
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, userID := range req.FriendUserIDs {
|
|
|
|
|
|
|
|
if err := s.conversationRpcClient.SingleChatFirstCreateConversation(ctx, req.OwnerUserID, userID); err != nil {
|
|
|
|
|
|
|
|
log.ZError(ctx, "ImportFriends SingleChatFirstCreateConversation", err, "ownerUserID", req.OwnerUserID, "friendUserID", userID)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
return &pbfriend.ImportFriendResp{}, nil
|
|
|
|
return &pbfriend.ImportFriendResp{}, nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|