2023-02-02 19:40:54 +08:00
|
|
|
package localcache
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"context"
|
2023-03-16 10:46:06 +08:00
|
|
|
"github.com/OpenIMSDK/Open-IM-Server/pkg/common/config"
|
|
|
|
|
"github.com/OpenIMSDK/Open-IM-Server/pkg/discoveryregistry"
|
|
|
|
|
"github.com/OpenIMSDK/Open-IM-Server/pkg/proto/conversation"
|
2023-02-02 19:40:54 +08:00
|
|
|
"sync"
|
|
|
|
|
)
|
|
|
|
|
|
2023-02-08 17:56:04 +08:00
|
|
|
type ConversationLocalCacheInterface interface {
|
2023-02-09 14:40:49 +08:00
|
|
|
GetRecvMsgNotNotifyUserIDs(ctx context.Context, groupID string) ([]string, error)
|
2023-02-08 17:56:04 +08:00
|
|
|
}
|
|
|
|
|
|
2023-02-02 19:40:54 +08:00
|
|
|
type ConversationLocalCache struct {
|
|
|
|
|
lock sync.Mutex
|
|
|
|
|
SuperGroupRecvMsgNotNotifyUserIDs map[string][]string
|
2023-02-23 17:28:57 +08:00
|
|
|
client discoveryregistry.SvcDiscoveryRegistry
|
2023-02-02 19:40:54 +08:00
|
|
|
}
|
|
|
|
|
|
2023-03-03 17:42:26 +08:00
|
|
|
func NewConversationLocalCache(client discoveryregistry.SvcDiscoveryRegistry) *ConversationLocalCache {
|
|
|
|
|
return &ConversationLocalCache{
|
2023-02-02 19:40:54 +08:00
|
|
|
SuperGroupRecvMsgNotNotifyUserIDs: make(map[string][]string, 0),
|
2023-02-08 18:29:11 +08:00
|
|
|
client: client,
|
2023-02-02 19:40:54 +08:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-02-09 14:40:49 +08:00
|
|
|
func (g *ConversationLocalCache) GetRecvMsgNotNotifyUserIDs(ctx context.Context, groupID string) ([]string, error) {
|
2023-02-23 17:28:57 +08:00
|
|
|
conn, err := g.client.GetConn(config.Config.RpcRegisterName.OpenImConversationName)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return nil, err
|
|
|
|
|
}
|
|
|
|
|
client := conversation.NewConversationClient(conn)
|
|
|
|
|
resp, err := client.GetRecvMsgNotNotifyUserIDs(ctx, &conversation.GetRecvMsgNotNotifyUserIDsReq{
|
|
|
|
|
GroupID: groupID,
|
|
|
|
|
})
|
|
|
|
|
if err != nil {
|
|
|
|
|
return nil, err
|
|
|
|
|
}
|
|
|
|
|
return resp.UserIDs, nil
|
2023-02-02 19:40:54 +08:00
|
|
|
}
|