mirror of
				https://github.com/openimsdk/open-im-server.git
				synced 2025-10-26 21:22:16 +08:00 
			
		
		
		
	* 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: support client config * feat: support client config
		
			
				
	
	
		
			70 lines
		
	
	
		
			1.8 KiB
		
	
	
	
		
			Go
		
	
	
	
	
	
			
		
		
	
	
			70 lines
		
	
	
		
			1.8 KiB
		
	
	
	
		
			Go
		
	
	
	
	
	
| package redis
 | |
| 
 | |
| import (
 | |
| 	"context"
 | |
| 	"time"
 | |
| 
 | |
| 	"github.com/openimsdk/open-im-server/v3/pkg/common/storage/cache"
 | |
| 	"github.com/openimsdk/open-im-server/v3/pkg/common/storage/cache/cachekey"
 | |
| 	"github.com/openimsdk/open-im-server/v3/pkg/common/storage/database"
 | |
| 	"github.com/redis/go-redis/v9"
 | |
| )
 | |
| 
 | |
| func NewClientConfigCache(rdb redis.UniversalClient, mgo database.ClientConfig) cache.ClientConfigCache {
 | |
| 	rc := newRocksCacheClient(rdb)
 | |
| 	return &ClientConfigCache{
 | |
| 		mgo:      mgo,
 | |
| 		rcClient: rc,
 | |
| 		delete:   rc.GetBatchDeleter(),
 | |
| 	}
 | |
| }
 | |
| 
 | |
| type ClientConfigCache struct {
 | |
| 	mgo      database.ClientConfig
 | |
| 	rcClient *rocksCacheClient
 | |
| 	delete   cache.BatchDeleter
 | |
| }
 | |
| 
 | |
| func (x *ClientConfigCache) getExpireTime(userID string) time.Duration {
 | |
| 	if userID == "" {
 | |
| 		return time.Hour * 24
 | |
| 	} else {
 | |
| 		return time.Hour
 | |
| 	}
 | |
| }
 | |
| 
 | |
| func (x *ClientConfigCache) getClientConfigKey(userID string) string {
 | |
| 	return cachekey.GetClientConfigKey(userID)
 | |
| }
 | |
| 
 | |
| func (x *ClientConfigCache) GetConfig(ctx context.Context, userID string) (map[string]string, error) {
 | |
| 	return getCache(ctx, x.rcClient, x.getClientConfigKey(userID), x.getExpireTime(userID), func(ctx context.Context) (map[string]string, error) {
 | |
| 		return x.mgo.Get(ctx, userID)
 | |
| 	})
 | |
| }
 | |
| 
 | |
| func (x *ClientConfigCache) DeleteUserCache(ctx context.Context, userIDs []string) error {
 | |
| 	keys := make([]string, 0, len(userIDs))
 | |
| 	for _, userID := range userIDs {
 | |
| 		keys = append(keys, x.getClientConfigKey(userID))
 | |
| 	}
 | |
| 	return x.delete.ExecDelWithKeys(ctx, keys)
 | |
| }
 | |
| 
 | |
| func (x *ClientConfigCache) GetUserConfig(ctx context.Context, userID string) (map[string]string, error) {
 | |
| 	config, err := x.GetConfig(ctx, "")
 | |
| 	if err != nil {
 | |
| 		return nil, err
 | |
| 	}
 | |
| 	if userID != "" {
 | |
| 		userConfig, err := x.GetConfig(ctx, userID)
 | |
| 		if err != nil {
 | |
| 			return nil, err
 | |
| 		}
 | |
| 		for k, v := range userConfig {
 | |
| 			config[k] = v
 | |
| 		}
 | |
| 	}
 | |
| 	return config, nil
 | |
| }
 |