@ -16,6 +16,7 @@ package friend
import (
import (
"context"
"context"
"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/database/mgo"
"github.com/openimsdk/open-im-server/v3/pkg/common/storage/database/mgo"
@ -30,7 +31,7 @@ import (
"github.com/openimsdk/open-im-server/v3/pkg/common/storage/controller"
"github.com/openimsdk/open-im-server/v3/pkg/common/storage/controller"
"github.com/openimsdk/open-im-server/v3/pkg/rpcclient"
"github.com/openimsdk/open-im-server/v3/pkg/rpcclient"
"github.com/openimsdk/protocol/constant"
"github.com/openimsdk/protocol/constant"
pbfriend "github.com/openimsdk/protocol/ f ri end "
"github.com/openimsdk/protocol/ relatio n"
"github.com/openimsdk/protocol/sdkws"
"github.com/openimsdk/protocol/sdkws"
"github.com/openimsdk/tools/db/mongoutil"
"github.com/openimsdk/tools/db/mongoutil"
"github.com/openimsdk/tools/discovery"
"github.com/openimsdk/tools/discovery"
@ -40,7 +41,7 @@ import (
)
)
type friendServer struct {
type friendServer struct {
frien dData base controller . FriendDatabase
db controller . FriendDatabase
blackDatabase controller . BlackDatabase
blackDatabase controller . BlackDatabase
userRpcClient * rpcclient . UserRpcClient
userRpcClient * rpcclient . UserRpcClient
notificationSender * FriendNotificationSender
notificationSender * FriendNotificationSender
@ -54,7 +55,7 @@ type Config struct {
RpcConfig config . Friend
RpcConfig config . Friend
RedisConfig config . Redis
RedisConfig config . Redis
MongodbConfig config . Mongo
MongodbConfig config . Mongo
// ZookeeperConfig config.ZooKeeper
// ZookeeperConfig config.ZooKeeper
NotificationConfig config . Notification
NotificationConfig config . Notification
Share config . Share
Share config . Share
WebhooksConfig config . Webhooks
WebhooksConfig config . Webhooks
@ -100,8 +101,8 @@ func Start(ctx context.Context, config *Config, client discovery.SvcDiscoveryReg
localcache . InitLocalCache ( & config . LocalCacheConfig )
localcache . InitLocalCache ( & config . LocalCacheConfig )
// Register Friend server with refactored MongoDB and Redis integrations
// Register Friend server with refactored MongoDB and Redis integrations
pbf ri end . RegisterFriendServer ( server , & friendServer {
relatio n. RegisterFriendServer ( server , & friendServer {
frien dData base : controller . NewFriendDatabase (
db: controller . NewFriendDatabase (
friendMongoDB ,
friendMongoDB ,
friendRequestMongoDB ,
friendRequestMongoDB ,
redis . NewFriendCacheRedis ( rdb , & config . LocalCacheConfig , friendMongoDB , redis . GetRocksCacheOptions ( ) ) ,
redis . NewFriendCacheRedis ( rdb , & config . LocalCacheConfig , friendMongoDB , redis . GetRocksCacheOptions ( ) ) ,
@ -123,8 +124,8 @@ func Start(ctx context.Context, config *Config, client discovery.SvcDiscoveryReg
}
}
// ok.
// ok.
func ( s * friendServer ) ApplyToAddFriend ( ctx context . Context , req * pbf ri end . ApplyToAddFriendReq ) ( resp * pbf ri end . ApplyToAddFriendResp , err error ) {
func ( s * friendServer ) ApplyToAddFriend ( ctx context . Context , req * relatio n. ApplyToAddFriendReq ) ( resp * relatio n. ApplyToAddFriendResp , err error ) {
resp = & pbf ri end . ApplyToAddFriendResp { }
resp = & relatio n. ApplyToAddFriendResp { }
if err := authverify . CheckAccessV3 ( ctx , req . FromUserID , s . config . Share . IMAdminUserID ) ; err != nil {
if err := authverify . CheckAccessV3 ( ctx , req . FromUserID , s . config . Share . IMAdminUserID ) ; err != nil {
return nil , err
return nil , err
}
}
@ -138,14 +139,14 @@ func (s *friendServer) ApplyToAddFriend(ctx context.Context, req *pbfriend.Apply
return nil , err
return nil , err
}
}
in1 , in2 , err := s . frien dData base . CheckIn ( ctx , req . FromUserID , req . ToUserID )
in1 , in2 , err := s . db. CheckIn ( ctx , req . FromUserID , req . ToUserID )
if err != nil {
if err != nil {
return nil , err
return nil , err
}
}
if in1 && in2 {
if in1 && in2 {
return nil , servererrs . ErrRelationshipAlready . WrapMsg ( "already friends has f" )
return nil , servererrs . ErrRelationshipAlready . WrapMsg ( "already friends has f" )
}
}
if err = s . frien dData base . AddFriendRequest ( ctx , req . FromUserID , req . ToUserID , req . ReqMsg , req . Ex ) ; err != nil {
if err = s . db. AddFriendRequest ( ctx , req . FromUserID , req . ToUserID , req . ReqMsg , req . Ex ) ; err != nil {
return nil , err
return nil , err
}
}
s . notificationSender . FriendApplicationAddNotification ( ctx , req )
s . notificationSender . FriendApplicationAddNotification ( ctx , req )
@ -154,7 +155,7 @@ func (s *friendServer) ApplyToAddFriend(ctx context.Context, req *pbfriend.Apply
}
}
// ok.
// ok.
func ( s * friendServer ) ImportFriends ( ctx context . Context , req * pbf ri end . ImportFriendReq ) ( resp * pbf ri end . ImportFriendResp , err error ) {
func ( s * friendServer ) ImportFriends ( ctx context . Context , req * relatio n. ImportFriendReq ) ( resp * relatio n. ImportFriendResp , err error ) {
if err := authverify . CheckAdmin ( ctx , s . config . Share . IMAdminUserID ) ; err != nil {
if err := authverify . CheckAdmin ( ctx , s . config . Share . IMAdminUserID ) ; err != nil {
return nil , err
return nil , err
}
}
@ -172,11 +173,11 @@ func (s *friendServer) ImportFriends(ctx context.Context, req *pbfriend.ImportFr
return nil , err
return nil , err
}
}
if err := s . frien dData base . BecomeFriends ( ctx , req . OwnerUserID , req . FriendUserIDs , constant . BecomeFriendByImport ) ; err != nil {
if err := s . db. BecomeFriends ( ctx , req . OwnerUserID , req . FriendUserIDs , constant . BecomeFriendByImport ) ; err != nil {
return nil , err
return nil , err
}
}
for _ , userID := range req . FriendUserIDs {
for _ , userID := range req . FriendUserIDs {
s . notificationSender . FriendApplicationAgreedNotification ( ctx , & pbf ri end . RespondFriendApplyReq {
s . notificationSender . FriendApplicationAgreedNotification ( ctx , & relatio n. RespondFriendApplyReq {
FromUserID : req . OwnerUserID ,
FromUserID : req . OwnerUserID ,
ToUserID : userID ,
ToUserID : userID ,
HandleResult : constant . FriendResponseAgree ,
HandleResult : constant . FriendResponseAgree ,
@ -184,12 +185,12 @@ func (s *friendServer) ImportFriends(ctx context.Context, req *pbfriend.ImportFr
}
}
s . webhookAfterImportFriends ( ctx , & s . config . WebhooksConfig . AfterImportFriends , req )
s . webhookAfterImportFriends ( ctx , & s . config . WebhooksConfig . AfterImportFriends , req )
return & pbf ri end . ImportFriendResp { } , nil
return & relatio n. ImportFriendResp { } , nil
}
}
// ok.
// ok.
func ( s * friendServer ) RespondFriendApply ( ctx context . Context , req * pbf ri end . RespondFriendApplyReq ) ( resp * pbf ri end . RespondFriendApplyResp , err error ) {
func ( s * friendServer ) RespondFriendApply ( ctx context . Context , req * relatio n. RespondFriendApplyReq ) ( resp * relatio n. RespondFriendApplyResp , err error ) {
resp = & pbf ri end . RespondFriendApplyResp { }
resp = & relatio n. RespondFriendApplyResp { }
if err := authverify . CheckAccessV3 ( ctx , req . ToUserID , s . config . Share . IMAdminUserID ) ; err != nil {
if err := authverify . CheckAccessV3 ( ctx , req . ToUserID , s . config . Share . IMAdminUserID ) ; err != nil {
return nil , err
return nil , err
}
}
@ -204,7 +205,7 @@ func (s *friendServer) RespondFriendApply(ctx context.Context, req *pbfriend.Res
if err := s . webhookBeforeAddFriendAgree ( ctx , & s . config . WebhooksConfig . BeforeAddFriendAgree , req ) ; err != nil && err != servererrs . ErrCallbackContinue {
if err := s . webhookBeforeAddFriendAgree ( ctx , & s . config . WebhooksConfig . BeforeAddFriendAgree , req ) ; err != nil && err != servererrs . ErrCallbackContinue {
return nil , err
return nil , err
}
}
err := s . frien dData base . AgreeFriendRequest ( ctx , & friendRequest )
err := s . db. AgreeFriendRequest ( ctx , & friendRequest )
if err != nil {
if err != nil {
return nil , err
return nil , err
}
}
@ -212,7 +213,7 @@ func (s *friendServer) RespondFriendApply(ctx context.Context, req *pbfriend.Res
return resp , nil
return resp , nil
}
}
if req . HandleResult == constant . FriendResponseRefuse {
if req . HandleResult == constant . FriendResponseRefuse {
err := s . frien dData base . RefuseFriendRequest ( ctx , & friendRequest )
err := s . db. RefuseFriendRequest ( ctx , & friendRequest )
if err != nil {
if err != nil {
return nil , err
return nil , err
}
}
@ -223,16 +224,16 @@ func (s *friendServer) RespondFriendApply(ctx context.Context, req *pbfriend.Res
}
}
// ok.
// ok.
func ( s * friendServer ) DeleteFriend ( ctx context . Context , req * pbf ri end . DeleteFriendReq ) ( resp * pbf ri end . DeleteFriendResp , err error ) {
func ( s * friendServer ) DeleteFriend ( ctx context . Context , req * relatio n. DeleteFriendReq ) ( resp * relatio n. DeleteFriendResp , err error ) {
resp = & pbf ri end . DeleteFriendResp { }
resp = & relatio n. DeleteFriendResp { }
if err := s . userRpcClient . Access ( ctx , req . OwnerUserID ) ; err != nil {
if err := s . userRpcClient . Access ( ctx , req . OwnerUserID ) ; err != nil {
return nil , err
return nil , err
}
}
_ , err = s . frien dData base . FindFriendsWithError ( ctx , req . OwnerUserID , [ ] string { req . FriendUserID } )
_ , err = s . db. FindFriendsWithError ( ctx , req . OwnerUserID , [ ] string { req . FriendUserID } )
if err != nil {
if err != nil {
return nil , err
return nil , err
}
}
if err := s . frien dData base . Delete ( ctx , req . OwnerUserID , [ ] string { req . FriendUserID } ) ; err != nil {
if err := s . db. Delete ( ctx , req . OwnerUserID , [ ] string { req . FriendUserID } ) ; err != nil {
return nil , err
return nil , err
}
}
s . notificationSender . FriendDeletedNotification ( ctx , req )
s . notificationSender . FriendDeletedNotification ( ctx , req )
@ -241,19 +242,19 @@ func (s *friendServer) DeleteFriend(ctx context.Context, req *pbfriend.DeleteFri
}
}
// ok.
// ok.
func ( s * friendServer ) SetFriendRemark ( ctx context . Context , req * pbf ri end . SetFriendRemarkReq ) ( resp * pbf ri end . SetFriendRemarkResp , err error ) {
func ( s * friendServer ) SetFriendRemark ( ctx context . Context , req * relatio n. SetFriendRemarkReq ) ( resp * relatio n. SetFriendRemarkResp , err error ) {
if err = s . webhookBeforeSetFriendRemark ( ctx , & s . config . WebhooksConfig . BeforeSetFriendRemark , req ) ; err != nil && err != servererrs . ErrCallbackContinue {
if err = s . webhookBeforeSetFriendRemark ( ctx , & s . config . WebhooksConfig . BeforeSetFriendRemark , req ) ; err != nil && err != servererrs . ErrCallbackContinue {
return nil , err
return nil , err
}
}
resp = & pbf ri end . SetFriendRemarkResp { }
resp = & relatio n. SetFriendRemarkResp { }
if err := s . userRpcClient . Access ( ctx , req . OwnerUserID ) ; err != nil {
if err := s . userRpcClient . Access ( ctx , req . OwnerUserID ) ; err != nil {
return nil , err
return nil , err
}
}
_ , err = s . frien dData base . FindFriendsWithError ( ctx , req . OwnerUserID , [ ] string { req . FriendUserID } )
_ , err = s . db. FindFriendsWithError ( ctx , req . OwnerUserID , [ ] string { req . FriendUserID } )
if err != nil {
if err != nil {
return nil , err
return nil , err
}
}
if err := s . frien dData base . UpdateRemark ( ctx , req . OwnerUserID , req . FriendUserID , req . Remark ) ; err != nil {
if err := s . db. UpdateRemark ( ctx , req . OwnerUserID , req . FriendUserID , req . Remark ) ; err != nil {
return nil , err
return nil , err
}
}
s . webhookAfterSetFriendRemark ( ctx , & s . config . WebhooksConfig . AfterSetFriendRemark , req )
s . webhookAfterSetFriendRemark ( ctx , & s . config . WebhooksConfig . AfterSetFriendRemark , req )
@ -262,29 +263,40 @@ func (s *friendServer) SetFriendRemark(ctx context.Context, req *pbfriend.SetFri
}
}
// ok.
// ok.
func ( s * friendServer ) GetDesignatedFriends ( ctx context . Context , req * pbf ri end . GetDesignatedFriendsReq ) ( resp * pbf ri end . GetDesignatedFriendsResp , err error ) {
func ( s * friendServer ) GetDesignatedFriends ( ctx context . Context , req * relatio n. GetDesignatedFriendsReq ) ( resp * relatio n. GetDesignatedFriendsResp , err error ) {
resp = & pbf ri end . GetDesignatedFriendsResp { }
resp = & relatio n. GetDesignatedFriendsResp { }
if datautil . Duplicate ( req . FriendUserIDs ) {
if datautil . Duplicate ( req . FriendUserIDs ) {
return nil , errs . ErrArgs . WrapMsg ( "friend userID repeated" )
return nil , errs . ErrArgs . WrapMsg ( "friend userID repeated" )
}
}
friends , err := s . friendDatabase . FindFriendsWithError ( ctx , req . OwnerUserID , req . FriendUserIDs )
friends , err := s . getFriend ( ctx , req . OwnerUserID , req . FriendUserIDs )
if err != nil {
if err != nil {
return nil , err
return nil , err
}
}
if resp . FriendsInfo , err = convert . FriendsDB2Pb ( ctx , friends , s . userRpcClient . GetUsersInfoMap ) ; err != nil {
return & relation . GetDesignatedFriendsResp {
FriendsInfo : friends ,
} , nil
}
func ( s * friendServer ) getFriend ( ctx context . Context , ownerUserID string , friendUserIDs [ ] string ) ( [ ] * sdkws . FriendInfo , error ) {
if len ( friendUserIDs ) == 0 {
return nil , nil
}
friends , err := s . db . FindFriendsWithError ( ctx , ownerUserID , friendUserIDs )
if err != nil {
return nil , err
return nil , err
}
}
return resp , nil
return convert. FriendsDB2Pb ( ctx , friends , s . userRpcClient . GetUsersInfoMap )
}
}
// Get the list of friend requests sent out proactively.
// Get the list of friend requests sent out proactively.
func ( s * friendServer ) GetDesignatedFriendsApply ( ctx context . Context ,
func ( s * friendServer ) GetDesignatedFriendsApply ( ctx context . Context ,
req * pbfriend . GetDesignatedFriendsApplyReq ) ( resp * pbfriend . GetDesignatedFriendsApplyResp , err error ) {
req * relation . GetDesignatedFriendsApplyReq ,
friendRequests , err := s . friendDatabase . FindBothFriendRequests ( ctx , req . FromUserID , req . ToUserID )
) ( resp * relation . GetDesignatedFriendsApplyResp , err error ) {
friendRequests , err := s . db . FindBothFriendRequests ( ctx , req . FromUserID , req . ToUserID )
if err != nil {
if err != nil {
return nil , err
return nil , err
}
}
resp = & pbf ri end . GetDesignatedFriendsApplyResp { }
resp = & relatio n. GetDesignatedFriendsApplyResp { }
resp . FriendRequests , err = convert . FriendRequestDB2Pb ( ctx , friendRequests , s . userRpcClient . GetUsersInfoMap )
resp . FriendRequests , err = convert . FriendRequestDB2Pb ( ctx , friendRequests , s . userRpcClient . GetUsersInfoMap )
if err != nil {
if err != nil {
return nil , err
return nil , err
@ -293,15 +305,15 @@ func (s *friendServer) GetDesignatedFriendsApply(ctx context.Context,
}
}
// Get received friend requests (i.e., those initiated by others).
// Get received friend requests (i.e., those initiated by others).
func ( s * friendServer ) GetPaginationFriendsApplyTo ( ctx context . Context , req * pbf ri end . GetPaginationFriendsApplyToReq ) ( resp * pbf ri end . GetPaginationFriendsApplyToResp , err error ) {
func ( s * friendServer ) GetPaginationFriendsApplyTo ( ctx context . Context , req * relatio n. GetPaginationFriendsApplyToReq ) ( resp * relatio n. GetPaginationFriendsApplyToResp , err error ) {
if err := s . userRpcClient . Access ( ctx , req . UserID ) ; err != nil {
if err := s . userRpcClient . Access ( ctx , req . UserID ) ; err != nil {
return nil , err
return nil , err
}
}
total , friendRequests , err := s . frien dData base . PageFriendRequestToMe ( ctx , req . UserID , req . Pagination )
total , friendRequests , err := s . db. PageFriendRequestToMe ( ctx , req . UserID , req . Pagination )
if err != nil {
if err != nil {
return nil , err
return nil , err
}
}
resp = & pbf ri end . GetPaginationFriendsApplyToResp { }
resp = & relatio n. GetPaginationFriendsApplyToResp { }
resp . FriendRequests , err = convert . FriendRequestDB2Pb ( ctx , friendRequests , s . userRpcClient . GetUsersInfoMap )
resp . FriendRequests , err = convert . FriendRequestDB2Pb ( ctx , friendRequests , s . userRpcClient . GetUsersInfoMap )
if err != nil {
if err != nil {
return nil , err
return nil , err
@ -310,12 +322,12 @@ func (s *friendServer) GetPaginationFriendsApplyTo(ctx context.Context, req *pbf
return resp , nil
return resp , nil
}
}
func ( s * friendServer ) GetPaginationFriendsApplyFrom ( ctx context . Context , req * pbf ri end . GetPaginationFriendsApplyFromReq ) ( resp * pbf ri end . GetPaginationFriendsApplyFromResp , err error ) {
func ( s * friendServer ) GetPaginationFriendsApplyFrom ( ctx context . Context , req * relatio n. GetPaginationFriendsApplyFromReq ) ( resp * relatio n. GetPaginationFriendsApplyFromResp , err error ) {
resp = & pbf ri end . GetPaginationFriendsApplyFromResp { }
resp = & relatio n. GetPaginationFriendsApplyFromResp { }
if err := s . userRpcClient . Access ( ctx , req . UserID ) ; err != nil {
if err := s . userRpcClient . Access ( ctx , req . UserID ) ; err != nil {
return nil , err
return nil , err
}
}
total , friendRequests , err := s . frien dData base . PageFriendRequestFromMe ( ctx , req . UserID , req . Pagination )
total , friendRequests , err := s . db. PageFriendRequestFromMe ( ctx , req . UserID , req . Pagination )
if err != nil {
if err != nil {
return nil , err
return nil , err
}
}
@ -328,24 +340,24 @@ func (s *friendServer) GetPaginationFriendsApplyFrom(ctx context.Context, req *p
}
}
// ok.
// ok.
func ( s * friendServer ) IsFriend ( ctx context . Context , req * pbf ri end . IsFriendReq ) ( resp * pbf ri end . IsFriendResp , err error ) {
func ( s * friendServer ) IsFriend ( ctx context . Context , req * relatio n. IsFriendReq ) ( resp * relatio n. IsFriendResp , err error ) {
resp = & pbf ri end . IsFriendResp { }
resp = & relatio n. IsFriendResp { }
resp . InUser1Friends , resp . InUser2Friends , err = s . frien dData base . CheckIn ( ctx , req . UserID1 , req . UserID2 )
resp . InUser1Friends , resp . InUser2Friends , err = s . db. CheckIn ( ctx , req . UserID1 , req . UserID2 )
if err != nil {
if err != nil {
return nil , err
return nil , err
}
}
return resp , nil
return resp , nil
}
}
func ( s * friendServer ) GetPaginationFriends ( ctx context . Context , req * pbf ri end . GetPaginationFriendsReq ) ( resp * pbf ri end . GetPaginationFriendsResp , err error ) {
func ( s * friendServer ) GetPaginationFriends ( ctx context . Context , req * relatio n. GetPaginationFriendsReq ) ( resp * relatio n. GetPaginationFriendsResp , err error ) {
if err := s . userRpcClient . Access ( ctx , req . UserID ) ; err != nil {
if err := s . userRpcClient . Access ( ctx , req . UserID ) ; err != nil {
return nil , err
return nil , err
}
}
total , friends , err := s . frien dData base . PageOwnerFriends ( ctx , req . UserID , req . Pagination )
total , friends , err := s . db. PageOwnerFriends ( ctx , req . UserID , req . Pagination )
if err != nil {
if err != nil {
return nil , err
return nil , err
}
}
resp = & pbf ri end . GetPaginationFriendsResp { }
resp = & relatio n. GetPaginationFriendsResp { }
resp . FriendsInfo , err = convert . FriendsDB2Pb ( ctx , friends , s . userRpcClient . GetUsersInfoMap )
resp . FriendsInfo , err = convert . FriendsDB2Pb ( ctx , friends , s . userRpcClient . GetUsersInfoMap )
if err != nil {
if err != nil {
return nil , err
return nil , err
@ -354,19 +366,19 @@ func (s *friendServer) GetPaginationFriends(ctx context.Context, req *pbfriend.G
return resp , nil
return resp , nil
}
}
func ( s * friendServer ) GetFriendIDs ( ctx context . Context , req * pbf ri end . GetFriendIDsReq ) ( resp * pbf ri end . GetFriendIDsResp , err error ) {
func ( s * friendServer ) GetFriendIDs ( ctx context . Context , req * relatio n. GetFriendIDsReq ) ( resp * relatio n. GetFriendIDsResp , err error ) {
if err := s . userRpcClient . Access ( ctx , req . UserID ) ; err != nil {
if err := s . userRpcClient . Access ( ctx , req . UserID ) ; err != nil {
return nil , err
return nil , err
}
}
resp = & pbf ri end . GetFriendIDsResp { }
resp = & relatio n. GetFriendIDsResp { }
resp . FriendIDs , err = s . frien dData base . FindFriendUserIDs ( ctx , req . UserID )
resp . FriendIDs , err = s . db. FindFriendUserIDs ( ctx , req . UserID )
if err != nil {
if err != nil {
return nil , err
return nil , err
}
}
return resp , nil
return resp , nil
}
}
func ( s * friendServer ) GetSpecifiedFriendsInfo ( ctx context . Context , req * pbf ri end . GetSpecifiedFriendsInfoReq ) ( * pbf ri end . GetSpecifiedFriendsInfoResp , error ) {
func ( s * friendServer ) GetSpecifiedFriendsInfo ( ctx context . Context , req * relatio n. GetSpecifiedFriendsInfoReq ) ( * relatio n. GetSpecifiedFriendsInfoResp , error ) {
if len ( req . UserIDList ) == 0 {
if len ( req . UserIDList ) == 0 {
return nil , errs . ErrArgs . WrapMsg ( "userIDList is empty" )
return nil , errs . ErrArgs . WrapMsg ( "userIDList is empty" )
}
}
@ -377,7 +389,7 @@ func (s *friendServer) GetSpecifiedFriendsInfo(ctx context.Context, req *pbfrien
if err != nil {
if err != nil {
return nil , err
return nil , err
}
}
friends , err := s . frien dData base . FindFriendsWithError ( ctx , req . OwnerUserID , req . UserIDList )
friends , err := s . db. FindFriendsWithError ( ctx , req . OwnerUserID , req . UserIDList )
if err != nil {
if err != nil {
return nil , err
return nil , err
}
}
@ -391,8 +403,8 @@ func (s *friendServer) GetSpecifiedFriendsInfo(ctx context.Context, req *pbfrien
blackMap := datautil . SliceToMap ( blacks , func ( e * model . Black ) string {
blackMap := datautil . SliceToMap ( blacks , func ( e * model . Black ) string {
return e . BlockUserID
return e . BlockUserID
} )
} )
resp := & pbf ri end . GetSpecifiedFriendsInfoResp {
resp := & relatio n. GetSpecifiedFriendsInfoResp {
Infos : make ( [ ] * pbf ri end . GetSpecifiedFriendsInfoInfo , 0 , len ( req . UserIDList ) ) ,
Infos : make ( [ ] * relatio n. GetSpecifiedFriendsInfoInfo , 0 , len ( req . UserIDList ) ) ,
}
}
for _ , userID := range req . UserIDList {
for _ , userID := range req . UserIDList {
user := userMap [ userID ]
user := userMap [ userID ]
@ -401,7 +413,6 @@ func (s *friendServer) GetSpecifiedFriendsInfo(ctx context.Context, req *pbfrien
}
}
var friendInfo * sdkws . FriendInfo
var friendInfo * sdkws . FriendInfo
if friend := friendMap [ userID ] ; friend != nil {
if friend := friendMap [ userID ] ; friend != nil {
friendInfo = & sdkws . FriendInfo {
friendInfo = & sdkws . FriendInfo {
OwnerUserID : friend . OwnerUserID ,
OwnerUserID : friend . OwnerUserID ,
Remark : friend . Remark ,
Remark : friend . Remark ,
@ -422,7 +433,7 @@ func (s *friendServer) GetSpecifiedFriendsInfo(ctx context.Context, req *pbfrien
Ex : black . Ex ,
Ex : black . Ex ,
}
}
}
}
resp . Infos = append ( resp . Infos , & pbf ri end . GetSpecifiedFriendsInfoInfo {
resp . Infos = append ( resp . Infos , & relatio n. GetSpecifiedFriendsInfoInfo {
UserInfo : user ,
UserInfo : user ,
FriendInfo : friendInfo ,
FriendInfo : friendInfo ,
BlackInfo : blackInfo ,
BlackInfo : blackInfo ,
@ -430,10 +441,11 @@ func (s *friendServer) GetSpecifiedFriendsInfo(ctx context.Context, req *pbfrien
}
}
return resp , nil
return resp , nil
}
}
func ( s * friendServer ) UpdateFriends (
func ( s * friendServer ) UpdateFriends (
ctx context . Context ,
ctx context . Context ,
req * pbf ri end . UpdateFriendsReq ,
req * relatio n. UpdateFriendsReq ,
) ( * pbf ri end . UpdateFriendsResp , error ) {
) ( * relatio n. UpdateFriendsResp , error ) {
if len ( req . FriendUserIDs ) == 0 {
if len ( req . FriendUserIDs ) == 0 {
return nil , errs . ErrArgs . WrapMsg ( "friendIDList is empty" )
return nil , errs . ErrArgs . WrapMsg ( "friendIDList is empty" )
}
}
@ -441,7 +453,7 @@ func (s *friendServer) UpdateFriends(
return nil , errs . ErrArgs . WrapMsg ( "friendIDList repeated" )
return nil , errs . ErrArgs . WrapMsg ( "friendIDList repeated" )
}
}
_ , err := s . frien dData base . FindFriendsWithError ( ctx , req . OwnerUserID , req . FriendUserIDs )
_ , err := s . db. FindFriendsWithError ( ctx , req . OwnerUserID , req . FriendUserIDs )
if err != nil {
if err != nil {
return nil , err
return nil , err
}
}
@ -457,12 +469,27 @@ func (s *friendServer) UpdateFriends(
if req . Ex != nil {
if req . Ex != nil {
val [ "ex" ] = req . Ex . Value
val [ "ex" ] = req . Ex . Value
}
}
if err = s . frien dData base . UpdateFriends ( ctx , req . OwnerUserID , req . FriendUserIDs , val ) ; err != nil {
if err = s . db. UpdateFriends ( ctx , req . OwnerUserID , req . FriendUserIDs , val ) ; err != nil {
return nil , err
return nil , err
}
}
resp := & pbf ri end . UpdateFriendsResp { }
resp := & relatio n. UpdateFriendsResp { }
s . notificationSender . FriendsInfoUpdateNotification ( ctx , req . OwnerUserID , req . FriendUserIDs )
s . notificationSender . FriendsInfoUpdateNotification ( ctx , req . OwnerUserID , req . FriendUserIDs )
return resp , nil
return resp , nil
}
}
func ( s * friendServer ) GetIncrementalFriendsApplyTo ( ctx context . Context , req * relation . GetIncrementalFriendsApplyToReq ) ( * relation . GetIncrementalFriendsApplyToResp , error ) {
// TODO implement me
return nil , nil
}
func ( s * friendServer ) GetIncrementalFriendsApplyFrom ( ctx context . Context , req * relation . GetIncrementalFriendsApplyFromReq ) ( * relation . GetIncrementalFriendsApplyFromResp , error ) {
// TODO implement me
return nil , nil
}
func ( s * friendServer ) GetIncrementalBlacks ( ctx context . Context , req * relation . GetIncrementalBlacksReq ) ( * relation . GetIncrementalBlacksResp , error ) {
// TODO implement me
return nil , nil
}