Пример #1
0
// add user to room recent user list redis
// add user id to set, use Hash save user info
func (r *ActiveRoom) AddUserToRecent(user *model.User) {
	//add userinfo to Hash
	userKey := "user:"******"id":     strconv.Itoa(user.Id),
		"name":   user.Name,
		"avatar": user.AvatarUrl(),
	}

	redisClient.Hmset(userKey, userInfo)
	// add user id to room recent user list
	roomKey := "room:" + r.RoomKey + ":users"
	redisClient.Sadd(roomKey, []byte(strconv.Itoa(user.Id)))
}
Пример #2
0
func NewOnlineUser(user *model.User, ws *websocket.Conn, room *ActiveRoom) *OnlineUser {
	onlineUser := &OnlineUser{
		Id:         user.Id,
		Connection: ws,
		Send:       make(chan *Event, 512),
		Room:       room,

		Info: &UserInfo{
			Name:   user.Name,
			Email:  user.Email,
			Avatar: user.AvatarUrl(),
		},
	}

	return onlineUser
}