mirror of
https://github.com/openimsdk/open-im-server.git
synced 2025-04-06 04:15:46 +08:00
fix: fix group getGroupMemberIDs is 0 err (#2108)
This commit is contained in:
parent
4cd42d7e19
commit
4ed575a53c
@ -33,10 +33,7 @@ func (s *groupServer) GetGroupInfoCache(
|
|||||||
return resp, nil
|
return resp, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *groupServer) GetGroupMemberCache(
|
func (s *groupServer) GetGroupMemberCache(ctx context.Context, req *pbgroup.GetGroupMemberCacheReq) (resp *pbgroup.GetGroupMemberCacheResp, err error) {
|
||||||
ctx context.Context,
|
|
||||||
req *pbgroup.GetGroupMemberCacheReq,
|
|
||||||
) (resp *pbgroup.GetGroupMemberCacheResp, err error) {
|
|
||||||
members, err := s.db.TakeGroupMember(ctx, req.GroupID, req.GroupMemberID)
|
members, err := s.db.TakeGroupMember(ctx, req.GroupID, req.GroupMemberID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
@ -952,6 +952,7 @@ func (s *groupServer) SetGroupInfo(ctx context.Context, req *pbgroup.SetGroupInf
|
|||||||
return nil, errs.Wrap(errs.ErrDismissedAlready)
|
return nil, errs.Wrap(errs.ErrDismissedAlready)
|
||||||
}
|
}
|
||||||
resp := &pbgroup.SetGroupInfoResp{}
|
resp := &pbgroup.SetGroupInfoResp{}
|
||||||
|
|
||||||
count, err := s.db.FindGroupMemberNum(ctx, group.GroupID)
|
count, err := s.db.FindGroupMemberNum(ctx, group.GroupID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
@ -1078,6 +1079,7 @@ func (s *groupServer) GetGroups(ctx context.Context, req *pbgroup.GetGroupsReq)
|
|||||||
total, group, err = s.db.SearchGroup(ctx, req.GroupName, req.Pagination)
|
total, group, err = s.db.SearchGroup(ctx, req.GroupName, req.Pagination)
|
||||||
resp.Total = uint32(total)
|
resp.Total = uint32(total)
|
||||||
}
|
}
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@ -1085,10 +1087,12 @@ func (s *groupServer) GetGroups(ctx context.Context, req *pbgroup.GetGroupsReq)
|
|||||||
groupIDs := utils.Slice(group, func(e *relationtb.GroupModel) string {
|
groupIDs := utils.Slice(group, func(e *relationtb.GroupModel) string {
|
||||||
return e.GroupID
|
return e.GroupID
|
||||||
})
|
})
|
||||||
|
|
||||||
ownerMembers, err := s.db.FindGroupsOwner(ctx, groupIDs)
|
ownerMembers, err := s.db.FindGroupsOwner(ctx, groupIDs)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
ownerMemberMap := utils.SliceToMap(ownerMembers, func(e *relationtb.GroupMemberModel) string {
|
ownerMemberMap := utils.SliceToMap(ownerMembers, func(e *relationtb.GroupMemberModel) string {
|
||||||
return e.GroupID
|
return e.GroupID
|
||||||
})
|
})
|
||||||
|
@ -137,6 +137,7 @@ func (m *msgServer) SearchMessage(ctx context.Context, req *msg.SearchMessageReq
|
|||||||
groupIDs = append(groupIDs, chatLog.GroupID)
|
groupIDs = append(groupIDs, chatLog.GroupID)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// Retrieve sender and receiver information
|
||||||
if len(sendIDs) != 0 {
|
if len(sendIDs) != 0 {
|
||||||
sendInfos, err := m.UserLocalCache.GetUsersInfo(ctx, sendIDs)
|
sendInfos, err := m.UserLocalCache.GetUsersInfo(ctx, sendIDs)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -155,6 +156,8 @@ func (m *msgServer) SearchMessage(ctx context.Context, req *msg.SearchMessageReq
|
|||||||
recvMap[recvInfo.UserID] = recvInfo.Nickname
|
recvMap[recvInfo.UserID] = recvInfo.Nickname
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Retrieve group information including member counts
|
||||||
if len(groupIDs) != 0 {
|
if len(groupIDs) != 0 {
|
||||||
groupInfos, err := m.GroupLocalCache.GetGroupInfos(ctx, groupIDs)
|
groupInfos, err := m.GroupLocalCache.GetGroupInfos(ctx, groupIDs)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -162,8 +165,14 @@ func (m *msgServer) SearchMessage(ctx context.Context, req *msg.SearchMessageReq
|
|||||||
}
|
}
|
||||||
for _, groupInfo := range groupInfos {
|
for _, groupInfo := range groupInfos {
|
||||||
groupMap[groupInfo.GroupID] = groupInfo
|
groupMap[groupInfo.GroupID] = groupInfo
|
||||||
|
// Get actual member count
|
||||||
|
memberIDs, err := m.GroupLocalCache.GetGroupMemberIDs(ctx, groupInfo.GroupID)
|
||||||
|
if err == nil {
|
||||||
|
groupInfo.MemberCount = uint32(len(memberIDs)) // Update the member count with actual number
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// Construct response with updated information
|
||||||
for _, chatLog := range chatLogs {
|
for _, chatLog := range chatLogs {
|
||||||
pbchatLog := &msg.ChatLog{}
|
pbchatLog := &msg.ChatLog{}
|
||||||
utils.CopyStructFields(pbchatLog, chatLog)
|
utils.CopyStructFields(pbchatLog, chatLog)
|
||||||
@ -175,14 +184,14 @@ func (m *msgServer) SearchMessage(ctx context.Context, req *msg.SearchMessageReq
|
|||||||
switch chatLog.SessionType {
|
switch chatLog.SessionType {
|
||||||
case constant.SingleChatType, constant.NotificationChatType:
|
case constant.SingleChatType, constant.NotificationChatType:
|
||||||
pbchatLog.RecvNickname = recvMap[chatLog.RecvID]
|
pbchatLog.RecvNickname = recvMap[chatLog.RecvID]
|
||||||
|
|
||||||
case constant.GroupChatType, constant.SuperGroupChatType:
|
case constant.GroupChatType, constant.SuperGroupChatType:
|
||||||
pbchatLog.SenderFaceURL = groupMap[chatLog.GroupID].FaceURL
|
groupInfo := groupMap[chatLog.GroupID]
|
||||||
pbchatLog.GroupMemberCount = groupMap[chatLog.GroupID].MemberCount
|
pbchatLog.SenderFaceURL = groupInfo.FaceURL
|
||||||
pbchatLog.RecvID = groupMap[chatLog.GroupID].GroupID
|
pbchatLog.GroupMemberCount = groupInfo.MemberCount // Reflects actual member count
|
||||||
pbchatLog.GroupName = groupMap[chatLog.GroupID].GroupName
|
pbchatLog.RecvID = groupInfo.GroupID
|
||||||
pbchatLog.GroupOwner = groupMap[chatLog.GroupID].OwnerUserID
|
pbchatLog.GroupName = groupInfo.GroupName
|
||||||
pbchatLog.GroupType = groupMap[chatLog.GroupID].GroupType
|
pbchatLog.GroupOwner = groupInfo.OwnerUserID
|
||||||
|
pbchatLog.GroupType = groupInfo.GroupType
|
||||||
}
|
}
|
||||||
resp.ChatLogs = append(resp.ChatLogs, pbchatLog)
|
resp.ChatLogs = append(resp.ChatLogs, pbchatLog)
|
||||||
}
|
}
|
||||||
|
@ -60,6 +60,7 @@ func CheckAdmin(ctx context.Context, config *config.GlobalConfig) error {
|
|||||||
}
|
}
|
||||||
return errs.ErrNoPermission.Wrap(fmt.Sprintf("user %s is not admin userID", mcontext.GetOpUserID(ctx)))
|
return errs.ErrNoPermission.Wrap(fmt.Sprintf("user %s is not admin userID", mcontext.GetOpUserID(ctx)))
|
||||||
}
|
}
|
||||||
|
|
||||||
func CheckIMAdmin(ctx context.Context, config *config.GlobalConfig) error {
|
func CheckIMAdmin(ctx context.Context, config *config.GlobalConfig) error {
|
||||||
if utils.IsContain(mcontext.GetOpUserID(ctx), config.IMAdmin.UserID) {
|
if utils.IsContain(mcontext.GetOpUserID(ctx), config.IMAdmin.UserID) {
|
||||||
return nil
|
return nil
|
||||||
|
@ -49,11 +49,7 @@ func NewGroupRpcClient(discov discoveryregistry.SvcDiscoveryRegistry, config *co
|
|||||||
return GroupRpcClient(*NewGroup(discov, config))
|
return GroupRpcClient(*NewGroup(discov, config))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (g *GroupRpcClient) GetGroupInfos(
|
func (g *GroupRpcClient) GetGroupInfos(ctx context.Context, groupIDs []string, complete bool) ([]*sdkws.GroupInfo, error) {
|
||||||
ctx context.Context,
|
|
||||||
groupIDs []string,
|
|
||||||
complete bool,
|
|
||||||
) ([]*sdkws.GroupInfo, error) {
|
|
||||||
resp, err := g.Client.GetGroupsInfo(ctx, &group.GetGroupsInfoReq{
|
resp, err := g.Client.GetGroupsInfo(ctx, &group.GetGroupsInfoReq{
|
||||||
GroupIDs: groupIDs,
|
GroupIDs: groupIDs,
|
||||||
})
|
})
|
||||||
@ -184,11 +180,7 @@ func (g *GroupRpcClient) GetGroupInfoCache(ctx context.Context, groupID string)
|
|||||||
return resp.GroupInfo, nil
|
return resp.GroupInfo, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (g *GroupRpcClient) GetGroupMemberCache(
|
func (g *GroupRpcClient) GetGroupMemberCache(ctx context.Context, groupID string, groupMemberID string) (*sdkws.GroupMemberFullInfo, error) {
|
||||||
ctx context.Context,
|
|
||||||
groupID string,
|
|
||||||
groupMemberID string,
|
|
||||||
) (*sdkws.GroupMemberFullInfo, error) {
|
|
||||||
resp, err := g.Client.GetGroupMemberCache(ctx, &group.GetGroupMemberCacheReq{
|
resp, err := g.Client.GetGroupMemberCache(ctx, &group.GetGroupMemberCacheReq{
|
||||||
GroupID: groupID,
|
GroupID: groupID,
|
||||||
GroupMemberID: groupMemberID,
|
GroupMemberID: groupMemberID,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user