diff --git a/go.mod b/go.mod index 5b7c583c3..8f36d5856 100644 --- a/go.mod +++ b/go.mod @@ -46,7 +46,11 @@ require ( github.com/minio/minio-go v6.0.14+incompatible ) -require github.com/go-sql-driver/mysql v1.6.0 +require ( + github.com/go-sql-driver/mysql v1.6.0 + k8s.io/apimachinery v0.27.1 + k8s.io/client-go v0.27.1 +) require ( cloud.google.com/go v0.105.0 // indirect @@ -131,8 +135,6 @@ require ( gopkg.in/inf.v0 v0.9.1 // indirect gopkg.in/yaml.v2 v2.4.0 // indirect k8s.io/api v0.27.1 // indirect - k8s.io/apimachinery v0.27.1 // indirect - k8s.io/client-go v0.27.1 // indirect k8s.io/klog/v2 v2.90.1 // indirect k8s.io/kube-openapi v0.0.0-20230308215209-15aac26d736a // indirect k8s.io/utils v0.0.0-20230209194617-a36077c30491 // indirect diff --git a/go.sum b/go.sum index 7efb70a38..2c223f730 100644 --- a/go.sum +++ b/go.sum @@ -495,6 +495,7 @@ github.com/go-sql-driver/mysql v1.6.0 h1:BCTh4TKNUYmOmMUcQ3IipzF5prigylS7XXjEkfC github.com/go-sql-driver/mysql v1.6.0/go.mod h1:DCzpHaOWr8IXmIStZouvnhqoel9Qv2LBy8hT2VhHyBg= github.com/go-stack/stack v1.8.0 h1:5SgMzNM5HxrEjV0ww2lTmX6E2Izsfxas4+YHWRs3Lsk= github.com/go-stack/stack v1.8.0/go.mod h1:v0f6uXyyMGvRgIKkXu+yp6POWl0qKG85gN/melR3HDY= +github.com/go-task/slim-sprig v0.0.0-20210107165309-348f09dbbbc0 h1:p104kn46Q8WdvHunIJ9dAyjPVtrBPhSr3KT2yUst43I= github.com/go-zookeeper/zk v1.0.3 h1:7M2kwOsc//9VeeFiPtf+uSJlVpU66x9Ba5+8XK7/TDg= github.com/go-zookeeper/zk v1.0.3/go.mod h1:nOB03cncLtlp4t+UAkGSV+9beXP/akpekBwL+UX1Qcw= github.com/goccy/go-json v0.10.0 h1:mXKd9Qw4NuzShiRlOXKews24ufknHO7gx30lsDyokKA= @@ -507,7 +508,6 @@ github.com/golang-jwt/jwt/v4 v4.4.2/go.mod h1:m21LjoU+eqJr34lmDMbreY2eSTRJ1cv77w github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q= github.com/golang/groupcache v0.0.0-20190702054246-869f871628b6/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc= github.com/golang/groupcache v0.0.0-20191227052852-215e87163ea7/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc= -github.com/golang/groupcache v0.0.0-20200121045136-8c9f03a8e57e h1:1r7pUrabqp18hOBcwBwiTsbnFeTZHV9eER/QT5JVZxY= github.com/golang/groupcache v0.0.0-20200121045136-8c9f03a8e57e/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc= github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da h1:oI5xCqsCo564l8iNU+DwB5epxmsaqB+rhGL0m5jtYqE= github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc= @@ -536,7 +536,6 @@ github.com/golang/protobuf v1.4.2/go.mod h1:oDoupMAO8OvCJWAcko0GGGIgR6R6ocIYbsSw github.com/golang/protobuf v1.4.3/go.mod h1:oDoupMAO8OvCJWAcko0GGGIgR6R6ocIYbsSw735rRwI= github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk= github.com/golang/protobuf v1.5.1/go.mod h1:DopwsBzvsk0Fs44TXzsVbJyPhcCPeIwnvohx4u74HPM= -github.com/golang/protobuf v1.5.2 h1:ROPKBNFfQgOUMifHyP+KYbvpjbdoFNs+aK7DXlji0Tw= github.com/golang/protobuf v1.5.2/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY= github.com/golang/protobuf v1.5.3 h1:KhyjKVUg7Usr/dYsdSqoFveMYd5ko72D+zANwlG1mmg= github.com/golang/protobuf v1.5.3/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY= @@ -585,6 +584,7 @@ github.com/google/pprof v0.0.0-20210122040257-d980be63207e/go.mod h1:kpwsk12EmLe github.com/google/pprof v0.0.0-20210226084205-cbba55b83ad5/go.mod h1:kpwsk12EmLew5upagYY7GY0pfYCcupk39gWOCRROcvE= github.com/google/pprof v0.0.0-20210601050228-01bbb1931b22/go.mod h1:kpwsk12EmLew5upagYY7GY0pfYCcupk39gWOCRROcvE= github.com/google/pprof v0.0.0-20210609004039-a478d1d731e9/go.mod h1:kpwsk12EmLew5upagYY7GY0pfYCcupk39gWOCRROcvE= +github.com/google/pprof v0.0.0-20210720184732-4bb14d4b1be1 h1:K6RDEckDVWvDI9JAJYCmNdQXq6neHJOYx3V6jnqNEec= github.com/google/pprof v0.0.0-20210720184732-4bb14d4b1be1/go.mod h1:kpwsk12EmLew5upagYY7GY0pfYCcupk39gWOCRROcvE= github.com/google/renameio v0.1.0/go.mod h1:KWCgfxg9yswjAJkECMjeO8J8rahYeXnNhOm40UhjYkI= github.com/google/uuid v1.1.2/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= @@ -722,7 +722,8 @@ github.com/nxadm/tail v1.4.8 h1:nPr65rt6Y5JFSKQO7qToXr7pePgD6Gwiw05lkbyAQTE= github.com/olivere/elastic/v7 v7.0.23 h1:b7tjMogDMhf2CisGI+L02LXLVa0ZyE82Z15XfW1e8t8= github.com/olivere/elastic/v7 v7.0.23/go.mod h1:OuWmD2DiuYhddWegBKPWQuelVKBLrW0fa/VUYgxuGTY= github.com/onsi/ginkgo v1.16.5 h1:8xi0RTUf59SOSfEtZMvwTvXYMzG4gV23XVHOZiXNtnE= -github.com/onsi/gomega v1.18.1 h1:M1GfJqGRrBrrGGsbxzV5dqM2U2ApXefZCQpkukxYRLE= +github.com/onsi/ginkgo/v2 v2.9.1 h1:zie5Ly042PD3bsCvsSOPvRnFwyo3rKe64TJlD6nu0mk= +github.com/onsi/gomega v1.27.4 h1:Z2AnStgsdSayCMDiCU42qIz+HLqEPcgiOCXjAU/w+8E= github.com/opentracing/opentracing-go v1.2.0/go.mod h1:GxEUsuufX4nBwe+T+Wl9TAgYrxe9dPLANfrWvHYVTgc= github.com/pelletier/go-toml/v2 v2.0.6 h1:nrzqCb7j9cDFj2coyLNLaZuJTLjWjlaz6nvTvIwycIU= github.com/pelletier/go-toml/v2 v2.0.6/go.mod h1:eumQOmlWiOPt5WriQQqoM5y18pDHwha2N+QD+EUNTek= @@ -769,8 +770,8 @@ github.com/robfig/cron/v3 v3.0.1/go.mod h1:eQICP3HwyT7UooqI/z+Ov+PtYAWygg1TEWWzG github.com/rogpeppe/fastuuid v1.2.0/go.mod h1:jVj6XXZzXRy/MSR5jhDC/2q6DgLz+nrA6LYCDYWNEvQ= github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4= github.com/rogpeppe/go-internal v1.6.1/go.mod h1:xXDCJY+GAPziupqXw64V24skbSoqbTEfhy4qGm1nDQc= -github.com/rogpeppe/go-internal v1.8.0 h1:FCbCCtXNOY3UtUuHUYaghJg4y7Fd14rXifAYUAtL9R8= github.com/rogpeppe/go-internal v1.8.0/go.mod h1:WmiCO8CzOY8rg0OYDC4/i/2WRWAB6poM+XZ2dLUbcbE= +github.com/rogpeppe/go-internal v1.10.0 h1:TMyTOH3F/DB16zRVcYyreMH6GnZZrwQVAoYjRBZyWFQ= github.com/rs/xid v1.2.1 h1:mhH9Nq+C1fY2l1XIpgxIiUOfNpRBYH1kKcr+qfKgjRc= github.com/rs/xid v1.2.1/go.mod h1:+uKXf+4Djp6Md1KODXJxgGQPKngRmWyn10oCKFzNHOQ= github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= @@ -947,8 +948,6 @@ golang.org/x/net v0.0.0-20220909164309-bea034e7d591/go.mod h1:YDH+HFinaLZZlnHAfS golang.org/x/net v0.0.0-20221012135044-0b7e1fb9d458/go.mod h1:YDH+HFinaLZZlnHAfSS6ZXJJ9M9t4Dl22yv3iI2vPwk= golang.org/x/net v0.0.0-20221014081412-f15817d10f9b/go.mod h1:YDH+HFinaLZZlnHAfSS6ZXJJ9M9t4Dl22yv3iI2vPwk= golang.org/x/net v0.4.0/go.mod h1:MBQ8lrhLObU/6UmLb4fmbmk5OcyYmqtbGd/9yIeKjEE= -golang.org/x/net v0.5.0 h1:GyT4nK/YDHSqa1c4753ouYCDajOYKTja9Xb/OHtgvSw= -golang.org/x/net v0.5.0/go.mod h1:DivGGAXEgPSlEBzxGzZI+ZLohi+xUj054jfeKui00ws= golang.org/x/net v0.8.0 h1:Zrh2ngAOFYneWTAIAPethzeaQLuHwhuBkuV6ZiRnUaQ= golang.org/x/net v0.8.0/go.mod h1:QVkue5JL9kW//ek3r6jTKnTFis1tRmNAW2P1shuFdJc= golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= @@ -1068,8 +1067,6 @@ golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBc golang.org/x/sys v0.0.0-20220728004956-3c1f35247d10/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.3.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.4.0 h1:Zr2JFtRQNX3BCZ8YtxRE9hNJYC8J6I1MVbMg6owUp18= -golang.org/x/sys v0.4.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.6.0 h1:MVltZSvRTcU2ljQOhs94SXPftV6DCNnZViHeQps87pQ= golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/term v0.0.0-20201117132131-f5c789dd3221/go.mod h1:Nr5EML6q2oocZ2LXRh80K7BxOlk5/8JxuGnuhpl+muw= @@ -1090,7 +1087,6 @@ golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ= golang.org/x/text v0.3.8/go.mod h1:E6s5w1FMmriuDzIBO73fBruAKo1PCIq6d2Q6DHfQ8WQ= golang.org/x/text v0.4.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8= golang.org/x/text v0.5.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8= -golang.org/x/text v0.6.0 h1:3XmdazWV+ubf7QgHSTWeykHOci5oeekaGJBLkrkaw4k= golang.org/x/text v0.6.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8= golang.org/x/text v0.8.0 h1:57P1ETyNKtuIjB4SRd15iJxuhj8Gc416Y78H3qgMh68= golang.org/x/text v0.8.0/go.mod h1:e1OnstbJyHTd6l/uOt8jFFHp6TRDWZR/bV3emEE/zU8= @@ -1154,6 +1150,7 @@ golang.org/x/tools v0.1.3/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk= golang.org/x/tools v0.1.4/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk= golang.org/x/tools v0.1.5/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk= golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc= +golang.org/x/tools v0.7.0 h1:W4OVu8VVOaIO0yzWMNdepAulS7YfoS3Zabrm8DOXXU4= golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= diff --git a/internal/rpc/group/group.go b/internal/rpc/group/group.go index b1e74f4a7..e13a6afda 100644 --- a/internal/rpc/group/group.go +++ b/internal/rpc/group/group.go @@ -3,6 +3,7 @@ package group import ( "context" "fmt" + "github.com/OpenIMSDK/Open-IM-Server/pkg/rpcclient/notification2" "math/big" "math/rand" "strconv" @@ -26,8 +27,6 @@ import ( pbConversation "github.com/OpenIMSDK/Open-IM-Server/pkg/proto/conversation" pbGroup "github.com/OpenIMSDK/Open-IM-Server/pkg/proto/group" "github.com/OpenIMSDK/Open-IM-Server/pkg/proto/sdkws" - "github.com/OpenIMSDK/Open-IM-Server/pkg/rpcclient/check" - "github.com/OpenIMSDK/Open-IM-Server/pkg/rpcclient/notification" "github.com/OpenIMSDK/Open-IM-Server/pkg/utils" "google.golang.org/grpc" ) @@ -48,19 +47,28 @@ func Start(client discoveryregistry.SvcDiscoveryRegistry, server *grpc.Server) e if err != nil { return err } + user := rpcclient.NewUserClient(client) + database := controller.InitGroupDatabase(db, rdb, mongo.GetDatabase()) pbGroup.RegisterGroupServer(server, &groupServer{ - GroupDatabase: controller.InitGroupDatabase(db, rdb, mongo.GetDatabase()), - UserCheck: check.NewUserCheck(client), - Notification: notification.NewCheck(client), + GroupDatabase: database, + User: user, + Notification: notification2.NewGroupNotificationSender(database, client, func(ctx context.Context, userIDs []string) ([]rpcclient.CommonUser, error) { + users, err := user.GetUsersInfo(ctx, userIDs) + if err != nil { + return nil, err + } + return utils.Slice(users, func(e *sdkws.UserInfo) rpcclient.CommonUser { return e }), nil + }), conversationRpcClient: rpcclient.NewConversationClient(client), }) return nil } type groupServer struct { - GroupDatabase controller.GroupDatabase - UserCheck *check.UserCheck - Notification *notification.Check + GroupDatabase controller.GroupDatabase + User *rpcclient.UserClient + //Notification *notification.Check + Notification *notification2.GroupNotificationSender conversationRpcClient *rpcclient.ConversationClient } @@ -81,7 +89,7 @@ func (s *groupServer) GetUsernameMap(ctx context.Context, userIDs []string, comp if len(userIDs) == 0 { return map[string]string{}, nil } - users, err := s.UserCheck.GetPublicUserInfos(ctx, userIDs, complete) + users, err := s.User.GetPublicUserInfos(ctx, userIDs, complete) if err != nil { return nil, err } @@ -130,11 +138,11 @@ func (s *groupServer) CreateGroup(ctx context.Context, req *pbGroup.CreateGroupR if req.OwnerUserID == "" { return nil, errs.ErrArgs.Wrap("no group owner") } - userIDs := append(append(req.InitMembers, req.AdminUserIDs...), req.OwnerUserID) + userIDs := append(append(req.InitMembers, req.AdminUserIDs...), req.OwnerUserID, mcontext.GetOpUserID(ctx)) if utils.Duplicate(userIDs) { return nil, errs.ErrArgs.Wrap("group member repeated") } - userMap, err := s.UserCheck.GetUsersInfoMap(ctx, userIDs, true) + userMap, err := s.User.GetUsersInfoMap(ctx, userIDs) if err != nil { return nil, err } @@ -194,7 +202,7 @@ func (s *groupServer) CreateGroup(ctx context.Context, req *pbGroup.CreateGroupR } }() } else { - s.Notification.GroupCreatedNotification(ctx, group.GroupID, userIDs) + s.Notification.GroupCreatedNotification(ctx, group, groupMembers, userMap) } return resp, nil } @@ -258,7 +266,7 @@ func (s *groupServer) InviteUserToGroup(ctx context.Context, req *pbGroup.Invite if group.Status == constant.GroupStatusDismissed { return nil, errs.ErrDismissedAlready.Wrap() } - userMap, err := s.UserCheck.GetUsersInfoMap(ctx, req.InvitedUserIDs, true) + userMap, err := s.User.GetUsersInfoMap(ctx, req.InvitedUserIDs) if err != nil { return nil, err } @@ -497,7 +505,7 @@ func (s *groupServer) GetGroupApplicationList(ctx context.Context, req *pbGroup. } userIDs = utils.Distinct(userIDs) groupIDs = utils.Distinct(groupIDs) - userMap, err := s.UserCheck.GetPublicUserInfoMap(ctx, userIDs, true) + userMap, err := s.User.GetPublicUserInfoMap(ctx, userIDs, true) if err != nil { return nil, err } @@ -586,7 +594,7 @@ func (s *groupServer) GroupApplicationResponse(ctx context.Context, req *pbGroup } else if !s.IsNotFound(err) { return nil, err } - user, err := s.UserCheck.GetPublicUserInfo(ctx, req.FromUserID) + user, err := s.User.GetPublicUserInfo(ctx, req.FromUserID) if err != nil { return nil, err } @@ -624,7 +632,7 @@ func (s *groupServer) GroupApplicationResponse(ctx context.Context, req *pbGroup } func (s *groupServer) JoinGroup(ctx context.Context, req *pbGroup.JoinGroupReq) (resp *pbGroup.JoinGroupResp, err error) { - user, err := s.UserCheck.GetUserInfo(ctx, req.InviterUserID) + user, err := s.User.GetUserInfo(ctx, req.InviterUserID) if err != nil { return nil, err } @@ -660,7 +668,7 @@ func (s *groupServer) JoinGroup(ctx context.Context, req *pbGroup.JoinGroupReq) if err := s.GroupDatabase.CreateGroup(ctx, nil, []*relationTb.GroupMemberModel{groupMember}); err != nil { return nil, err } - s.Notification.MemberEnterDirectlyNotification(ctx, req.GroupID, req.InviterUserID, mcontext.GetOperationID(ctx)) + s.Notification.MemberEnterDirectlyNotification(ctx, req.GroupID, req.InviterUserID) return resp, nil } groupRequest := relationTb.GroupRequestModel{ @@ -723,10 +731,10 @@ func (s *groupServer) SetGroupInfo(ctx context.Context, req *pbGroup.SetGroupInf if group.Status == constant.GroupStatusDismissed { return nil, utils.Wrap(errs.ErrDismissedAlready, "") } - userIDs, err := s.GroupDatabase.FindGroupMemberUserID(ctx, group.GroupID) - if err != nil { - return nil, err - } + //userIDs, err := s.GroupDatabase.FindGroupMemberUserID(ctx, group.GroupID) + //if err != nil { + // return nil, err + //} resp := &pbGroup.SetGroupInfoResp{} data := UpdateGroupInfoMap(req.GroupInfoForSet) if len(data) == 0 { @@ -739,7 +747,12 @@ func (s *groupServer) SetGroupInfo(ctx context.Context, req *pbGroup.SetGroupInf if err != nil { return nil, err } - s.Notification.GroupInfoSetNotification(ctx, req.GroupInfoForSet.GroupID, group.GroupName, group.Notification, group.Introduction, group.FaceURL, req.GroupInfoForSet.NeedVerification) + members, err := s.GroupDatabase.FindGroupMember(ctx, []string{group.GroupID}, nil, nil) + if err != nil { + return nil, err + } + userIDs := utils.Slice(members, func(e *relationTb.GroupMemberModel) string { return e.GroupID }) + s.Notification.GroupInfoSetNotification(ctx, group, members, req.GroupInfoForSet.NeedVerification.GetValuePtr()) if req.GroupInfoForSet.Notification != "" { args := &pbConversation.ModifyConversationFieldReq{ Conversation: &pbConversation.Conversation{ @@ -861,7 +874,7 @@ func (s *groupServer) GetGroupMembersCMS(ctx context.Context, req *pbGroup.GetGr func (s *groupServer) GetUserReqApplicationList(ctx context.Context, req *pbGroup.GetUserReqApplicationListReq) (*pbGroup.GetUserReqApplicationListResp, error) { resp := &pbGroup.GetUserReqApplicationListResp{} - user, err := s.UserCheck.GetPublicUserInfo(ctx, req.UserID) + user, err := s.User.GetPublicUserInfo(ctx, req.UserID) if err != nil { return nil, err } diff --git a/pkg/common/db/table/relation/user.go b/pkg/common/db/table/relation/user.go index 474a04fab..7eac8ab0f 100644 --- a/pkg/common/db/table/relation/user.go +++ b/pkg/common/db/table/relation/user.go @@ -20,7 +20,7 @@ type UserModel struct { } func (u *UserModel) GetNickname() string { - return UserModelTableName + return u.Nickname } func (u *UserModel) GetFaceURL() string { diff --git a/pkg/rpcclient/meta.go b/pkg/rpcclient/meta.go index effd0baf2..55f2f4ccf 100644 --- a/pkg/rpcclient/meta.go +++ b/pkg/rpcclient/meta.go @@ -39,3 +39,10 @@ type CommonUser interface { GetUserID() string GetEx() string } + +type CommonGroup interface { + GetNickname() string + GetFaceURL() string + GetGroupID() string + GetEx() string +} diff --git a/pkg/rpcclient/notification2/group.go b/pkg/rpcclient/notification2/group.go new file mode 100644 index 000000000..e97784ca7 --- /dev/null +++ b/pkg/rpcclient/notification2/group.go @@ -0,0 +1,605 @@ +package notification2 + +import ( + "context" + "github.com/OpenIMSDK/Open-IM-Server/pkg/common/constant" + "github.com/OpenIMSDK/Open-IM-Server/pkg/common/db/controller" + "github.com/OpenIMSDK/Open-IM-Server/pkg/common/db/table/relation" + "github.com/OpenIMSDK/Open-IM-Server/pkg/common/log" + "github.com/OpenIMSDK/Open-IM-Server/pkg/common/mcontext" + "github.com/OpenIMSDK/Open-IM-Server/pkg/discoveryregistry" + "github.com/OpenIMSDK/Open-IM-Server/pkg/errs" + pbGroup "github.com/OpenIMSDK/Open-IM-Server/pkg/proto/group" + "github.com/OpenIMSDK/Open-IM-Server/pkg/proto/sdkws" + "github.com/OpenIMSDK/Open-IM-Server/pkg/rpcclient" + "github.com/OpenIMSDK/Open-IM-Server/pkg/utils" + "github.com/golang/protobuf/jsonpb" + "github.com/golang/protobuf/proto" +) + +func NewGroupNotificationSender(db controller.GroupDatabase, sdr discoveryregistry.SvcDiscoveryRegistry, fn func(ctx context.Context, userIDs []string) ([]rpcclient.CommonUser, error)) *GroupNotificationSender { + return &GroupNotificationSender{ + msgClient: rpcclient.NewMsgClient(sdr), + getUsersInfo: fn, + db: db, + } +} + +type GroupNotificationSender struct { + msgClient *rpcclient.MsgClient + // 找不到报错 + getUsersInfo func(ctx context.Context, userIDs []string) ([]rpcclient.CommonUser, error) + db controller.GroupDatabase +} + +func (g *GroupNotificationSender) getGroupInfo(ctx context.Context, groupID string) (*sdkws.GroupInfo, error) { + gm, err := g.db.TakeGroup(ctx, groupID) + if err != nil { + return nil, err + } + return &sdkws.GroupInfo{ + GroupID: gm.GroupID, + GroupName: gm.GroupName, + Notification: gm.Notification, + Introduction: gm.Introduction, + FaceURL: gm.FaceURL, + //OwnerUserID: gm.OwnerUserID, + CreateTime: gm.CreateTime.UnixMilli(), + //MemberCount: gm.MemberCount, + Ex: gm.Ex, + Status: gm.Status, + CreatorUserID: gm.CreatorUserID, + GroupType: gm.GroupType, + NeedVerification: gm.NeedVerification, + LookMemberInfo: gm.LookMemberInfo, + ApplyMemberFriend: gm.ApplyMemberFriend, + NotificationUpdateTime: gm.NotificationUpdateTime.UnixMilli(), + NotificationUserID: gm.NotificationUserID, + }, nil +} + +func (g *GroupNotificationSender) groupDB2PB(group *relation.GroupModel, ownerUserID string, memberCount uint32) *sdkws.GroupInfo { + return &sdkws.GroupInfo{ + GroupID: group.GroupID, + GroupName: group.GroupName, + Notification: group.Notification, + Introduction: group.Introduction, + FaceURL: group.FaceURL, + OwnerUserID: ownerUserID, + CreateTime: group.CreateTime.UnixMilli(), + MemberCount: memberCount, + Ex: group.Ex, + Status: group.Status, + CreatorUserID: group.CreatorUserID, + GroupType: group.GroupType, + NeedVerification: group.NeedVerification, + LookMemberInfo: group.LookMemberInfo, + ApplyMemberFriend: group.ApplyMemberFriend, + NotificationUpdateTime: group.NotificationUpdateTime.UnixMilli(), + NotificationUserID: group.NotificationUserID, + } +} + +func (g *GroupNotificationSender) groupMemberDB2PB(member *relation.GroupMemberModel, appMangerLevel int32) *sdkws.GroupMemberFullInfo { + return &sdkws.GroupMemberFullInfo{ + GroupID: member.GroupID, + UserID: member.UserID, + RoleLevel: member.RoleLevel, + JoinTime: member.JoinTime.UnixMilli(), + Nickname: member.Nickname, + FaceURL: member.FaceURL, + AppMangerLevel: appMangerLevel, + JoinSource: member.JoinSource, + OperatorUserID: member.OperatorUserID, + Ex: member.Ex, + MuteEndTime: member.MuteEndTime.UnixMilli(), + InviterUserID: member.InviterUserID, + } +} + +func (g *GroupNotificationSender) getUsersInfoMap(ctx context.Context, userIDs []string) (map[string]*sdkws.UserInfo, error) { + users, err := g.getUsersInfo(ctx, userIDs) + if err != nil { + return nil, err + } + result := make(map[string]*sdkws.UserInfo) + for _, user := range users { + result[user.GetUserID()] = user.(*sdkws.UserInfo) + } + return result, nil +} + +func (g *GroupNotificationSender) getFromToUserNickname(ctx context.Context, fromUserID, toUserID string) (string, string, error) { + users, err := g.getUsersInfoMap(ctx, []string{fromUserID, toUserID}) + if err != nil { + return "", "", nil + } + return users[fromUserID].Nickname, users[toUserID].Nickname, nil +} + +func (g *GroupNotificationSender) groupNotification(ctx context.Context, contentType int32, m proto.Message, sendID, groupID, recvUserID string) (err error) { + var tips sdkws.TipsComm + tips.Detail, err = proto.Marshal(m) + if err != nil { + return err + } + marshaler := jsonpb.Marshaler{ + OrigName: true, + EnumsAsInts: false, + EmitDefaults: false, + } + tips.JsonDetail, err = marshaler.MarshalToString(m) + if err != nil { + return err + } + fromUserNickname, toUserNickname, err := g.getFromToUserNickname(ctx, sendID, recvUserID) + if err != nil { + return err + } + //cn := config.Config.Notification + switch contentType { + case constant.GroupCreatedNotification: + tips.DefaultTips = fromUserNickname + case constant.GroupInfoSetNotification: + tips.DefaultTips = fromUserNickname + case constant.JoinGroupApplicationNotification: + tips.DefaultTips = fromUserNickname + case constant.MemberQuitNotification: + tips.DefaultTips = fromUserNickname + case constant.GroupApplicationAcceptedNotification: + tips.DefaultTips = toUserNickname + case constant.GroupApplicationRejectedNotification: + tips.DefaultTips = toUserNickname + case constant.GroupOwnerTransferredNotification: + tips.DefaultTips = toUserNickname + case constant.MemberKickedNotification: + tips.DefaultTips = toUserNickname + case constant.MemberInvitedNotification: + tips.DefaultTips = toUserNickname + case constant.MemberEnterNotification: + tips.DefaultTips = toUserNickname + case constant.GroupDismissedNotification: + tips.DefaultTips = toUserNickname + case constant.GroupMutedNotification: + tips.DefaultTips = toUserNickname + case constant.GroupCancelMutedNotification: + tips.DefaultTips = toUserNickname + case constant.GroupMemberMutedNotification: + tips.DefaultTips = toUserNickname + case constant.GroupMemberCancelMutedNotification: + tips.DefaultTips = toUserNickname + case constant.GroupMemberInfoSetNotification: + tips.DefaultTips = toUserNickname + case constant.GroupMemberSetToAdminNotification: + tips.DefaultTips = toUserNickname + case constant.GroupMemberSetToOrdinaryUserNotification: + tips.DefaultTips = toUserNickname + default: + return errs.ErrInternalServer.Wrap("unknown group notification type") + } + var n rpcclient.NotificationMsg + n.SendID = sendID + n.RecvID = recvUserID + n.ContentType = contentType + n.SessionType = constant.SingleChatType + n.MsgFrom = constant.SysMsgType + n.Content, err = proto.Marshal(&tips) + if err != nil { + return + } + return g.msgClient.Notification(ctx, &n) +} + +func (g *GroupNotificationSender) GroupCreatedNotification(ctx context.Context, group *relation.GroupModel, members []*relation.GroupMemberModel, userMap map[string]*sdkws.UserInfo) (err error) { + defer log.ZDebug(ctx, "return") + defer func() { + if err != nil { + log.ZError(ctx, "GroupCreatedNotification failed", err) + } + }() + groupInfo, err := g.mergeGroupFull(ctx, group.GroupID, group, &members, &userMap) + if err != nil { + return err + } + return g.groupNotification(ctx, constant.GroupCreatedNotification, groupInfo, mcontext.GetOpUserID(ctx), group.GroupID, "") +} + +func (g *GroupNotificationSender) mergeGroupFull(ctx context.Context, groupID string, group *relation.GroupModel, ms *[]*relation.GroupMemberModel, users *map[string]*sdkws.UserInfo) (groupInfo *sdkws.GroupCreatedTips, err error) { + defer log.ZDebug(ctx, "return") + defer func() { + if err != nil { + log.ZError(ctx, "mergeGroupFull failed", err) + } + }() + if group == nil { + group, err = g.db.TakeGroup(ctx, groupID) + if err != nil { + return nil, err + } + } + var members []*relation.GroupMemberModel + if ms == nil || len(*ms) == 0 { + members, err = g.db.FindGroupMember(ctx, []string{groupID}, nil, nil) + if err != nil { + return nil, err + } + if ms != nil { + *ms = members + } + } else { + members = *ms + } + opUserID := mcontext.GetOpUserID(ctx) + var userMap map[string]*sdkws.UserInfo + if users == nil || len(*users) == 0 { + userIDs := utils.Slice(members, func(e *relation.GroupMemberModel) string { return e.UserID }) + userIDs = append(userIDs, opUserID) + userMap, err = g.getUsersInfoMap(ctx, userIDs) + if err != nil { + return nil, err + } + if users != nil { + *users = userMap + } + } else { + userMap = *users + } + var ( + opUserMember *sdkws.GroupMemberFullInfo + groupOwnerMember *sdkws.GroupMemberFullInfo + ) + for _, member := range members { + if member.UserID == opUserID { + opUserMember = g.groupMemberDB2PB(member, userMap[member.UserID].AppMangerLevel) + } + if member.RoleLevel == constant.GroupOwner { + groupOwnerMember = g.groupMemberDB2PB(member, userMap[member.UserID].AppMangerLevel) + } + if opUserMember != nil && groupOwnerMember != nil { + break + } + } + if opUser := userMap[opUserID]; opUser != nil && opUserMember == nil { + opUserMember = &sdkws.GroupMemberFullInfo{ + GroupID: group.GroupID, + UserID: opUser.UserID, + Nickname: opUser.Nickname, + FaceURL: opUser.FaceURL, + AppMangerLevel: opUser.AppMangerLevel, + } + } + groupInfo = &sdkws.GroupCreatedTips{Group: g.groupDB2PB(group, opUserID, uint32(len(members))), + OpUser: opUserMember, GroupOwnerUser: groupOwnerMember} + return groupInfo, nil +} + +func (g *GroupNotificationSender) GroupInfoSetNotification(ctx context.Context, group *relation.GroupModel, members []*relation.GroupMemberModel, needVerification *int32) error { + groupInfo, err := g.mergeGroupFull(ctx, group.GroupID, group, &members, nil) + if err != nil { + return err + } + groupInfoChangedTips := &sdkws.GroupInfoSetTips{Group: groupInfo.Group, OpUser: groupInfo.GroupOwnerUser} + if needVerification != nil { + groupInfoChangedTips.Group.NeedVerification = *needVerification + } + return g.groupNotification(ctx, constant.GroupInfoSetNotification, groupInfoChangedTips, mcontext.GetOpUserID(ctx), group.GroupID, "") +} + +//func (g *GroupNotificationSender) mergeGroupAndUser(ctx context.Context, groupID string, userIDs []string) (*sdkws.GroupInfo, map[string]*sdkws.UserInfo, error) { +// //g.groupDB2PB(group, opUserID, uint32(len(members)) +// groupInfo, err := g.db.TakeGroup(ctx, groupID) +// if err != nil { +// return nil, nil, err +// } +// owner, err := g.db.TakeGroupOwner(ctx, groupID) +// if err != nil { +// return nil, nil, err +// } +// memberUserIDs, err := g.db.FindGroupMemberUserID(ctx, groupID) +// if err != nil { +// return nil, nil, err +// } +// g.getUsersInfoMap(ctx, memberUserIDs) +// return nil, nil, nil +//} + +func (g *GroupNotificationSender) JoinGroupApplicationNotification(ctx context.Context, req *pbGroup.JoinGroupReq) error { + var members []*relation.GroupMemberModel + var userMap map[string]*sdkws.UserInfo + groupInfo, err := g.mergeGroupFull(ctx, req.GroupID, nil, &members, &userMap) + if err != nil { + return err + } + joinGroupApplicationTips := &sdkws.JoinGroupApplicationTips{Group: groupInfo.Group} + for _, member := range members { + if member.UserID == req.InviterUserID { + if user := userMap[member.UserID]; user != nil { + joinGroupApplicationTips.Applicant = &sdkws.PublicUserInfo{ + UserID: user.UserID, + Nickname: user.Nickname, + FaceURL: user.FaceURL, + Ex: user.Ex, + } + } + break + } + } + joinGroupApplicationTips.ReqMsg = req.ReqMessage + for _, member := range members { + if member.RoleLevel == constant.GroupOwner || member.RoleLevel == constant.GroupAdmin { + err := g.groupNotification(ctx, constant.JoinGroupApplicationNotification, joinGroupApplicationTips, mcontext.GetOpUserID(ctx), "", member.UserID) + if err != nil { + return err + } + } + } + return nil +} + +func (g *GroupNotificationSender) MemberQuitNotification(ctx context.Context, req *pbGroup.QuitGroupReq) error { + var members []*relation.GroupMemberModel + var userMap map[string]*sdkws.UserInfo + groupInfo, err := g.mergeGroupFull(ctx, req.GroupID, nil, &members, &userMap) + if err != nil { + return err + } + opUserID := mcontext.GetOpUserID(ctx) + memberQuitTips := &sdkws.MemberQuitTips{Group: groupInfo.Group, QuitUser: &sdkws.GroupMemberFullInfo{}} + for _, member := range members { + if member.UserID == opUserID { + if user := userMap[member.UserID]; user != nil { + memberQuitTips.QuitUser = g.groupMemberDB2PB(member, user.AppMangerLevel) + } + break + } + } + for _, member := range members { + if member.RoleLevel == constant.GroupOwner || member.RoleLevel == constant.GroupAdmin { + err := g.groupNotification(ctx, constant.JoinGroupApplicationNotification, memberQuitTips, mcontext.GetOpUserID(ctx), "", member.UserID) + if err != nil { + return err + } + } + } + return nil +} + +func (g *GroupNotificationSender) GroupApplicationAcceptedNotification(ctx context.Context, req *pbGroup.GroupApplicationResponseReq) error { + var members []*relation.GroupMemberModel + groupInfo, err := g.mergeGroupFull(ctx, req.GroupID, nil, &members, nil) + if err != nil { + return err + } + groupApplicationAcceptedTips := &sdkws.GroupApplicationAcceptedTips{Group: groupInfo.Group, OpUser: groupInfo.OpUser, HandleMsg: req.HandledMsg} + err = g.groupNotification(ctx, constant.GroupApplicationAcceptedNotification, groupApplicationAcceptedTips, mcontext.GetOpUserID(ctx), "", req.FromUserID) + if err != nil { + log.ZError(ctx, "groupNotification failed", err) + } + groupApplicationAcceptedTips.ReceiverAs = 1 + for _, member := range members { + if member.RoleLevel == constant.GroupOwner || member.RoleLevel == constant.GroupAdmin { + err = g.groupNotification(ctx, constant.GroupApplicationAcceptedNotification, groupApplicationAcceptedTips, mcontext.GetOpUserID(ctx), "", req.FromUserID) + if err != nil { + log.ZError(ctx, "groupNotification failed", err) + } + } + } + return nil +} + +func (g *GroupNotificationSender) GroupApplicationRejectedNotification(ctx context.Context, req *pbGroup.GroupApplicationResponseReq) error { + var members []*relation.GroupMemberModel + groupInfo, err := g.mergeGroupFull(ctx, req.GroupID, nil, &members, nil) + if err != nil { + return err + } + groupApplicationRejectedTips := sdkws.GroupApplicationRejectedTips{Group: groupInfo.Group, OpUser: groupInfo.OpUser, HandleMsg: req.HandledMsg} + if err := g.groupNotification(ctx, constant.GroupApplicationRejectedNotification, &groupApplicationRejectedTips, mcontext.GetOpUserID(ctx), "", req.FromUserID); err != nil { + log.ZError(ctx, "groupNotification failed", err) + } + for _, member := range members { + if member.RoleLevel == constant.GroupOwner || member.RoleLevel == constant.GroupAdmin { + if err := g.groupNotification(ctx, constant.GroupApplicationRejectedNotification, &groupApplicationRejectedTips, mcontext.GetOpUserID(ctx), "", req.FromUserID); err != nil { + log.ZError(ctx, "groupNotification failed", err) + } + } + } + return nil +} + +func (g *GroupNotificationSender) GroupOwnerTransferredNotification(ctx context.Context, req *pbGroup.TransferGroupOwnerReq) error { + var members []*relation.GroupMemberModel + groupInfo, err := g.mergeGroupFull(ctx, req.GroupID, nil, &members, nil) + if err != nil { + return err + } + groupOwnerTransferredTips := &sdkws.GroupOwnerTransferredTips{Group: groupInfo.Group, OpUser: groupInfo.OpUser, NewGroupOwner: groupInfo.GroupOwnerUser} + return g.groupNotification(ctx, constant.GroupOwnerTransferredNotification, groupOwnerTransferredTips, mcontext.GetOpUserID(ctx), req.GroupID, "") +} + +func (g *GroupNotificationSender) MemberKickedNotification(ctx context.Context, req *pbGroup.KickGroupMemberReq, kickedUserIDList []string) error { + var members []*relation.GroupMemberModel + groupInfo, err := g.mergeGroupFull(ctx, req.GroupID, nil, &members, nil) + if err != nil { + return err + } + memberKickedTips := &sdkws.MemberKickedTips{Group: groupInfo.Group, OpUser: groupInfo.OpUser} + //for _, v := range kickedUserIDList { + // var groupMemberInfo sdkws.GroupMemberFullInfo + // if err := c.setGroupMemberInfo(ctx, req.GroupID, v, &groupMemberInfo); err != nil { + // continue + // } + // MemberKickedTips.KickedUserList = append(MemberKickedTips.KickedUserList, &groupMemberInfo) + //} + return g.groupNotification(ctx, constant.MemberKickedNotification, memberKickedTips, mcontext.GetOpUserID(ctx), req.GroupID, "") +} + +func (g *GroupNotificationSender) MemberInvitedNotification(ctx context.Context, groupID, reason string, invitedUserIDList []string) error { + var members []*relation.GroupMemberModel + var userMap map[string]*sdkws.UserInfo + groupInfo, err := g.mergeGroupFull(ctx, groupID, nil, &members, &userMap) + if err != nil { + return err + } + memberInvitedTips := &sdkws.MemberInvitedTips{Group: groupInfo.Group, OpUser: groupInfo.OpUser} + groupMembers, err := g.db.FindGroupMember(ctx, []string{groupID}, invitedUserIDList, nil) + if err != nil { + return err + } + for _, member := range groupMembers { + user, ok := userMap[member.UserID] + if !ok { + continue + } + memberInvitedTips.InvitedUserList = append(memberInvitedTips.InvitedUserList, g.groupMemberDB2PB(member, user.AppMangerLevel)) + } + return g.groupNotification(ctx, constant.MemberInvitedNotification, memberInvitedTips, mcontext.GetOpUserID(ctx), groupID, "") +} + +func (g *GroupNotificationSender) MemberEnterNotification(ctx context.Context, req *pbGroup.GroupApplicationResponseReq) error { + var members []*relation.GroupMemberModel + var userMap map[string]*sdkws.UserInfo + groupInfo, err := g.mergeGroupFull(ctx, req.GroupID, nil, &members, &userMap) + if err != nil { + return err + } + MemberEnterTips := sdkws.MemberEnterTips{Group: groupInfo.Group} + for _, member := range members { + if member.UserID == req.FromUserID { + if user := userMap[member.UserID]; user != nil { + MemberEnterTips.EntrantUser = g.groupMemberDB2PB(member, user.AppMangerLevel) + } + break + } + } + return g.groupNotification(ctx, constant.MemberEnterNotification, &MemberEnterTips, mcontext.GetOpUserID(ctx), req.GroupID, "") +} + +func (g *GroupNotificationSender) groupMemberFullInfo(members []*relation.GroupMemberModel, userMap map[string]*sdkws.UserInfo, userID string) *sdkws.GroupMemberFullInfo { + for _, member := range members { + if member.UserID == userID { + if user := userMap[member.UserID]; user != nil { + return g.groupMemberDB2PB(member, user.AppMangerLevel) + } + return g.groupMemberDB2PB(member, 0) + } + } + return nil +} + +func (g *GroupNotificationSender) GroupDismissedNotification(ctx context.Context, req *pbGroup.DismissGroupReq) error { + var members []*relation.GroupMemberModel + var userMap map[string]*sdkws.UserInfo + groupInfo, err := g.mergeGroupFull(ctx, req.GroupID, nil, &members, &userMap) + if err != nil { + return err + } + tips := &sdkws.GroupDismissedTips{Group: groupInfo.Group, OpUser: groupInfo.OpUser} + return g.groupNotification(ctx, constant.GroupDismissedNotification, tips, mcontext.GetOpUserID(ctx), req.GroupID, "") +} + +func (g *GroupNotificationSender) GroupMemberMutedNotification(ctx context.Context, groupID, groupMemberUserID string, mutedSeconds uint32) error { + var members []*relation.GroupMemberModel + var userMap map[string]*sdkws.UserInfo + groupInfo, err := g.mergeGroupFull(ctx, groupID, nil, &members, &userMap) + if err != nil { + return err + } + tips := sdkws.GroupMemberMutedTips{Group: groupInfo.Group, MutedSeconds: mutedSeconds, + OpUser: groupInfo.OpUser, MutedUser: g.groupMemberFullInfo(members, userMap, groupMemberUserID)} + tips.MutedSeconds = mutedSeconds + return g.groupNotification(ctx, constant.GroupMemberMutedNotification, &tips, mcontext.GetOpUserID(ctx), groupID, "") +} + +func (g *GroupNotificationSender) GroupMemberCancelMutedNotification(ctx context.Context, groupID, groupMemberUserID string) error { + var members []*relation.GroupMemberModel + var userMap map[string]*sdkws.UserInfo + groupInfo, err := g.mergeGroupFull(ctx, groupID, nil, &members, &userMap) + if err != nil { + return err + } + tips := sdkws.GroupMemberCancelMutedTips{Group: groupInfo.Group, + OpUser: groupInfo.OpUser, MutedUser: g.groupMemberFullInfo(members, userMap, groupMemberUserID)} + return g.groupNotification(ctx, constant.GroupMemberCancelMutedNotification, &tips, mcontext.GetOpUserID(ctx), groupID, "") +} + +func (g *GroupNotificationSender) GroupMutedNotification(ctx context.Context, groupID string) error { + var members []*relation.GroupMemberModel + var userMap map[string]*sdkws.UserInfo + groupInfo, err := g.mergeGroupFull(ctx, groupID, nil, &members, &userMap) + if err != nil { + return err + } + tips := sdkws.GroupMutedTips{Group: groupInfo.Group, OpUser: groupInfo.OpUser} + return g.groupNotification(ctx, constant.GroupMutedNotification, &tips, mcontext.GetOpUserID(ctx), groupID, "") +} + +func (g *GroupNotificationSender) GroupCancelMutedNotification(ctx context.Context, groupID string) error { + var members []*relation.GroupMemberModel + var userMap map[string]*sdkws.UserInfo + groupInfo, err := g.mergeGroupFull(ctx, groupID, nil, &members, &userMap) + if err != nil { + return err + } + tips := sdkws.GroupCancelMutedTips{Group: groupInfo.Group, OpUser: groupInfo.OpUser} + return g.groupNotification(ctx, constant.GroupMutedNotification, &tips, mcontext.GetOpUserID(ctx), groupID, "") +} + +func (g *GroupNotificationSender) GroupMemberInfoSetNotification(ctx context.Context, groupID, groupMemberUserID string) error { + var members []*relation.GroupMemberModel + var userMap map[string]*sdkws.UserInfo + groupInfo, err := g.mergeGroupFull(ctx, groupID, nil, &members, &userMap) + if err != nil { + return err + } + tips := sdkws.GroupMemberInfoSetTips{Group: groupInfo.Group, + OpUser: groupInfo.OpUser, ChangedUser: g.groupMemberFullInfo(members, userMap, groupMemberUserID)} + return g.groupNotification(ctx, constant.GroupMemberCancelMutedNotification, &tips, mcontext.GetOpUserID(ctx), groupID, "") +} + +func (g *GroupNotificationSender) GroupMemberSetToAdminNotification(ctx context.Context, groupID, groupMemberUserID string, notificationType int32) error { + var members []*relation.GroupMemberModel + var userMap map[string]*sdkws.UserInfo + groupInfo, err := g.mergeGroupFull(ctx, groupID, nil, &members, &userMap) + if err != nil { + return err + } + tips := sdkws.GroupMemberInfoSetTips{Group: groupInfo.Group, + OpUser: groupInfo.OpUser, ChangedUser: g.groupMemberFullInfo(members, userMap, groupMemberUserID)} + return g.groupNotification(ctx, constant.GroupMemberCancelMutedNotification, &tips, mcontext.GetOpUserID(ctx), groupID, "") +} + +func (g *GroupNotificationSender) MemberEnterDirectlyNotification(ctx context.Context, groupID string, entrantUserID string) error { + var members []*relation.GroupMemberModel + var userMap map[string]*sdkws.UserInfo + groupInfo, err := g.mergeGroupFull(ctx, groupID, nil, &members, &userMap) + if err != nil { + return err + } + tips := sdkws.MemberEnterTips{Group: groupInfo.Group, EntrantUser: g.groupMemberFullInfo(members, userMap, entrantUserID)} + return g.groupNotification(ctx, constant.GroupMemberCancelMutedNotification, &tips, mcontext.GetOpUserID(ctx), groupID, "") +} + +type NotificationMsg struct { + SendID string + RecvID string + Content []byte // sdkws.TipsComm + MsgFrom int32 + ContentType int32 + SessionType int32 + SenderNickname string + SenderFaceURL string +} + +func (g *GroupNotificationSender) SuperGroupNotification(ctx context.Context, sendID, recvID string) error { + n := &NotificationMsg{ + SendID: sendID, + RecvID: recvID, + MsgFrom: constant.SysMsgType, + ContentType: constant.SuperGroupUpdateNotification, + SessionType: constant.SingleChatType, + } + _ = n // todo + //g.Notification(ctx, n) + return nil +}