|
|
@ -28,7 +28,7 @@ func NewOnlineCache(user rpcclient.UserRpcClient, group *GroupLocalCache, rdb re
|
|
|
|
for message := range rdb.Subscribe(ctx, cachekey.OnlineChannel).Channel() {
|
|
|
|
for message := range rdb.Subscribe(ctx, cachekey.OnlineChannel).Channel() {
|
|
|
|
userID, platformIDs, err := useronline.ParseUserOnlineStatus(message.Payload)
|
|
|
|
userID, platformIDs, err := useronline.ParseUserOnlineStatus(message.Payload)
|
|
|
|
if err != nil {
|
|
|
|
if err != nil {
|
|
|
|
log.ZError(ctx, "OnlineCache redis subscribe parseUserOnlineStatus", err, "payload", message.Payload, "channel", message.Channel)
|
|
|
|
log.ZError(ctx, "OnlineCache setUserOnline redis subscribe parseUserOnlineStatus", err, "payload", message.Payload, "channel", message.Channel)
|
|
|
|
continue
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
}
|
|
|
|
storageCache := x.setUserOnline(userID, platformIDs)
|
|
|
|
storageCache := x.setUserOnline(userID, platformIDs)
|
|
|
@ -48,9 +48,15 @@ type OnlineCache struct {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func (o *OnlineCache) GetUserOnlinePlatform(ctx context.Context, userID string) ([]int32, error) {
|
|
|
|
func (o *OnlineCache) GetUserOnlinePlatform(ctx context.Context, userID string) ([]int32, error) {
|
|
|
|
return o.local.Get(userID, func() ([]int32, error) {
|
|
|
|
platformIDs, err := o.local.Get(userID, func() ([]int32, error) {
|
|
|
|
return o.user.GetUserOnlinePlatform(ctx, userID)
|
|
|
|
return o.user.GetUserOnlinePlatform(ctx, userID)
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
|
|
|
|
log.ZError(ctx, "OnlineCache GetUserOnlinePlatform", err, "userID", userID)
|
|
|
|
|
|
|
|
return nil, err
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
log.ZDebug(ctx, "OnlineCache GetUserOnlinePlatform", "userID", userID, "platformIDs", platformIDs)
|
|
|
|
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func (o *OnlineCache) GetUserOnline(ctx context.Context, userID string) (bool, error) {
|
|
|
|
func (o *OnlineCache) GetUserOnline(ctx context.Context, userID string) (bool, error) {
|
|
|
@ -61,39 +67,39 @@ func (o *OnlineCache) GetUserOnline(ctx context.Context, userID string) (bool, e
|
|
|
|
return len(platformIDs) > 0, nil
|
|
|
|
return len(platformIDs) > 0, nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func (o *OnlineCache) GetUsersOnline(ctx context.Context, userIDs []string) ([]string, error) {
|
|
|
|
//func (o *OnlineCache) GetUsersOnline(ctx context.Context, userIDs []string) ([]string, error) {
|
|
|
|
onlineUserIDs := make([]string, 0, len(userIDs))
|
|
|
|
// onlineUserIDs := make([]string, 0, len(userIDs))
|
|
|
|
for _, userID := range userIDs {
|
|
|
|
// for _, userID := range userIDs {
|
|
|
|
online, err := o.GetUserOnline(ctx, userID)
|
|
|
|
// online, err := o.GetUserOnline(ctx, userID)
|
|
|
|
if err != nil {
|
|
|
|
// if err != nil {
|
|
|
|
return nil, err
|
|
|
|
// return nil, err
|
|
|
|
}
|
|
|
|
// }
|
|
|
|
if online {
|
|
|
|
// if online {
|
|
|
|
onlineUserIDs = append(onlineUserIDs, userID)
|
|
|
|
// onlineUserIDs = append(onlineUserIDs, userID)
|
|
|
|
}
|
|
|
|
// }
|
|
|
|
}
|
|
|
|
// }
|
|
|
|
log.ZDebug(ctx, "OnlineCache GetUsersOnline", "userIDs", userIDs, "onlineUserIDs", onlineUserIDs)
|
|
|
|
// log.ZDebug(ctx, "OnlineCache GetUsersOnline", "userIDs", userIDs, "onlineUserIDs", onlineUserIDs)
|
|
|
|
return onlineUserIDs, nil
|
|
|
|
// return onlineUserIDs, nil
|
|
|
|
}
|
|
|
|
//}
|
|
|
|
|
|
|
|
//
|
|
|
|
func (o *OnlineCache) GetGroupOnline(ctx context.Context, groupID string) ([]string, error) {
|
|
|
|
//func (o *OnlineCache) GetGroupOnline(ctx context.Context, groupID string) ([]string, error) {
|
|
|
|
userIDs, err := o.group.GetGroupMemberIDs(ctx, groupID)
|
|
|
|
// userIDs, err := o.group.GetGroupMemberIDs(ctx, groupID)
|
|
|
|
if err != nil {
|
|
|
|
// if err != nil {
|
|
|
|
return nil, err
|
|
|
|
// return nil, err
|
|
|
|
}
|
|
|
|
// }
|
|
|
|
var onlineUserIDs []string
|
|
|
|
// var onlineUserIDs []string
|
|
|
|
for _, userID := range userIDs {
|
|
|
|
// for _, userID := range userIDs {
|
|
|
|
online, err := o.GetUserOnline(ctx, userID)
|
|
|
|
// online, err := o.GetUserOnline(ctx, userID)
|
|
|
|
if err != nil {
|
|
|
|
// if err != nil {
|
|
|
|
return nil, err
|
|
|
|
// return nil, err
|
|
|
|
}
|
|
|
|
// }
|
|
|
|
if online {
|
|
|
|
// if online {
|
|
|
|
onlineUserIDs = append(onlineUserIDs, userID)
|
|
|
|
// onlineUserIDs = append(onlineUserIDs, userID)
|
|
|
|
}
|
|
|
|
// }
|
|
|
|
}
|
|
|
|
// }
|
|
|
|
log.ZDebug(ctx, "OnlineCache GetGroupOnline", "groupID", groupID, "onlineUserIDs", onlineUserIDs, "allUserID", userIDs)
|
|
|
|
// log.ZDebug(ctx, "OnlineCache GetGroupOnline", "groupID", groupID, "onlineUserIDs", onlineUserIDs, "allUserID", userIDs)
|
|
|
|
return onlineUserIDs, nil
|
|
|
|
// return onlineUserIDs, nil
|
|
|
|
}
|
|
|
|
//}
|
|
|
|
|
|
|
|
|
|
|
|
func (o *OnlineCache) setUserOnline(userID string, platformIDs []int32) bool {
|
|
|
|
func (o *OnlineCache) setUserOnline(userID string, platformIDs []int32) bool {
|
|
|
|
return o.local.SetHas(userID, platformIDs)
|
|
|
|
return o.local.SetHas(userID, platformIDs)
|
|
|
|