mirror of
https://github.com/openimsdk/open-im-server.git
synced 2025-12-13 16:47:36 +08:00
Merge main into sweep/imctl-module
This commit is contained in:
commit
6302f7b073
@ -18,9 +18,6 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
"net"
|
"net"
|
||||||
"net/http"
|
|
||||||
"os"
|
|
||||||
"runtime"
|
|
||||||
"strconv"
|
"strconv"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
@ -46,16 +43,6 @@ func main() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func startPprof() {
|
|
||||||
runtime.GOMAXPROCS(1)
|
|
||||||
runtime.SetMutexProfileFraction(1)
|
|
||||||
runtime.SetBlockProfileRate(1)
|
|
||||||
if err := http.ListenAndServe(":6060", nil); err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
os.Exit(0)
|
|
||||||
}
|
|
||||||
|
|
||||||
func run(port int) error {
|
func run(port int) error {
|
||||||
if port == 0 {
|
if port == 0 {
|
||||||
return fmt.Errorf("port is empty")
|
return fmt.Errorf("port is empty")
|
||||||
@ -92,7 +79,6 @@ func run(port int) error {
|
|||||||
}
|
}
|
||||||
fmt.Println("start api server, address: ", address, ", OpenIM version: ", config.Version)
|
fmt.Println("start api server, address: ", address, ", OpenIM version: ", config.Version)
|
||||||
log.ZInfo(context.Background(), "start server success", "address", address, "version", config.Version)
|
log.ZInfo(context.Background(), "start server success", "address", address, "version", config.Version)
|
||||||
go startPprof()
|
|
||||||
err = router.Run(address)
|
err = router.Run(address)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.ZError(context.Background(), "api run failed ", err, "address", address)
|
log.ZError(context.Background(), "api run failed ", err, "address", address)
|
||||||
|
|||||||
2
go.mod
2
go.mod
@ -37,7 +37,7 @@ require (
|
|||||||
require github.com/google/uuid v1.3.0
|
require github.com/google/uuid v1.3.0
|
||||||
|
|
||||||
require (
|
require (
|
||||||
github.com/OpenIMSDK/protocol v0.0.15
|
github.com/OpenIMSDK/protocol v0.0.18
|
||||||
github.com/OpenIMSDK/tools v0.0.14
|
github.com/OpenIMSDK/tools v0.0.14
|
||||||
github.com/aliyun/aliyun-oss-go-sdk v2.2.8+incompatible
|
github.com/aliyun/aliyun-oss-go-sdk v2.2.8+incompatible
|
||||||
github.com/go-redis/redis v6.15.9+incompatible
|
github.com/go-redis/redis v6.15.9+incompatible
|
||||||
|
|||||||
4
go.sum
4
go.sum
@ -17,8 +17,8 @@ cloud.google.com/go/storage v1.30.1/go.mod h1:NfxhC0UJE1aXSx7CIIbCf7y9HKT7Biccwk
|
|||||||
firebase.google.com/go v3.13.0+incompatible h1:3TdYC3DDi6aHn20qoRkxwGqNgdjtblwVAyRLQwGn/+4=
|
firebase.google.com/go v3.13.0+incompatible h1:3TdYC3DDi6aHn20qoRkxwGqNgdjtblwVAyRLQwGn/+4=
|
||||||
firebase.google.com/go v3.13.0+incompatible/go.mod h1:xlah6XbEyW6tbfSklcfe5FHJIwjt8toICdV5Wh9ptHs=
|
firebase.google.com/go v3.13.0+incompatible/go.mod h1:xlah6XbEyW6tbfSklcfe5FHJIwjt8toICdV5Wh9ptHs=
|
||||||
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
|
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
|
||||||
github.com/OpenIMSDK/protocol v0.0.15 h1:KrrvdHH9kFF/tFYL2FXRPAr2e5F5DctSHfHq6MQjUI4=
|
github.com/OpenIMSDK/protocol v0.0.18 h1:hXukFiDMLZx7s+hDCQePIK9ABiHyNlobNL4MppvOuMY=
|
||||||
github.com/OpenIMSDK/protocol v0.0.15/go.mod h1:F25dFrwrIx3lkNoiuf6FkCfxuwf8L4Z8UIsdTHP/r0Y=
|
github.com/OpenIMSDK/protocol v0.0.18/go.mod h1:F25dFrwrIx3lkNoiuf6FkCfxuwf8L4Z8UIsdTHP/r0Y=
|
||||||
github.com/OpenIMSDK/tools v0.0.14 h1:WLof/+WxyPyRST+QkoTKubYCiV73uCLiL8pgnpH/yKQ=
|
github.com/OpenIMSDK/tools v0.0.14 h1:WLof/+WxyPyRST+QkoTKubYCiV73uCLiL8pgnpH/yKQ=
|
||||||
github.com/OpenIMSDK/tools v0.0.14/go.mod h1:eg+q4A34Qmu73xkY0mt37FHGMCMfC6CtmOnm0kFEGFI=
|
github.com/OpenIMSDK/tools v0.0.14/go.mod h1:eg+q4A34Qmu73xkY0mt37FHGMCMfC6CtmOnm0kFEGFI=
|
||||||
github.com/QcloudApi/qcloud_sign_golang v0.0.0-20141224014652-e4130a326409/go.mod h1:1pk82RBxDY/JZnPQrtqHlUFfCctgdorsd9M06fMynOM=
|
github.com/QcloudApi/qcloud_sign_golang v0.0.0-20141224014652-e4130a326409/go.mod h1:1pk82RBxDY/JZnPQrtqHlUFfCctgdorsd9M06fMynOM=
|
||||||
|
|||||||
@ -88,3 +88,7 @@ func (o *FriendApi) IsFriend(c *gin.Context) {
|
|||||||
func (o *FriendApi) GetFriendIDs(c *gin.Context) {
|
func (o *FriendApi) GetFriendIDs(c *gin.Context) {
|
||||||
a2r.Call(friend.FriendClient.GetFriendIDs, o.Client, c)
|
a2r.Call(friend.FriendClient.GetFriendIDs, o.Client, c)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (o *FriendApi) GetSpecifiedFriendsInfo(c *gin.Context) {
|
||||||
|
a2r.Call(friend.FriendClient.GetSpecifiedFriendsInfo, o.Client, c)
|
||||||
|
}
|
||||||
|
|||||||
@ -170,12 +170,7 @@ func (m *MessageApi) getSendMsgReq(c *gin.Context, req apistruct.SendMsg) (sendM
|
|||||||
log.ZDebug(c, "getSendMsgReq", "req", req.Content)
|
log.ZDebug(c, "getSendMsgReq", "req", req.Content)
|
||||||
switch req.ContentType {
|
switch req.ContentType {
|
||||||
case constant.Text:
|
case constant.Text:
|
||||||
text, ok := req.Content["text"].(string)
|
data = apistruct.TextElem{}
|
||||||
if !ok {
|
|
||||||
return nil, errs.ErrArgs.WithDetail("text is not string")
|
|
||||||
}
|
|
||||||
data = apistruct.TextContentElem{Content: text}
|
|
||||||
log.ZDebug(c, "getSendMsgReq", "data", data)
|
|
||||||
case constant.Picture:
|
case constant.Picture:
|
||||||
data = apistruct.PictureElem{}
|
data = apistruct.PictureElem{}
|
||||||
case constant.Voice:
|
case constant.Voice:
|
||||||
|
|||||||
@ -106,6 +106,7 @@ func NewGinRouter(discov discoveryregistry.SvcDiscoveryRegistry, rdb redis.Unive
|
|||||||
friendRouterGroup.POST("/import_friend", f.ImportFriends)
|
friendRouterGroup.POST("/import_friend", f.ImportFriends)
|
||||||
friendRouterGroup.POST("/is_friend", f.IsFriend)
|
friendRouterGroup.POST("/is_friend", f.IsFriend)
|
||||||
friendRouterGroup.POST("/get_friend_id", f.GetFriendIDs)
|
friendRouterGroup.POST("/get_friend_id", f.GetFriendIDs)
|
||||||
|
friendRouterGroup.POST("/get_specified_friends_info", f.GetSpecifiedFriendsInfo)
|
||||||
}
|
}
|
||||||
g := NewGroupApi(*groupRpc)
|
g := NewGroupApi(*groupRpc)
|
||||||
groupRouterGroup := r.Group("/group", ParseToken)
|
groupRouterGroup := r.Group("/group", ParseToken)
|
||||||
|
|||||||
@ -17,6 +17,8 @@ package friend
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
|
||||||
|
"github.com/OpenIMSDK/protocol/sdkws"
|
||||||
|
|
||||||
"github.com/OpenIMSDK/Open-IM-Server/pkg/authverify"
|
"github.com/OpenIMSDK/Open-IM-Server/pkg/authverify"
|
||||||
|
|
||||||
"github.com/OpenIMSDK/tools/log"
|
"github.com/OpenIMSDK/tools/log"
|
||||||
@ -357,3 +359,66 @@ func (s *friendServer) GetFriendIDs(
|
|||||||
}
|
}
|
||||||
return resp, nil
|
return resp, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (s *friendServer) GetSpecifiedFriendsInfo(ctx context.Context, req *pbfriend.GetSpecifiedFriendsInfoReq) (*pbfriend.GetSpecifiedFriendsInfoResp, error) {
|
||||||
|
if len(req.UserIDList) == 0 {
|
||||||
|
return nil, errs.ErrArgs.Wrap("userIDList is empty")
|
||||||
|
}
|
||||||
|
if utils.Duplicate(req.UserIDList) {
|
||||||
|
return nil, errs.ErrArgs.Wrap("userIDList repeated")
|
||||||
|
}
|
||||||
|
userMap, err := s.userRpcClient.GetUsersInfoMap(ctx, req.UserIDList)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
friends, err := s.friendDatabase.FindFriendsWithError(ctx, req.OwnerUserID, req.UserIDList)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
blacks, err := s.blackDatabase.FindBlackInfos(ctx, req.OwnerUserID, req.UserIDList)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
friendMap := utils.SliceToMap(friends, func(e *tablerelation.FriendModel) string {
|
||||||
|
return e.FriendUserID
|
||||||
|
})
|
||||||
|
blackMap := utils.SliceToMap(blacks, func(e *tablerelation.BlackModel) string {
|
||||||
|
return e.BlockUserID
|
||||||
|
})
|
||||||
|
resp := &pbfriend.GetSpecifiedFriendsInfoResp{
|
||||||
|
Infos: make([]*pbfriend.GetSpecifiedFriendsInfoInfo, 0, len(req.UserIDList)),
|
||||||
|
}
|
||||||
|
for _, userID := range req.UserIDList {
|
||||||
|
user := userMap[userID]
|
||||||
|
if user == nil {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
var friendInfo *sdkws.FriendInfo
|
||||||
|
if friend := friendMap[userID]; friend != nil {
|
||||||
|
friendInfo = &sdkws.FriendInfo{
|
||||||
|
OwnerUserID: friend.OwnerUserID,
|
||||||
|
Remark: friend.Remark,
|
||||||
|
CreateTime: friend.CreateTime.UnixMilli(),
|
||||||
|
AddSource: friend.AddSource,
|
||||||
|
OperatorUserID: friend.OperatorUserID,
|
||||||
|
Ex: friend.Ex,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
var blackInfo *sdkws.BlackInfo
|
||||||
|
if black := blackMap[userID]; black != nil {
|
||||||
|
blackInfo = &sdkws.BlackInfo{
|
||||||
|
OwnerUserID: black.OwnerUserID,
|
||||||
|
CreateTime: black.CreateTime.UnixMilli(),
|
||||||
|
AddSource: black.AddSource,
|
||||||
|
OperatorUserID: black.OperatorUserID,
|
||||||
|
Ex: black.Ex,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
resp.Infos = append(resp.Infos, &pbfriend.GetSpecifiedFriendsInfoInfo{
|
||||||
|
UserInfo: user,
|
||||||
|
FriendInfo: friendInfo,
|
||||||
|
BlackInfo: blackInfo,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
return resp, nil
|
||||||
|
}
|
||||||
|
|||||||
@ -22,12 +22,7 @@ import (
|
|||||||
relationtb "github.com/OpenIMSDK/Open-IM-Server/pkg/common/db/table/relation"
|
relationtb "github.com/OpenIMSDK/Open-IM-Server/pkg/common/db/table/relation"
|
||||||
)
|
)
|
||||||
|
|
||||||
func (s *groupServer) FindGroupMember(
|
func (s *groupServer) FindGroupMember(ctx context.Context, groupIDs []string, userIDs []string, roleLevels []int32) ([]*relationtb.GroupMemberModel, error) {
|
||||||
ctx context.Context,
|
|
||||||
groupIDs []string,
|
|
||||||
userIDs []string,
|
|
||||||
roleLevels []int32,
|
|
||||||
) ([]*relationtb.GroupMemberModel, error) {
|
|
||||||
members, err := s.GroupDatabase.FindGroupMember(ctx, groupIDs, userIDs, roleLevels)
|
members, err := s.GroupDatabase.FindGroupMember(ctx, groupIDs, userIDs, roleLevels)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
|||||||
@ -114,6 +114,24 @@ type groupServer struct {
|
|||||||
msgRpcClient rpcclient.MessageRpcClient
|
msgRpcClient rpcclient.MessageRpcClient
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (s *groupServer) NotificationUserInfoUpdate(ctx context.Context, req *pbgroup.NotificationUserInfoUpdateReq) (*pbgroup.NotificationUserInfoUpdateResp, error) {
|
||||||
|
defer log.ZDebug(ctx, "return")
|
||||||
|
|
||||||
|
members, err := s.GroupDatabase.FindGroupMember(ctx, nil, []string{req.UserID}, nil)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
for _, member := range members {
|
||||||
|
if member.Nickname != "" && member.FaceURL != "" {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
if err := s.Notification.GroupMemberInfoSetNotification(ctx, member.GroupID, member.UserID); err != nil {
|
||||||
|
log.ZError(ctx, "setGroupMemberInfo notification failed", err, "member", member.UserID, "groupID", member.GroupID)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return &pbgroup.NotificationUserInfoUpdateResp{}, nil
|
||||||
|
}
|
||||||
|
|
||||||
func (s *groupServer) CheckGroupAdmin(ctx context.Context, groupID string) error {
|
func (s *groupServer) CheckGroupAdmin(ctx context.Context, groupID string) error {
|
||||||
if !authverify.IsAppManagerUid(ctx) {
|
if !authverify.IsAppManagerUid(ctx) {
|
||||||
groupMember, err := s.GroupDatabase.TakeGroupMember(ctx, groupID, mcontext.GetOpUserID(ctx))
|
groupMember, err := s.GroupDatabase.TakeGroupMember(ctx, groupID, mcontext.GetOpUserID(ctx))
|
||||||
|
|||||||
@ -128,7 +128,9 @@ func (m *msgServer) messageVerification(ctx context.Context, data *msg.SendMsgRe
|
|||||||
|
|
||||||
func (m *msgServer) encapsulateMsgData(msg *sdkws.MsgData) {
|
func (m *msgServer) encapsulateMsgData(msg *sdkws.MsgData) {
|
||||||
msg.ServerMsgID = GetMsgID(msg.SendID)
|
msg.ServerMsgID = GetMsgID(msg.SendID)
|
||||||
|
if msg.SendTime == 0 {
|
||||||
msg.SendTime = utils.GetCurrentTimestampByMill()
|
msg.SendTime = utils.GetCurrentTimestampByMill()
|
||||||
|
}
|
||||||
switch msg.ContentType {
|
switch msg.ContentType {
|
||||||
case constant.Text:
|
case constant.Text:
|
||||||
fallthrough
|
fallthrough
|
||||||
|
|||||||
@ -50,6 +50,7 @@ type userServer struct {
|
|||||||
friendNotificationSender *notification.FriendNotificationSender
|
friendNotificationSender *notification.FriendNotificationSender
|
||||||
userNotificationSender *notification.UserNotificationSender
|
userNotificationSender *notification.UserNotificationSender
|
||||||
friendRpcClient *rpcclient.FriendRpcClient
|
friendRpcClient *rpcclient.FriendRpcClient
|
||||||
|
groupRpcClient *rpcclient.GroupRpcClient
|
||||||
RegisterCenter registry.SvcDiscoveryRegistry
|
RegisterCenter registry.SvcDiscoveryRegistry
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -81,11 +82,13 @@ func Start(client registry.SvcDiscoveryRegistry, server *grpc.Server) error {
|
|||||||
userMongoDB := unrelation.NewUserMongoDriver(mongo.GetDatabase())
|
userMongoDB := unrelation.NewUserMongoDriver(mongo.GetDatabase())
|
||||||
database := controller.NewUserDatabase(userDB, cache, tx.NewGorm(db), userMongoDB)
|
database := controller.NewUserDatabase(userDB, cache, tx.NewGorm(db), userMongoDB)
|
||||||
friendRpcClient := rpcclient.NewFriendRpcClient(client)
|
friendRpcClient := rpcclient.NewFriendRpcClient(client)
|
||||||
|
groupRpcClient := rpcclient.NewGroupRpcClient(client)
|
||||||
msgRpcClient := rpcclient.NewMessageRpcClient(client)
|
msgRpcClient := rpcclient.NewMessageRpcClient(client)
|
||||||
u := &userServer{
|
u := &userServer{
|
||||||
UserDatabase: database,
|
UserDatabase: database,
|
||||||
RegisterCenter: client,
|
RegisterCenter: client,
|
||||||
friendRpcClient: &friendRpcClient,
|
friendRpcClient: &friendRpcClient,
|
||||||
|
groupRpcClient: &groupRpcClient,
|
||||||
friendNotificationSender: notification.NewFriendNotificationSender(&msgRpcClient, notification.WithDBFunc(database.FindWithError)),
|
friendNotificationSender: notification.NewFriendNotificationSender(&msgRpcClient, notification.WithDBFunc(database.FindWithError)),
|
||||||
userNotificationSender: notification.NewUserNotificationSender(&msgRpcClient, notification.WithUserFunc(database.FindWithError)),
|
userNotificationSender: notification.NewUserNotificationSender(&msgRpcClient, notification.WithUserFunc(database.FindWithError)),
|
||||||
}
|
}
|
||||||
@ -125,6 +128,11 @@ func (s *userServer) UpdateUserInfo(ctx context.Context, req *pbuser.UpdateUserI
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
if req.UserInfo.Nickname != "" || req.UserInfo.FaceURL != "" {
|
||||||
|
if err := s.groupRpcClient.NotificationUserInfoUpdate(ctx, req.UserInfo.UserID); err != nil {
|
||||||
|
log.ZError(ctx, "NotificationUserInfoUpdate", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
for _, friendID := range friends {
|
for _, friendID := range friends {
|
||||||
s.friendNotificationSender.FriendInfoUpdatedNotification(ctx, req.UserInfo.UserID, friendID)
|
s.friendNotificationSender.FriendInfoUpdatedNotification(ctx, req.UserInfo.UserID, friendID)
|
||||||
}
|
}
|
||||||
|
|||||||
@ -72,11 +72,8 @@ type CustomElem struct {
|
|||||||
Description string `mapstructure:"description"`
|
Description string `mapstructure:"description"`
|
||||||
Extension string `mapstructure:"extension"`
|
Extension string `mapstructure:"extension"`
|
||||||
}
|
}
|
||||||
type TextElem struct {
|
|
||||||
Text string `mapstructure:"text" validate:"required"`
|
|
||||||
}
|
|
||||||
|
|
||||||
type TextContentElem struct {
|
type TextElem struct {
|
||||||
Content string `json:"content" validate:"required"`
|
Content string `json:"content" validate:"required"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
2
pkg/common/db/cache/user.go
vendored
2
pkg/common/db/cache/user.go
vendored
@ -244,7 +244,7 @@ func (u *UserCacheRedis) SetUserStatus(ctx context.Context, list []*user.OnlineS
|
|||||||
}
|
}
|
||||||
if newPlatformIDs == nil {
|
if newPlatformIDs == nil {
|
||||||
onlineStatus.Status = constant.Offline
|
onlineStatus.Status = constant.Offline
|
||||||
onlineStatus.PlatformIDs = nil
|
onlineStatus.PlatformIDs = []int32{}
|
||||||
newjsonData, err := json.Marshal(&onlineStatus)
|
newjsonData, err := json.Marshal(&onlineStatus)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return errs.Wrap(err)
|
return errs.Wrap(err)
|
||||||
|
|||||||
@ -36,6 +36,7 @@ type BlackDatabase interface {
|
|||||||
pageNumber, showNumber int32,
|
pageNumber, showNumber int32,
|
||||||
) (blacks []*relation.BlackModel, total int64, err error)
|
) (blacks []*relation.BlackModel, total int64, err error)
|
||||||
FindBlackIDs(ctx context.Context, ownerUserID string) (blackIDs []string, err error)
|
FindBlackIDs(ctx context.Context, ownerUserID string) (blackIDs []string, err error)
|
||||||
|
FindBlackInfos(ctx context.Context, ownerUserID string, userIDs []string) (blacks []*relation.BlackModel, err error)
|
||||||
// CheckIn 检查user2是否在user1的黑名单列表中(inUser1Blacks==true) 检查user1是否在user2的黑名单列表中(inUser2Blacks==true)
|
// CheckIn 检查user2是否在user1的黑名单列表中(inUser1Blacks==true) 检查user1是否在user2的黑名单列表中(inUser2Blacks==true)
|
||||||
CheckIn(ctx context.Context, userID1, userID2 string) (inUser1Blacks bool, inUser2Blacks bool, err error)
|
CheckIn(ctx context.Context, userID1, userID2 string) (inUser1Blacks bool, inUser2Blacks bool, err error)
|
||||||
}
|
}
|
||||||
@ -102,3 +103,7 @@ func (b *blackDatabase) CheckIn(
|
|||||||
func (b *blackDatabase) FindBlackIDs(ctx context.Context, ownerUserID string) (blackIDs []string, err error) {
|
func (b *blackDatabase) FindBlackIDs(ctx context.Context, ownerUserID string) (blackIDs []string, err error) {
|
||||||
return b.cache.GetBlackIDs(ctx, ownerUserID)
|
return b.cache.GetBlackIDs(ctx, ownerUserID)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (b *blackDatabase) FindBlackInfos(ctx context.Context, ownerUserID string, userIDs []string) (blacks []*relation.BlackModel, err error) {
|
||||||
|
return b.black.FindOwnerBlackInfos(ctx, ownerUserID, userIDs)
|
||||||
|
}
|
||||||
|
|||||||
@ -41,83 +41,34 @@ type GroupDatabase interface {
|
|||||||
TakeGroup(ctx context.Context, groupID string) (group *relationtb.GroupModel, err error)
|
TakeGroup(ctx context.Context, groupID string) (group *relationtb.GroupModel, err error)
|
||||||
FindGroup(ctx context.Context, groupIDs []string) (groups []*relationtb.GroupModel, err error)
|
FindGroup(ctx context.Context, groupIDs []string) (groups []*relationtb.GroupModel, err error)
|
||||||
FindNotDismissedGroup(ctx context.Context, groupIDs []string) (groups []*relationtb.GroupModel, err error)
|
FindNotDismissedGroup(ctx context.Context, groupIDs []string) (groups []*relationtb.GroupModel, err error)
|
||||||
SearchGroup(
|
SearchGroup(ctx context.Context, keyword string, pageNumber, showNumber int32) (uint32, []*relationtb.GroupModel, error)
|
||||||
ctx context.Context,
|
|
||||||
keyword string,
|
|
||||||
pageNumber, showNumber int32,
|
|
||||||
) (uint32, []*relationtb.GroupModel, error)
|
|
||||||
UpdateGroup(ctx context.Context, groupID string, data map[string]any) error
|
UpdateGroup(ctx context.Context, groupID string, data map[string]any) error
|
||||||
DismissGroup(ctx context.Context, groupID string, deleteMember bool) error // 解散群,并删除群成员
|
DismissGroup(ctx context.Context, groupID string, deleteMember bool) error // 解散群,并删除群成员
|
||||||
GetGroupIDsByGroupType(ctx context.Context, groupType int) (groupIDs []string, err error)
|
GetGroupIDsByGroupType(ctx context.Context, groupType int) (groupIDs []string, err error)
|
||||||
// GroupMember
|
// GroupMember
|
||||||
TakeGroupMember(
|
TakeGroupMember(ctx context.Context, groupID string, userID string) (groupMember *relationtb.GroupMemberModel, err error)
|
||||||
ctx context.Context,
|
|
||||||
groupID string,
|
|
||||||
userID string,
|
|
||||||
) (groupMember *relationtb.GroupMemberModel, err error)
|
|
||||||
TakeGroupOwner(ctx context.Context, groupID string) (*relationtb.GroupMemberModel, error)
|
TakeGroupOwner(ctx context.Context, groupID string) (*relationtb.GroupMemberModel, error)
|
||||||
FindGroupMember(
|
FindGroupMember(ctx context.Context, groupIDs []string, userIDs []string, roleLevels []int32) ([]*relationtb.GroupMemberModel, error)
|
||||||
ctx context.Context,
|
|
||||||
groupIDs []string,
|
|
||||||
userIDs []string,
|
|
||||||
roleLevels []int32,
|
|
||||||
) ([]*relationtb.GroupMemberModel, error)
|
|
||||||
FindGroupMemberUserID(ctx context.Context, groupID string) ([]string, error)
|
FindGroupMemberUserID(ctx context.Context, groupID string) ([]string, error)
|
||||||
FindGroupMemberNum(ctx context.Context, groupID string) (uint32, error)
|
FindGroupMemberNum(ctx context.Context, groupID string) (uint32, error)
|
||||||
FindUserManagedGroupID(ctx context.Context, userID string) (groupIDs []string, err error)
|
FindUserManagedGroupID(ctx context.Context, userID string) (groupIDs []string, err error)
|
||||||
PageGroupRequest(
|
PageGroupRequest(ctx context.Context, groupIDs []string, pageNumber, showNumber int32) (uint32, []*relationtb.GroupRequestModel, error)
|
||||||
ctx context.Context,
|
|
||||||
groupIDs []string,
|
PageGetJoinGroup(ctx context.Context, userID string, pageNumber, showNumber int32) (total uint32, totalGroupMembers []*relationtb.GroupMemberModel, err error)
|
||||||
pageNumber, showNumber int32,
|
PageGetGroupMember(ctx context.Context, groupID string, pageNumber, showNumber int32) (total uint32, totalGroupMembers []*relationtb.GroupMemberModel, err error)
|
||||||
) (uint32, []*relationtb.GroupRequestModel, error)
|
SearchGroupMember(ctx context.Context, keyword string, groupIDs []string, userIDs []string, roleLevels []int32, pageNumber, showNumber int32) (uint32, []*relationtb.GroupMemberModel, error)
|
||||||
// PageGroupMember(ctx context.Context, groupIDs []string, userIDs []string, roleLevels []int32, pageNumber,
|
HandlerGroupRequest(ctx context.Context, groupID string, userID string, handledMsg string, handleResult int32, member *relationtb.GroupMemberModel) error
|
||||||
// showNumber int32) (uint32, []*relationtb.GroupMemberModel, error)
|
|
||||||
PageGetJoinGroup(
|
|
||||||
ctx context.Context,
|
|
||||||
userID string,
|
|
||||||
pageNumber, showNumber int32,
|
|
||||||
) (total uint32, totalGroupMembers []*relationtb.GroupMemberModel, err error)
|
|
||||||
PageGetGroupMember(
|
|
||||||
ctx context.Context,
|
|
||||||
groupID string,
|
|
||||||
pageNumber, showNumber int32,
|
|
||||||
) (total uint32, totalGroupMembers []*relationtb.GroupMemberModel, err error)
|
|
||||||
SearchGroupMember(
|
|
||||||
ctx context.Context,
|
|
||||||
keyword string,
|
|
||||||
groupIDs []string,
|
|
||||||
userIDs []string,
|
|
||||||
roleLevels []int32,
|
|
||||||
pageNumber, showNumber int32,
|
|
||||||
) (uint32, []*relationtb.GroupMemberModel, error)
|
|
||||||
HandlerGroupRequest(
|
|
||||||
ctx context.Context,
|
|
||||||
groupID string,
|
|
||||||
userID string,
|
|
||||||
handledMsg string,
|
|
||||||
handleResult int32,
|
|
||||||
member *relationtb.GroupMemberModel,
|
|
||||||
) error
|
|
||||||
DeleteGroupMember(ctx context.Context, groupID string, userIDs []string) error
|
DeleteGroupMember(ctx context.Context, groupID string, userIDs []string) error
|
||||||
MapGroupMemberUserID(ctx context.Context, groupIDs []string) (map[string]*relationtb.GroupSimpleUserID, error)
|
MapGroupMemberUserID(ctx context.Context, groupIDs []string) (map[string]*relationtb.GroupSimpleUserID, error)
|
||||||
MapGroupMemberNum(ctx context.Context, groupIDs []string) (map[string]uint32, error)
|
MapGroupMemberNum(ctx context.Context, groupIDs []string) (map[string]uint32, error)
|
||||||
TransferGroupOwner(
|
TransferGroupOwner(ctx context.Context, groupID string, oldOwnerUserID, newOwnerUserID string, roleLevel int32) error // 转让群
|
||||||
ctx context.Context,
|
|
||||||
groupID string,
|
|
||||||
oldOwnerUserID, newOwnerUserID string,
|
|
||||||
roleLevel int32,
|
|
||||||
) error // 转让群
|
|
||||||
UpdateGroupMember(ctx context.Context, groupID string, userID string, data map[string]any) error
|
UpdateGroupMember(ctx context.Context, groupID string, userID string, data map[string]any) error
|
||||||
UpdateGroupMembers(ctx context.Context, data []*relationtb.BatchUpdateGroupMember) error
|
UpdateGroupMembers(ctx context.Context, data []*relationtb.BatchUpdateGroupMember) error
|
||||||
// GroupRequest
|
// GroupRequest
|
||||||
CreateGroupRequest(ctx context.Context, requests []*relationtb.GroupRequestModel) error
|
CreateGroupRequest(ctx context.Context, requests []*relationtb.GroupRequestModel) error
|
||||||
TakeGroupRequest(ctx context.Context, groupID string, userID string) (*relationtb.GroupRequestModel, error)
|
TakeGroupRequest(ctx context.Context, groupID string, userID string) (*relationtb.GroupRequestModel, error)
|
||||||
FindGroupRequests(ctx context.Context, groupID string, userIDs []string) (int64, []*relationtb.GroupRequestModel, error)
|
FindGroupRequests(ctx context.Context, groupID string, userIDs []string) (int64, []*relationtb.GroupRequestModel, error)
|
||||||
PageGroupRequestUser(
|
PageGroupRequestUser(ctx context.Context, userID string, pageNumber, showNumber int32) (uint32, []*relationtb.GroupRequestModel, error)
|
||||||
ctx context.Context,
|
|
||||||
userID string,
|
|
||||||
pageNumber, showNumber int32,
|
|
||||||
) (uint32, []*relationtb.GroupRequestModel, error)
|
|
||||||
// SuperGroupModelInterface
|
// SuperGroupModelInterface
|
||||||
FindSuperGroup(ctx context.Context, groupIDs []string) ([]*unrelationtb.SuperGroupModel, error)
|
FindSuperGroup(ctx context.Context, groupIDs []string) ([]*unrelationtb.SuperGroupModel, error)
|
||||||
FindJoinSuperGroup(ctx context.Context, userID string) ([]string, error)
|
FindJoinSuperGroup(ctx context.Context, userID string) ([]string, error)
|
||||||
@ -310,12 +261,22 @@ func (g *groupDatabase) PageGroupRequest(
|
|||||||
return g.groupRequestDB.PageGroup(ctx, groupIDs, pageNumber, showNumber)
|
return g.groupRequestDB.PageGroup(ctx, groupIDs, pageNumber, showNumber)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (g *groupDatabase) FindGroupMember(
|
func (g *groupDatabase) FindGroupMember(ctx context.Context, groupIDs []string, userIDs []string, roleLevels []int32) (totalGroupMembers []*relationtb.GroupMemberModel, err error) {
|
||||||
ctx context.Context,
|
if len(groupIDs) == 0 && len(roleLevels) == 0 && len(userIDs) == 1 {
|
||||||
groupIDs []string,
|
gIDs, err := g.cache.GetJoinedGroupIDs(ctx, userIDs[0])
|
||||||
userIDs []string,
|
if err != nil {
|
||||||
roleLevels []int32,
|
return nil, err
|
||||||
) (totalGroupMembers []*relationtb.GroupMemberModel, err error) {
|
}
|
||||||
|
var res []*relationtb.GroupMemberModel
|
||||||
|
for _, groupID := range gIDs {
|
||||||
|
v, err := g.cache.GetGroupMemberInfo(ctx, groupID, userIDs[0])
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
res = append(res, v)
|
||||||
|
}
|
||||||
|
return res, nil
|
||||||
|
}
|
||||||
if len(roleLevels) == 0 {
|
if len(roleLevels) == 0 {
|
||||||
for _, groupID := range groupIDs {
|
for _, groupID := range groupIDs {
|
||||||
groupMembers, err := g.cache.GetGroupMembersInfo(ctx, groupID, userIDs)
|
groupMembers, err := g.cache.GetGroupMembersInfo(ctx, groupID, userIDs)
|
||||||
@ -451,13 +412,8 @@ func (g *groupDatabase) MapGroupMemberNum(ctx context.Context, groupIDs []string
|
|||||||
return m, nil
|
return m, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (g *groupDatabase) TransferGroupOwner(
|
func (g *groupDatabase) TransferGroupOwner(ctx context.Context, groupID string, oldOwnerUserID, newOwnerUserID string, roleLevel int32) error {
|
||||||
ctx context.Context,
|
return g.tx.Transaction(func(tx any) error {
|
||||||
groupID string,
|
|
||||||
oldOwnerUserID, newOwnerUserID string,
|
|
||||||
roleLevel int32,
|
|
||||||
) error {
|
|
||||||
if err := g.tx.Transaction(func(tx any) error {
|
|
||||||
rowsAffected, err := g.groupMemberDB.NewTx(tx).UpdateRoleLevel(ctx, groupID, oldOwnerUserID, roleLevel)
|
rowsAffected, err := g.groupMemberDB.NewTx(tx).UpdateRoleLevel(ctx, groupID, oldOwnerUserID, roleLevel)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
@ -472,11 +428,8 @@ func (g *groupDatabase) TransferGroupOwner(
|
|||||||
if rowsAffected != 1 {
|
if rowsAffected != 1 {
|
||||||
return utils.Wrap(fmt.Errorf("newOwnerUserID %s rowsAffected = %d", newOwnerUserID, rowsAffected), "")
|
return utils.Wrap(fmt.Errorf("newOwnerUserID %s rowsAffected = %d", newOwnerUserID, rowsAffected), "")
|
||||||
}
|
}
|
||||||
return nil
|
return g.cache.DelGroupMembersInfo(groupID, oldOwnerUserID, newOwnerUserID).DelGroupMembersHash(groupID).ExecDel(ctx)
|
||||||
}); err != nil {
|
})
|
||||||
return err
|
|
||||||
}
|
|
||||||
return g.cache.DelGroupMembersInfo(groupID, oldOwnerUserID, newOwnerUserID).ExecDel(ctx)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (g *groupDatabase) UpdateGroupMember(
|
func (g *groupDatabase) UpdateGroupMember(
|
||||||
|
|||||||
@ -17,6 +17,8 @@ package relation
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
|
||||||
|
"github.com/OpenIMSDK/tools/errs"
|
||||||
|
|
||||||
"github.com/OpenIMSDK/tools/ormutil"
|
"github.com/OpenIMSDK/tools/ormutil"
|
||||||
|
|
||||||
"gorm.io/gorm"
|
"gorm.io/gorm"
|
||||||
@ -103,3 +105,7 @@ func (b *BlackGorm) FindBlackUserIDs(ctx context.Context, ownerUserID string) (b
|
|||||||
"",
|
"",
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (b *BlackGorm) FindOwnerBlackInfos(ctx context.Context, ownerUserID string, userIDs []string) (blacks []*relation.BlackModel, err error) {
|
||||||
|
return blacks, errs.Wrap(b.db(ctx).Where("owner_user_id = ? and block_user_id in ?", ownerUserID, userIDs).Find(&blacks).Error)
|
||||||
|
}
|
||||||
|
|||||||
@ -43,10 +43,7 @@ type BlackModelInterface interface {
|
|||||||
Update(ctx context.Context, blacks []*BlackModel) (err error)
|
Update(ctx context.Context, blacks []*BlackModel) (err error)
|
||||||
Find(ctx context.Context, blacks []*BlackModel) (blackList []*BlackModel, err error)
|
Find(ctx context.Context, blacks []*BlackModel) (blackList []*BlackModel, err error)
|
||||||
Take(ctx context.Context, ownerUserID, blockUserID string) (black *BlackModel, err error)
|
Take(ctx context.Context, ownerUserID, blockUserID string) (black *BlackModel, err error)
|
||||||
FindOwnerBlacks(
|
FindOwnerBlacks(ctx context.Context, ownerUserID string, pageNumber, showNumber int32) (blacks []*BlackModel, total int64, err error)
|
||||||
ctx context.Context,
|
FindOwnerBlackInfos(ctx context.Context, ownerUserID string, userIDs []string) (blacks []*BlackModel, err error)
|
||||||
ownerUserID string,
|
|
||||||
pageNumber, showNumber int32,
|
|
||||||
) (blacks []*BlackModel, total int64, err error)
|
|
||||||
FindBlackUserIDs(ctx context.Context, ownerUserID string) (blackUserIDs []string, err error)
|
FindBlackUserIDs(ctx context.Context, ownerUserID string) (blackUserIDs []string, err error)
|
||||||
}
|
}
|
||||||
|
|||||||
@ -208,3 +208,10 @@ func (g *GroupRpcClient) DismissGroup(ctx context.Context, groupID string) error
|
|||||||
})
|
})
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (g *GroupRpcClient) NotificationUserInfoUpdate(ctx context.Context, userID string) error {
|
||||||
|
_, err := g.Client.NotificationUserInfoUpdate(ctx, &group.NotificationUserInfoUpdateReq{
|
||||||
|
UserID: userID,
|
||||||
|
})
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|||||||
@ -147,7 +147,10 @@ func (u *UserRpcClient) GetUserGlobalMsgRecvOpt(ctx context.Context, userID stri
|
|||||||
resp, err := u.Client.GetGlobalRecvMessageOpt(ctx, &user.GetGlobalRecvMessageOptReq{
|
resp, err := u.Client.GetGlobalRecvMessageOpt(ctx, &user.GetGlobalRecvMessageOptReq{
|
||||||
UserID: userID,
|
UserID: userID,
|
||||||
})
|
})
|
||||||
return resp.GlobalRecvMsgOpt, err
|
if err != nil {
|
||||||
|
return 0, err
|
||||||
|
}
|
||||||
|
return resp.GlobalRecvMsgOpt, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// Access verifies the access rights for the provided user ID.
|
// Access verifies the access rights for the provided user ID.
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user