fix: Fix Bug related issues with OpenIM actions PR (#921)

* feat: add test changelog file

Signed-off-by: Xinwei Xiong(cubxxw-openim) <3293172751nss@gmail.com>

* feat: add test changelog file

Signed-off-by: Xinwei Xiong(cubxxw-openim) <3293172751nss@gmail.com>

* feat: add test changelog file

Signed-off-by: Xinwei Xiong(cubxxw-openim) <3293172751nss@gmail.com>

* feat: add test changelog file

Signed-off-by: Xinwei Xiong(cubxxw-openim) <3293172751nss@gmail.com>

* feat: add test changelog file

Signed-off-by: Xinwei Xiong(cubxxw-openim) <3293172751nss@gmail.com>

* feat: add test changelog file

Signed-off-by: Xinwei Xiong(cubxxw-openim) <3293172751nss@gmail.com>

* feat: add test changelog file

Signed-off-by: Xinwei Xiong(cubxxw-openim) <3293172751nss@gmail.com>

* feat: add scripts test

Signed-off-by: Xinwei Xiong(cubxxw-openim) <3293172751nss@gmail.com>

* feat: add scripts test and format

Signed-off-by: Xinwei Xiong(cubxxw-openim) <3293172751nss@gmail.com>

* feat: add scripts test and format

Signed-off-by: Xinwei Xiong(cubxxw-openim) <3293172751nss@gmail.com>

* feat: add scripts test and format

Signed-off-by: Xinwei Xiong(cubxxw-openim) <3293172751nss@gmail.com>

* feat: add scripts test and format

Signed-off-by: Xinwei Xiong(cubxxw-openim) <3293172751nss@gmail.com>

* feat: add scripts test and format

Signed-off-by: Xinwei Xiong(cubxxw-openim) <3293172751nss@gmail.com>

* feat: add scripts test and format

Signed-off-by: Xinwei Xiong(cubxxw-openim) <3293172751nss@gmail.com>

* feat: add scripts test and format

Signed-off-by: Xinwei Xiong(cubxxw-openim) <3293172751nss@gmail.com>

* feat: add scripts test and format

Signed-off-by: Xinwei Xiong(cubxxw-openim) <3293172751nss@gmail.com>

* feat: add scripts test and format

Signed-off-by: Xinwei Xiong(cubxxw-openim) <3293172751nss@gmail.com>

---------

Signed-off-by: Xinwei Xiong(cubxxw-openim) <3293172751nss@gmail.com>
This commit is contained in:
Xinwei Xiong
2023-08-23 16:45:52 +08:00
committed by GitHub
parent 73c4b68052
commit b2ea4ce2a3
100 changed files with 939 additions and 832 deletions
+6 -6
View File
@@ -17,7 +17,7 @@ package convert
import (
"time"
pbGroup "github.com/OpenIMSDK/protocol/group"
pbgroup "github.com/OpenIMSDK/protocol/group"
sdkws "github.com/OpenIMSDK/protocol/sdkws"
"github.com/OpenIMSDK/Open-IM-Server/pkg/common/db/table/relation"
@@ -45,7 +45,7 @@ func Db2PbGroupInfo(m *relation.GroupModel, ownerUserID string, memberCount uint
}
}
func Pb2DbGroupRequest(req *pbGroup.GroupApplicationResponseReq, handleUserID string) *relation.GroupRequestModel {
func Pb2DbGroupRequest(req *pbgroup.GroupApplicationResponseReq, handleUserID string) *relation.GroupRequestModel {
return &relation.GroupRequestModel{
UserID: req.FromUserID,
GroupID: req.GroupID,
@@ -61,8 +61,8 @@ func Db2PbCMSGroup(
ownerUserID string,
ownerUserName string,
memberCount uint32,
) *pbGroup.CMSGroup {
return &pbGroup.CMSGroup{
) *pbgroup.CMSGroup {
return &pbgroup.CMSGroup{
GroupInfo: Db2PbGroupInfo(m, ownerUserID, memberCount),
GroupOwnerUserID: ownerUserID,
GroupOwnerUserName: ownerUserName,
@@ -110,8 +110,8 @@ func Db2PbGroupAbstractInfo(
groupID string,
groupMemberNumber uint32,
groupMemberListHash uint64,
) *pbGroup.GroupAbstractInfo {
return &pbGroup.GroupAbstractInfo{
) *pbgroup.GroupAbstractInfo {
return &pbgroup.GroupAbstractInfo{
GroupID: groupID,
GroupMemberNumber: groupMemberNumber,
GroupMemberListHash: groupMemberListHash,
+4 -4
View File
@@ -19,10 +19,10 @@ import (
"github.com/OpenIMSDK/protocol/sdkws"
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 UsersDB2Pb(users []*relationTb.UserModel) (result []*sdkws.UserInfo) {
func UsersDB2Pb(users []*relationtb.UserModel) (result []*sdkws.UserInfo) {
for _, user := range users {
var userPb sdkws.UserInfo
userPb.UserID = user.UserID
@@ -37,8 +37,8 @@ func UsersDB2Pb(users []*relationTb.UserModel) (result []*sdkws.UserInfo) {
return result
}
func UserPb2DB(user *sdkws.UserInfo) *relationTb.UserModel {
var userDB relationTb.UserModel
func UserPb2DB(user *sdkws.UserInfo) *relationtb.UserModel {
var userDB relationtb.UserModel
userDB.UserID = user.UserID
userDB.Nickname = user.Nickname
userDB.FaceURL = user.FaceURL
+3 -3
View File
@@ -21,7 +21,7 @@ import (
"github.com/dtm-labs/rockscache"
"github.com/redis/go-redis/v9"
relationTb "github.com/OpenIMSDK/Open-IM-Server/pkg/common/db/table/relation"
relationtb "github.com/OpenIMSDK/Open-IM-Server/pkg/common/db/table/relation"
)
const (
@@ -43,12 +43,12 @@ type BlackCacheRedis struct {
metaCache
expireTime time.Duration
rcClient *rockscache.Client
blackDB relationTb.BlackModelInterface
blackDB relationtb.BlackModelInterface
}
func NewBlackCacheRedis(
rdb redis.UniversalClient,
blackDB relationTb.BlackModelInterface,
blackDB relationtb.BlackModelInterface,
options rockscache.Options,
) BlackCache {
rcClient := rockscache.NewClient(rdb, options)
+15 -15
View File
@@ -27,7 +27,7 @@ import (
"github.com/OpenIMSDK/tools/utils"
"github.com/OpenIMSDK/Open-IM-Server/pkg/common/db/relation"
relationTb "github.com/OpenIMSDK/Open-IM-Server/pkg/common/db/table/relation"
relationtb "github.com/OpenIMSDK/Open-IM-Server/pkg/common/db/table/relation"
)
const (
@@ -54,7 +54,7 @@ type ConversationCache interface {
DelUserConversationIDsHash(ownerUserIDs ...string) ConversationCache
// get one conversation from msgCache
GetConversation(ctx context.Context, ownerUserID, conversationID string) (*relationTb.ConversationModel, error)
GetConversation(ctx context.Context, ownerUserID, conversationID string) (*relationtb.ConversationModel, error)
DelConversations(ownerUserID string, conversationIDs ...string) ConversationCache
DelUsersConversation(conversationID string, ownerUserIDs ...string) ConversationCache
// get one conversation from msgCache
@@ -62,9 +62,9 @@ type ConversationCache interface {
ctx context.Context,
ownerUserID string,
conversationIDs []string,
) ([]*relationTb.ConversationModel, error)
) ([]*relationtb.ConversationModel, error)
// get one user's all conversations from msgCache
GetUserAllConversations(ctx context.Context, ownerUserID string) ([]*relationTb.ConversationModel, error)
GetUserAllConversations(ctx context.Context, ownerUserID string) ([]*relationtb.ConversationModel, error)
// get user conversation recv msg from msgCache
GetUserRecvMsgOpt(ctx context.Context, ownerUserID, conversationID string) (opt int, err error)
DelUserRecvMsgOpt(ownerUserID, conversationID string) ConversationCache
@@ -81,14 +81,14 @@ type ConversationCache interface {
GetConversationsByConversationID(
ctx context.Context,
conversationIDs []string,
) ([]*relationTb.ConversationModel, error)
) ([]*relationtb.ConversationModel, error)
DelConversationByConversationID(conversationIDs ...string) ConversationCache
}
func NewConversationRedis(
rdb redis.UniversalClient,
opts rockscache.Options,
db relationTb.ConversationModelInterface,
db relationtb.ConversationModelInterface,
) ConversationCache {
rcClient := rockscache.NewClient(rdb, opts)
return &ConversationRedisCache{
@@ -102,7 +102,7 @@ func NewConversationRedis(
type ConversationRedisCache struct {
metaCache
rcClient *rockscache.Client
conversationDB relationTb.ConversationModelInterface
conversationDB relationtb.ConversationModelInterface
expireTime time.Duration
}
@@ -214,13 +214,13 @@ func (c *ConversationRedisCache) DelUserConversationIDsHash(ownerUserIDs ...stri
func (c *ConversationRedisCache) GetConversation(
ctx context.Context,
ownerUserID, conversationID string,
) (*relationTb.ConversationModel, error) {
) (*relationtb.ConversationModel, error) {
return getCache(
ctx,
c.rcClient,
c.getConversationKey(ownerUserID, conversationID),
c.expireTime,
func(ctx context.Context) (*relationTb.ConversationModel, error) {
func(ctx context.Context) (*relationtb.ConversationModel, error) {
return c.conversationDB.Take(ctx, ownerUserID, conversationID)
},
)
@@ -237,7 +237,7 @@ func (c *ConversationRedisCache) DelConversations(ownerUserID string, conversati
}
func (c *ConversationRedisCache) getConversationIndex(
convsation *relationTb.ConversationModel,
convsation *relationtb.ConversationModel,
keys []string,
) (int, error) {
key := c.getConversationKey(convsation.OwnerUserID, convsation.ConversationID)
@@ -253,7 +253,7 @@ func (c *ConversationRedisCache) GetConversations(
ctx context.Context,
ownerUserID string,
conversationIDs []string,
) ([]*relationTb.ConversationModel, error) {
) ([]*relationtb.ConversationModel, error) {
var keys []string
for _, conversarionID := range conversationIDs {
keys = append(keys, c.getConversationKey(ownerUserID, conversarionID))
@@ -264,7 +264,7 @@ func (c *ConversationRedisCache) GetConversations(
keys,
c.expireTime,
c.getConversationIndex,
func(ctx context.Context) ([]*relationTb.ConversationModel, error) {
func(ctx context.Context) ([]*relationtb.ConversationModel, error) {
return c.conversationDB.Find(ctx, ownerUserID, conversationIDs)
},
)
@@ -273,7 +273,7 @@ func (c *ConversationRedisCache) GetConversations(
func (c *ConversationRedisCache) GetUserAllConversations(
ctx context.Context,
ownerUserID string,
) ([]*relationTb.ConversationModel, error) {
) ([]*relationtb.ConversationModel, error) {
conversationIDs, err := c.GetUserConversationIDs(ctx, ownerUserID)
if err != nil {
return nil, err
@@ -288,7 +288,7 @@ func (c *ConversationRedisCache) GetUserAllConversations(
keys,
c.expireTime,
c.getConversationIndex,
func(ctx context.Context) ([]*relationTb.ConversationModel, error) {
func(ctx context.Context) ([]*relationtb.ConversationModel, error) {
return c.conversationDB.FindUserIDAllConversations(ctx, ownerUserID)
},
)
@@ -425,7 +425,7 @@ func (c *ConversationRedisCache) DelUserAllHasReadSeqs(
func (c *ConversationRedisCache) GetConversationsByConversationID(
ctx context.Context,
conversationIDs []string,
) ([]*relationTb.ConversationModel, error) {
) ([]*relationtb.ConversationModel, error) {
panic("implement me")
}
+6 -6
View File
@@ -23,7 +23,7 @@ import (
"github.com/OpenIMSDK/tools/utils"
relationTb "github.com/OpenIMSDK/Open-IM-Server/pkg/common/db/table/relation"
relationtb "github.com/OpenIMSDK/Open-IM-Server/pkg/common/db/table/relation"
)
const (
@@ -41,21 +41,21 @@ type FriendCache interface {
// call when friendID List changed
DelFriendIDs(ownerUserID ...string) FriendCache
// get single friendInfo from msgCache
GetFriend(ctx context.Context, ownerUserID, friendUserID string) (friend *relationTb.FriendModel, err error)
GetFriend(ctx context.Context, ownerUserID, friendUserID string) (friend *relationtb.FriendModel, err error)
// del friend when friend info changed
DelFriend(ownerUserID, friendUserID string) FriendCache
}
type FriendCacheRedis struct {
metaCache
friendDB relationTb.FriendModelInterface
friendDB relationtb.FriendModelInterface
expireTime time.Duration
rcClient *rockscache.Client
}
func NewFriendCacheRedis(
rdb redis.UniversalClient,
friendDB relationTb.FriendModelInterface,
friendDB relationtb.FriendModelInterface,
options rockscache.Options,
) FriendCache {
rcClient := rockscache.NewClient(rdb, options)
@@ -140,13 +140,13 @@ func (f *FriendCacheRedis) DelTwoWayFriendIDs(ctx context.Context, ownerUserID s
func (f *FriendCacheRedis) GetFriend(
ctx context.Context,
ownerUserID, friendUserID string,
) (friend *relationTb.FriendModel, err error) {
) (friend *relationtb.FriendModel, err error) {
return getCache(
ctx,
f.rcClient,
f.getFriendKey(ownerUserID, friendUserID),
f.expireTime,
func(ctx context.Context) (*relationTb.FriendModel, error) {
func(ctx context.Context) (*relationtb.FriendModel, error) {
return f.friendDB.Take(ctx, ownerUserID, friendUserID)
},
)
+40 -40
View File
@@ -25,8 +25,8 @@ import (
"github.com/OpenIMSDK/tools/utils"
relationTb "github.com/OpenIMSDK/Open-IM-Server/pkg/common/db/table/relation"
unrelationTb "github.com/OpenIMSDK/Open-IM-Server/pkg/common/db/table/unrelation"
relationtb "github.com/OpenIMSDK/Open-IM-Server/pkg/common/db/table/relation"
unrelationtb "github.com/OpenIMSDK/Open-IM-Server/pkg/common/db/table/unrelation"
)
const (
@@ -44,17 +44,17 @@ const (
type GroupCache interface {
metaCache
NewCache() GroupCache
GetGroupsInfo(ctx context.Context, groupIDs []string) (groups []*relationTb.GroupModel, err error)
GetGroupInfo(ctx context.Context, groupID string) (group *relationTb.GroupModel, err error)
GetGroupsInfo(ctx context.Context, groupIDs []string) (groups []*relationtb.GroupModel, err error)
GetGroupInfo(ctx context.Context, groupID string) (group *relationtb.GroupModel, err error)
DelGroupsInfo(groupIDs ...string) GroupCache
GetJoinedSuperGroupIDs(ctx context.Context, userID string) (joinedSuperGroupIDs []string, err error)
DelJoinedSuperGroupIDs(userIDs ...string) GroupCache
GetSuperGroupMemberIDs(ctx context.Context, groupIDs ...string) (models []*unrelationTb.SuperGroupModel, err error)
GetSuperGroupMemberIDs(ctx context.Context, groupIDs ...string) (models []*unrelationtb.SuperGroupModel, err error)
DelSuperGroupMemberIDs(groupIDs ...string) GroupCache
GetGroupMembersHash(ctx context.Context, groupID string) (hashCode uint64, err error)
GetGroupMemberHashMap(ctx context.Context, groupIDs []string) (map[string]*relationTb.GroupSimpleUserID, error)
GetGroupMemberHashMap(ctx context.Context, groupIDs []string) (map[string]*relationtb.GroupSimpleUserID, error)
DelGroupMembersHash(groupID string) GroupCache
GetGroupMemberIDs(ctx context.Context, groupID string) (groupMemberIDs []string, err error)
@@ -68,19 +68,19 @@ type GroupCache interface {
GetGroupMemberInfo(
ctx context.Context,
groupID, userID string,
) (groupMember *relationTb.GroupMemberModel, err error)
) (groupMember *relationtb.GroupMemberModel, err error)
GetGroupMembersInfo(
ctx context.Context,
groupID string,
userID []string,
) (groupMembers []*relationTb.GroupMemberModel, err error)
GetAllGroupMembersInfo(ctx context.Context, groupID string) (groupMembers []*relationTb.GroupMemberModel, err error)
) (groupMembers []*relationtb.GroupMemberModel, err error)
GetAllGroupMembersInfo(ctx context.Context, groupID string) (groupMembers []*relationtb.GroupMemberModel, err error)
GetGroupMembersPage(
ctx context.Context,
groupID string,
userID []string,
showNumber, pageNumber int32,
) (total uint32, groupMembers []*relationTb.GroupMemberModel, err error)
) (total uint32, groupMembers []*relationtb.GroupMemberModel, err error)
DelGroupMembersInfo(groupID string, userID ...string) GroupCache
@@ -90,10 +90,10 @@ type GroupCache interface {
type GroupCacheRedis struct {
metaCache
groupDB relationTb.GroupModelInterface
groupMemberDB relationTb.GroupMemberModelInterface
groupRequestDB relationTb.GroupRequestModelInterface
mongoDB unrelationTb.SuperGroupModelInterface
groupDB relationtb.GroupModelInterface
groupMemberDB relationtb.GroupMemberModelInterface
groupRequestDB relationtb.GroupRequestModelInterface
mongoDB unrelationtb.SuperGroupModelInterface
expireTime time.Duration
rcClient *rockscache.Client
hashCode func(ctx context.Context, groupID string) (uint64, error)
@@ -101,10 +101,10 @@ type GroupCacheRedis struct {
func NewGroupCacheRedis(
rdb redis.UniversalClient,
groupDB relationTb.GroupModelInterface,
groupMemberDB relationTb.GroupMemberModelInterface,
groupRequestDB relationTb.GroupRequestModelInterface,
mongoClient unrelationTb.SuperGroupModelInterface,
groupDB relationtb.GroupModelInterface,
groupMemberDB relationtb.GroupMemberModelInterface,
groupRequestDB relationtb.GroupRequestModelInterface,
mongoClient unrelationtb.SuperGroupModelInterface,
hashCode func(ctx context.Context, groupID string) (uint64, error),
opts rockscache.Options,
) GroupCache {
@@ -162,7 +162,7 @@ func (g *GroupCacheRedis) getGroupMemberNumKey(groupID string) string {
return groupMemberNumKey + groupID
}
func (g *GroupCacheRedis) GetGroupIndex(group *relationTb.GroupModel, keys []string) (int, error) {
func (g *GroupCacheRedis) GetGroupIndex(group *relationtb.GroupModel, keys []string) (int, error) {
key := g.getGroupInfoKey(group.GroupID)
for i, _key := range keys {
if _key == key {
@@ -172,7 +172,7 @@ func (g *GroupCacheRedis) GetGroupIndex(group *relationTb.GroupModel, keys []str
return 0, errIndex
}
func (g *GroupCacheRedis) GetGroupMemberIndex(groupMember *relationTb.GroupMemberModel, keys []string) (int, error) {
func (g *GroupCacheRedis) GetGroupMemberIndex(groupMember *relationtb.GroupMemberModel, keys []string) (int, error) {
key := g.getGroupMemberInfoKey(groupMember.GroupID, groupMember.UserID)
for i, _key := range keys {
if _key == key {
@@ -186,7 +186,7 @@ func (g *GroupCacheRedis) GetGroupMemberIndex(groupMember *relationTb.GroupMembe
func (g *GroupCacheRedis) GetGroupsInfo(
ctx context.Context,
groupIDs []string,
) (groups []*relationTb.GroupModel, err error) {
) (groups []*relationtb.GroupModel, err error) {
var keys []string
for _, group := range groupIDs {
keys = append(keys, g.getGroupInfoKey(group))
@@ -197,19 +197,19 @@ func (g *GroupCacheRedis) GetGroupsInfo(
keys,
g.expireTime,
g.GetGroupIndex,
func(ctx context.Context) ([]*relationTb.GroupModel, error) {
func(ctx context.Context) ([]*relationtb.GroupModel, error) {
return g.groupDB.Find(ctx, groupIDs)
},
)
}
func (g *GroupCacheRedis) GetGroupInfo(ctx context.Context, groupID string) (group *relationTb.GroupModel, err error) {
func (g *GroupCacheRedis) GetGroupInfo(ctx context.Context, groupID string) (group *relationtb.GroupModel, err error) {
return getCache(
ctx,
g.rcClient,
g.getGroupInfoKey(groupID),
g.expireTime,
func(ctx context.Context) (*relationTb.GroupModel, error) {
func(ctx context.Context) (*relationtb.GroupModel, error) {
return g.groupDB.Take(ctx, groupID)
},
)
@@ -247,7 +247,7 @@ func (g *GroupCacheRedis) GetJoinedSuperGroupIDs(
func (g *GroupCacheRedis) GetSuperGroupMemberIDs(
ctx context.Context,
groupIDs ...string,
) (models []*unrelationTb.SuperGroupModel, err error) {
) (models []*unrelationtb.SuperGroupModel, err error) {
var keys []string
for _, group := range groupIDs {
keys = append(keys, g.getSuperGroupMemberIDsKey(group))
@@ -257,7 +257,7 @@ func (g *GroupCacheRedis) GetSuperGroupMemberIDs(
g.rcClient,
keys,
g.expireTime,
func(model *unrelationTb.SuperGroupModel, keys []string) (int, error) {
func(model *unrelationtb.SuperGroupModel, keys []string) (int, error) {
for i, key := range keys {
if g.getSuperGroupMemberIDsKey(model.GroupID) == key {
return i, nil
@@ -265,7 +265,7 @@ func (g *GroupCacheRedis) GetSuperGroupMemberIDs(
}
return 0, errIndex
},
func(ctx context.Context) ([]*unrelationTb.SuperGroupModel, error) {
func(ctx context.Context) ([]*unrelationtb.SuperGroupModel, error) {
return g.mongoDB.FindSuperGroup(ctx, groupIDs)
},
)
@@ -305,7 +305,7 @@ func (g *GroupCacheRedis) GetGroupMembersHash(ctx context.Context, groupID strin
// return 0, err
// }
// log.ZInfo(ctx, "GetGroupMembersHash", "groupID", groupID, "userIDs", userIDs)
// var members []*relationTb.GroupMemberModel
// var members []*relationtb.GroupMemberModel
// if len(userIDs) > 0 {
// members, err = g.GetGroupMembersInfo(ctx, groupID, userIDs)
// if err != nil {
@@ -313,7 +313,7 @@ func (g *GroupCacheRedis) GetGroupMembersHash(ctx context.Context, groupID strin
// }
// utils.Sort(userIDs, true)
// }
// memberMap := make(map[string]*relationTb.GroupMemberModel)
// memberMap := make(map[string]*relationtb.GroupMemberModel)
// for i, member := range members {
// memberMap[member.UserID] = members[i]
// }
@@ -354,8 +354,8 @@ func (g *GroupCacheRedis) GetGroupMembersHash(ctx context.Context, groupID strin
func (g *GroupCacheRedis) GetGroupMemberHashMap(
ctx context.Context,
groupIDs []string,
) (map[string]*relationTb.GroupSimpleUserID, error) {
res := make(map[string]*relationTb.GroupSimpleUserID)
) (map[string]*relationtb.GroupSimpleUserID, error) {
res := make(map[string]*relationtb.GroupSimpleUserID)
for _, groupID := range groupIDs {
hash, err := g.GetGroupMembersHash(ctx, groupID)
if err != nil {
@@ -366,7 +366,7 @@ func (g *GroupCacheRedis) GetGroupMemberHashMap(
if err != nil {
return nil, err
}
res[groupID] = &relationTb.GroupSimpleUserID{Hash: hash, MemberNum: uint32(num)}
res[groupID] = &relationtb.GroupSimpleUserID{Hash: hash, MemberNum: uint32(num)}
}
return res, nil
}
@@ -433,13 +433,13 @@ func (g *GroupCacheRedis) DelJoinedGroupID(userIDs ...string) GroupCache {
func (g *GroupCacheRedis) GetGroupMemberInfo(
ctx context.Context,
groupID, userID string,
) (groupMember *relationTb.GroupMemberModel, err error) {
) (groupMember *relationtb.GroupMemberModel, err error) {
return getCache(
ctx,
g.rcClient,
g.getGroupMemberInfoKey(groupID, userID),
g.expireTime,
func(ctx context.Context) (*relationTb.GroupMemberModel, error) {
func(ctx context.Context) (*relationtb.GroupMemberModel, error) {
return g.groupMemberDB.Take(ctx, groupID, userID)
},
)
@@ -449,7 +449,7 @@ func (g *GroupCacheRedis) GetGroupMembersInfo(
ctx context.Context,
groupID string,
userIDs []string,
) ([]*relationTb.GroupMemberModel, error) {
) ([]*relationtb.GroupMemberModel, error) {
var keys []string
for _, userID := range userIDs {
keys = append(keys, g.getGroupMemberInfoKey(groupID, userID))
@@ -460,7 +460,7 @@ func (g *GroupCacheRedis) GetGroupMembersInfo(
keys,
g.expireTime,
g.GetGroupMemberIndex,
func(ctx context.Context) ([]*relationTb.GroupMemberModel, error) {
func(ctx context.Context) ([]*relationtb.GroupMemberModel, error) {
return g.groupMemberDB.Find(ctx, []string{groupID}, userIDs, nil)
},
)
@@ -471,7 +471,7 @@ func (g *GroupCacheRedis) GetGroupMembersPage(
groupID string,
userIDs []string,
showNumber, pageNumber int32,
) (total uint32, groupMembers []*relationTb.GroupMemberModel, err error) {
) (total uint32, groupMembers []*relationtb.GroupMemberModel, err error) {
groupMemberIDs, err := g.GetGroupMemberIDs(ctx, groupID)
if err != nil {
return 0, nil, err
@@ -488,7 +488,7 @@ func (g *GroupCacheRedis) GetGroupMembersPage(
func (g *GroupCacheRedis) GetAllGroupMembersInfo(
ctx context.Context,
groupID string,
) (groupMembers []*relationTb.GroupMemberModel, err error) {
) (groupMembers []*relationtb.GroupMemberModel, err error) {
groupMemberIDs, err := g.GetGroupMemberIDs(ctx, groupID)
if err != nil {
return nil, err
@@ -499,7 +499,7 @@ func (g *GroupCacheRedis) GetAllGroupMembersInfo(
func (g *GroupCacheRedis) GetAllGroupMemberInfo(
ctx context.Context,
groupID string,
) ([]*relationTb.GroupMemberModel, error) {
) ([]*relationtb.GroupMemberModel, error) {
groupMemberIDs, err := g.GetGroupMemberIDs(ctx, groupID)
if err != nil {
return nil, err
@@ -514,7 +514,7 @@ func (g *GroupCacheRedis) GetAllGroupMemberInfo(
keys,
g.expireTime,
g.GetGroupMemberIndex,
func(ctx context.Context) ([]*relationTb.GroupMemberModel, error) {
func(ctx context.Context) ([]*relationtb.GroupMemberModel, error) {
return g.groupMemberDB.Find(ctx, []string{groupID}, groupMemberIDs, nil)
},
)
+2 -2
View File
@@ -33,7 +33,7 @@ import (
"github.com/OpenIMSDK/tools/utils"
"github.com/OpenIMSDK/Open-IM-Server/pkg/common/config"
unRelationTb "github.com/OpenIMSDK/Open-IM-Server/pkg/common/db/table/unrelation"
unrelationtb "github.com/OpenIMSDK/Open-IM-Server/pkg/common/db/table/unrelation"
"github.com/redis/go-redis/v9"
)
@@ -143,7 +143,7 @@ type msgCache struct {
rdb redis.UniversalClient
expireTime time.Duration
rcClient *rockscache.Client
msgDocDatabase unRelationTb.MsgDocModelInterface
msgDocDatabase unrelationtb.MsgDocModelInterface
}
func (c *msgCache) getMaxSeqKey(conversationID string) string {
+10 -10
View File
@@ -29,7 +29,7 @@ import (
"github.com/dtm-labs/rockscache"
"github.com/redis/go-redis/v9"
relationTb "github.com/OpenIMSDK/Open-IM-Server/pkg/common/db/table/relation"
relationtb "github.com/OpenIMSDK/Open-IM-Server/pkg/common/db/table/relation"
)
const (
@@ -45,8 +45,8 @@ const (
type UserCache interface {
metaCache
NewCache() UserCache
GetUserInfo(ctx context.Context, userID string) (userInfo *relationTb.UserModel, err error)
GetUsersInfo(ctx context.Context, userIDs []string) ([]*relationTb.UserModel, error)
GetUserInfo(ctx context.Context, userID string) (userInfo *relationtb.UserModel, err error)
GetUsersInfo(ctx context.Context, userIDs []string) ([]*relationtb.UserModel, error)
DelUsersInfo(userIDs ...string) UserCache
GetUserGlobalRecvMsgOpt(ctx context.Context, userID string) (opt int, err error)
DelUsersGlobalRecvMsgOpt(userIDs ...string) UserCache
@@ -57,14 +57,14 @@ type UserCache interface {
type UserCacheRedis struct {
metaCache
rdb redis.UniversalClient
userDB relationTb.UserModelInterface
userDB relationtb.UserModelInterface
expireTime time.Duration
rcClient *rockscache.Client
}
func NewUserCacheRedis(
rdb redis.UniversalClient,
userDB relationTb.UserModelInterface,
userDB relationtb.UserModelInterface,
options rockscache.Options,
) UserCache {
rcClient := rockscache.NewClient(rdb, options)
@@ -99,19 +99,19 @@ func (u *UserCacheRedis) getUserStatusHashKey(userID string, Id int32) string {
return userID + "_" + string(Id) + platformID
}
func (u *UserCacheRedis) GetUserInfo(ctx context.Context, userID string) (userInfo *relationTb.UserModel, err error) {
func (u *UserCacheRedis) GetUserInfo(ctx context.Context, userID string) (userInfo *relationtb.UserModel, err error) {
return getCache(
ctx,
u.rcClient,
u.getUserInfoKey(userID),
u.expireTime,
func(ctx context.Context) (*relationTb.UserModel, error) {
func(ctx context.Context) (*relationtb.UserModel, error) {
return u.userDB.Take(ctx, userID)
},
)
}
func (u *UserCacheRedis) GetUsersInfo(ctx context.Context, userIDs []string) ([]*relationTb.UserModel, error) {
func (u *UserCacheRedis) GetUsersInfo(ctx context.Context, userIDs []string) ([]*relationtb.UserModel, error) {
var keys []string
for _, userID := range userIDs {
keys = append(keys, u.getUserInfoKey(userID))
@@ -121,7 +121,7 @@ func (u *UserCacheRedis) GetUsersInfo(ctx context.Context, userIDs []string) ([]
u.rcClient,
keys,
u.expireTime,
func(user *relationTb.UserModel, keys []string) (int, error) {
func(user *relationtb.UserModel, keys []string) (int, error) {
for i, key := range keys {
if key == u.getUserInfoKey(user.UserID) {
return i, nil
@@ -129,7 +129,7 @@ func (u *UserCacheRedis) GetUsersInfo(ctx context.Context, userIDs []string) ([]
}
return 0, errIndex
},
func(ctx context.Context) ([]*relationTb.UserModel, error) {
func(ctx context.Context) ([]*relationtb.UserModel, error) {
return u.userDB.Find(ctx, userIDs)
},
)
+6 -6
View File
@@ -15,23 +15,23 @@
package controller
import (
pbMsg "github.com/OpenIMSDK/protocol/msg"
pbmsg "github.com/OpenIMSDK/protocol/msg"
relationTb "github.com/OpenIMSDK/Open-IM-Server/pkg/common/db/table/relation"
relationtb "github.com/OpenIMSDK/Open-IM-Server/pkg/common/db/table/relation"
)
type ChatLogDatabase interface {
CreateChatLog(msg *pbMsg.MsgDataToMQ) error
CreateChatLog(msg *pbmsg.MsgDataToMQ) error
}
func NewChatLogDatabase(chatLogModelInterface relationTb.ChatLogModelInterface) ChatLogDatabase {
func NewChatLogDatabase(chatLogModelInterface relationtb.ChatLogModelInterface) ChatLogDatabase {
return &chatLogDatabase{chatLogModel: chatLogModelInterface}
}
type chatLogDatabase struct {
chatLogModel relationTb.ChatLogModelInterface
chatLogModel relationtb.ChatLogModelInterface
}
func (c *chatLogDatabase) CreateChatLog(msg *pbMsg.MsgDataToMQ) error {
func (c *chatLogDatabase) CreateChatLog(msg *pbmsg.MsgDataToMQ) error {
return c.chatLogModel.Create(msg)
}
+26 -26
View File
@@ -26,36 +26,36 @@ import (
"github.com/OpenIMSDK/tools/utils"
"github.com/OpenIMSDK/Open-IM-Server/pkg/common/db/cache"
relationTb "github.com/OpenIMSDK/Open-IM-Server/pkg/common/db/table/relation"
relationtb "github.com/OpenIMSDK/Open-IM-Server/pkg/common/db/table/relation"
)
type ConversationDatabase interface {
// UpdateUserConversationFiled 更新用户该会话的属性信息
UpdateUsersConversationFiled(ctx context.Context, userIDs []string, conversationID string, args map[string]interface{}) error
// CreateConversation 创建一批新的会话
CreateConversation(ctx context.Context, conversations []*relationTb.ConversationModel) error
CreateConversation(ctx context.Context, conversations []*relationtb.ConversationModel) error
// SyncPeerUserPrivateConversation 同步对端私聊会话内部保证事务操作
SyncPeerUserPrivateConversationTx(ctx context.Context, conversation []*relationTb.ConversationModel) error
SyncPeerUserPrivateConversationTx(ctx context.Context, conversation []*relationtb.ConversationModel) error
// FindConversations 根据会话ID获取某个用户的多个会话
FindConversations(ctx context.Context, ownerUserID string, conversationIDs []string) ([]*relationTb.ConversationModel, error)
FindConversations(ctx context.Context, ownerUserID string, conversationIDs []string) ([]*relationtb.ConversationModel, error)
// FindRecvMsgNotNotifyUserIDs 获取超级大群开启免打扰的用户ID
FindRecvMsgNotNotifyUserIDs(ctx context.Context, groupID string) ([]string, error)
// GetUserAllConversation 获取一个用户在服务器上所有的会话
GetUserAllConversation(ctx context.Context, ownerUserID string) ([]*relationTb.ConversationModel, error)
GetUserAllConversation(ctx context.Context, ownerUserID string) ([]*relationtb.ConversationModel, error)
// SetUserConversations 设置用户多个会话属性,如果会话不存在则创建,否则更新,内部保证原子性
SetUserConversations(ctx context.Context, ownerUserID string, conversations []*relationTb.ConversationModel) error
SetUserConversations(ctx context.Context, ownerUserID string, conversations []*relationtb.ConversationModel) error
// SetUsersConversationFiledTx 设置多个用户会话关于某个字段的更新操作,如果会话不存在则创建,否则更新,内部保证事务操作
SetUsersConversationFiledTx(ctx context.Context, userIDs []string, conversation *relationTb.ConversationModel, filedMap map[string]interface{}) error
SetUsersConversationFiledTx(ctx context.Context, userIDs []string, conversation *relationtb.ConversationModel, filedMap map[string]interface{}) error
CreateGroupChatConversation(ctx context.Context, groupID string, userIDs []string) error
GetConversationIDs(ctx context.Context, userID string) ([]string, error)
GetUserConversationIDsHash(ctx context.Context, ownerUserID string) (hash uint64, err error)
GetAllConversationIDs(ctx context.Context) ([]string, error)
GetUserAllHasReadSeqs(ctx context.Context, ownerUserID string) (map[string]int64, error)
GetConversationsByConversationID(ctx context.Context, conversationIDs []string) ([]*relationTb.ConversationModel, error)
GetConversationIDsNeedDestruct(ctx context.Context) ([]*relationTb.ConversationModel, error)
GetConversationsByConversationID(ctx context.Context, conversationIDs []string) ([]*relationtb.ConversationModel, error)
GetConversationIDsNeedDestruct(ctx context.Context) ([]*relationtb.ConversationModel, error)
}
func NewConversationDatabase(conversation relationTb.ConversationModelInterface, cache cache.ConversationCache, tx tx.Tx) ConversationDatabase {
func NewConversationDatabase(conversation relationtb.ConversationModelInterface, cache cache.ConversationCache, tx tx.Tx) ConversationDatabase {
return &conversationDatabase{
conversationDB: conversation,
cache: cache,
@@ -64,12 +64,12 @@ func NewConversationDatabase(conversation relationTb.ConversationModelInterface,
}
type conversationDatabase struct {
conversationDB relationTb.ConversationModelInterface
conversationDB relationtb.ConversationModelInterface
cache cache.ConversationCache
tx tx.Tx
}
func (c *conversationDatabase) SetUsersConversationFiledTx(ctx context.Context, userIDs []string, conversation *relationTb.ConversationModel, filedMap map[string]interface{}) (err error) {
func (c *conversationDatabase) SetUsersConversationFiledTx(ctx context.Context, userIDs []string, conversation *relationtb.ConversationModel, filedMap map[string]interface{}) (err error) {
cache := c.cache.NewCache()
if err := c.tx.Transaction(func(tx any) error {
conversationTx := c.conversationDB.NewTx(tx)
@@ -91,10 +91,10 @@ func (c *conversationDatabase) SetUsersConversationFiledTx(ctx context.Context,
}
NotUserIDs := utils.DifferenceString(haveUserIDs, userIDs)
log.ZDebug(ctx, "SetUsersConversationFiledTx", "NotUserIDs", NotUserIDs, "haveUserIDs", haveUserIDs, "userIDs", userIDs)
var conversations []*relationTb.ConversationModel
var conversations []*relationtb.ConversationModel
now := time.Now()
for _, v := range NotUserIDs {
temp := new(relationTb.ConversationModel)
temp := new(relationtb.ConversationModel)
if err := utils.CopyStructFields(temp, conversation); err != nil {
return err
}
@@ -124,7 +124,7 @@ func (c *conversationDatabase) UpdateUsersConversationFiled(ctx context.Context,
return c.cache.DelUsersConversation(conversationID, userIDs...).ExecDel(ctx)
}
func (c *conversationDatabase) CreateConversation(ctx context.Context, conversations []*relationTb.ConversationModel) error {
func (c *conversationDatabase) CreateConversation(ctx context.Context, conversations []*relationtb.ConversationModel) error {
if err := c.conversationDB.Create(ctx, conversations); err != nil {
return err
}
@@ -137,7 +137,7 @@ func (c *conversationDatabase) CreateConversation(ctx context.Context, conversat
return cache.DelConversationIDs(userIDs...).DelUserConversationIDsHash(userIDs...).ExecDel(ctx)
}
func (c *conversationDatabase) SyncPeerUserPrivateConversationTx(ctx context.Context, conversations []*relationTb.ConversationModel) error {
func (c *conversationDatabase) SyncPeerUserPrivateConversationTx(ctx context.Context, conversations []*relationtb.ConversationModel) error {
cache := c.cache.NewCache()
if err := c.tx.Transaction(func(tx any) error {
conversationTx := c.conversationDB.NewTx(tx)
@@ -161,7 +161,7 @@ func (c *conversationDatabase) SyncPeerUserPrivateConversationTx(ctx context.Con
newConversation.UserID = userID
newConversation.ConversationID = conversation.ConversationID
newConversation.IsPrivateChat = conversation.IsPrivateChat
if err := conversationTx.Create(ctx, []*relationTb.ConversationModel{&newConversation}); err != nil {
if err := conversationTx.Create(ctx, []*relationtb.ConversationModel{&newConversation}); err != nil {
return err
}
cache = cache.DelConversationIDs(ownerUserID).DelUserConversationIDsHash(ownerUserID)
@@ -175,19 +175,19 @@ func (c *conversationDatabase) SyncPeerUserPrivateConversationTx(ctx context.Con
return cache.ExecDel(ctx)
}
func (c *conversationDatabase) FindConversations(ctx context.Context, ownerUserID string, conversationIDs []string) ([]*relationTb.ConversationModel, error) {
func (c *conversationDatabase) FindConversations(ctx context.Context, ownerUserID string, conversationIDs []string) ([]*relationtb.ConversationModel, error) {
return c.cache.GetConversations(ctx, ownerUserID, conversationIDs)
}
func (c *conversationDatabase) GetConversation(ctx context.Context, ownerUserID string, conversationID string) (*relationTb.ConversationModel, error) {
func (c *conversationDatabase) GetConversation(ctx context.Context, ownerUserID string, conversationID string) (*relationtb.ConversationModel, error) {
return c.cache.GetConversation(ctx, ownerUserID, conversationID)
}
func (c *conversationDatabase) GetUserAllConversation(ctx context.Context, ownerUserID string) ([]*relationTb.ConversationModel, error) {
func (c *conversationDatabase) GetUserAllConversation(ctx context.Context, ownerUserID string) ([]*relationtb.ConversationModel, error) {
return c.cache.GetUserAllConversations(ctx, ownerUserID)
}
func (c *conversationDatabase) SetUserConversations(ctx context.Context, ownerUserID string, conversations []*relationTb.ConversationModel) error {
func (c *conversationDatabase) SetUserConversations(ctx context.Context, ownerUserID string, conversations []*relationtb.ConversationModel) error {
cache := c.cache.NewCache()
if err := c.tx.Transaction(func(tx any) error {
var conversationIDs []string
@@ -213,7 +213,7 @@ func (c *conversationDatabase) SetUserConversations(ctx context.Context, ownerUs
existConversationIDs = append(existConversationIDs, conversation.ConversationID)
}
var notExistConversations []*relationTb.ConversationModel
var notExistConversations []*relationtb.ConversationModel
for _, conversation := range conversations {
if !utils.IsContain(conversation.ConversationID, existConversationIDs) {
notExistConversations = append(notExistConversations, conversation)
@@ -246,9 +246,9 @@ func (c *conversationDatabase) CreateGroupChatConversation(ctx context.Context,
return err
}
notExistUserIDs := utils.DifferenceString(userIDs, existConversationUserIDs)
var conversations []*relationTb.ConversationModel
var conversations []*relationtb.ConversationModel
for _, v := range notExistUserIDs {
conversation := relationTb.ConversationModel{ConversationType: constant.SuperGroupChatType, GroupID: groupID, OwnerUserID: v, ConversationID: conversationID}
conversation := relationtb.ConversationModel{ConversationType: constant.SuperGroupChatType, GroupID: groupID, OwnerUserID: v, ConversationID: conversationID}
conversations = append(conversations, &conversation)
cache = cache.DelConversations(v, conversationID)
}
@@ -289,10 +289,10 @@ func (c *conversationDatabase) GetUserAllHasReadSeqs(ctx context.Context, ownerU
return c.cache.GetUserAllHasReadSeqs(ctx, ownerUserID)
}
func (c *conversationDatabase) GetConversationsByConversationID(ctx context.Context, conversationIDs []string) ([]*relationTb.ConversationModel, error) {
func (c *conversationDatabase) GetConversationsByConversationID(ctx context.Context, conversationIDs []string) ([]*relationtb.ConversationModel, error) {
return c.conversationDB.GetConversationsByConversationID(ctx, conversationIDs)
}
func (c *conversationDatabase) GetConversationIDsNeedDestruct(ctx context.Context) ([]*relationTb.ConversationModel, error) {
func (c *conversationDatabase) GetConversationIDsNeedDestruct(ctx context.Context) ([]*relationtb.ConversationModel, error) {
return c.conversationDB.GetConversationIDsNeedDestruct(ctx)
}
+55 -55
View File
@@ -30,22 +30,22 @@ import (
"github.com/OpenIMSDK/Open-IM-Server/pkg/common/db/cache"
"github.com/OpenIMSDK/Open-IM-Server/pkg/common/db/relation"
relationTb "github.com/OpenIMSDK/Open-IM-Server/pkg/common/db/table/relation"
unRelationTb "github.com/OpenIMSDK/Open-IM-Server/pkg/common/db/table/unrelation"
relationtb "github.com/OpenIMSDK/Open-IM-Server/pkg/common/db/table/relation"
unrelationtb "github.com/OpenIMSDK/Open-IM-Server/pkg/common/db/table/unrelation"
"github.com/OpenIMSDK/Open-IM-Server/pkg/common/db/unrelation"
)
type GroupDatabase interface {
// Group
CreateGroup(ctx context.Context, groups []*relationTb.GroupModel, groupMembers []*relationTb.GroupMemberModel) error
TakeGroup(ctx context.Context, groupID string) (group *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)
CreateGroup(ctx context.Context, groups []*relationtb.GroupModel, groupMembers []*relationtb.GroupMemberModel) error
TakeGroup(ctx context.Context, groupID string) (group *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)
SearchGroup(
ctx context.Context,
keyword string,
pageNumber, showNumber int32,
) (uint32, []*relationTb.GroupModel, error)
) (uint32, []*relationtb.GroupModel, error)
UpdateGroup(ctx context.Context, groupID string, data map[string]any) error
DismissGroup(ctx context.Context, groupID string, deleteMember bool) error // 解散群,并删除群成员
GetGroupIDsByGroupType(ctx context.Context, groupType int) (groupIDs []string, err error)
@@ -54,14 +54,14 @@ type GroupDatabase interface {
ctx context.Context,
groupID string,
userID string,
) (groupMember *relationTb.GroupMemberModel, err error)
TakeGroupOwner(ctx context.Context, groupID string) (*relationTb.GroupMemberModel, error)
) (groupMember *relationtb.GroupMemberModel, err error)
TakeGroupOwner(ctx context.Context, groupID string) (*relationtb.GroupMemberModel, error)
FindGroupMember(
ctx context.Context,
groupIDs []string,
userIDs []string,
roleLevels []int32,
) ([]*relationTb.GroupMemberModel, error)
) ([]*relationtb.GroupMemberModel, error)
FindGroupMemberUserID(ctx context.Context, groupID string) ([]string, error)
FindGroupMemberNum(ctx context.Context, groupID string) (uint32, error)
FindUserManagedGroupID(ctx context.Context, userID string) (groupIDs []string, err error)
@@ -69,19 +69,19 @@ type GroupDatabase interface {
ctx context.Context,
groupIDs []string,
pageNumber, showNumber int32,
) (uint32, []*relationTb.GroupRequestModel, error)
) (uint32, []*relationtb.GroupRequestModel, error)
// PageGroupMember(ctx context.Context, groupIDs []string, userIDs []string, roleLevels []int32, pageNumber,
// showNumber int32) (uint32, []*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)
) (total uint32, totalGroupMembers []*relationtb.GroupMemberModel, err error)
PageGetGroupMember(
ctx context.Context,
groupID string,
pageNumber, showNumber int32,
) (total uint32, totalGroupMembers []*relationTb.GroupMemberModel, err error)
) (total uint32, totalGroupMembers []*relationtb.GroupMemberModel, err error)
SearchGroupMember(
ctx context.Context,
keyword string,
@@ -89,17 +89,17 @@ type GroupDatabase interface {
userIDs []string,
roleLevels []int32,
pageNumber, showNumber int32,
) (uint32, []*relationTb.GroupMemberModel, error)
) (uint32, []*relationtb.GroupMemberModel, error)
HandlerGroupRequest(
ctx context.Context,
groupID string,
userID string,
handledMsg string,
handleResult int32,
member *relationTb.GroupMemberModel,
member *relationtb.GroupMemberModel,
) 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)
TransferGroupOwner(
ctx context.Context,
@@ -108,18 +108,18 @@ type GroupDatabase interface {
roleLevel int32,
) 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
CreateGroupRequest(ctx context.Context, requests []*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)
CreateGroupRequest(ctx context.Context, requests []*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)
PageGroupRequestUser(
ctx context.Context,
userID string,
pageNumber, showNumber int32,
) (uint32, []*relationTb.GroupRequestModel, error)
) (uint32, []*relationtb.GroupRequestModel, error)
// 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)
CreateSuperGroup(ctx context.Context, groupID string, initMemberIDList []string) error
DeleteSuperGroup(ctx context.Context, groupID string) error
@@ -133,12 +133,12 @@ type GroupDatabase interface {
}
func NewGroupDatabase(
group relationTb.GroupModelInterface,
member relationTb.GroupMemberModelInterface,
request relationTb.GroupRequestModelInterface,
group relationtb.GroupModelInterface,
member relationtb.GroupMemberModelInterface,
request relationtb.GroupRequestModelInterface,
tx tx.Tx,
ctxTx tx.CtxTx,
superGroup unRelationTb.SuperGroupModelInterface,
superGroup unrelationtb.SuperGroupModelInterface,
cache cache.GroupCache,
) GroupDatabase {
database := &groupDatabase{
@@ -177,13 +177,13 @@ func InitGroupDatabase(db *gorm.DB, rdb redis.UniversalClient, database *mongo.D
}
type groupDatabase struct {
groupDB relationTb.GroupModelInterface
groupMemberDB relationTb.GroupMemberModelInterface
groupRequestDB relationTb.GroupRequestModelInterface
groupDB relationtb.GroupModelInterface
groupMemberDB relationtb.GroupMemberModelInterface
groupRequestDB relationtb.GroupRequestModelInterface
tx tx.Tx
ctxTx tx.CtxTx
cache cache.GroupCache
mongoDB unRelationTb.SuperGroupModelInterface
mongoDB unrelationtb.SuperGroupModelInterface
}
func (g *groupDatabase) GetGroupIDsByGroupType(ctx context.Context, groupType int) (groupIDs []string, err error) {
@@ -204,8 +204,8 @@ func (g *groupDatabase) FindGroupMemberNum(ctx context.Context, groupID string)
func (g *groupDatabase) CreateGroup(
ctx context.Context,
groups []*relationTb.GroupModel,
groupMembers []*relationTb.GroupMemberModel,
groups []*relationtb.GroupModel,
groupMembers []*relationtb.GroupMemberModel,
) error {
cache := g.cache.NewCache()
if err := g.tx.Transaction(func(tx any) error {
@@ -219,7 +219,7 @@ func (g *groupDatabase) CreateGroup(
return err
}
}
createGroupIDs := utils.DistinctAnyGetComparable(groups, func(group *relationTb.GroupModel) string {
createGroupIDs := utils.DistinctAnyGetComparable(groups, func(group *relationtb.GroupModel) string {
return group.GroupID
})
m := make(map[string]struct{})
@@ -239,11 +239,11 @@ func (g *groupDatabase) CreateGroup(
return cache.ExecDel(ctx)
}
func (g *groupDatabase) TakeGroup(ctx context.Context, groupID string) (group *relationTb.GroupModel, err error) {
func (g *groupDatabase) TakeGroup(ctx context.Context, groupID string) (group *relationtb.GroupModel, err error) {
return g.cache.GetGroupInfo(ctx, groupID)
}
func (g *groupDatabase) FindGroup(ctx context.Context, groupIDs []string) (groups []*relationTb.GroupModel, err error) {
func (g *groupDatabase) FindGroup(ctx context.Context, groupIDs []string) (groups []*relationtb.GroupModel, err error) {
return g.cache.GetGroupsInfo(ctx, groupIDs)
}
@@ -251,7 +251,7 @@ func (g *groupDatabase) SearchGroup(
ctx context.Context,
keyword string,
pageNumber, showNumber int32,
) (uint32, []*relationTb.GroupModel, error) {
) (uint32, []*relationtb.GroupModel, error) {
return g.groupDB.Search(ctx, keyword, pageNumber, showNumber)
}
@@ -290,11 +290,11 @@ func (g *groupDatabase) TakeGroupMember(
ctx context.Context,
groupID string,
userID string,
) (groupMember *relationTb.GroupMemberModel, err error) {
) (groupMember *relationtb.GroupMemberModel, err error) {
return g.cache.GetGroupMemberInfo(ctx, groupID, userID)
}
func (g *groupDatabase) TakeGroupOwner(ctx context.Context, groupID string) (*relationTb.GroupMemberModel, error) {
func (g *groupDatabase) TakeGroupOwner(ctx context.Context, groupID string) (*relationtb.GroupMemberModel, error) {
return g.groupMemberDB.TakeOwner(ctx, groupID) // todo cache group owner
}
@@ -306,7 +306,7 @@ func (g *groupDatabase) PageGroupRequest(
ctx context.Context,
groupIDs []string,
pageNumber, showNumber int32,
) (uint32, []*relationTb.GroupRequestModel, error) {
) (uint32, []*relationtb.GroupRequestModel, error) {
return g.groupRequestDB.PageGroup(ctx, groupIDs, pageNumber, showNumber)
}
@@ -315,7 +315,7 @@ func (g *groupDatabase) FindGroupMember(
groupIDs []string,
userIDs []string,
roleLevels []int32,
) (totalGroupMembers []*relationTb.GroupMemberModel, err error) {
) (totalGroupMembers []*relationtb.GroupMemberModel, err error) {
if len(roleLevels) == 0 {
for _, groupID := range groupIDs {
groupMembers, err := g.cache.GetGroupMembersInfo(ctx, groupID, userIDs)
@@ -333,7 +333,7 @@ func (g *groupDatabase) PageGetJoinGroup(
ctx context.Context,
userID string,
pageNumber, showNumber int32,
) (total uint32, totalGroupMembers []*relationTb.GroupMemberModel, err error) {
) (total uint32, totalGroupMembers []*relationtb.GroupMemberModel, err error) {
groupIDs, err := g.cache.GetJoinedGroupIDs(ctx, userID)
if err != nil {
return 0, nil, err
@@ -352,7 +352,7 @@ func (g *groupDatabase) PageGetGroupMember(
ctx context.Context,
groupID string,
pageNumber, showNumber int32,
) (total uint32, totalGroupMembers []*relationTb.GroupMemberModel, err error) {
) (total uint32, totalGroupMembers []*relationtb.GroupMemberModel, err error) {
groupMemberIDs, err := g.cache.GetGroupMemberIDs(ctx, groupID)
if err != nil {
return 0, nil, err
@@ -375,7 +375,7 @@ func (g *groupDatabase) SearchGroupMember(
userIDs []string,
roleLevels []int32,
pageNumber, showNumber int32,
) (uint32, []*relationTb.GroupMemberModel, error) {
) (uint32, []*relationtb.GroupMemberModel, error) {
return g.groupMemberDB.SearchMember(ctx, keyword, groupIDs, userIDs, roleLevels, pageNumber, showNumber)
}
@@ -385,7 +385,7 @@ func (g *groupDatabase) HandlerGroupRequest(
userID string,
handledMsg string,
handleResult int32,
member *relationTb.GroupMemberModel,
member *relationtb.GroupMemberModel,
) error {
//cache := g.cache.NewCache()
//if err := g.tx.Transaction(func(tx any) error {
@@ -393,7 +393,7 @@ func (g *groupDatabase) HandlerGroupRequest(
// return err
// }
// if member != nil {
// if err := g.groupMemberDB.NewTx(tx).Create(ctx, []*relationTb.GroupMemberModel{member}); err != nil {
// if err := g.groupMemberDB.NewTx(tx).Create(ctx, []*relationtb.GroupMemberModel{member}); err != nil {
// return err
// }
// cache = cache.DelGroupMembersHash(groupID).DelGroupMemberIDs(groupID).DelGroupsMemberNum(groupID).DelJoinedGroupID(member.UserID)
@@ -409,7 +409,7 @@ func (g *groupDatabase) HandlerGroupRequest(
return err
}
if member != nil {
if err := g.groupMemberDB.NewTx(tx).Create(ctx, []*relationTb.GroupMemberModel{member}); err != nil {
if err := g.groupMemberDB.NewTx(tx).Create(ctx, []*relationtb.GroupMemberModel{member}); err != nil {
return err
}
if err := g.cache.NewCache().DelGroupMembersHash(groupID).DelGroupMembersInfo(groupID, member.UserID).DelGroupMemberIDs(groupID).DelGroupsMemberNum(groupID).DelJoinedGroupID(member.UserID).ExecDel(ctx); err != nil {
@@ -435,7 +435,7 @@ func (g *groupDatabase) DeleteGroupMember(ctx context.Context, groupID string, u
func (g *groupDatabase) MapGroupMemberUserID(
ctx context.Context,
groupIDs []string,
) (map[string]*relationTb.GroupSimpleUserID, error) {
) (map[string]*relationtb.GroupSimpleUserID, error) {
return g.cache.GetGroupMemberHashMap(ctx, groupIDs)
}
@@ -491,7 +491,7 @@ func (g *groupDatabase) UpdateGroupMember(
return g.cache.DelGroupMembersInfo(groupID, userID).ExecDel(ctx)
}
func (g *groupDatabase) UpdateGroupMembers(ctx context.Context, data []*relationTb.BatchUpdateGroupMember) error {
func (g *groupDatabase) UpdateGroupMembers(ctx context.Context, data []*relationtb.BatchUpdateGroupMember) error {
cache := g.cache.NewCache()
if err := g.tx.Transaction(func(tx any) error {
for _, item := range data {
@@ -507,7 +507,7 @@ func (g *groupDatabase) UpdateGroupMembers(ctx context.Context, data []*relation
return cache.ExecDel(ctx)
}
func (g *groupDatabase) CreateGroupRequest(ctx context.Context, requests []*relationTb.GroupRequestModel) error {
func (g *groupDatabase) CreateGroupRequest(ctx context.Context, requests []*relationtb.GroupRequestModel) error {
return g.tx.Transaction(func(tx any) error {
db := g.groupRequestDB.NewTx(tx)
for _, request := range requests {
@@ -523,7 +523,7 @@ func (g *groupDatabase) TakeGroupRequest(
ctx context.Context,
groupID string,
userID string,
) (*relationTb.GroupRequestModel, error) {
) (*relationtb.GroupRequestModel, error) {
return g.groupRequestDB.Take(ctx, groupID, userID)
}
@@ -531,14 +531,14 @@ func (g *groupDatabase) PageGroupRequestUser(
ctx context.Context,
userID string,
pageNumber, showNumber int32,
) (uint32, []*relationTb.GroupRequestModel, error) {
) (uint32, []*relationtb.GroupRequestModel, error) {
return g.groupRequestDB.Page(ctx, userID, pageNumber, showNumber)
}
func (g *groupDatabase) FindSuperGroup(
ctx context.Context,
groupIDs []string,
) (models []*unRelationTb.SuperGroupModel, err error) {
) (models []*unrelationtb.SuperGroupModel, err error) {
return g.cache.GetSuperGroupMemberIDs(ctx, groupIDs...)
}
@@ -596,10 +596,10 @@ func (g *groupDatabase) CountRangeEverydayTotal(ctx context.Context, start time.
return g.groupDB.CountRangeEverydayTotal(ctx, start, end)
}
func (g *groupDatabase) FindGroupRequests(ctx context.Context, groupID string, userIDs []string) (int64, []*relationTb.GroupRequestModel, error) {
func (g *groupDatabase) FindGroupRequests(ctx context.Context, groupID string, userIDs []string) (int64, []*relationtb.GroupRequestModel, error) {
return g.groupRequestDB.FindGroupRequests(ctx, groupID, userIDs)
}
func (g *groupDatabase) FindNotDismissedGroup(ctx context.Context, groupIDs []string) (groups []*relationTb.GroupModel, err error) {
func (g *groupDatabase) FindNotDismissedGroup(ctx context.Context, groupIDs []string) (groups []*relationtb.GroupModel, err error) {
return g.groupDB.FindNotDismissedGroup(ctx, groupIDs)
}
+30 -30
View File
@@ -27,14 +27,14 @@ import (
"github.com/OpenIMSDK/Open-IM-Server/pkg/common/config"
"github.com/OpenIMSDK/Open-IM-Server/pkg/common/convert"
"github.com/OpenIMSDK/Open-IM-Server/pkg/common/db/cache"
unRelationTb "github.com/OpenIMSDK/Open-IM-Server/pkg/common/db/table/unrelation"
unrelationtb "github.com/OpenIMSDK/Open-IM-Server/pkg/common/db/table/unrelation"
"github.com/OpenIMSDK/Open-IM-Server/pkg/common/db/unrelation"
"github.com/OpenIMSDK/Open-IM-Server/pkg/common/kafka"
"github.com/OpenIMSDK/Open-IM-Server/pkg/common/prome"
"go.mongodb.org/mongo-driver/mongo"
pbMsg "github.com/OpenIMSDK/protocol/msg"
pbmsg "github.com/OpenIMSDK/protocol/msg"
"github.com/OpenIMSDK/protocol/sdkws"
"github.com/OpenIMSDK/tools/utils"
)
@@ -48,7 +48,7 @@ type CommonMsgDatabase interface {
// 批量插入消息
BatchInsertChat2DB(ctx context.Context, conversationID string, msgs []*sdkws.MsgData, currentMaxSeq int64) error
// 撤回消息
RevokeMsg(ctx context.Context, conversationID string, seq int64, revoke *unRelationTb.RevokeModel) error
RevokeMsg(ctx context.Context, conversationID string, seq int64, revoke *unrelationtb.RevokeModel) error
// mark as read
MarkSingleChatMsgsAsRead(ctx context.Context, userID string, conversationID string, seqs []int64) error
// 刪除redis中消息缓存
@@ -93,7 +93,7 @@ type CommonMsgDatabase interface {
GetConversationMinMaxSeqInMongoAndCache(ctx context.Context, conversationID string) (minSeqMongo, maxSeqMongo, minSeqCache, maxSeqCache int64, err error)
SetSendMsgStatus(ctx context.Context, id string, status int32) error
GetSendMsgStatus(ctx context.Context, id string) (int32, error)
SearchMessage(ctx context.Context, req *pbMsg.SearchMessageReq) (total int32, msgData []*sdkws.MsgData, err error)
SearchMessage(ctx context.Context, req *pbmsg.SearchMessageReq) (total int32, msgData []*sdkws.MsgData, err error)
// to mq
MsgToMQ(ctx context.Context, key string, msg2mq *sdkws.MsgData) error
@@ -109,7 +109,7 @@ type CommonMsgDatabase interface {
ase bool,
pageNumber int32,
showNumber int32,
) (msgCount int64, userCount int64, users []*unRelationTb.UserCount, dateCount map[string]int64, err error)
) (msgCount int64, userCount int64, users []*unrelationtb.UserCount, dateCount map[string]int64, err error)
RangeGroupSendCount(
ctx context.Context,
start time.Time,
@@ -117,11 +117,11 @@ type CommonMsgDatabase interface {
ase bool,
pageNumber int32,
showNumber int32,
) (msgCount int64, userCount int64, groups []*unRelationTb.GroupCount, dateCount map[string]int64, err error)
) (msgCount int64, userCount int64, groups []*unrelationtb.GroupCount, dateCount map[string]int64, err error)
ConvertMsgsDocLen(ctx context.Context, conversationIDs []string)
}
func NewCommonMsgDatabase(msgDocModel unRelationTb.MsgDocModelInterface, cacheModel cache.MsgModel) CommonMsgDatabase {
func NewCommonMsgDatabase(msgDocModel unrelationtb.MsgDocModelInterface, cacheModel cache.MsgModel) CommonMsgDatabase {
return &commonMsgDatabase{
msgDocDatabase: msgDocModel,
cache: cacheModel,
@@ -139,8 +139,8 @@ func InitCommonMsgDatabase(rdb redis.UniversalClient, database *mongo.Database)
}
type commonMsgDatabase struct {
msgDocDatabase unRelationTb.MsgDocModelInterface
msg unRelationTb.MsgDocModel
msgDocDatabase unrelationtb.MsgDocModelInterface
msg unrelationtb.MsgDocModel
cache cache.MsgModel
producer *kafka.Producer
producerToMongo *kafka.Producer
@@ -155,14 +155,14 @@ func (db *commonMsgDatabase) MsgToMQ(ctx context.Context, key string, msg2mq *sd
func (db *commonMsgDatabase) MsgToModifyMQ(ctx context.Context, key, conversationID string, messages []*sdkws.MsgData) error {
if len(messages) > 0 {
_, _, err := db.producerToModify.SendMessage(ctx, key, &pbMsg.MsgDataToModifyByMQ{ConversationID: conversationID, Messages: messages})
_, _, err := db.producerToModify.SendMessage(ctx, key, &pbmsg.MsgDataToModifyByMQ{ConversationID: conversationID, Messages: messages})
return err
}
return nil
}
func (db *commonMsgDatabase) MsgToPushMQ(ctx context.Context, key, conversationID string, msg2mq *sdkws.MsgData) (int32, int64, error) {
partition, offset, err := db.producerToPush.SendMessage(ctx, key, &pbMsg.PushMsgDataToMQ{MsgData: msg2mq, ConversationID: conversationID})
partition, offset, err := db.producerToPush.SendMessage(ctx, key, &pbmsg.PushMsgDataToMQ{MsgData: msg2mq, ConversationID: conversationID})
if err != nil {
log.ZError(ctx, "MsgToPushMQ", err, "key", key, "msg2mq", msg2mq)
return 0, 0, err
@@ -172,7 +172,7 @@ func (db *commonMsgDatabase) MsgToPushMQ(ctx context.Context, key, conversationI
func (db *commonMsgDatabase) MsgToMongoMQ(ctx context.Context, key, conversationID string, messages []*sdkws.MsgData, lastSeq int64) error {
if len(messages) > 0 {
_, _, err := db.producerToMongo.SendMessage(ctx, key, &pbMsg.MsgDataToMongoByMQ{LastSeq: lastSeq, ConversationID: conversationID, MsgData: messages})
_, _, err := db.producerToMongo.SendMessage(ctx, key, &pbmsg.MsgDataToMongoByMQ{LastSeq: lastSeq, ConversationID: conversationID, MsgData: messages})
return err
}
return nil
@@ -188,13 +188,13 @@ func (db *commonMsgDatabase) BatchInsertBlock(ctx context.Context, conversationI
var ok bool
switch key {
case updateKeyMsg:
var msg *unRelationTb.MsgDataModel
msg, ok = field.(*unRelationTb.MsgDataModel)
var msg *unrelationtb.MsgDataModel
msg, ok = field.(*unrelationtb.MsgDataModel)
if msg != nil && msg.Seq != firstSeq+int64(i) {
return errs.ErrInternalServer.Wrap("seq is invalid")
}
case updateKeyRevoke:
_, ok = field.(*unRelationTb.RevokeModel)
_, ok = field.(*unrelationtb.RevokeModel)
default:
return errs.ErrInternalServer.Wrap("key is invalid")
}
@@ -234,9 +234,9 @@ func (db *commonMsgDatabase) BatchInsertBlock(ctx context.Context, conversationI
continue // 匹配到了,继续下一个(不一定修改)
}
}
doc := unRelationTb.MsgDocModel{
doc := unrelationtb.MsgDocModel{
DocID: db.msg.GetDocID(conversationID, seq),
Msg: make([]*unRelationTb.MsgInfoModel, num),
Msg: make([]*unrelationtb.MsgInfoModel, num),
}
var insert int // 插入的数量
for j := i; j < len(fields); j++ {
@@ -247,18 +247,18 @@ func (db *commonMsgDatabase) BatchInsertBlock(ctx context.Context, conversationI
insert++
switch key {
case updateKeyMsg:
doc.Msg[db.msg.GetMsgIndex(seq)] = &unRelationTb.MsgInfoModel{
Msg: fields[j].(*unRelationTb.MsgDataModel),
doc.Msg[db.msg.GetMsgIndex(seq)] = &unrelationtb.MsgInfoModel{
Msg: fields[j].(*unrelationtb.MsgDataModel),
}
case updateKeyRevoke:
doc.Msg[db.msg.GetMsgIndex(seq)] = &unRelationTb.MsgInfoModel{
Revoke: fields[j].(*unRelationTb.RevokeModel),
doc.Msg[db.msg.GetMsgIndex(seq)] = &unrelationtb.MsgInfoModel{
Revoke: fields[j].(*unrelationtb.RevokeModel),
}
}
}
for i, model := range doc.Msg {
if model == nil {
model = &unRelationTb.MsgInfoModel{}
model = &unrelationtb.MsgInfoModel{}
doc.Msg[i] = model
}
if model.DelList == nil {
@@ -288,9 +288,9 @@ func (db *commonMsgDatabase) BatchInsertChat2DB(ctx context.Context, conversatio
if msg == nil {
continue
}
var offlinePushModel *unRelationTb.OfflinePushModel
var offlinePushModel *unrelationtb.OfflinePushModel
if msg.OfflinePushInfo != nil {
offlinePushModel = &unRelationTb.OfflinePushModel{
offlinePushModel = &unrelationtb.OfflinePushModel{
Title: msg.OfflinePushInfo.Title,
Desc: msg.OfflinePushInfo.Desc,
Ex: msg.OfflinePushInfo.Ex,
@@ -298,7 +298,7 @@ func (db *commonMsgDatabase) BatchInsertChat2DB(ctx context.Context, conversatio
IOSBadgeCount: msg.OfflinePushInfo.IOSBadgeCount,
}
}
msgs[i] = &unRelationTb.MsgDataModel{
msgs[i] = &unrelationtb.MsgDataModel{
SendID: msg.SendID,
RecvID: msg.RecvID,
GroupID: msg.GroupID,
@@ -325,7 +325,7 @@ func (db *commonMsgDatabase) BatchInsertChat2DB(ctx context.Context, conversatio
return db.BatchInsertBlock(ctx, conversationID, msgs, updateKeyMsg, msgList[0].Seq)
}
func (db *commonMsgDatabase) RevokeMsg(ctx context.Context, conversationID string, seq int64, revoke *unRelationTb.RevokeModel) error {
func (db *commonMsgDatabase) RevokeMsg(ctx context.Context, conversationID string, seq int64, revoke *unrelationtb.RevokeModel) error {
return db.BatchInsertBlock(ctx, conversationID, []any{revoke}, updateKeyRevoke, seq)
}
@@ -413,7 +413,7 @@ func (db *commonMsgDatabase) getMsgBySeqs(ctx context.Context, userID, conversat
return totalMsgs, nil
}
func (db *commonMsgDatabase) findMsgInfoBySeq(ctx context.Context, userID, docID string, seqs []int64) (totalMsgs []*unRelationTb.MsgInfoModel, err error) {
func (db *commonMsgDatabase) findMsgInfoBySeq(ctx context.Context, userID, docID string, seqs []int64) (totalMsgs []*unrelationtb.MsgInfoModel, err error) {
msgs, err := db.msgDocDatabase.GetMsgBySeqIndexIn1Doc(ctx, userID, docID, seqs)
for _, msg := range msgs {
if msg.IsRead {
@@ -927,7 +927,7 @@ func (db *commonMsgDatabase) RangeUserSendCount(
ase bool,
pageNumber int32,
showNumber int32,
) (msgCount int64, userCount int64, users []*unRelationTb.UserCount, dateCount map[string]int64, err error) {
) (msgCount int64, userCount int64, users []*unrelationtb.UserCount, dateCount map[string]int64, err error) {
return db.msgDocDatabase.RangeUserSendCount(ctx, start, end, group, ase, pageNumber, showNumber)
}
@@ -938,11 +938,11 @@ func (db *commonMsgDatabase) RangeGroupSendCount(
ase bool,
pageNumber int32,
showNumber int32,
) (msgCount int64, userCount int64, groups []*unRelationTb.GroupCount, dateCount map[string]int64, err error) {
) (msgCount int64, userCount int64, groups []*unrelationtb.GroupCount, dateCount map[string]int64, err error) {
return db.msgDocDatabase.RangeGroupSendCount(ctx, start, end, ase, pageNumber, showNumber)
}
func (db *commonMsgDatabase) SearchMessage(ctx context.Context, req *pbMsg.SearchMessageReq) (total int32, msgData []*sdkws.MsgData, err error) {
func (db *commonMsgDatabase) SearchMessage(ctx context.Context, req *pbmsg.SearchMessageReq) (total int32, msgData []*sdkws.MsgData, err error) {
var totalMsgs []*sdkws.MsgData
total, msgs, err := db.msgDocDatabase.SearchMessage(ctx, req)
if err != nil {
+5 -5
View File
@@ -28,7 +28,7 @@ import (
"go.mongodb.org/mongo-driver/bson"
"github.com/OpenIMSDK/Open-IM-Server/pkg/common/config"
unRelationTb "github.com/OpenIMSDK/Open-IM-Server/pkg/common/db/table/unrelation"
unrelationtb "github.com/OpenIMSDK/Open-IM-Server/pkg/common/db/table/unrelation"
"github.com/OpenIMSDK/Open-IM-Server/pkg/common/db/unrelation"
)
@@ -173,10 +173,10 @@ func Test_Insert(t *testing.T) {
var arr []any
for i := 0; i < 345; i++ {
if i%2 == 0 {
arr = append(arr, (*unRelationTb.MsgDataModel)(nil))
arr = append(arr, (*unrelationtb.MsgDataModel)(nil))
continue
}
arr = append(arr, &unRelationTb.MsgDataModel{
arr = append(arr, &unrelationtb.MsgDataModel{
Seq: int64(i),
Content: fmt.Sprintf("test-%d", i),
})
@@ -191,7 +191,7 @@ func Test_Revoke(t *testing.T) {
ctx := context.Background()
var arr []any
for i := 0; i < 456; i++ {
arr = append(arr, &unRelationTb.RevokeModel{
arr = append(arr, &unrelationtb.RevokeModel{
UserID: "uid_" + strconv.Itoa(i),
Nickname: "uname_" + strconv.Itoa(i),
Time: time.Now().UnixMilli(),
@@ -254,7 +254,7 @@ func Test_FindBySeq(t *testing.T) {
//
// c := mongo.GetClient().Database("openIM").Collection("msg")
//
// var o unRelationTb.MsgDocModel
// var o unrelationtb.MsgDocModel
//
// err = c.FindOne(context.Background(), bson.M{"doc_id": "test:0"}).Decode(&o)
// if err != nil {
+3 -3
View File
@@ -20,7 +20,7 @@ import (
"github.com/OpenIMSDK/protocol/user"
unRelationTb "github.com/OpenIMSDK/Open-IM-Server/pkg/common/db/table/unrelation"
unrelationtb "github.com/OpenIMSDK/Open-IM-Server/pkg/common/db/table/unrelation"
"github.com/OpenIMSDK/tools/errs"
"github.com/OpenIMSDK/tools/tx"
@@ -71,10 +71,10 @@ type userDatabase struct {
userDB relation.UserModelInterface
cache cache.UserCache
tx tx.Tx
mongoDB unRelationTb.UserModelInterface
mongoDB unrelationtb.UserModelInterface
}
func NewUserDatabase(userDB relation.UserModelInterface, cache cache.UserCache, tx tx.Tx, mongoDB unRelationTb.UserModelInterface) UserDatabase {
func NewUserDatabase(userDB relation.UserModelInterface, cache cache.UserCache, tx tx.Tx, mongoDB unrelationtb.UserModelInterface) UserDatabase {
return &userDatabase{userDB: userDB, cache: cache, tx: tx, mongoDB: mongoDB}
}
+2 -2
View File
@@ -21,7 +21,7 @@ import (
"gorm.io/gorm"
"github.com/OpenIMSDK/protocol/constant"
pbMsg "github.com/OpenIMSDK/protocol/msg"
pbmsg "github.com/OpenIMSDK/protocol/msg"
sdkws "github.com/OpenIMSDK/protocol/sdkws"
"github.com/OpenIMSDK/tools/utils"
@@ -36,7 +36,7 @@ func NewChatLogGorm(db *gorm.DB) relation.ChatLogModelInterface {
return &ChatLogGorm{NewMetaDB(db, &relation.ChatLogModel{})}
}
func (c *ChatLogGorm) Create(msg *pbMsg.MsgDataToMQ) error {
func (c *ChatLogGorm) Create(msg *pbmsg.MsgDataToMQ) error {
chatLog := new(relation.ChatLogModel)
copier.Copy(chatLog, msg.MsgData)
switch msg.MsgData.SessionType {
+3 -3
View File
@@ -18,7 +18,7 @@ import (
"fmt"
"time"
mysqlDriver "github.com/go-sql-driver/mysql"
mysqldriver "github.com/go-sql-driver/mysql"
"gorm.io/driver/mysql"
"github.com/OpenIMSDK/tools/errs"
@@ -94,7 +94,7 @@ func connectToDatabase(dsn string, maxRetry int) (*gorm.DB, error) {
if err == nil {
return db, nil
}
if mysqlErr, ok := err.(*mysqlDriver.MySQLError); ok && mysqlErr.Number == 1045 {
if mysqlErr, ok := err.(*mysqldriver.MySQLError); ok && mysqlErr.Number == 1045 {
return nil, err
}
time.Sleep(time.Duration(1) * time.Second)
@@ -117,7 +117,7 @@ func replaceDuplicateKey(err error) errs.CodeError {
}
func IsMysqlDuplicateKey(err error) bool {
if mysqlErr, ok := err.(*mysqlDriver.MySQLError); ok {
if mysqlErr, ok := err.(*mysqldriver.MySQLError); ok {
return mysqlErr.Number == 1062
}
return false
+2 -2
View File
@@ -17,7 +17,7 @@ package relation
import (
"time"
pbMsg "github.com/OpenIMSDK/protocol/msg"
pbmsg "github.com/OpenIMSDK/protocol/msg"
)
const (
@@ -47,5 +47,5 @@ func (ChatLogModel) TableName() string {
}
type ChatLogModelInterface interface {
Create(msg *pbMsg.MsgDataToMQ) error
Create(msg *pbmsg.MsgDataToMQ) error
}
+2 -2
View File
@@ -21,7 +21,7 @@ import (
"io"
"io/ioutil"
"net/http"
urlLib "net/url"
urllib "net/url"
"time"
"github.com/OpenIMSDK/protocol/constant"
@@ -110,7 +110,7 @@ func callBackPostReturn(
callbackConfig config.CallBackConfig,
) error {
defer log.ZDebug(ctx, "callback", "url", url, "command", command, "input", input, "callbackConfig", callbackConfig)
v := urlLib.Values{}
v := urllib.Values{}
v.Set(constant.CallbackCommand, command)
url = url + "?" + v.Encode()
b, err := Post(ctx, url, nil, input, callbackConfig.CallbackTimeOut)
+3 -3
View File
@@ -22,7 +22,7 @@ import (
"github.com/OpenIMSDK/Open-IM-Server/pkg/common/config"
grpcPrometheus "github.com/grpc-ecosystem/go-grpc-prometheus"
grpcprometheus "github.com/grpc-ecosystem/go-grpc-prometheus"
"google.golang.org/grpc"
"google.golang.org/grpc/credentials/insecure"
@@ -79,9 +79,9 @@ func Start(
prome.NewGrpcRequestCounter()
prome.NewGrpcRequestFailedCounter()
prome.NewGrpcRequestSuccessCounter()
unaryInterceptor := mw.InterceptChain(grpcPrometheus.UnaryServerInterceptor, mw.RpcServerInterceptor)
unaryInterceptor := mw.InterceptChain(grpcprometheus.UnaryServerInterceptor, mw.RpcServerInterceptor)
options = append(options, []grpc.ServerOption{
grpc.StreamInterceptor(grpcPrometheus.StreamServerInterceptor),
grpc.StreamInterceptor(grpcprometheus.StreamServerInterceptor),
grpc.UnaryInterceptor(unaryInterceptor),
}...)
} else {
+16 -16
View File
@@ -20,7 +20,7 @@ import (
"google.golang.org/grpc"
pbConversation "github.com/OpenIMSDK/protocol/conversation"
pbconversation "github.com/OpenIMSDK/protocol/conversation"
"github.com/OpenIMSDK/tools/discoveryregistry"
"github.com/OpenIMSDK/tools/errs"
@@ -28,7 +28,7 @@ import (
)
type Conversation struct {
Client pbConversation.ConversationClient
Client pbconversation.ConversationClient
conn grpc.ClientConnInterface
discov discoveryregistry.SvcDiscoveryRegistry
}
@@ -38,7 +38,7 @@ func NewConversation(discov discoveryregistry.SvcDiscoveryRegistry) *Conversatio
if err != nil {
panic(err)
}
client := pbConversation.NewConversationClient(conn)
client := pbconversation.NewConversationClient(conn)
return &Conversation{discov: discov, conn: conn, Client: client}
}
@@ -49,7 +49,7 @@ func NewConversationRpcClient(discov discoveryregistry.SvcDiscoveryRegistry) Con
}
func (c *ConversationRpcClient) GetSingleConversationRecvMsgOpt(ctx context.Context, userID, conversationID string) (int32, error) {
var req pbConversation.GetConversationReq
var req pbconversation.GetConversationReq
req.OwnerUserID = userID
req.ConversationID = conversationID
conversation, err := c.Client.GetConversation(ctx, &req)
@@ -60,46 +60,46 @@ func (c *ConversationRpcClient) GetSingleConversationRecvMsgOpt(ctx context.Cont
}
func (c *ConversationRpcClient) SingleChatFirstCreateConversation(ctx context.Context, recvID, sendID string) error {
_, err := c.Client.CreateSingleChatConversations(ctx, &pbConversation.CreateSingleChatConversationsReq{RecvID: recvID, SendID: sendID})
_, err := c.Client.CreateSingleChatConversations(ctx, &pbconversation.CreateSingleChatConversationsReq{RecvID: recvID, SendID: sendID})
return err
}
func (c *ConversationRpcClient) GroupChatFirstCreateConversation(ctx context.Context, groupID string, userIDs []string) error {
_, err := c.Client.CreateGroupChatConversations(ctx, &pbConversation.CreateGroupChatConversationsReq{UserIDs: userIDs, GroupID: groupID})
_, err := c.Client.CreateGroupChatConversations(ctx, &pbconversation.CreateGroupChatConversationsReq{UserIDs: userIDs, GroupID: groupID})
return err
}
func (c *ConversationRpcClient) SetConversationMaxSeq(ctx context.Context, ownerUserIDs []string, conversationID string, maxSeq int64) error {
_, err := c.Client.SetConversationMaxSeq(ctx, &pbConversation.SetConversationMaxSeqReq{OwnerUserID: ownerUserIDs, ConversationID: conversationID, MaxSeq: maxSeq})
_, err := c.Client.SetConversationMaxSeq(ctx, &pbconversation.SetConversationMaxSeqReq{OwnerUserID: ownerUserIDs, ConversationID: conversationID, MaxSeq: maxSeq})
return err
}
func (c *ConversationRpcClient) SetConversations(ctx context.Context, userIDs []string, conversation *pbConversation.ConversationReq) error {
_, err := c.Client.SetConversations(ctx, &pbConversation.SetConversationsReq{UserIDs: userIDs, Conversation: conversation})
func (c *ConversationRpcClient) SetConversations(ctx context.Context, userIDs []string, conversation *pbconversation.ConversationReq) error {
_, err := c.Client.SetConversations(ctx, &pbconversation.SetConversationsReq{UserIDs: userIDs, Conversation: conversation})
return err
}
func (c *ConversationRpcClient) GetConversationIDs(ctx context.Context, ownerUserID string) ([]string, error) {
resp, err := c.Client.GetConversationIDs(ctx, &pbConversation.GetConversationIDsReq{UserID: ownerUserID})
resp, err := c.Client.GetConversationIDs(ctx, &pbconversation.GetConversationIDsReq{UserID: ownerUserID})
if err != nil {
return nil, err
}
return resp.ConversationIDs, nil
}
func (c *ConversationRpcClient) GetConversation(ctx context.Context, ownerUserID, conversationID string) (*pbConversation.Conversation, error) {
resp, err := c.Client.GetConversation(ctx, &pbConversation.GetConversationReq{OwnerUserID: ownerUserID, ConversationID: conversationID})
func (c *ConversationRpcClient) GetConversation(ctx context.Context, ownerUserID, conversationID string) (*pbconversation.Conversation, error) {
resp, err := c.Client.GetConversation(ctx, &pbconversation.GetConversationReq{OwnerUserID: ownerUserID, ConversationID: conversationID})
if err != nil {
return nil, err
}
return resp.Conversation, nil
}
func (c *ConversationRpcClient) GetConversationsByConversationID(ctx context.Context, conversationIDs []string) ([]*pbConversation.Conversation, error) {
func (c *ConversationRpcClient) GetConversationsByConversationID(ctx context.Context, conversationIDs []string) ([]*pbconversation.Conversation, error) {
if len(conversationIDs) == 0 {
return nil, nil
}
resp, err := c.Client.GetConversationsByConversationID(ctx, &pbConversation.GetConversationsByConversationIDReq{ConversationIDs: conversationIDs})
resp, err := c.Client.GetConversationsByConversationID(ctx, &pbconversation.GetConversationsByConversationIDReq{ConversationIDs: conversationIDs})
if err != nil {
return nil, err
}
@@ -113,13 +113,13 @@ func (c *ConversationRpcClient) GetConversations(
ctx context.Context,
ownerUserID string,
conversationIDs []string,
) ([]*pbConversation.Conversation, error) {
) ([]*pbconversation.Conversation, error) {
if len(conversationIDs) == 0 {
return nil, nil
}
resp, err := c.Client.GetConversations(
ctx,
&pbConversation.GetConversationsReq{OwnerUserID: ownerUserID, ConversationIDs: conversationIDs},
&pbconversation.GetConversationsReq{OwnerUserID: ownerUserID, ConversationIDs: conversationIDs},
)
if err != nil {
return nil, err
+9 -9
View File
@@ -20,12 +20,12 @@ import (
"github.com/OpenIMSDK/tools/mcontext"
"github.com/OpenIMSDK/protocol/constant"
pbFriend "github.com/OpenIMSDK/protocol/friend"
pbfriend "github.com/OpenIMSDK/protocol/friend"
"github.com/OpenIMSDK/protocol/sdkws"
"github.com/OpenIMSDK/Open-IM-Server/pkg/common/convert"
"github.com/OpenIMSDK/Open-IM-Server/pkg/common/db/controller"
relationTb "github.com/OpenIMSDK/Open-IM-Server/pkg/common/db/table/relation"
relationtb "github.com/OpenIMSDK/Open-IM-Server/pkg/common/db/table/relation"
"github.com/OpenIMSDK/Open-IM-Server/pkg/rpcclient"
)
@@ -46,7 +46,7 @@ func WithFriendDB(db controller.FriendDatabase) friendNotificationSenderOptions
}
func WithDBFunc(
fn func(ctx context.Context, userIDs []string) (users []*relationTb.UserModel, err error),
fn func(ctx context.Context, userIDs []string) (users []*relationtb.UserModel, err error),
) friendNotificationSenderOptions {
return func(s *FriendNotificationSender) {
f := func(ctx context.Context, userIDs []string) (result []CommonUser, err error) {
@@ -127,7 +127,7 @@ func (f *FriendNotificationSender) UserInfoUpdatedNotification(ctx context.Conte
func (f *FriendNotificationSender) FriendApplicationAddNotification(
ctx context.Context,
req *pbFriend.ApplyToAddFriendReq,
req *pbfriend.ApplyToAddFriendReq,
) error {
tips := sdkws.FriendApplicationTips{FromToUserID: &sdkws.FromToUserID{
FromUserID: req.FromUserID,
@@ -138,7 +138,7 @@ func (f *FriendNotificationSender) FriendApplicationAddNotification(
func (f *FriendNotificationSender) FriendApplicationAgreedNotification(
ctx context.Context,
req *pbFriend.RespondFriendApplyReq,
req *pbfriend.RespondFriendApplyReq,
) error {
tips := sdkws.FriendApplicationApprovedTips{FromToUserID: &sdkws.FromToUserID{
FromUserID: req.FromUserID,
@@ -149,7 +149,7 @@ func (f *FriendNotificationSender) FriendApplicationAgreedNotification(
func (f *FriendNotificationSender) FriendApplicationRefusedNotification(
ctx context.Context,
req *pbFriend.RespondFriendApplyReq,
req *pbfriend.RespondFriendApplyReq,
) error {
tips := sdkws.FriendApplicationApprovedTips{FromToUserID: &sdkws.FromToUserID{
FromUserID: req.FromUserID,
@@ -182,7 +182,7 @@ func (f *FriendNotificationSender) FriendAddedNotification(
return f.Notification(ctx, fromUserID, toUserID, constant.FriendAddedNotification, &tips)
}
func (f *FriendNotificationSender) FriendDeletedNotification(ctx context.Context, req *pbFriend.DeleteFriendReq) error {
func (f *FriendNotificationSender) FriendDeletedNotification(ctx context.Context, req *pbfriend.DeleteFriendReq) error {
tips := sdkws.FriendDeletedTips{FromToUserID: &sdkws.FromToUserID{
FromUserID: req.OwnerUserID,
ToUserID: req.FriendUserID,
@@ -197,14 +197,14 @@ func (f *FriendNotificationSender) FriendRemarkSetNotification(ctx context.Conte
return f.Notification(ctx, fromUserID, toUserID, constant.FriendRemarkSetNotification, &tips)
}
func (f *FriendNotificationSender) BlackAddedNotification(ctx context.Context, req *pbFriend.AddBlackReq) error {
func (f *FriendNotificationSender) BlackAddedNotification(ctx context.Context, req *pbfriend.AddBlackReq) error {
tips := sdkws.BlackAddedTips{FromToUserID: &sdkws.FromToUserID{}}
tips.FromToUserID.FromUserID = req.OwnerUserID
tips.FromToUserID.ToUserID = req.BlackUserID
return f.Notification(ctx, req.OwnerUserID, req.BlackUserID, constant.BlackAddedNotification, &tips)
}
func (f *FriendNotificationSender) BlackDeletedNotification(ctx context.Context, req *pbFriend.RemoveBlackReq) {
func (f *FriendNotificationSender) BlackDeletedNotification(ctx context.Context, req *pbfriend.RemoveBlackReq) {
blackDeletedTips := sdkws.BlackDeletedTips{FromToUserID: &sdkws.FromToUserID{
FromUserID: req.OwnerUserID,
ToUserID: req.BlackUserID,
+5 -5
View File
@@ -19,7 +19,7 @@ import (
"fmt"
"github.com/OpenIMSDK/protocol/constant"
pbGroup "github.com/OpenIMSDK/protocol/group"
pbgroup "github.com/OpenIMSDK/protocol/group"
"github.com/OpenIMSDK/protocol/sdkws"
"github.com/OpenIMSDK/tools/errs"
"github.com/OpenIMSDK/tools/log"
@@ -317,7 +317,7 @@ func (g *GroupNotificationSender) GroupInfoSetAnnouncementNotification(ctx conte
return g.Notification(ctx, mcontext.GetOpUserID(ctx), tips.Group.GroupID, constant.GroupInfoSetAnnouncementNotification, tips, rpcclient.WithRpcGetUserName())
}
func (g *GroupNotificationSender) JoinGroupApplicationNotification(ctx context.Context, req *pbGroup.JoinGroupReq) (err error) {
func (g *GroupNotificationSender) JoinGroupApplicationNotification(ctx context.Context, req *pbgroup.JoinGroupReq) (err error) {
defer log.ZDebug(ctx, "return")
defer func() {
if err != nil {
@@ -362,7 +362,7 @@ func (g *GroupNotificationSender) MemberQuitNotification(ctx context.Context, me
return g.Notification(ctx, mcontext.GetOpUserID(ctx), member.GroupID, constant.MemberQuitNotification, tips)
}
func (g *GroupNotificationSender) GroupApplicationAcceptedNotification(ctx context.Context, req *pbGroup.GroupApplicationResponseReq) (err error) {
func (g *GroupNotificationSender) GroupApplicationAcceptedNotification(ctx context.Context, req *pbgroup.GroupApplicationResponseReq) (err error) {
defer log.ZDebug(ctx, "return")
defer func() {
if err != nil {
@@ -390,7 +390,7 @@ func (g *GroupNotificationSender) GroupApplicationAcceptedNotification(ctx conte
return nil
}
func (g *GroupNotificationSender) GroupApplicationRejectedNotification(ctx context.Context, req *pbGroup.GroupApplicationResponseReq) (err error) {
func (g *GroupNotificationSender) GroupApplicationRejectedNotification(ctx context.Context, req *pbgroup.GroupApplicationResponseReq) (err error) {
defer log.ZDebug(ctx, "return")
defer func() {
if err != nil {
@@ -418,7 +418,7 @@ func (g *GroupNotificationSender) GroupApplicationRejectedNotification(ctx conte
return nil
}
func (g *GroupNotificationSender) GroupOwnerTransferredNotification(ctx context.Context, req *pbGroup.TransferGroupOwnerReq) (err error) {
func (g *GroupNotificationSender) GroupOwnerTransferredNotification(ctx context.Context, req *pbgroup.TransferGroupOwnerReq) (err error) {
defer log.ZDebug(ctx, "return")
defer func() {
if err != nil {
+2 -2
View File
@@ -21,7 +21,7 @@ import (
"github.com/OpenIMSDK/protocol/sdkws"
"github.com/OpenIMSDK/Open-IM-Server/pkg/common/db/controller"
relationTb "github.com/OpenIMSDK/Open-IM-Server/pkg/common/db/table/relation"
relationtb "github.com/OpenIMSDK/Open-IM-Server/pkg/common/db/table/relation"
"github.com/OpenIMSDK/Open-IM-Server/pkg/rpcclient"
)
@@ -41,7 +41,7 @@ func WithUserDB(db controller.UserDatabase) userNotificationSenderOptions {
}
func WithUserFunc(
fn func(ctx context.Context, userIDs []string) (users []*relationTb.UserModel, err error),
fn func(ctx context.Context, userIDs []string) (users []*relationtb.UserModel, err error),
) userNotificationSenderOptions {
return func(u *UserNotificationSender) {
f := func(ctx context.Context, userIDs []string) (result []CommonUser, err error) {
+15 -3
View File
@@ -31,12 +31,14 @@ import (
"github.com/OpenIMSDK/Open-IM-Server/pkg/common/config"
)
// User represents a structure holding connection details for the User RPC client.
type User struct {
conn grpc.ClientConnInterface
Client user.UserClient
Discov discoveryregistry.SvcDiscoveryRegistry
}
// NewUser initializes and returns a User instance based on the provided service discovery registry.
func NewUser(discov discoveryregistry.SvcDiscoveryRegistry) *User {
conn, err := discov.GetConn(context.Background(), config.Config.RpcRegisterName.OpenImUserName)
if err != nil {
@@ -46,17 +48,21 @@ func NewUser(discov discoveryregistry.SvcDiscoveryRegistry) *User {
return &User{Discov: discov, Client: client, conn: conn}
}
// UserRpcClient represents the structure for a User RPC client.
type UserRpcClient User
// NewUserRpcClientByUser initializes a UserRpcClient based on the provided User instance.
func NewUserRpcClientByUser(user *User) *UserRpcClient {
rpc := UserRpcClient(*user)
return &rpc
}
// NewUserRpcClient initializes a UserRpcClient based on the provided service discovery registry.
func NewUserRpcClient(client discoveryregistry.SvcDiscoveryRegistry) UserRpcClient {
return UserRpcClient(*NewUser(client))
}
// GetUsersInfo retrieves information for multiple users based on their user IDs.
func (u *UserRpcClient) GetUsersInfo(ctx context.Context, userIDs []string) ([]*sdkws.UserInfo, error) {
resp, err := u.Client.GetDesignateUsers(ctx, &user.GetDesignateUsersReq{
UserIDs: userIDs,
@@ -72,6 +78,7 @@ func (u *UserRpcClient) GetUsersInfo(ctx context.Context, userIDs []string) ([]*
return resp.UsersInfo, nil
}
// GetUserInfo retrieves information for a single user based on the provided user ID.
func (u *UserRpcClient) GetUserInfo(ctx context.Context, userID string) (*sdkws.UserInfo, error) {
users, err := u.GetUsersInfo(ctx, []string{userID})
if err != nil {
@@ -80,6 +87,7 @@ func (u *UserRpcClient) GetUserInfo(ctx context.Context, userID string) (*sdkws.
return users[0], nil
}
// GetUsersInfoMap retrieves a map of user information indexed by their user IDs.
func (u *UserRpcClient) GetUsersInfoMap(ctx context.Context, userIDs []string) (map[string]*sdkws.UserInfo, error) {
users, err := u.GetUsersInfo(ctx, userIDs)
if err != nil {
@@ -90,6 +98,7 @@ func (u *UserRpcClient) GetUsersInfoMap(ctx context.Context, userIDs []string) (
}), nil
}
// GetPublicUserInfos retrieves public information for multiple users based on their user IDs.
func (u *UserRpcClient) GetPublicUserInfos(
ctx context.Context,
userIDs []string,
@@ -109,6 +118,7 @@ func (u *UserRpcClient) GetPublicUserInfos(
}), nil
}
// GetPublicUserInfo retrieves public information for a single user based on the provided user ID.
func (u *UserRpcClient) GetPublicUserInfo(ctx context.Context, userID string) (*sdkws.PublicUserInfo, error) {
users, err := u.GetPublicUserInfos(ctx, []string{userID}, true)
if err != nil {
@@ -117,6 +127,7 @@ func (u *UserRpcClient) GetPublicUserInfo(ctx context.Context, userID string) (*
return users[0], nil
}
// GetPublicUserInfoMap retrieves a map of public user information indexed by their user IDs.
func (u *UserRpcClient) GetPublicUserInfoMap(
ctx context.Context,
userIDs []string,
@@ -131,16 +142,15 @@ func (u *UserRpcClient) GetPublicUserInfoMap(
}), nil
}
// GetUserGlobalMsgRecvOpt retrieves the global message receive option for a user based on the provided user ID.
func (u *UserRpcClient) GetUserGlobalMsgRecvOpt(ctx context.Context, userID string) (int32, error) {
resp, err := u.Client.GetGlobalRecvMessageOpt(ctx, &user.GetGlobalRecvMessageOptReq{
UserID: userID,
})
if err != nil {
return 0, err
}
return resp.GlobalRecvMsgOpt, err
}
// Access verifies the access rights for the provided user ID.
func (u *UserRpcClient) Access(ctx context.Context, ownerUserID string) error {
_, err := u.GetUserInfo(ctx, ownerUserID)
if err != nil {
@@ -149,6 +159,7 @@ func (u *UserRpcClient) Access(ctx context.Context, ownerUserID string) error {
return authverify.CheckAccessV3(ctx, ownerUserID)
}
// GetAllUserIDs retrieves all user IDs with pagination options.
func (u *UserRpcClient) GetAllUserIDs(ctx context.Context, pageNumber, showNumber int32) ([]string, error) {
resp, err := u.Client.GetAllUserID(ctx, &user.GetAllUserIDReq{Pagination: &sdkws.RequestPagination{PageNumber: pageNumber, ShowNumber: showNumber}})
if err != nil {
@@ -157,6 +168,7 @@ func (u *UserRpcClient) GetAllUserIDs(ctx context.Context, pageNumber, showNumbe
return resp.UserIDs, nil
}
// SetUserStatus sets the status for a user based on the provided user ID, status, and platform ID.
func (u *UserRpcClient) SetUserStatus(ctx context.Context, userID string, status int32, platformID int) error {
_, err := u.Client.SetUserStatus(ctx, &user.SetUserStatusReq{StatusList: []*user.OnlineStatus{{UserID: userID, Status: status, PlatformIDs: []int32{int32(platformID)}}}})
return err