package chat;

import java.util.Vector;

public class TextChatRoom implements ChatRoom {

	Vector<Chatter> participants;
	String topic;
	TextChatter chatId;
	
	public TextChatRoom (String topic) {
		this.topic = topic;
		chatId = new TextChatter("Chatroom " + topic);
		participants = new Vector<Chatter>();
		System.out.println("new text ChatRoom created with topic : "+topic);
	}
	
	public void rejoindre(Chatter bob) {
		participants.add(bob);
		poster(bob.getPseudo()+" a rejoint la room.",chatId);
	}

	public void quitter(Chatter bob) {
		participants.remove(bob);
		poster(bob.getPseudo()+" a quitté la room.",chatId);
	}

	public String getTopic() {
		return topic;
	}

	public void poster(String message, Chatter auteur) {
		for (int i = 0 ; i < participants.size() ; i++) {
			Chatter c = participants.get(i);
			if (! auteur.equals(c))
				c.recevoirMessage(message,auteur);
		}
	}

}
