Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static boolean Leer_conversaciones (List <Map<String,String>> lista_conversaciones, Connection connection, String id_chat, int ultimo_id_conversacion, String [] error){
- boolean ret = true;
- String comando = "select id_conversacion, texto, ref_usuario "
- + "from conversaciones "
- + "where id_conversacion > ? " //Desde el último recibido.
- + "and ref_chat = ? "
- + "order by "
- + "id_conversacion " // Ordenadas por el id_conversacion
- + "asc ";
- if (ultimo_id_conversacion == 0){ //Mi primera conexión.
- comando = comando + "limit 50"; //Las 50 últimas.
- } //De mayor a menor
- try {
- PreparedStatement preparestatement=connection.prepareStatement(comando);
- preparestatement.setInt(1, ultimo_id_conversacion);
- preparestatement.setString(2, id_chat);
- ResultSet resultset = preparestatement.executeQuery();
- while (resultset.next()){
- String mensaje = resultset.getString("texto");
- int tam = mensaje.length();
- if (tam > 60){
- int i = 60;
- StringBuilder stringbuilder = new StringBuilder();
- stringbuilder.append(mensaje);
- while (true){
- if (stringbuilder.charAt(i) == ' ' || i >= stringbuilder.length()-1){
- stringbuilder.insert(i,"\n");
- break;
- }
- i++;
- }
- if (tam > 120){
- i = 120;
- while (true){
- if (stringbuilder.charAt(i) == ' ' || i >= stringbuilder.length()-1){
- stringbuilder.insert(i,"\n");
- break;
- }
- i++;
- }
- }
- if (tam > 180){
- i = 180;
- while (true){
- if (stringbuilder.charAt(i) == ' ' || i >= stringbuilder.length()-1){
- stringbuilder.insert(i,"\n");
- break;
- }
- i++;
- }
- }
- if (tam > 240){
- i = 240;
- while (true){
- if (stringbuilder.charAt(i) == ' ' || i >= stringbuilder.length()-1){
- stringbuilder.insert(i,"\n");
- break;
- }
- i++;
- }
- }
- mensaje = stringbuilder.toString();
- }
- String usuario = resultset.getString("ref_usuario");
- String id_conversacion = resultset.getString("id_conversacion");
- Map <String, String> entrada = new HashMap();
- entrada.put("texto", mensaje);
- entrada.put("usuario", usuario);
- entrada.put("id_conversacion", id_conversacion);
- lista_conversaciones.add(entrada);
- }
- preparestatement.close();
- resultset.close();
- }
- catch (Exception e){
- String mensaje = e.getMessage();
- if (mensaje == null) {
- mensaje = "";
- }
- error [0] = java.text.MessageFormat.format(java.util.ResourceBundle.getBundle("recursos/Bundle_controladores_clases_chats").getString("ERROR AL ACCEDER A LA CUENTA {0}"), new Object[] {mensaje});
- ret = false;
- }
- return ret;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement