diff --git a/Application/Clavardage/src/controller/Controller.java b/Application/Clavardage/src/controller/Controller.java index 656333b..8f39d6b 100644 --- a/Application/Clavardage/src/controller/Controller.java +++ b/Application/Clavardage/src/controller/Controller.java @@ -38,6 +38,7 @@ public class Controller { private ListeningThreadUDP udp_connect_thread; private ListeningThreadTCPConnection tcp_connect_thread; private Historique histoire; + private Chat activeChat; /** * Constructor of Controller @@ -341,7 +342,7 @@ public class Controller { public void openSession(RemoteUser rm) { myUser.addChats(rm); Chat c = myUser.getChats().get(myUser.getChatIndexOf(rm)); - + this.activeChat = c; if(c.getActive()) { JOptionPane.showMessageDialog(null ,"Already a session with "+c.getRemoteUser().getPseudo()); } @@ -356,24 +357,26 @@ public class Controller { c.setSocket(link); JOptionPane.showMessageDialog(null ,"New session with "+c.getRemoteUser().getPseudo()); - // TODO Récupération de la conversation (historique) + + // RECUPERATION HISTORIQUE try { System.out.println(this.getHistory().retrieveMessage(getMyUser(), c.getRemoteUser())); } catch (SQLException e) { System.out.println("souci avec le retrieveMsg"); e.printStackTrace(); } - c.activate(); + + c.activate(); // } } public void closeSession(Chat c) { - sendMsg(new Msg_Text(myUser.getAddIP(),"end"), c); + sendMessage(new Msg_Text(myUser.getAddIP(),"end"), c); this.myUser.closeChat(c); } - public void sendMsg(Message msg,Chat c) { + public void sendMessage(Message msg,Chat c) { PrintWriter out=null; try { out = new PrintWriter(c.getUserSocket().getOutputStream(),true); @@ -402,69 +405,13 @@ public class Controller { } - // Plus utilisé - public void TCPmessage(int index) throws IOException { - Socket link=null; - String s1; - try { - link=new Socket(this.myUser.getRemoteUsersList().get(index).getAddIP(),this.myUser.getRemoteUsersList().get(index).getPortTCP()); - - System.out.println("Server is listening on port"+this.myUser.getPortTCP()+"of localhost"); - }catch(IOException e) { - - System.out.println("Server is not listening on port"+this.myUser.getPortTCP()+" of localhost"); - - } - BufferedReader in=null; - try { - in = new BufferedReader(new InputStreamReader(link.getInputStream())); - } catch (IOException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - try { - PrintWriter out = new PrintWriter(link.getOutputStream(),true); - } catch (IOException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - String input; - String dateString; - Date date; - Calendar date1=Calendar.getInstance(); - - String s2 = (this.myUser.getPseudo()+" reçoit un message"); - try { - while (!(input=in.readLine()).equals("end")) { - System.out.print("client_recoit:"+input); - date=new Date(); - date1.setTime(date); - dateString=date1.toString(); - - this.getHistory().saveMessage(this.getMyUser(), getMyUser().getRemoteUsersList().get(index),input ,dateString ); - } - } catch (IOException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - /*or (int i=0; i<4; i++) { - System.out.println("client envoie"); - out.println("coucou \n"); - } - out.println("end");*/ - try { - link.close(); - } catch (IOException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } + public void askToSend(String textMessage){ + sendMessage(new Msg_Text(myUser.getAddIP(),textMessage), this.activeChat); + } - - - /********************* Fonction debug console => A mettre dans l'interface ******************************************/ /** @@ -524,9 +471,8 @@ public class Controller { ctr1.interfaceRunning =true; ctr1.view=Interface.createAndShowGUI(ctr1); - /** Simulation of a session **/ - - + /** Simulation of a session 1 message **/ + /* // AFFICHAGE REMOTE USER CHOISIE System.out.println("("+ctr1.myUser.getPseudo()+" ) OPEN SESSION WITH "+ctr1.myUser.getRemoteUsersList().get(0).getPseudo()); // SELECTION DE L UTILISATEUR @@ -536,10 +482,10 @@ public class Controller { // RECUPERATION DE LA CONVERSATION Chat chatwithrm0 = ctr1.myUser.getChats().get(ctr1.myUser.getChatIndexOf(rm0)); // SEND MESSAGE - ctr1.sendMsg(new Msg_Text(ctr1.myUser.getAddIP(),"test"), chatwithrm0); + ctr1.sendMessage(new Msg_Text(ctr1.myUser.getAddIP(),"test"), chatwithrm0); // CLOSE SESSION ctr1.closeSession(chatwithrm0); - + */ /** Unused function **/ // MANUAL SELECTION OF ACTIVE USER diff --git a/Application/Clavardage/src/view/Interface.java b/Application/Clavardage/src/view/Interface.java index b524d1e..56cec7f 100644 --- a/Application/Clavardage/src/view/Interface.java +++ b/Application/Clavardage/src/view/Interface.java @@ -107,6 +107,7 @@ public class Interface extends JFrame implements ActionListener, WindowListener String Textinput = MessagetextField.getText(); Messagelabel.setText("Message: " + Textinput); //TODO mettre Textinput dans la database + controller.askToSend(Textinput); MessagetextField.setText(""); }else if(e.getSource() == RemoteUserButton) { //Shows remote user list RemoteUserbox.setVisible(true);