saveMessage integrated in new function (sendMsg)
This commit is contained in:
parent
c9e317bd27
commit
5b1b1663db
2 changed files with 36 additions and 6 deletions
|
@ -53,7 +53,8 @@ public class Controller {
|
|||
* </p>
|
||||
*/
|
||||
private Controller(int portUDPsend,int portUDPlistening,int portTCP) {
|
||||
this.histoire=histoire;
|
||||
this.histoire= new Historique();
|
||||
|
||||
InetAddress addIP = null;
|
||||
try
|
||||
{
|
||||
|
@ -352,11 +353,30 @@ public class Controller {
|
|||
e.printStackTrace();
|
||||
}
|
||||
|
||||
DateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
|
||||
Date date = new Date();
|
||||
out.println(dateFormat.format(date));
|
||||
String message = (String) msg.getMessage(); // TODO check if instance of Msg_Text or anything else and threat it given a type
|
||||
|
||||
out.println(msg.getMessage());
|
||||
// Date l'envoie du message
|
||||
String dateString;
|
||||
Date date;
|
||||
Calendar date1=Calendar.getInstance();
|
||||
date = new Date();
|
||||
date1.setTime(date);
|
||||
dateString=date1.toString();
|
||||
|
||||
/*
|
||||
System.out.println(this.getHistory());
|
||||
System.out.println(this.myUser.getPseudo());
|
||||
System.out.println(c.getRemoteUser().getPseudo());
|
||||
System.out.println(message);
|
||||
System.out.println(dateString);
|
||||
*/
|
||||
// Sauvegarde dans la base de données
|
||||
//this.getHistory().saveMessage(this.myUser, c.getRemoteUser(),message ,dateString);
|
||||
|
||||
// Envoie du message (avec la date)
|
||||
DateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
|
||||
out.println(dateFormat.format(date));
|
||||
out.println(message);
|
||||
}
|
||||
|
||||
// Plus utilisé
|
||||
|
@ -397,6 +417,7 @@ public class Controller {
|
|||
date=new Date();
|
||||
date1.setTime(date);
|
||||
dateString=date1.toString();
|
||||
|
||||
this.getHistory().saveMessage(this.getMyUser(), getMyUser().getRemoteUsersList().get(index),input ,dateString );
|
||||
}
|
||||
} catch (IOException e) {
|
||||
|
|
|
@ -9,6 +9,7 @@ import java.io.PrintWriter;
|
|||
import java.net.Socket;
|
||||
import java.text.DateFormat;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Calendar;
|
||||
import java.util.Date;
|
||||
|
||||
public class ListeningThreadTCPChat extends ListeningThread{
|
||||
|
@ -38,6 +39,12 @@ public class ListeningThreadTCPChat extends ListeningThread{
|
|||
public void run() {
|
||||
BufferedReader in = null;
|
||||
String msg = null;
|
||||
String input;
|
||||
String dateString;
|
||||
Date date;
|
||||
Calendar date1=Calendar.getInstance();
|
||||
//RemoteUser rm; // TODO retrouver l'utilisateur distant
|
||||
|
||||
try {
|
||||
System.out.println("("+this.controller.myUser.getPseudo()+") WAIT FOR NEW MESSAGE ");
|
||||
in =new BufferedReader(new InputStreamReader(this.socket.getInputStream()));
|
||||
|
@ -45,10 +52,12 @@ public class ListeningThreadTCPChat extends ListeningThread{
|
|||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
String input;
|
||||
try {
|
||||
while (!(input=in.readLine()).equals("end")) {
|
||||
System.out.println("("+this.controller.myUser.getPseudo()+") recoit : "+input);
|
||||
// TODO save history (we have to choose to save it when message is receive or sent)
|
||||
//this.controller.getHistory().saveMessage(this.controller.myUser, rm,input ,dateString );
|
||||
|
||||
}
|
||||
} catch (IOException e) {
|
||||
// TODO Auto-generated catch block
|
||||
|
|
Loading…
Reference in a new issue