<commit_before>##
# Copyright 2012 <NAME> < <EMAIL> >.
#
# This file is part of SpotifyDJ.
#
# SpotifyDJ is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# SpotifyDJ is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with SpotifyDJ.If not, see <http://www.gnu.org/licenses/>.
##

class Room extends EventEmitter
	constructor: (@webService, @model, @user) ->
		@_clear()


	_clear: () ->
		@name = null;
		@player = null;
		@trackQueue = null;
		@currentTrack = null;

	enter: (@name) =>
		@emitEvent('enter');
		return @refreshTrackQueue()
	exit: () -> @_clear();

	haveMyVote: (uri) =>
		for elem in @trackQueue
			if elem.track.uri == uri
				for vote in elem.votes
					if (vote.id == @user.getId())
						return true;
		return false;

	buildTrackQueue: (roomData) ->
		res = []
		for elem in roomData.queue
			data = {};
			data.track = elem.track;
			data.votes = elem.votes;
			data.haveMyVote = false;
			for user in elem.votes
				if (@user.getId() == user.id)
					data.haveMyVote = true;
					break;
			res.push(data);
		return res;

	buildCurrentTrack: (roomData) ->
		if (!roomData.currentTrack)
			return null;
		data = {};
		data.track = roomData.currentTrack.track;
		data.votes = roomData.currentTrack.votes;
		return data;

	buildPlayer: (roomData) -> roomData.players.length != 0;

	refreshTrackQueue: () ->
		p = @webService.query("room/#{@name}");
		p.catch () => @_clear();
		return p.then (data) =>
			@player = @buildPlayer(data);
			@trackQueue = @buildTrackQueue(data);
			@currentTrack = @buildCurrentTrack(data);
<commit_msg>Remove bug that make the room change to null<commit_after>##
# Copyright 2012 <NAME> < <EMAIL> >.
#
# This file is part of SpotifyDJ.
#
# SpotifyDJ is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# SpotifyDJ is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with SpotifyDJ.If not, see <http://www.gnu.org/licenses/>.
##

class Room extends EventEmitter
	constructor: (@webService, @model, @user) ->
		@_clear()


	_clear: () ->
		@name = null;
		@player = null;
		@trackQueue = null;
		@currentTrack = null;

	enter: (@name) =>
		@emitEvent('enter');
		return @refreshTrackQueue()
	exit: () -> @_clear();

	haveMyVote: (uri) =>
		for elem in @trackQueue
			if elem.track.uri == uri
				for vote in elem.votes
					if (vote.id == @user.getId())
						return true;
		return false;

	buildTrackQueue: (roomData) ->
		res = []
		for elem in roomData.queue
			data = {};
			data.track = elem.track;
			data.votes = elem.votes;
			data.haveMyVote = false;
			for user in elem.votes
				if (@user.getId() == user.id)
					data.haveMyVote = true;
					break;
			res.push(data);
		return res;

	buildCurrentTrack: (roomData) ->
		if (!roomData.currentTrack)
			return null;
		data = {};
		data.track = roomData.currentTrack.track;
		data.votes = roomData.currentTrack.votes;
		return data;

	buildPlayer: (roomData) -> roomData.players.length != 0;

	refreshTrackQueue: () ->
		p = @webService.query("room/#{@name}");
		return p.then (data) =>
			@player = @buildPlayer(data);
			@trackQueue = @buildTrackQueue(data);
			@currentTrack = @buildCurrentTrack(data);

{'fraction_non_alphanumeric': 0.1272590361445783, 'fraction_numerical': 0.0030120481927710845, 'mean_word_length': 3.559496567505721, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 32, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2464009', 'n_tokens_mistral': 1431, 'n_tokens_neox': 1269, 'n_words': 422}