mirror of
https://github.com/openimsdk/open-im-server.git
synced 2025-05-17 09:44:47 +08:00
fix: standalone mode cannot be used (#3360)
* pb * fix: Modifying other fields while setting IsPrivateChat does not take effect * fix: quote message error revoke * refactoring scheduled tasks * refactoring scheduled tasks * refactoring scheduled tasks * refactoring scheduled tasks * refactoring scheduled tasks * refactoring scheduled tasks * upgrading pkg tools * fix * fix * optimize log output * feat: support GetLastMessage * feat: support GetLastMessage * feat: s3 switch * feat: s3 switch * fix: GetUsersOnline * feat: SendBusinessNotification supported configuration parameters * feat: SendBusinessNotification supported configuration parameters * feat: SendBusinessNotification supported configuration parameters * feat: seq conversion failed without exiting * fix: DeleteDoc crash * fix: fill send time * fix: fill send time * fix: crash caused by withdrawing messages from users who have left the group * fix: user msg timestamp * seq read config * seq read config * fix: the source message of the reference is withdrawn, and the referenced message is deleted * feat: optimize the default notification.yml * fix: shouldPushOffline * fix: the sorting is wrong after canceling the administrator in group settings * feat: Sending messages supports returning fields modified by webhook * feat: Sending messages supports returning fields modified by webhook * feat: Sending messages supports returning fields modified by webhook * fix: oss specifies content-type when uploading * fix: the version number contains a line break * fix: the version number contains a line break * feat: GetConversationsHasReadAndMaxSeq support pinned * feat: GetConversationsHasReadAndMaxSeq support pinned * feat: GetConversationsHasReadAndMaxSeq support pinned * fix: transferring the group owner to a muted member, incremental version error * feat: unified conversion code * feat: update gomake * fix: in standalone mode, the user online status is wrong
This commit is contained in:
parent
1d7660bedb
commit
632a65303c
2
go.mod
2
go.mod
@ -13,7 +13,7 @@ require (
|
|||||||
github.com/grpc-ecosystem/go-grpc-prometheus v1.2.0
|
github.com/grpc-ecosystem/go-grpc-prometheus v1.2.0
|
||||||
github.com/mitchellh/mapstructure v1.5.0
|
github.com/mitchellh/mapstructure v1.5.0
|
||||||
github.com/openimsdk/protocol v0.0.73-alpha.6
|
github.com/openimsdk/protocol v0.0.73-alpha.6
|
||||||
github.com/openimsdk/tools v0.0.50-alpha.81
|
github.com/openimsdk/tools v0.0.50-alpha.83
|
||||||
github.com/pkg/errors v0.9.1 // indirect
|
github.com/pkg/errors v0.9.1 // indirect
|
||||||
github.com/prometheus/client_golang v1.18.0
|
github.com/prometheus/client_golang v1.18.0
|
||||||
github.com/stretchr/testify v1.9.0
|
github.com/stretchr/testify v1.9.0
|
||||||
|
4
go.sum
4
go.sum
@ -349,8 +349,8 @@ github.com/openimsdk/gomake v0.0.15-alpha.5 h1:eEZCEHm+NsmcO3onXZPIUbGFCYPYbsX5b
|
|||||||
github.com/openimsdk/gomake v0.0.15-alpha.5/go.mod h1:PndCozNc2IsQIciyn9mvEblYWZwJmAI+06z94EY+csI=
|
github.com/openimsdk/gomake v0.0.15-alpha.5/go.mod h1:PndCozNc2IsQIciyn9mvEblYWZwJmAI+06z94EY+csI=
|
||||||
github.com/openimsdk/protocol v0.0.73-alpha.6 h1:sna9coWG7HN1zObBPtvG0Ki/vzqHXiB4qKbA5P3w7kc=
|
github.com/openimsdk/protocol v0.0.73-alpha.6 h1:sna9coWG7HN1zObBPtvG0Ki/vzqHXiB4qKbA5P3w7kc=
|
||||||
github.com/openimsdk/protocol v0.0.73-alpha.6/go.mod h1:WF7EuE55vQvpyUAzDXcqg+B+446xQyEba0X35lTINmw=
|
github.com/openimsdk/protocol v0.0.73-alpha.6/go.mod h1:WF7EuE55vQvpyUAzDXcqg+B+446xQyEba0X35lTINmw=
|
||||||
github.com/openimsdk/tools v0.0.50-alpha.81 h1:VbuJKtigNXLkCKB/Q6f2UHsqoSaTOAwS8F51c1nhOCA=
|
github.com/openimsdk/tools v0.0.50-alpha.83 h1:7c1D40YGqIWUmGfCII5pduETGC/8c2DyS9SQ4LvoplU=
|
||||||
github.com/openimsdk/tools v0.0.50-alpha.81/go.mod h1:n2poR3asX1e1XZce4O+MOWAp+X02QJRFvhcLCXZdzRo=
|
github.com/openimsdk/tools v0.0.50-alpha.83/go.mod h1:n2poR3asX1e1XZce4O+MOWAp+X02QJRFvhcLCXZdzRo=
|
||||||
github.com/pelletier/go-toml/v2 v2.2.2 h1:aYUidT7k73Pcl9nb2gScu7NSrKCSHIDE89b3+6Wq+LM=
|
github.com/pelletier/go-toml/v2 v2.2.2 h1:aYUidT7k73Pcl9nb2gScu7NSrKCSHIDE89b3+6Wq+LM=
|
||||||
github.com/pelletier/go-toml/v2 v2.2.2/go.mod h1:1t835xjRzz80PqgE6HHgN2JOsmgYu/h4qDAS4n929Rs=
|
github.com/pelletier/go-toml/v2 v2.2.2/go.mod h1:1t835xjRzz80PqgE6HHgN2JOsmgYu/h4qDAS4n929Rs=
|
||||||
github.com/pierrec/lz4/v4 v4.1.21 h1:yOVMLb6qSIDP67pl/5F7RepeKYu/VmTyEXvuMI5d9mQ=
|
github.com/pierrec/lz4/v4 v4.1.21 h1:yOVMLb6qSIDP67pl/5F7RepeKYu/VmTyEXvuMI5d9mQ=
|
||||||
|
@ -9,12 +9,8 @@ import (
|
|||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
"github.com/gin-gonic/gin/binding"
|
"github.com/gin-gonic/gin/binding"
|
||||||
"github.com/go-playground/validator/v10"
|
"github.com/go-playground/validator/v10"
|
||||||
"github.com/openimsdk/open-im-server/v3/pkg/authverify"
|
|
||||||
"github.com/openimsdk/tools/mcontext"
|
|
||||||
"github.com/openimsdk/tools/utils/datautil"
|
|
||||||
clientv3 "go.etcd.io/etcd/client/v3"
|
|
||||||
|
|
||||||
"github.com/openimsdk/open-im-server/v3/internal/api/jssdk"
|
"github.com/openimsdk/open-im-server/v3/internal/api/jssdk"
|
||||||
|
"github.com/openimsdk/open-im-server/v3/pkg/authverify"
|
||||||
"github.com/openimsdk/open-im-server/v3/pkg/common/config"
|
"github.com/openimsdk/open-im-server/v3/pkg/common/config"
|
||||||
"github.com/openimsdk/open-im-server/v3/pkg/common/prommetrics"
|
"github.com/openimsdk/open-im-server/v3/pkg/common/prommetrics"
|
||||||
"github.com/openimsdk/open-im-server/v3/pkg/common/servererrs"
|
"github.com/openimsdk/open-im-server/v3/pkg/common/servererrs"
|
||||||
@ -32,6 +28,7 @@ import (
|
|||||||
"github.com/openimsdk/tools/discovery/etcd"
|
"github.com/openimsdk/tools/discovery/etcd"
|
||||||
"github.com/openimsdk/tools/log"
|
"github.com/openimsdk/tools/log"
|
||||||
"github.com/openimsdk/tools/mw"
|
"github.com/openimsdk/tools/mw"
|
||||||
|
clientv3 "go.etcd.io/etcd/client/v3"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
@ -271,7 +268,6 @@ func newGinRouter(ctx context.Context, client discovery.Conn, cfg *Config) (*gin
|
|||||||
conversationGroup.POST("/get_owner_conversation", c.GetOwnerConversation)
|
conversationGroup.POST("/get_owner_conversation", c.GetOwnerConversation)
|
||||||
conversationGroup.POST("/get_not_notify_conversation_ids", c.GetNotNotifyConversationIDs)
|
conversationGroup.POST("/get_not_notify_conversation_ids", c.GetNotNotifyConversationIDs)
|
||||||
conversationGroup.POST("/get_pinned_conversation_ids", c.GetPinnedConversationIDs)
|
conversationGroup.POST("/get_pinned_conversation_ids", c.GetPinnedConversationIDs)
|
||||||
conversationGroup.POST("/update_conversations_by_user", c.UpdateConversationsByUser)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
@ -315,7 +311,6 @@ func newGinRouter(ctx context.Context, client discovery.Conn, cfg *Config) (*gin
|
|||||||
configGroup.POST("/get_config_list", cm.GetConfigList)
|
configGroup.POST("/get_config_list", cm.GetConfigList)
|
||||||
configGroup.POST("/get_config", cm.GetConfig)
|
configGroup.POST("/get_config", cm.GetConfig)
|
||||||
configGroup.POST("/set_config", cm.SetConfig)
|
configGroup.POST("/set_config", cm.SetConfig)
|
||||||
configGroup.POST("/set_configs", cm.SetConfigs)
|
|
||||||
configGroup.POST("/reset_config", cm.ResetConfig)
|
configGroup.POST("/reset_config", cm.ResetConfig)
|
||||||
configGroup.POST("/set_enable_config_manager", cm.SetEnableConfigManager)
|
configGroup.POST("/set_enable_config_manager", cm.SetEnableConfigManager)
|
||||||
configGroup.POST("/get_enable_config_manager", cm.GetEnableConfigManager)
|
configGroup.POST("/get_enable_config_manager", cm.GetEnableConfigManager)
|
||||||
@ -359,9 +354,7 @@ func GinParseToken(authClient *rpcli.AuthClient) gin.HandlerFunc {
|
|||||||
|
|
||||||
func setGinIsAdmin(imAdminUserID []string) gin.HandlerFunc {
|
func setGinIsAdmin(imAdminUserID []string) gin.HandlerFunc {
|
||||||
return func(c *gin.Context) {
|
return func(c *gin.Context) {
|
||||||
opUserID := mcontext.GetOpUserID(c)
|
c.Set(authverify.CtxAdminUserIDsKey, imAdminUserID)
|
||||||
admin := datautil.Contain(opUserID, imAdminUserID...)
|
|
||||||
c.Set(authverify.CtxIsAdminKey, admin)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -49,7 +49,7 @@ type WsServer struct {
|
|||||||
unregisterChan chan *Client
|
unregisterChan chan *Client
|
||||||
kickHandlerChan chan *kickHandler
|
kickHandlerChan chan *kickHandler
|
||||||
clients UserMap
|
clients UserMap
|
||||||
online *rpccache.OnlineCache
|
online rpccache.OnlineCache
|
||||||
subscription *Subscription
|
subscription *Subscription
|
||||||
clientPool sync.Pool
|
clientPool sync.Pool
|
||||||
onlineUserNum atomic.Int64
|
onlineUserNum atomic.Int64
|
||||||
|
@ -48,15 +48,7 @@ func (mc *OnlineHistoryMongoConsumerHandler) HandleChatWs2Mongo(ctx context.Cont
|
|||||||
log.ZDebug(ctx, "mongo consumer recv msg", "msgs", msgFromMQ.String())
|
log.ZDebug(ctx, "mongo consumer recv msg", "msgs", msgFromMQ.String())
|
||||||
err = mc.msgTransferDatabase.BatchInsertChat2DB(ctx, msgFromMQ.ConversationID, msgFromMQ.MsgData, msgFromMQ.LastSeq)
|
err = mc.msgTransferDatabase.BatchInsertChat2DB(ctx, msgFromMQ.ConversationID, msgFromMQ.MsgData, msgFromMQ.LastSeq)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.ZError(
|
log.ZError(ctx, "single data insert to mongo err", err, "msg", msgFromMQ.MsgData, "conversationID", msgFromMQ.ConversationID)
|
||||||
ctx,
|
|
||||||
"single data insert to mongo err",
|
|
||||||
err,
|
|
||||||
"msg",
|
|
||||||
msgFromMQ.MsgData,
|
|
||||||
"conversationID",
|
|
||||||
msgFromMQ.ConversationID,
|
|
||||||
)
|
|
||||||
prommetrics.MsgInsertMongoFailedCounter.Inc()
|
prommetrics.MsgInsertMongoFailedCounter.Inc()
|
||||||
} else {
|
} else {
|
||||||
prommetrics.MsgInsertMongoSuccessCounter.Inc()
|
prommetrics.MsgInsertMongoSuccessCounter.Inc()
|
||||||
|
@ -33,7 +33,7 @@ type ConsumerHandler struct {
|
|||||||
offlinePusher offlinepush.OfflinePusher
|
offlinePusher offlinepush.OfflinePusher
|
||||||
onlinePusher OnlinePusher
|
onlinePusher OnlinePusher
|
||||||
pushDatabase controller.PushDatabase
|
pushDatabase controller.PushDatabase
|
||||||
onlineCache *rpccache.OnlineCache
|
onlineCache rpccache.OnlineCache
|
||||||
groupLocalCache *rpccache.GroupLocalCache
|
groupLocalCache *rpccache.GroupLocalCache
|
||||||
conversationLocalCache *rpccache.ConversationLocalCache
|
conversationLocalCache *rpccache.ConversationLocalCache
|
||||||
webhookClient *webhook.Client
|
webhookClient *webhook.Client
|
||||||
@ -120,11 +120,7 @@ func (c *ConsumerHandler) HandleMs2PsChat(ctx context.Context, msg []byte) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (c *ConsumerHandler) WaitCache() {
|
func (c *ConsumerHandler) WaitCache() {
|
||||||
c.onlineCache.Lock.Lock()
|
c.onlineCache.WaitCache()
|
||||||
for c.onlineCache.CurrentPhase.Load() < rpccache.DoSubscribeOver {
|
|
||||||
c.onlineCache.Cond.Wait()
|
|
||||||
}
|
|
||||||
c.onlineCache.Lock.Unlock()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Push2User Suitable for two types of conversations, one is SingleChatType and the other is NotificationChatType.
|
// Push2User Suitable for two types of conversations, one is SingleChatType and the other is NotificationChatType.
|
||||||
|
@ -51,15 +51,15 @@ func CheckSystemAccount(ctx context.Context, level int32) bool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const (
|
const (
|
||||||
CtxIsAdminKey = "CtxIsAdminKey"
|
CtxAdminUserIDsKey = "CtxAdminUserIDsKey"
|
||||||
)
|
)
|
||||||
|
|
||||||
func WithIMAdminUserIDs(ctx context.Context, imAdminUserID []string) context.Context {
|
func WithIMAdminUserIDs(ctx context.Context, imAdminUserID []string) context.Context {
|
||||||
return context.WithValue(ctx, CtxIsAdminKey, imAdminUserID)
|
return context.WithValue(ctx, CtxAdminUserIDsKey, imAdminUserID)
|
||||||
}
|
}
|
||||||
|
|
||||||
func GetIMAdminUserIDs(ctx context.Context) []string {
|
func GetIMAdminUserIDs(ctx context.Context) []string {
|
||||||
imAdminUserID, _ := ctx.Value(CtxIsAdminKey).([]string)
|
imAdminUserID, _ := ctx.Value(CtxAdminUserIDsKey).([]string)
|
||||||
return imAdminUserID
|
return imAdminUserID
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -47,64 +47,6 @@ func init() {
|
|||||||
prommetrics.RegistryAll()
|
prommetrics.RegistryAll()
|
||||||
}
|
}
|
||||||
|
|
||||||
func getConfigRpcMaxRequestBody(value reflect.Value) *conf.MaxRequestBody {
|
|
||||||
for value.Kind() == reflect.Pointer {
|
|
||||||
value = value.Elem()
|
|
||||||
}
|
|
||||||
if value.Kind() == reflect.Struct {
|
|
||||||
num := value.NumField()
|
|
||||||
for i := 0; i < num; i++ {
|
|
||||||
field := value.Field(i)
|
|
||||||
if !field.CanInterface() {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
for field.Kind() == reflect.Pointer {
|
|
||||||
field = field.Elem()
|
|
||||||
}
|
|
||||||
switch elem := field.Interface().(type) {
|
|
||||||
case conf.Share:
|
|
||||||
return &elem.RPCMaxBodySize
|
|
||||||
case conf.MaxRequestBody:
|
|
||||||
return &elem
|
|
||||||
}
|
|
||||||
if field.Kind() == reflect.Struct {
|
|
||||||
if elem := getConfigRpcMaxRequestBody(field); elem != nil {
|
|
||||||
return elem
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func getConfigShare(value reflect.Value) *conf.Share {
|
|
||||||
for value.Kind() == reflect.Pointer {
|
|
||||||
value = value.Elem()
|
|
||||||
}
|
|
||||||
if value.Kind() == reflect.Struct {
|
|
||||||
num := value.NumField()
|
|
||||||
for i := 0; i < num; i++ {
|
|
||||||
field := value.Field(i)
|
|
||||||
if !field.CanInterface() {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
for field.Kind() == reflect.Pointer {
|
|
||||||
field = field.Elem()
|
|
||||||
}
|
|
||||||
switch elem := field.Interface().(type) {
|
|
||||||
case conf.Share:
|
|
||||||
return &elem
|
|
||||||
}
|
|
||||||
if field.Kind() == reflect.Struct {
|
|
||||||
if elem := getConfigShare(field); elem != nil {
|
|
||||||
return elem
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func Start[T any](ctx context.Context, disc *conf.Discovery, prometheusConfig *conf.Prometheus, listenIP,
|
func Start[T any](ctx context.Context, disc *conf.Discovery, prometheusConfig *conf.Prometheus, listenIP,
|
||||||
registerIP string, autoSetPorts bool, rpcPorts []int, index int, rpcRegisterName string, notification *conf.Notification, config T,
|
registerIP string, autoSetPorts bool, rpcPorts []int, index int, rpcRegisterName string, notification *conf.Notification, config T,
|
||||||
watchConfigNames []string, watchServiceNames []string,
|
watchConfigNames []string, watchServiceNames []string,
|
||||||
@ -122,8 +64,8 @@ func Start[T any](ctx context.Context, disc *conf.Discovery, prometheusConfig *c
|
|||||||
|
|
||||||
options = append(options,
|
options = append(options,
|
||||||
grpcsrv.GrpcServerMetadataContext(),
|
grpcsrv.GrpcServerMetadataContext(),
|
||||||
grpcsrv.GrpcServerLogger(),
|
|
||||||
grpcsrv.GrpcServerErrorConvert(),
|
grpcsrv.GrpcServerErrorConvert(),
|
||||||
|
grpcsrv.GrpcServerLogger(),
|
||||||
grpcsrv.GrpcServerRequestValidate(),
|
grpcsrv.GrpcServerRequestValidate(),
|
||||||
grpcsrv.GrpcServerPanicCapture(),
|
grpcsrv.GrpcServerPanicCapture(),
|
||||||
)
|
)
|
||||||
|
39
pkg/common/startrpc/tools.go
Normal file
39
pkg/common/startrpc/tools.go
Normal file
@ -0,0 +1,39 @@
|
|||||||
|
package startrpc
|
||||||
|
|
||||||
|
import (
|
||||||
|
"reflect"
|
||||||
|
|
||||||
|
conf "github.com/openimsdk/open-im-server/v3/pkg/common/config"
|
||||||
|
)
|
||||||
|
|
||||||
|
func getConfig[T any](value reflect.Value) *T {
|
||||||
|
for value.Kind() == reflect.Pointer {
|
||||||
|
value = value.Elem()
|
||||||
|
}
|
||||||
|
if value.Kind() == reflect.Struct {
|
||||||
|
num := value.NumField()
|
||||||
|
for i := 0; i < num; i++ {
|
||||||
|
field := value.Field(i)
|
||||||
|
for field.Kind() == reflect.Pointer {
|
||||||
|
field = field.Elem()
|
||||||
|
}
|
||||||
|
if field.Kind() == reflect.Struct {
|
||||||
|
if elem, ok := field.Interface().(T); ok {
|
||||||
|
return &elem
|
||||||
|
}
|
||||||
|
if elem := getConfig[T](field); elem != nil {
|
||||||
|
return elem
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func getConfigRpcMaxRequestBody(value reflect.Value) *conf.MaxRequestBody {
|
||||||
|
return getConfig[conf.MaxRequestBody](value)
|
||||||
|
}
|
||||||
|
|
||||||
|
func getConfigShare(value reflect.Value) *conf.Share {
|
||||||
|
return getConfig[conf.Share](value)
|
||||||
|
}
|
@ -9,6 +9,7 @@ import (
|
|||||||
"sync/atomic"
|
"sync/atomic"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/openimsdk/open-im-server/v3/pkg/common/config"
|
||||||
"github.com/openimsdk/open-im-server/v3/pkg/rpcli"
|
"github.com/openimsdk/open-im-server/v3/pkg/rpcli"
|
||||||
"github.com/openimsdk/protocol/constant"
|
"github.com/openimsdk/protocol/constant"
|
||||||
"github.com/openimsdk/protocol/user"
|
"github.com/openimsdk/protocol/user"
|
||||||
@ -23,9 +24,25 @@ import (
|
|||||||
"github.com/redis/go-redis/v9"
|
"github.com/redis/go-redis/v9"
|
||||||
)
|
)
|
||||||
|
|
||||||
func NewOnlineCache(client *rpcli.UserClient, group *GroupLocalCache, rdb redis.UniversalClient, fullUserCache bool, fn func(ctx context.Context, userID string, platformIDs []int32)) (*OnlineCache, error) {
|
const (
|
||||||
|
Begin uint32 = iota
|
||||||
|
DoOnlineStatusOver
|
||||||
|
DoSubscribeOver
|
||||||
|
)
|
||||||
|
|
||||||
|
type OnlineCache interface {
|
||||||
|
GetUserOnlinePlatform(ctx context.Context, userID string) ([]int32, error)
|
||||||
|
GetUserOnline(ctx context.Context, userID string) (bool, error)
|
||||||
|
GetUsersOnline(ctx context.Context, userIDs []string) ([]string, []string, error)
|
||||||
|
WaitCache()
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewOnlineCache(client *rpcli.UserClient, group *GroupLocalCache, rdb redis.UniversalClient, fullUserCache bool, fn func(ctx context.Context, userID string, platformIDs []int32)) (OnlineCache, error) {
|
||||||
|
if config.Standalone() {
|
||||||
|
return disableOnlineCache{client: client}, nil
|
||||||
|
}
|
||||||
l := &sync.Mutex{}
|
l := &sync.Mutex{}
|
||||||
x := &OnlineCache{
|
x := &defaultOnlineCache{
|
||||||
client: client,
|
client: client,
|
||||||
group: group,
|
group: group,
|
||||||
fullUserCache: fullUserCache,
|
fullUserCache: fullUserCache,
|
||||||
@ -60,13 +77,7 @@ func NewOnlineCache(client *rpcli.UserClient, group *GroupLocalCache, rdb redis.
|
|||||||
return x, nil
|
return x, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
const (
|
type defaultOnlineCache struct {
|
||||||
Begin uint32 = iota
|
|
||||||
DoOnlineStatusOver
|
|
||||||
DoSubscribeOver
|
|
||||||
)
|
|
||||||
|
|
||||||
type OnlineCache struct {
|
|
||||||
client *rpcli.UserClient
|
client *rpcli.UserClient
|
||||||
group *GroupLocalCache
|
group *GroupLocalCache
|
||||||
|
|
||||||
@ -82,7 +93,7 @@ type OnlineCache struct {
|
|||||||
CurrentPhase atomic.Uint32
|
CurrentPhase atomic.Uint32
|
||||||
}
|
}
|
||||||
|
|
||||||
func (o *OnlineCache) initUsersOnlineStatus(ctx context.Context) (err error) {
|
func (o *defaultOnlineCache) initUsersOnlineStatus(ctx context.Context) (err error) {
|
||||||
log.ZDebug(ctx, "init users online status begin")
|
log.ZDebug(ctx, "init users online status begin")
|
||||||
|
|
||||||
var (
|
var (
|
||||||
@ -135,7 +146,7 @@ func (o *OnlineCache) initUsersOnlineStatus(ctx context.Context) (err error) {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (o *OnlineCache) doSubscribe(ctx context.Context, rdb redis.UniversalClient, fn func(ctx context.Context, userID string, platformIDs []int32)) {
|
func (o *defaultOnlineCache) doSubscribe(ctx context.Context, rdb redis.UniversalClient, fn func(ctx context.Context, userID string, platformIDs []int32)) {
|
||||||
o.Lock.Lock()
|
o.Lock.Lock()
|
||||||
ch := rdb.Subscribe(ctx, cachekey.OnlineChannel).Channel()
|
ch := rdb.Subscribe(ctx, cachekey.OnlineChannel).Channel()
|
||||||
for o.CurrentPhase.Load() < DoOnlineStatusOver {
|
for o.CurrentPhase.Load() < DoOnlineStatusOver {
|
||||||
@ -186,7 +197,7 @@ func (o *OnlineCache) doSubscribe(ctx context.Context, rdb redis.UniversalClient
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (o *OnlineCache) getUserOnlinePlatform(ctx context.Context, userID string) ([]int32, error) {
|
func (o *defaultOnlineCache) getUserOnlinePlatform(ctx context.Context, userID string) ([]int32, error) {
|
||||||
platformIDs, err := o.lruCache.Get(userID, func() ([]int32, error) {
|
platformIDs, err := o.lruCache.Get(userID, func() ([]int32, error) {
|
||||||
return o.client.GetUserOnlinePlatform(ctx, userID)
|
return o.client.GetUserOnlinePlatform(ctx, userID)
|
||||||
})
|
})
|
||||||
@ -198,7 +209,7 @@ func (o *OnlineCache) getUserOnlinePlatform(ctx context.Context, userID string)
|
|||||||
return platformIDs, nil
|
return platformIDs, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (o *OnlineCache) GetUserOnlinePlatform(ctx context.Context, userID string) ([]int32, error) {
|
func (o *defaultOnlineCache) GetUserOnlinePlatform(ctx context.Context, userID string) ([]int32, error) {
|
||||||
platformIDs, err := o.getUserOnlinePlatform(ctx, userID)
|
platformIDs, err := o.getUserOnlinePlatform(ctx, userID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
@ -208,7 +219,7 @@ func (o *OnlineCache) GetUserOnlinePlatform(ctx context.Context, userID string)
|
|||||||
return platformIDs, nil
|
return platformIDs, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (o *OnlineCache) GetUserOnline(ctx context.Context, userID string) (bool, error) {
|
func (o *defaultOnlineCache) GetUserOnline(ctx context.Context, userID string) (bool, error) {
|
||||||
platformIDs, err := o.getUserOnlinePlatform(ctx, userID)
|
platformIDs, err := o.getUserOnlinePlatform(ctx, userID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return false, err
|
return false, err
|
||||||
@ -216,7 +227,7 @@ func (o *OnlineCache) GetUserOnline(ctx context.Context, userID string) (bool, e
|
|||||||
return len(platformIDs) > 0, nil
|
return len(platformIDs) > 0, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (o *OnlineCache) getUserOnlinePlatformBatch(ctx context.Context, userIDs []string) (map[string][]int32, error) {
|
func (o *defaultOnlineCache) getUserOnlinePlatformBatch(ctx context.Context, userIDs []string) (map[string][]int32, error) {
|
||||||
if len(userIDs) == 0 {
|
if len(userIDs) == 0 {
|
||||||
return nil, nil
|
return nil, nil
|
||||||
}
|
}
|
||||||
@ -240,7 +251,7 @@ func (o *OnlineCache) getUserOnlinePlatformBatch(ctx context.Context, userIDs []
|
|||||||
return platformIDsMap, nil
|
return platformIDsMap, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (o *OnlineCache) GetUsersOnline(ctx context.Context, userIDs []string) ([]string, []string, error) {
|
func (o *defaultOnlineCache) GetUsersOnline(ctx context.Context, userIDs []string) ([]string, []string, error) {
|
||||||
t := time.Now()
|
t := time.Now()
|
||||||
|
|
||||||
var (
|
var (
|
||||||
@ -276,7 +287,7 @@ func (o *OnlineCache) GetUsersOnline(ctx context.Context, userIDs []string) ([]s
|
|||||||
return onlineUserIDs, offlineUserIDs, nil
|
return onlineUserIDs, offlineUserIDs, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (o *OnlineCache) setUserOnline(userID string, platformIDs []int32) {
|
func (o *defaultOnlineCache) setUserOnline(userID string, platformIDs []int32) {
|
||||||
switch o.fullUserCache {
|
switch o.fullUserCache {
|
||||||
case true:
|
case true:
|
||||||
o.mapCache.Store(userID, platformIDs)
|
o.mapCache.Store(userID, platformIDs)
|
||||||
@ -285,6 +296,51 @@ func (o *OnlineCache) setUserOnline(userID string, platformIDs []int32) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (o *OnlineCache) setHasUserOnline(userID string, platformIDs []int32) bool {
|
func (o *defaultOnlineCache) setHasUserOnline(userID string, platformIDs []int32) bool {
|
||||||
return o.lruCache.SetHas(userID, platformIDs)
|
return o.lruCache.SetHas(userID, platformIDs)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (o *defaultOnlineCache) WaitCache() {
|
||||||
|
o.Lock.Lock()
|
||||||
|
for o.CurrentPhase.Load() < DoSubscribeOver {
|
||||||
|
o.Cond.Wait()
|
||||||
|
}
|
||||||
|
o.Lock.Unlock()
|
||||||
|
}
|
||||||
|
|
||||||
|
type disableOnlineCache struct {
|
||||||
|
client *rpcli.UserClient
|
||||||
|
}
|
||||||
|
|
||||||
|
func (o disableOnlineCache) GetUserOnlinePlatform(ctx context.Context, userID string) ([]int32, error) {
|
||||||
|
return o.client.GetUserOnlinePlatform(ctx, userID)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (o disableOnlineCache) GetUserOnline(ctx context.Context, userID string) (bool, error) {
|
||||||
|
onlinePlatform, err := o.client.GetUserOnlinePlatform(ctx, userID)
|
||||||
|
if err != nil {
|
||||||
|
return false, err
|
||||||
|
}
|
||||||
|
return len(onlinePlatform) > 0, err
|
||||||
|
}
|
||||||
|
|
||||||
|
func (o disableOnlineCache) GetUsersOnline(ctx context.Context, userIDs []string) ([]string, []string, error) {
|
||||||
|
var (
|
||||||
|
onlineUserIDs = make([]string, 0, len(userIDs))
|
||||||
|
offlineUserIDs = make([]string, 0, len(userIDs))
|
||||||
|
)
|
||||||
|
for _, userID := range userIDs {
|
||||||
|
online, err := o.GetUserOnline(ctx, userID)
|
||||||
|
if err != nil {
|
||||||
|
return nil, nil, err
|
||||||
|
}
|
||||||
|
if online {
|
||||||
|
onlineUserIDs = append(onlineUserIDs, userID)
|
||||||
|
} else {
|
||||||
|
offlineUserIDs = append(offlineUserIDs, userID)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return onlineUserIDs, offlineUserIDs, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (o disableOnlineCache) WaitCache() {}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user