mirror of
https://github.com/openimsdk/open-im-server.git
synced 2025-06-26 14:19:38 +08:00
feat: optimize friend and group applications
This commit is contained in:
parent
ea76481705
commit
912493efa9
2
go.mod
2
go.mod
@ -12,7 +12,7 @@ require (
|
|||||||
github.com/gorilla/websocket v1.5.1
|
github.com/gorilla/websocket v1.5.1
|
||||||
github.com/grpc-ecosystem/go-grpc-prometheus v1.2.0
|
github.com/grpc-ecosystem/go-grpc-prometheus v1.2.0
|
||||||
github.com/mitchellh/mapstructure v1.5.0
|
github.com/mitchellh/mapstructure v1.5.0
|
||||||
github.com/openimsdk/protocol v0.0.73-alpha.11
|
github.com/openimsdk/protocol v0.0.73-alpha.12
|
||||||
github.com/openimsdk/tools v0.0.50-alpha.84
|
github.com/openimsdk/tools v0.0.50-alpha.84
|
||||||
github.com/pkg/errors v0.9.1 // indirect
|
github.com/pkg/errors v0.9.1 // indirect
|
||||||
github.com/prometheus/client_golang v1.18.0
|
github.com/prometheus/client_golang v1.18.0
|
||||||
|
4
go.sum
4
go.sum
@ -347,8 +347,8 @@ github.com/onsi/gomega v1.25.0 h1:Vw7br2PCDYijJHSfBOWhov+8cAnUf8MfMaIOV323l6Y=
|
|||||||
github.com/onsi/gomega v1.25.0/go.mod h1:r+zV744Re+DiYCIPRlYOTxn0YkOLcAnW8k1xXdMPGhM=
|
github.com/onsi/gomega v1.25.0/go.mod h1:r+zV744Re+DiYCIPRlYOTxn0YkOLcAnW8k1xXdMPGhM=
|
||||||
github.com/openimsdk/gomake v0.0.15-alpha.5 h1:eEZCEHm+NsmcO3onXZPIUbGFCYPYbsX5beV3ZyOsGhY=
|
github.com/openimsdk/gomake v0.0.15-alpha.5 h1:eEZCEHm+NsmcO3onXZPIUbGFCYPYbsX5beV3ZyOsGhY=
|
||||||
github.com/openimsdk/gomake v0.0.15-alpha.5/go.mod h1:PndCozNc2IsQIciyn9mvEblYWZwJmAI+06z94EY+csI=
|
github.com/openimsdk/gomake v0.0.15-alpha.5/go.mod h1:PndCozNc2IsQIciyn9mvEblYWZwJmAI+06z94EY+csI=
|
||||||
github.com/openimsdk/protocol v0.0.73-alpha.11 h1:afrnUPNDLf1rEGmzhSdY/FEjGMeoVtwVFAv6t9c2wxA=
|
github.com/openimsdk/protocol v0.0.73-alpha.12 h1:2NYawXeHChYUeSme6QJ9pOLh+Empce2WmwEtbP4JvKk=
|
||||||
github.com/openimsdk/protocol v0.0.73-alpha.11/go.mod h1:WF7EuE55vQvpyUAzDXcqg+B+446xQyEba0X35lTINmw=
|
github.com/openimsdk/protocol v0.0.73-alpha.12/go.mod h1:WF7EuE55vQvpyUAzDXcqg+B+446xQyEba0X35lTINmw=
|
||||||
github.com/openimsdk/tools v0.0.50-alpha.84 h1:jN60Ys/0edZjL/TDmm/5VSJFP4pGYRipkWqhILJbq/8=
|
github.com/openimsdk/tools v0.0.50-alpha.84 h1:jN60Ys/0edZjL/TDmm/5VSJFP4pGYRipkWqhILJbq/8=
|
||||||
github.com/openimsdk/tools v0.0.50-alpha.84/go.mod h1:n2poR3asX1e1XZce4O+MOWAp+X02QJRFvhcLCXZdzRo=
|
github.com/openimsdk/tools v0.0.50-alpha.84/go.mod h1:n2poR3asX1e1XZce4O+MOWAp+X02QJRFvhcLCXZdzRo=
|
||||||
github.com/pelletier/go-toml/v2 v2.2.2 h1:aYUidT7k73Pcl9nb2gScu7NSrKCSHIDE89b3+6Wq+LM=
|
github.com/pelletier/go-toml/v2 v2.2.2 h1:aYUidT7k73Pcl9nb2gScu7NSrKCSHIDE89b3+6Wq+LM=
|
||||||
|
@ -372,6 +372,10 @@ func (g *groupServer) InviteUserToGroup(ctx context.Context, req *pbgroup.Invite
|
|||||||
return nil, servererrs.ErrDismissedAlready.WrapMsg("group dismissed checking group status found it dismissed")
|
return nil, servererrs.ErrDismissedAlready.WrapMsg("group dismissed checking group status found it dismissed")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if err := g.checkAdminOrInGroup(ctx, req.GroupID); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
userMap, err := g.userClient.GetUsersInfoMap(ctx, req.InvitedUserIDs)
|
userMap, err := g.userClient.GetUsersInfoMap(ctx, req.InvitedUserIDs)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
@ -422,7 +426,7 @@ func (g *groupServer) InviteUserToGroup(ctx context.Context, req *pbgroup.Invite
|
|||||||
ReqMessage: request.ReqMsg,
|
ReqMessage: request.ReqMsg,
|
||||||
JoinSource: request.JoinSource,
|
JoinSource: request.JoinSource,
|
||||||
InviterUserID: request.InviterUserID,
|
InviterUserID: request.InviterUserID,
|
||||||
})
|
}, request)
|
||||||
}
|
}
|
||||||
return &pbgroup.InviteUserToGroupResp{}, nil
|
return &pbgroup.InviteUserToGroupResp{}, nil
|
||||||
}
|
}
|
||||||
@ -978,7 +982,7 @@ func (g *groupServer) JoinGroup(ctx context.Context, req *pbgroup.JoinGroupReq)
|
|||||||
if err = g.db.CreateGroupRequest(ctx, []*model.GroupRequest{&groupRequest}); err != nil {
|
if err = g.db.CreateGroupRequest(ctx, []*model.GroupRequest{&groupRequest}); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
g.notification.JoinGroupApplicationNotification(ctx, req)
|
g.notification.JoinGroupApplicationNotification(ctx, req, &groupRequest)
|
||||||
return &pbgroup.JoinGroupResp{}, nil
|
return &pbgroup.JoinGroupResp{}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -370,13 +370,42 @@ func (g *NotificationSender) uuid() string {
|
|||||||
return uuid.New().String()
|
return uuid.New().String()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (g *NotificationSender) JoinGroupApplicationNotification(ctx context.Context, req *pbgroup.JoinGroupReq) {
|
func (g *NotificationSender) getGroupRequest(ctx context.Context, groupID string, userID string) (*sdkws.GroupRequest, error) {
|
||||||
|
request, err := g.db.TakeGroupRequest(ctx, groupID, userID)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
users, err := g.getUsersInfo(ctx, []string{userID})
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
if len(users) == 0 {
|
||||||
|
return nil, servererrs.ErrUserIDNotFound.WrapMsg(fmt.Sprintf("user %s not found", userID))
|
||||||
|
}
|
||||||
|
info, ok := users[0].(*sdkws.UserInfo)
|
||||||
|
if !ok {
|
||||||
|
info = &sdkws.UserInfo{
|
||||||
|
UserID: users[0].GetUserID(),
|
||||||
|
Nickname: users[0].GetNickname(),
|
||||||
|
FaceURL: users[0].GetFaceURL(),
|
||||||
|
Ex: users[0].GetEx(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return convert.Db2PbGroupRequest(request, info, nil), nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (g *NotificationSender) JoinGroupApplicationNotification(ctx context.Context, req *pbgroup.JoinGroupReq, dbReq *model.GroupRequest) {
|
||||||
var err error
|
var err error
|
||||||
defer func() {
|
defer func() {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.ZError(ctx, stringutil.GetFuncName(1)+" failed", err)
|
log.ZError(ctx, stringutil.GetFuncName(1)+" failed", err)
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
|
request, err := g.getGroupRequest(ctx, dbReq.GroupID, dbReq.UserID)
|
||||||
|
if err != nil {
|
||||||
|
log.ZError(ctx, "JoinGroupApplicationNotification getGroupRequest", err, "dbReq", dbReq)
|
||||||
|
return
|
||||||
|
}
|
||||||
var group *sdkws.GroupInfo
|
var group *sdkws.GroupInfo
|
||||||
group, err = g.getGroupInfo(ctx, req.GroupID)
|
group, err = g.getGroupInfo(ctx, req.GroupID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -392,7 +421,13 @@ func (g *NotificationSender) JoinGroupApplicationNotification(ctx context.Contex
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
userIDs = append(userIDs, req.InviterUserID, mcontext.GetOpUserID(ctx))
|
userIDs = append(userIDs, req.InviterUserID, mcontext.GetOpUserID(ctx))
|
||||||
tips := &sdkws.JoinGroupApplicationTips{Group: group, Applicant: user, ReqMsg: req.ReqMessage, Uuid: g.uuid()}
|
tips := &sdkws.JoinGroupApplicationTips{
|
||||||
|
Group: group,
|
||||||
|
Applicant: user,
|
||||||
|
ReqMsg: req.ReqMessage,
|
||||||
|
Uuid: g.uuid(),
|
||||||
|
Request: request,
|
||||||
|
}
|
||||||
for _, userID := range datautil.Distinct(userIDs) {
|
for _, userID := range datautil.Distinct(userIDs) {
|
||||||
g.Notification(ctx, mcontext.GetOpUserID(ctx), userID, constant.JoinGroupApplicationNotification, tips)
|
g.Notification(ctx, mcontext.GetOpUserID(ctx), userID, constant.JoinGroupApplicationNotification, tips)
|
||||||
}
|
}
|
||||||
@ -422,6 +457,11 @@ func (g *NotificationSender) GroupApplicationAcceptedNotification(ctx context.Co
|
|||||||
log.ZError(ctx, stringutil.GetFuncName(1)+" failed", err)
|
log.ZError(ctx, stringutil.GetFuncName(1)+" failed", err)
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
|
request, err := g.getGroupRequest(ctx, req.GroupID, req.FromUserID)
|
||||||
|
if err != nil {
|
||||||
|
log.ZError(ctx, "GroupApplicationAcceptedNotification getGroupRequest", err, "req", req)
|
||||||
|
return
|
||||||
|
}
|
||||||
var group *sdkws.GroupInfo
|
var group *sdkws.GroupInfo
|
||||||
group, err = g.getGroupInfo(ctx, req.GroupID)
|
group, err = g.getGroupInfo(ctx, req.GroupID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -437,7 +477,13 @@ func (g *NotificationSender) GroupApplicationAcceptedNotification(ctx context.Co
|
|||||||
if err = g.fillOpUser(ctx, &opUser, group.GroupID); err != nil {
|
if err = g.fillOpUser(ctx, &opUser, group.GroupID); err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
tips := &sdkws.GroupApplicationAcceptedTips{Group: group, OpUser: opUser, HandleMsg: req.HandledMsg, Uuid: g.uuid()}
|
tips := &sdkws.GroupApplicationAcceptedTips{
|
||||||
|
Group: group,
|
||||||
|
OpUser: opUser,
|
||||||
|
HandleMsg: req.HandledMsg,
|
||||||
|
Uuid: g.uuid(),
|
||||||
|
Request: request,
|
||||||
|
}
|
||||||
for _, userID := range append(userIDs, req.FromUserID) {
|
for _, userID := range append(userIDs, req.FromUserID) {
|
||||||
if userID == req.FromUserID {
|
if userID == req.FromUserID {
|
||||||
tips.ReceiverAs = applicantReceiver
|
tips.ReceiverAs = applicantReceiver
|
||||||
@ -455,6 +501,11 @@ func (g *NotificationSender) GroupApplicationRejectedNotification(ctx context.Co
|
|||||||
log.ZError(ctx, stringutil.GetFuncName(1)+" failed", err)
|
log.ZError(ctx, stringutil.GetFuncName(1)+" failed", err)
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
|
request, err := g.getGroupRequest(ctx, req.GroupID, req.FromUserID)
|
||||||
|
if err != nil {
|
||||||
|
log.ZError(ctx, "GroupApplicationAcceptedNotification getGroupRequest", err, "req", req)
|
||||||
|
return
|
||||||
|
}
|
||||||
var group *sdkws.GroupInfo
|
var group *sdkws.GroupInfo
|
||||||
group, err = g.getGroupInfo(ctx, req.GroupID)
|
group, err = g.getGroupInfo(ctx, req.GroupID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -470,7 +521,13 @@ func (g *NotificationSender) GroupApplicationRejectedNotification(ctx context.Co
|
|||||||
if err = g.fillOpUser(ctx, &opUser, group.GroupID); err != nil {
|
if err = g.fillOpUser(ctx, &opUser, group.GroupID); err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
tips := &sdkws.GroupApplicationRejectedTips{Group: group, OpUser: opUser, HandleMsg: req.HandledMsg, Uuid: g.uuid()}
|
tips := &sdkws.GroupApplicationRejectedTips{
|
||||||
|
Group: group,
|
||||||
|
OpUser: opUser,
|
||||||
|
HandleMsg: req.HandledMsg,
|
||||||
|
Uuid: g.uuid(),
|
||||||
|
Request: request,
|
||||||
|
}
|
||||||
for _, userID := range append(userIDs, req.FromUserID) {
|
for _, userID := range append(userIDs, req.FromUserID) {
|
||||||
if userID == req.FromUserID {
|
if userID == req.FromUserID {
|
||||||
tips.ReceiverAs = applicantReceiver
|
tips.ReceiverAs = applicantReceiver
|
||||||
|
@ -18,6 +18,7 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
|
|
||||||
"github.com/openimsdk/open-im-server/v3/pkg/dbbuild"
|
"github.com/openimsdk/open-im-server/v3/pkg/dbbuild"
|
||||||
|
"github.com/openimsdk/open-im-server/v3/pkg/notification/common_user"
|
||||||
"github.com/openimsdk/open-im-server/v3/pkg/rpcli"
|
"github.com/openimsdk/open-im-server/v3/pkg/rpcli"
|
||||||
|
|
||||||
"github.com/openimsdk/tools/mq/memamq"
|
"github.com/openimsdk/tools/mq/memamq"
|
||||||
@ -100,23 +101,24 @@ func Start(ctx context.Context, config *Config, client discovery.Conn, server gr
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
userClient := rpcli.NewUserClient(userConn)
|
userClient := rpcli.NewUserClient(userConn)
|
||||||
|
database := controller.NewFriendDatabase(
|
||||||
|
friendMongoDB,
|
||||||
|
friendRequestMongoDB,
|
||||||
|
redis.NewFriendCacheRedis(rdb, &config.LocalCacheConfig, friendMongoDB),
|
||||||
|
mgocli.GetTx(),
|
||||||
|
)
|
||||||
// Initialize notification sender
|
// Initialize notification sender
|
||||||
notificationSender := NewFriendNotificationSender(
|
notificationSender := NewFriendNotificationSender(
|
||||||
&config.NotificationConfig,
|
&config.NotificationConfig,
|
||||||
rpcli.NewMsgClient(msgConn),
|
rpcli.NewMsgClient(msgConn),
|
||||||
WithRpcFunc(userClient.GetUsersInfo),
|
WithRpcFunc(userClient.GetUsersInfo),
|
||||||
|
WithFriendDB(database),
|
||||||
)
|
)
|
||||||
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
|
||||||
relation.RegisterFriendServer(server, &friendServer{
|
relation.RegisterFriendServer(server, &friendServer{
|
||||||
db: controller.NewFriendDatabase(
|
db: database,
|
||||||
friendMongoDB,
|
|
||||||
friendRequestMongoDB,
|
|
||||||
redis.NewFriendCacheRedis(rdb, &config.LocalCacheConfig, friendMongoDB),
|
|
||||||
mgocli.GetTx(),
|
|
||||||
),
|
|
||||||
blackDatabase: controller.NewBlackDatabase(
|
blackDatabase: controller.NewBlackDatabase(
|
||||||
blackMongoDB,
|
blackMongoDB,
|
||||||
redis.NewBlackCacheRedis(rdb, &config.LocalCacheConfig, blackMongoDB),
|
redis.NewBlackCacheRedis(rdb, &config.LocalCacheConfig, blackMongoDB),
|
||||||
@ -328,7 +330,7 @@ func (s *friendServer) GetDesignatedFriendsApply(ctx context.Context, req *relat
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
resp = &relation.GetDesignatedFriendsApplyResp{}
|
resp = &relation.GetDesignatedFriendsApplyResp{}
|
||||||
resp.FriendRequests, err = convert.FriendRequestDB2Pb(ctx, friendRequests, s.userClient.GetUsersInfoMap)
|
resp.FriendRequests, err = convert.FriendRequestDB2Pb(ctx, friendRequests, s.getCommonUserMap)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@ -350,7 +352,7 @@ func (s *friendServer) GetPaginationFriendsApplyTo(ctx context.Context, req *rel
|
|||||||
}
|
}
|
||||||
|
|
||||||
resp = &relation.GetPaginationFriendsApplyToResp{}
|
resp = &relation.GetPaginationFriendsApplyToResp{}
|
||||||
resp.FriendRequests, err = convert.FriendRequestDB2Pb(ctx, friendRequests, s.userClient.GetUsersInfoMap)
|
resp.FriendRequests, err = convert.FriendRequestDB2Pb(ctx, friendRequests, s.getCommonUserMap)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@ -374,7 +376,7 @@ func (s *friendServer) GetPaginationFriendsApplyFrom(ctx context.Context, req *r
|
|||||||
}
|
}
|
||||||
|
|
||||||
resp = &relation.GetPaginationFriendsApplyFromResp{}
|
resp = &relation.GetPaginationFriendsApplyFromResp{}
|
||||||
resp.FriendRequests, err = convert.FriendRequestDB2Pb(ctx, friendRequests, s.userClient.GetUsersInfoMap)
|
resp.FriendRequests, err = convert.FriendRequestDB2Pb(ctx, friendRequests, s.getCommonUserMap)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@ -564,3 +566,13 @@ func (s *friendServer) GetSelfUnhandledApplyCount(ctx context.Context, req *rela
|
|||||||
Count: count,
|
Count: count,
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (s *friendServer) getCommonUserMap(ctx context.Context, userIDs []string) (map[string]common_user.CommonUser, error) {
|
||||||
|
users, err := s.userClient.GetUsersInfo(ctx, userIDs)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return datautil.SliceToMapAny(users, func(e *sdkws.UserInfo) (string, common_user.CommonUser) {
|
||||||
|
return e.UserID, e
|
||||||
|
}), nil
|
||||||
|
}
|
||||||
|
@ -19,6 +19,9 @@ import (
|
|||||||
|
|
||||||
"github.com/openimsdk/open-im-server/v3/pkg/rpcli"
|
"github.com/openimsdk/open-im-server/v3/pkg/rpcli"
|
||||||
"github.com/openimsdk/protocol/msg"
|
"github.com/openimsdk/protocol/msg"
|
||||||
|
"github.com/openimsdk/tools/errs"
|
||||||
|
"github.com/openimsdk/tools/log"
|
||||||
|
"github.com/openimsdk/tools/utils/datautil"
|
||||||
|
|
||||||
"github.com/openimsdk/open-im-server/v3/pkg/common/storage/database"
|
"github.com/openimsdk/open-im-server/v3/pkg/common/storage/database"
|
||||||
"github.com/openimsdk/open-im-server/v3/pkg/common/storage/versionctx"
|
"github.com/openimsdk/open-im-server/v3/pkg/common/storage/versionctx"
|
||||||
@ -52,9 +55,7 @@ func WithFriendDB(db controller.FriendDatabase) friendNotificationSenderOptions
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func WithDBFunc(
|
func WithDBFunc(fn func(ctx context.Context, userIDs []string) (users []*relationtb.User, err error)) friendNotificationSenderOptions {
|
||||||
fn func(ctx context.Context, userIDs []string) (users []*relationtb.User, err error),
|
|
||||||
) friendNotificationSenderOptions {
|
|
||||||
return func(s *FriendNotificationSender) {
|
return func(s *FriendNotificationSender) {
|
||||||
f := func(ctx context.Context, userIDs []string) (result []common_user.CommonUser, err error) {
|
f := func(ctx context.Context, userIDs []string) (result []common_user.CommonUser, err error) {
|
||||||
users, err := fn(ctx, userIDs)
|
users, err := fn(ctx, userIDs)
|
||||||
@ -70,9 +71,7 @@ func WithDBFunc(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func WithRpcFunc(
|
func WithRpcFunc(fn func(ctx context.Context, userIDs []string) ([]*sdkws.UserInfo, error)) friendNotificationSenderOptions {
|
||||||
fn func(ctx context.Context, userIDs []string) ([]*sdkws.UserInfo, error),
|
|
||||||
) friendNotificationSenderOptions {
|
|
||||||
return func(s *FriendNotificationSender) {
|
return func(s *FriendNotificationSender) {
|
||||||
f := func(ctx context.Context, userIDs []string) (result []common_user.CommonUser, err error) {
|
f := func(ctx context.Context, userIDs []string) (result []common_user.CommonUser, err error) {
|
||||||
users, err := fn(ctx, userIDs)
|
users, err := fn(ctx, userIDs)
|
||||||
@ -100,10 +99,7 @@ func NewFriendNotificationSender(conf *config.Notification, msgClient *rpcli.Msg
|
|||||||
return f
|
return f
|
||||||
}
|
}
|
||||||
|
|
||||||
func (f *FriendNotificationSender) getUsersInfoMap(
|
func (f *FriendNotificationSender) getUsersInfoMap(ctx context.Context, userIDs []string) (map[string]*sdkws.UserInfo, error) {
|
||||||
ctx context.Context,
|
|
||||||
userIDs []string,
|
|
||||||
) (map[string]*sdkws.UserInfo, error) {
|
|
||||||
users, err := f.getUsersInfo(ctx, userIDs)
|
users, err := f.getUsersInfo(ctx, userIDs)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
@ -116,10 +112,7 @@ func (f *FriendNotificationSender) getUsersInfoMap(
|
|||||||
}
|
}
|
||||||
|
|
||||||
//nolint:unused
|
//nolint:unused
|
||||||
func (f *FriendNotificationSender) getFromToUserNickname(
|
func (f *FriendNotificationSender) getFromToUserNickname(ctx context.Context, fromUserID, toUserID string) (string, string, error) {
|
||||||
ctx context.Context,
|
|
||||||
fromUserID, toUserID string,
|
|
||||||
) (string, string, error) {
|
|
||||||
users, err := f.getUsersInfoMap(ctx, []string{fromUserID, toUserID})
|
users, err := f.getUsersInfoMap(ctx, []string{fromUserID, toUserID})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", "", nil
|
return "", "", nil
|
||||||
@ -132,60 +125,107 @@ func (f *FriendNotificationSender) UserInfoUpdatedNotification(ctx context.Conte
|
|||||||
f.Notification(ctx, mcontext.GetOpUserID(ctx), changedUserID, constant.UserInfoUpdatedNotification, &tips)
|
f.Notification(ctx, mcontext.GetOpUserID(ctx), changedUserID, constant.UserInfoUpdatedNotification, &tips)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (f *FriendNotificationSender) getCommonUserMap(ctx context.Context, userIDs []string) (map[string]common_user.CommonUser, error) {
|
||||||
|
users, err := f.getUsersInfo(ctx, userIDs)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return datautil.SliceToMap(users, func(e common_user.CommonUser) string {
|
||||||
|
return e.GetUserID()
|
||||||
|
}), nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (f *FriendNotificationSender) getFriendRequests(ctx context.Context, fromUserID, toUserID string) (*sdkws.FriendRequest, error) {
|
||||||
|
if f.db == nil {
|
||||||
|
return nil, errs.ErrInternalServer.WithDetail("db is nil")
|
||||||
|
}
|
||||||
|
friendRequests, err := f.db.FindBothFriendRequests(ctx, fromUserID, toUserID)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
requests, err := convert.FriendRequestDB2Pb(ctx, friendRequests, f.getCommonUserMap)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
for _, request := range requests {
|
||||||
|
if request.FromUserID == fromUserID && request.ToUserID == toUserID {
|
||||||
|
return request, nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nil, errs.ErrRecordNotFound.WrapMsg("friend request not found", "fromUserID", fromUserID, "toUserID", toUserID)
|
||||||
|
}
|
||||||
|
|
||||||
func (f *FriendNotificationSender) FriendApplicationAddNotification(ctx context.Context, req *relation.ApplyToAddFriendReq) {
|
func (f *FriendNotificationSender) FriendApplicationAddNotification(ctx context.Context, req *relation.ApplyToAddFriendReq) {
|
||||||
tips := sdkws.FriendApplicationTips{FromToUserID: &sdkws.FromToUserID{
|
request, err := f.getFriendRequests(ctx, req.FromUserID, req.ToUserID)
|
||||||
|
if err != nil {
|
||||||
|
log.ZError(ctx, "FriendApplicationAddNotification get friend request", err, "fromUserID", req.FromUserID, "toUserID", req.ToUserID)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
tips := sdkws.FriendApplicationTips{
|
||||||
|
FromToUserID: &sdkws.FromToUserID{
|
||||||
FromUserID: req.FromUserID,
|
FromUserID: req.FromUserID,
|
||||||
ToUserID: req.ToUserID,
|
ToUserID: req.ToUserID,
|
||||||
}}
|
},
|
||||||
|
Request: request,
|
||||||
|
}
|
||||||
f.Notification(ctx, req.FromUserID, req.ToUserID, constant.FriendApplicationNotification, &tips)
|
f.Notification(ctx, req.FromUserID, req.ToUserID, constant.FriendApplicationNotification, &tips)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (f *FriendNotificationSender) FriendApplicationAgreedNotification(
|
func (f *FriendNotificationSender) FriendApplicationAgreedNotification(ctx context.Context, req *relation.RespondFriendApplyReq) {
|
||||||
ctx context.Context,
|
request, err := f.getFriendRequests(ctx, req.FromUserID, req.ToUserID)
|
||||||
req *relation.RespondFriendApplyReq,
|
if err != nil {
|
||||||
) {
|
log.ZError(ctx, "FriendApplicationAgreedNotification get friend request", err, "fromUserID", req.FromUserID, "toUserID", req.ToUserID)
|
||||||
tips := sdkws.FriendApplicationApprovedTips{FromToUserID: &sdkws.FromToUserID{
|
return
|
||||||
|
}
|
||||||
|
tips := sdkws.FriendApplicationApprovedTips{
|
||||||
|
FromToUserID: &sdkws.FromToUserID{
|
||||||
FromUserID: req.FromUserID,
|
FromUserID: req.FromUserID,
|
||||||
ToUserID: req.ToUserID,
|
ToUserID: req.ToUserID,
|
||||||
}, HandleMsg: req.HandleMsg}
|
},
|
||||||
|
HandleMsg: req.HandleMsg,
|
||||||
|
Request: request,
|
||||||
|
}
|
||||||
f.Notification(ctx, req.ToUserID, req.FromUserID, constant.FriendApplicationApprovedNotification, &tips)
|
f.Notification(ctx, req.ToUserID, req.FromUserID, constant.FriendApplicationApprovedNotification, &tips)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (f *FriendNotificationSender) FriendApplicationRefusedNotification(
|
func (f *FriendNotificationSender) FriendApplicationRefusedNotification(ctx context.Context, req *relation.RespondFriendApplyReq) {
|
||||||
ctx context.Context,
|
request, err := f.getFriendRequests(ctx, req.FromUserID, req.ToUserID)
|
||||||
req *relation.RespondFriendApplyReq,
|
if err != nil {
|
||||||
) {
|
log.ZError(ctx, "FriendApplicationRefusedNotification get friend request", err, "fromUserID", req.FromUserID, "toUserID", req.ToUserID)
|
||||||
tips := sdkws.FriendApplicationApprovedTips{FromToUserID: &sdkws.FromToUserID{
|
return
|
||||||
|
}
|
||||||
|
tips := sdkws.FriendApplicationRejectedTips{
|
||||||
|
FromToUserID: &sdkws.FromToUserID{
|
||||||
FromUserID: req.FromUserID,
|
FromUserID: req.FromUserID,
|
||||||
ToUserID: req.ToUserID,
|
ToUserID: req.ToUserID,
|
||||||
}, HandleMsg: req.HandleMsg}
|
},
|
||||||
|
HandleMsg: req.HandleMsg,
|
||||||
|
Request: request,
|
||||||
|
}
|
||||||
f.Notification(ctx, req.ToUserID, req.FromUserID, constant.FriendApplicationRejectedNotification, &tips)
|
f.Notification(ctx, req.ToUserID, req.FromUserID, constant.FriendApplicationRejectedNotification, &tips)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (f *FriendNotificationSender) FriendAddedNotification(
|
//func (f *FriendNotificationSender) FriendAddedNotification(ctx context.Context, operationID, opUserID, fromUserID, toUserID string) error {
|
||||||
ctx context.Context,
|
// tips := sdkws.FriendAddedTips{Friend: &sdkws.FriendInfo{}, OpUser: &sdkws.PublicUserInfo{}}
|
||||||
operationID, opUserID, fromUserID, toUserID string,
|
// user, err := f.getUsersInfo(ctx, []string{opUserID})
|
||||||
) error {
|
// if err != nil {
|
||||||
tips := sdkws.FriendAddedTips{Friend: &sdkws.FriendInfo{}, OpUser: &sdkws.PublicUserInfo{}}
|
// return err
|
||||||
user, err := f.getUsersInfo(ctx, []string{opUserID})
|
// }
|
||||||
if err != nil {
|
// tips.OpUser.UserID = user[0].GetUserID()
|
||||||
return err
|
// tips.OpUser.Ex = user[0].GetEx()
|
||||||
}
|
// tips.OpUser.Nickname = user[0].GetNickname()
|
||||||
tips.OpUser.UserID = user[0].GetUserID()
|
// tips.OpUser.FaceURL = user[0].GetFaceURL()
|
||||||
tips.OpUser.Ex = user[0].GetEx()
|
// friends, err := f.db.FindFriendsWithError(ctx, fromUserID, []string{toUserID})
|
||||||
tips.OpUser.Nickname = user[0].GetNickname()
|
// if err != nil {
|
||||||
tips.OpUser.FaceURL = user[0].GetFaceURL()
|
// return err
|
||||||
friends, err := f.db.FindFriendsWithError(ctx, fromUserID, []string{toUserID})
|
// }
|
||||||
if err != nil {
|
// tips.Friend, err = convert.FriendDB2Pb(ctx, friends[0], f.getUsersInfoMap)
|
||||||
return err
|
// if err != nil {
|
||||||
}
|
// return err
|
||||||
tips.Friend, err = convert.FriendDB2Pb(ctx, friends[0], f.getUsersInfoMap)
|
// }
|
||||||
if err != nil {
|
// f.Notification(ctx, fromUserID, toUserID, constant.FriendAddedNotification, &tips)
|
||||||
return err
|
// return nil
|
||||||
}
|
//}
|
||||||
f.Notification(ctx, fromUserID, toUserID, constant.FriendAddedNotification, &tips)
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (f *FriendNotificationSender) FriendDeletedNotification(ctx context.Context, req *relation.DeleteFriendReq) {
|
func (f *FriendNotificationSender) FriendDeletedNotification(ctx context.Context, req *relation.DeleteFriendReq) {
|
||||||
tips := sdkws.FriendDeletedTips{FromToUserID: &sdkws.FromToUserID{
|
tips := sdkws.FriendDeletedTips{FromToUserID: &sdkws.FromToUserID{
|
||||||
|
@ -17,7 +17,9 @@ package convert
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
"github.com/openimsdk/open-im-server/v3/pkg/common/storage/model"
|
"github.com/openimsdk/open-im-server/v3/pkg/common/storage/model"
|
||||||
|
"github.com/openimsdk/open-im-server/v3/pkg/notification/common_user"
|
||||||
"github.com/openimsdk/protocol/relation"
|
"github.com/openimsdk/protocol/relation"
|
||||||
|
|
||||||
"github.com/openimsdk/protocol/sdkws"
|
"github.com/openimsdk/protocol/sdkws"
|
||||||
@ -98,7 +100,7 @@ func FriendOnlyDB2PbOnly(friendsDB []*model.Friend) []*relation.FriendInfoOnly {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func FriendRequestDB2Pb(ctx context.Context, friendRequests []*model.FriendRequest, getUsers func(ctx context.Context, userIDs []string) (map[string]*sdkws.UserInfo, error)) ([]*sdkws.FriendRequest, error) {
|
func FriendRequestDB2Pb(ctx context.Context, friendRequests []*model.FriendRequest, getUsers func(ctx context.Context, userIDs []string) (map[string]common_user.CommonUser, error)) ([]*sdkws.FriendRequest, error) {
|
||||||
if len(friendRequests) == 0 {
|
if len(friendRequests) == 0 {
|
||||||
return nil, nil
|
return nil, nil
|
||||||
}
|
}
|
||||||
@ -117,11 +119,11 @@ func FriendRequestDB2Pb(ctx context.Context, friendRequests []*model.FriendReque
|
|||||||
fromUser := users[friendRequest.FromUserID]
|
fromUser := users[friendRequest.FromUserID]
|
||||||
res = append(res, &sdkws.FriendRequest{
|
res = append(res, &sdkws.FriendRequest{
|
||||||
FromUserID: friendRequest.FromUserID,
|
FromUserID: friendRequest.FromUserID,
|
||||||
FromNickname: fromUser.Nickname,
|
FromNickname: fromUser.GetNickname(),
|
||||||
FromFaceURL: fromUser.FaceURL,
|
FromFaceURL: fromUser.GetFaceURL(),
|
||||||
ToUserID: friendRequest.ToUserID,
|
ToUserID: friendRequest.ToUserID,
|
||||||
ToNickname: toUser.Nickname,
|
ToNickname: toUser.GetNickname(),
|
||||||
ToFaceURL: toUser.FaceURL,
|
ToFaceURL: toUser.GetFaceURL(),
|
||||||
HandleResult: friendRequest.HandleResult,
|
HandleResult: friendRequest.HandleResult,
|
||||||
ReqMsg: friendRequest.ReqMsg,
|
ReqMsg: friendRequest.ReqMsg,
|
||||||
CreateTime: friendRequest.CreateTime.UnixMilli(),
|
CreateTime: friendRequest.CreateTime.UnixMilli(),
|
||||||
|
Loading…
x
Reference in New Issue
Block a user