|
|
|
@ -16,6 +16,7 @@ package friend
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"context"
|
|
|
|
|
|
|
|
|
|
"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/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/rpcclient"
|
|
|
|
|
"github.com/openimsdk/protocol/constant"
|
|
|
|
|
pbfriend "github.com/openimsdk/protocol/friend"
|
|
|
|
|
"github.com/openimsdk/protocol/relation"
|
|
|
|
|
"github.com/openimsdk/protocol/sdkws"
|
|
|
|
|
"github.com/openimsdk/tools/db/mongoutil"
|
|
|
|
|
"github.com/openimsdk/tools/discovery"
|
|
|
|
@ -54,7 +55,7 @@ type Config struct {
|
|
|
|
|
RpcConfig config.Friend
|
|
|
|
|
RedisConfig config.Redis
|
|
|
|
|
MongodbConfig config.Mongo
|
|
|
|
|
//ZookeeperConfig config.ZooKeeper
|
|
|
|
|
// ZookeeperConfig config.ZooKeeper
|
|
|
|
|
NotificationConfig config.Notification
|
|
|
|
|
Share config.Share
|
|
|
|
|
WebhooksConfig config.Webhooks
|
|
|
|
@ -103,7 +104,7 @@ func Start(ctx context.Context, config *Config, client discovery.SvcDiscoveryReg
|
|
|
|
|
localcache.InitLocalCache(&config.LocalCacheConfig)
|
|
|
|
|
|
|
|
|
|
// Register Friend server with refactored MongoDB and Redis integrations
|
|
|
|
|
pbfriend.RegisterFriendServer(server, &friendServer{
|
|
|
|
|
relation.RegisterFriendServer(server, &friendServer{
|
|
|
|
|
friendDatabase: controller.NewFriendDatabase(
|
|
|
|
|
friendMongoDB,
|
|
|
|
|
friendRequestMongoDB,
|
|
|
|
@ -126,8 +127,8 @@ func Start(ctx context.Context, config *Config, client discovery.SvcDiscoveryReg
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// ok.
|
|
|
|
|
func (s *friendServer) ApplyToAddFriend(ctx context.Context, req *pbfriend.ApplyToAddFriendReq) (resp *pbfriend.ApplyToAddFriendResp, err error) {
|
|
|
|
|
resp = &pbfriend.ApplyToAddFriendResp{}
|
|
|
|
|
func (s *friendServer) ApplyToAddFriend(ctx context.Context, req *relation.ApplyToAddFriendReq) (resp *relation.ApplyToAddFriendResp, err error) {
|
|
|
|
|
resp = &relation.ApplyToAddFriendResp{}
|
|
|
|
|
if err := authverify.CheckAccessV3(ctx, req.FromUserID, s.config.Share.IMAdminUserID); err != nil {
|
|
|
|
|
return nil, err
|
|
|
|
|
}
|
|
|
|
@ -157,7 +158,7 @@ func (s *friendServer) ApplyToAddFriend(ctx context.Context, req *pbfriend.Apply
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// ok.
|
|
|
|
|
func (s *friendServer) ImportFriends(ctx context.Context, req *pbfriend.ImportFriendReq) (resp *pbfriend.ImportFriendResp, err error) {
|
|
|
|
|
func (s *friendServer) ImportFriends(ctx context.Context, req *relation.ImportFriendReq) (resp *relation.ImportFriendResp, err error) {
|
|
|
|
|
if err := authverify.CheckAdmin(ctx, s.config.Share.IMAdminUserID); err != nil {
|
|
|
|
|
return nil, err
|
|
|
|
|
}
|
|
|
|
@ -179,7 +180,7 @@ func (s *friendServer) ImportFriends(ctx context.Context, req *pbfriend.ImportFr
|
|
|
|
|
return nil, err
|
|
|
|
|
}
|
|
|
|
|
for _, userID := range req.FriendUserIDs {
|
|
|
|
|
s.notificationSender.FriendApplicationAgreedNotification(ctx, &pbfriend.RespondFriendApplyReq{
|
|
|
|
|
s.notificationSender.FriendApplicationAgreedNotification(ctx, &relation.RespondFriendApplyReq{
|
|
|
|
|
FromUserID: req.OwnerUserID,
|
|
|
|
|
ToUserID: userID,
|
|
|
|
|
HandleResult: constant.FriendResponseAgree,
|
|
|
|
@ -187,12 +188,12 @@ func (s *friendServer) ImportFriends(ctx context.Context, req *pbfriend.ImportFr
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
s.webhookAfterImportFriends(ctx, &s.config.WebhooksConfig.AfterImportFriends, req)
|
|
|
|
|
return &pbfriend.ImportFriendResp{}, nil
|
|
|
|
|
return &relation.ImportFriendResp{}, nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// ok.
|
|
|
|
|
func (s *friendServer) RespondFriendApply(ctx context.Context, req *pbfriend.RespondFriendApplyReq) (resp *pbfriend.RespondFriendApplyResp, err error) {
|
|
|
|
|
resp = &pbfriend.RespondFriendApplyResp{}
|
|
|
|
|
func (s *friendServer) RespondFriendApply(ctx context.Context, req *relation.RespondFriendApplyReq) (resp *relation.RespondFriendApplyResp, err error) {
|
|
|
|
|
resp = &relation.RespondFriendApplyResp{}
|
|
|
|
|
if err := authverify.CheckAccessV3(ctx, req.ToUserID, s.config.Share.IMAdminUserID); err != nil {
|
|
|
|
|
return nil, err
|
|
|
|
|
}
|
|
|
|
@ -226,8 +227,8 @@ func (s *friendServer) RespondFriendApply(ctx context.Context, req *pbfriend.Res
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// ok.
|
|
|
|
|
func (s *friendServer) DeleteFriend(ctx context.Context, req *pbfriend.DeleteFriendReq) (resp *pbfriend.DeleteFriendResp, err error) {
|
|
|
|
|
resp = &pbfriend.DeleteFriendResp{}
|
|
|
|
|
func (s *friendServer) DeleteFriend(ctx context.Context, req *relation.DeleteFriendReq) (resp *relation.DeleteFriendResp, err error) {
|
|
|
|
|
resp = &relation.DeleteFriendResp{}
|
|
|
|
|
if err := s.userRpcClient.Access(ctx, req.OwnerUserID); err != nil {
|
|
|
|
|
return nil, err
|
|
|
|
|
}
|
|
|
|
@ -244,11 +245,11 @@ func (s *friendServer) DeleteFriend(ctx context.Context, req *pbfriend.DeleteFri
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// ok.
|
|
|
|
|
func (s *friendServer) SetFriendRemark(ctx context.Context, req *pbfriend.SetFriendRemarkReq) (resp *pbfriend.SetFriendRemarkResp, err error) {
|
|
|
|
|
func (s *friendServer) SetFriendRemark(ctx context.Context, req *relation.SetFriendRemarkReq) (resp *relation.SetFriendRemarkResp, err error) {
|
|
|
|
|
if err = s.webhookBeforeSetFriendRemark(ctx, &s.config.WebhooksConfig.BeforeSetFriendRemark, req); err != nil && err != servererrs.ErrCallbackContinue {
|
|
|
|
|
return nil, err
|
|
|
|
|
}
|
|
|
|
|
resp = &pbfriend.SetFriendRemarkResp{}
|
|
|
|
|
resp = &relation.SetFriendRemarkResp{}
|
|
|
|
|
if err := s.userRpcClient.Access(ctx, req.OwnerUserID); err != nil {
|
|
|
|
|
return nil, err
|
|
|
|
|
}
|
|
|
|
@ -265,8 +266,8 @@ func (s *friendServer) SetFriendRemark(ctx context.Context, req *pbfriend.SetFri
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// ok.
|
|
|
|
|
func (s *friendServer) GetDesignatedFriends(ctx context.Context, req *pbfriend.GetDesignatedFriendsReq) (resp *pbfriend.GetDesignatedFriendsResp, err error) {
|
|
|
|
|
resp = &pbfriend.GetDesignatedFriendsResp{}
|
|
|
|
|
func (s *friendServer) GetDesignatedFriends(ctx context.Context, req *relation.GetDesignatedFriendsReq) (resp *relation.GetDesignatedFriendsResp, err error) {
|
|
|
|
|
resp = &relation.GetDesignatedFriendsResp{}
|
|
|
|
|
if datautil.Duplicate(req.FriendUserIDs) {
|
|
|
|
|
return nil, errs.ErrArgs.WrapMsg("friend userID repeated")
|
|
|
|
|
}
|
|
|
|
@ -282,12 +283,13 @@ func (s *friendServer) GetDesignatedFriends(ctx context.Context, req *pbfriend.G
|
|
|
|
|
|
|
|
|
|
// Get the list of friend requests sent out proactively.
|
|
|
|
|
func (s *friendServer) GetDesignatedFriendsApply(ctx context.Context,
|
|
|
|
|
req *pbfriend.GetDesignatedFriendsApplyReq) (resp *pbfriend.GetDesignatedFriendsApplyResp, err error) {
|
|
|
|
|
req *relation.GetDesignatedFriendsApplyReq,
|
|
|
|
|
) (resp *relation.GetDesignatedFriendsApplyResp, err error) {
|
|
|
|
|
friendRequests, err := s.friendDatabase.FindBothFriendRequests(ctx, req.FromUserID, req.ToUserID)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return nil, err
|
|
|
|
|
}
|
|
|
|
|
resp = &pbfriend.GetDesignatedFriendsApplyResp{}
|
|
|
|
|
resp = &relation.GetDesignatedFriendsApplyResp{}
|
|
|
|
|
resp.FriendRequests, err = convert.FriendRequestDB2Pb(ctx, friendRequests, s.userRpcClient.GetUsersInfoMap)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return nil, err
|
|
|
|
@ -296,7 +298,7 @@ func (s *friendServer) GetDesignatedFriendsApply(ctx context.Context,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Get received friend requests (i.e., those initiated by others).
|
|
|
|
|
func (s *friendServer) GetPaginationFriendsApplyTo(ctx context.Context, req *pbfriend.GetPaginationFriendsApplyToReq) (resp *pbfriend.GetPaginationFriendsApplyToResp, err error) {
|
|
|
|
|
func (s *friendServer) GetPaginationFriendsApplyTo(ctx context.Context, req *relation.GetPaginationFriendsApplyToReq) (resp *relation.GetPaginationFriendsApplyToResp, err error) {
|
|
|
|
|
if err := s.userRpcClient.Access(ctx, req.UserID); err != nil {
|
|
|
|
|
return nil, err
|
|
|
|
|
}
|
|
|
|
@ -304,7 +306,7 @@ func (s *friendServer) GetPaginationFriendsApplyTo(ctx context.Context, req *pbf
|
|
|
|
|
if err != nil {
|
|
|
|
|
return nil, err
|
|
|
|
|
}
|
|
|
|
|
resp = &pbfriend.GetPaginationFriendsApplyToResp{}
|
|
|
|
|
resp = &relation.GetPaginationFriendsApplyToResp{}
|
|
|
|
|
resp.FriendRequests, err = convert.FriendRequestDB2Pb(ctx, friendRequests, s.userRpcClient.GetUsersInfoMap)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return nil, err
|
|
|
|
@ -313,8 +315,8 @@ func (s *friendServer) GetPaginationFriendsApplyTo(ctx context.Context, req *pbf
|
|
|
|
|
return resp, nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (s *friendServer) GetPaginationFriendsApplyFrom(ctx context.Context, req *pbfriend.GetPaginationFriendsApplyFromReq) (resp *pbfriend.GetPaginationFriendsApplyFromResp, err error) {
|
|
|
|
|
resp = &pbfriend.GetPaginationFriendsApplyFromResp{}
|
|
|
|
|
func (s *friendServer) GetPaginationFriendsApplyFrom(ctx context.Context, req *relation.GetPaginationFriendsApplyFromReq) (resp *relation.GetPaginationFriendsApplyFromResp, err error) {
|
|
|
|
|
resp = &relation.GetPaginationFriendsApplyFromResp{}
|
|
|
|
|
if err := s.userRpcClient.Access(ctx, req.UserID); err != nil {
|
|
|
|
|
return nil, err
|
|
|
|
|
}
|
|
|
|
@ -331,8 +333,8 @@ func (s *friendServer) GetPaginationFriendsApplyFrom(ctx context.Context, req *p
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// ok.
|
|
|
|
|
func (s *friendServer) IsFriend(ctx context.Context, req *pbfriend.IsFriendReq) (resp *pbfriend.IsFriendResp, err error) {
|
|
|
|
|
resp = &pbfriend.IsFriendResp{}
|
|
|
|
|
func (s *friendServer) IsFriend(ctx context.Context, req *relation.IsFriendReq) (resp *relation.IsFriendResp, err error) {
|
|
|
|
|
resp = &relation.IsFriendResp{}
|
|
|
|
|
resp.InUser1Friends, resp.InUser2Friends, err = s.friendDatabase.CheckIn(ctx, req.UserID1, req.UserID2)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return nil, err
|
|
|
|
@ -340,7 +342,7 @@ func (s *friendServer) IsFriend(ctx context.Context, req *pbfriend.IsFriendReq)
|
|
|
|
|
return resp, nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (s *friendServer) GetPaginationFriends(ctx context.Context, req *pbfriend.GetPaginationFriendsReq) (resp *pbfriend.GetPaginationFriendsResp, err error) {
|
|
|
|
|
func (s *friendServer) GetPaginationFriends(ctx context.Context, req *relation.GetPaginationFriendsReq) (resp *relation.GetPaginationFriendsResp, err error) {
|
|
|
|
|
if err := s.userRpcClient.Access(ctx, req.UserID); err != nil {
|
|
|
|
|
return nil, err
|
|
|
|
|
}
|
|
|
|
@ -348,7 +350,7 @@ func (s *friendServer) GetPaginationFriends(ctx context.Context, req *pbfriend.G
|
|
|
|
|
if err != nil {
|
|
|
|
|
return nil, err
|
|
|
|
|
}
|
|
|
|
|
resp = &pbfriend.GetPaginationFriendsResp{}
|
|
|
|
|
resp = &relation.GetPaginationFriendsResp{}
|
|
|
|
|
resp.FriendsInfo, err = convert.FriendsDB2Pb(ctx, friends, s.userRpcClient.GetUsersInfoMap)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return nil, err
|
|
|
|
@ -357,11 +359,11 @@ func (s *friendServer) GetPaginationFriends(ctx context.Context, req *pbfriend.G
|
|
|
|
|
return resp, nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (s *friendServer) GetFriendIDs(ctx context.Context, req *pbfriend.GetFriendIDsReq) (resp *pbfriend.GetFriendIDsResp, err error) {
|
|
|
|
|
func (s *friendServer) GetFriendIDs(ctx context.Context, req *relation.GetFriendIDsReq) (resp *relation.GetFriendIDsResp, err error) {
|
|
|
|
|
if err := s.userRpcClient.Access(ctx, req.UserID); err != nil {
|
|
|
|
|
return nil, err
|
|
|
|
|
}
|
|
|
|
|
resp = &pbfriend.GetFriendIDsResp{}
|
|
|
|
|
resp = &relation.GetFriendIDsResp{}
|
|
|
|
|
resp.FriendIDs, err = s.friendDatabase.FindFriendUserIDs(ctx, req.UserID)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return nil, err
|
|
|
|
@ -369,7 +371,7 @@ func (s *friendServer) GetFriendIDs(ctx context.Context, req *pbfriend.GetFriend
|
|
|
|
|
return resp, nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (s *friendServer) GetSpecifiedFriendsInfo(ctx context.Context, req *pbfriend.GetSpecifiedFriendsInfoReq) (*pbfriend.GetSpecifiedFriendsInfoResp, error) {
|
|
|
|
|
func (s *friendServer) GetSpecifiedFriendsInfo(ctx context.Context, req *relation.GetSpecifiedFriendsInfoReq) (*relation.GetSpecifiedFriendsInfoResp, error) {
|
|
|
|
|
if len(req.UserIDList) == 0 {
|
|
|
|
|
return nil, errs.ErrArgs.WrapMsg("userIDList is empty")
|
|
|
|
|
}
|
|
|
|
@ -394,8 +396,8 @@ func (s *friendServer) GetSpecifiedFriendsInfo(ctx context.Context, req *pbfrien
|
|
|
|
|
blackMap := datautil.SliceToMap(blacks, func(e *model.Black) string {
|
|
|
|
|
return e.BlockUserID
|
|
|
|
|
})
|
|
|
|
|
resp := &pbfriend.GetSpecifiedFriendsInfoResp{
|
|
|
|
|
Infos: make([]*pbfriend.GetSpecifiedFriendsInfoInfo, 0, len(req.UserIDList)),
|
|
|
|
|
resp := &relation.GetSpecifiedFriendsInfoResp{
|
|
|
|
|
Infos: make([]*relation.GetSpecifiedFriendsInfoInfo, 0, len(req.UserIDList)),
|
|
|
|
|
}
|
|
|
|
|
for _, userID := range req.UserIDList {
|
|
|
|
|
user := userMap[userID]
|
|
|
|
@ -404,7 +406,6 @@ func (s *friendServer) GetSpecifiedFriendsInfo(ctx context.Context, req *pbfrien
|
|
|
|
|
}
|
|
|
|
|
var friendInfo *sdkws.FriendInfo
|
|
|
|
|
if friend := friendMap[userID]; friend != nil {
|
|
|
|
|
|
|
|
|
|
friendInfo = &sdkws.FriendInfo{
|
|
|
|
|
OwnerUserID: friend.OwnerUserID,
|
|
|
|
|
Remark: friend.Remark,
|
|
|
|
@ -425,7 +426,7 @@ func (s *friendServer) GetSpecifiedFriendsInfo(ctx context.Context, req *pbfrien
|
|
|
|
|
Ex: black.Ex,
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
resp.Infos = append(resp.Infos, &pbfriend.GetSpecifiedFriendsInfoInfo{
|
|
|
|
|
resp.Infos = append(resp.Infos, &relation.GetSpecifiedFriendsInfoInfo{
|
|
|
|
|
UserInfo: user,
|
|
|
|
|
FriendInfo: friendInfo,
|
|
|
|
|
BlackInfo: blackInfo,
|
|
|
|
@ -433,10 +434,11 @@ func (s *friendServer) GetSpecifiedFriendsInfo(ctx context.Context, req *pbfrien
|
|
|
|
|
}
|
|
|
|
|
return resp, nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (s *friendServer) UpdateFriends(
|
|
|
|
|
ctx context.Context,
|
|
|
|
|
req *pbfriend.UpdateFriendsReq,
|
|
|
|
|
) (*pbfriend.UpdateFriendsResp, error) {
|
|
|
|
|
req *relation.UpdateFriendsReq,
|
|
|
|
|
) (*relation.UpdateFriendsResp, error) {
|
|
|
|
|
if len(req.FriendUserIDs) == 0 {
|
|
|
|
|
return nil, errs.ErrArgs.WrapMsg("friendIDList is empty")
|
|
|
|
|
}
|
|
|
|
@ -464,8 +466,23 @@ func (s *friendServer) UpdateFriends(
|
|
|
|
|
return nil, err
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
resp := &pbfriend.UpdateFriendsResp{}
|
|
|
|
|
resp := &relation.UpdateFriendsResp{}
|
|
|
|
|
|
|
|
|
|
s.notificationSender.FriendsInfoUpdateNotification(ctx, req.OwnerUserID, req.FriendUserIDs)
|
|
|
|
|
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
|
|
|
|
|
}
|
|
|
|
|