Skip to content

Commit

Permalink
feat: room hot list need reged client
Browse files Browse the repository at this point in the history
  • Loading branch information
zijiren233 committed Oct 13, 2024
1 parent 2b5fb20 commit 676c4f8
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
10 changes: 5 additions & 5 deletions internal/op/room.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,26 +36,26 @@ func (r *Room) lazyInitHub() *Hub {
return h
}

func (r *Room) hubIsNotInited() bool {
func (r *Room) HubIsNotInited() bool {
return r.hub.Load() == nil
}

func (r *Room) ViewerCount() int64 {
if r.hubIsNotInited() {
if r.HubIsNotInited() {
return 0
}
return r.lazyInitHub().ClientNum()
}

func (r *Room) KickUser(userID string) error {
if r.hubIsNotInited() {
if r.HubIsNotInited() {
return nil
}
return r.lazyInitHub().KickUser(userID)
}

func (r *Room) Broadcast(data Message, conf ...BroadcastConf) error {
if r.hubIsNotInited() {
if r.HubIsNotInited() {
return nil
}
return r.lazyInitHub().Broadcast(data, conf...)
Expand All @@ -66,7 +66,7 @@ func (r *Room) SendToUser(user *User, data Message) error {
}

func (r *Room) SendToUserWithId(userID string, data Message) error {
if r.hubIsNotInited() {
if r.HubIsNotInited() {
return nil
}
return r.lazyInitHub().SendToUser(userID, data)
Expand Down
2 changes: 1 addition & 1 deletion server/handlers/room.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ var roomHotCache = refreshcache0.NewRefreshCache[[]*model.RoomListResp](func(con
rooms := make([]*model.RoomListResp, 0)
op.RangeRoomCache(func(key string, value *synccache.Entry[*op.Room]) bool {
v := value.Value()
if !v.Settings.Hidden && v.IsActive() {
if !v.Settings.Hidden && v.IsActive() && !v.HubIsNotInited() {
rooms = append(rooms, &model.RoomListResp{
RoomId: v.ID,
RoomName: v.Name,
Expand Down

0 comments on commit 676c4f8

Please sign in to comment.