mirror of
https://github.com/openimsdk/open-im-server.git
synced 2026-06-28 21:58:17 +08:00
查询共同所在的群
This commit is contained in:
parent
81f868a49f
commit
98b6b249ee
@ -18,3 +18,4 @@ prometheus:
|
||||
|
||||
|
||||
enableHistoryForNewMembers: true
|
||||
commonGroupsLimitWithFriend: 3
|
||||
|
||||
@ -19,6 +19,7 @@ import (
|
||||
"fmt"
|
||||
"math/big"
|
||||
"math/rand"
|
||||
"sort"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
@ -371,6 +372,7 @@ func (g *groupServer) GetCommonGroupsWithFriend(ctx context.Context, req *pbgrou
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if len(selfGroupIDs) == 0 {
|
||||
return &pbgroup.GetCommonGroupsWithFriendResp{
|
||||
Total: 0,
|
||||
@ -382,6 +384,7 @@ func (g *groupServer) GetCommonGroupsWithFriend(ctx context.Context, req *pbgrou
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if len(friendMembers) == 0 {
|
||||
return &pbgroup.GetCommonGroupsWithFriendResp{
|
||||
Total: 0,
|
||||
@ -392,12 +395,28 @@ func (g *groupServer) GetCommonGroupsWithFriend(ctx context.Context, req *pbgrou
|
||||
commonGroupIDs := datautil.Distinct(datautil.Slice(friendMembers, func(e *model.GroupMember) string {
|
||||
return e.GroupID
|
||||
}))
|
||||
|
||||
groups, err := g.getGroupsInfo(ctx, commonGroupIDs)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// Keep response deterministic by sorting common groups with member count descending.
|
||||
sort.SliceStable(groups, func(i, j int) bool {
|
||||
return groups[i].MemberCount > groups[j].MemberCount
|
||||
})
|
||||
total := len(groups)
|
||||
|
||||
limit := g.config.RpcConfig.CommonGroupsLimitWithFriend
|
||||
if limit <= 0 {
|
||||
limit = 3
|
||||
}
|
||||
if len(groups) > limit {
|
||||
groups = groups[:limit]
|
||||
}
|
||||
|
||||
return &pbgroup.GetCommonGroupsWithFriendResp{
|
||||
Total: uint32(len(groups)),
|
||||
Total: uint32(total),
|
||||
Groups: groups,
|
||||
}, nil
|
||||
}
|
||||
|
||||
@ -278,6 +278,7 @@ type Group struct {
|
||||
} `mapstructure:"rpc"`
|
||||
Prometheus Prometheus `mapstructure:"prometheus"`
|
||||
EnableHistoryForNewMembers bool `mapstructure:"enableHistoryForNewMembers"`
|
||||
CommonGroupsLimitWithFriend int `mapstructure:"commonGroupsLimitWithFriend"`
|
||||
}
|
||||
|
||||
type Msg struct {
|
||||
|
||||
@ -3,9 +3,9 @@ set -euo pipefail
|
||||
|
||||
# ====== 按需修改 ======
|
||||
API_BASE="${API_BASE:-http://127.0.0.1:10002}" # 你的 open-im-api 地址
|
||||
SELF_USER_ID="${SELF_USER_ID:-4642714021}" # 当前登录用户(拿 token 的用户)
|
||||
SELF_USER_ID="${SELF_USER_ID:-5694418935}" # 当前登录用户(拿 token 的用户)
|
||||
#FRIEND_USER_ID="${FRIEND_USER_ID:-1971806090}" # 要查询共同群的好友
|
||||
FRIEND_USER_ID="${FRIEND_USER_ID:-3870738564}" # 要查询共同群的好友
|
||||
FRIEND_USER_ID="${FRIEND_USER_ID:-1011009748}" # 要查询共同群的好友
|
||||
PLATFORM_ID="${PLATFORM_ID:-2}" # 1=iOS, 2=Android, 3=Windows...
|
||||
ADMIN_USER_ID="${ADMIN_USER_ID:-imAdmin}" # 管理员账号(用于签发用户 token)
|
||||
ADMIN_SECRET="${ADMIN_SECRET:-openIM123}" # 配置中的 share.secret
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user