Esempio n. 1
0
 private static MessData buildMessage(Chat chat, Cursor cursor) {
   Contact contact = chat.getContact();
   int sendingState = cursor.getInt(cursor.getColumnIndex(DatabaseHelper.SENDING_STATE));
   boolean isIncoming = cursor.getInt(cursor.getColumnIndex(DatabaseHelper.INCOMING)) == 0;
   String from = cursor.getString(cursor.getColumnIndex(DatabaseHelper.AUTHOR));
   String text = cursor.getString(cursor.getColumnIndex(DatabaseHelper.MESSAGE));
   long date = cursor.getLong(cursor.getColumnIndex(DatabaseHelper.DATE));
   short rowData = cursor.getShort(cursor.getColumnIndex(DatabaseHelper.ROW_DATA));
   // String serverMsgId = cursor.getString(cursor.getColumnIndex(DatabaseHelper.SERVER_MSG_ID));
   PlainMessage message;
   if (isIncoming) {
     message = new PlainMessage(from, chat.getProtocol(), date, text, true);
   } else {
     message = new PlainMessage(chat.getProtocol(), contact.getUserId(), date, text);
   }
   // message.setServerMsgId(serverMsgId);
   MessData messData;
   if (rowData == 0) {
     messData =
         Chat.buildMessage(
             contact,
             message,
             contact.isConference() ? from : chat.getFrom(message),
             false,
             isIncoming
                 ? Chat.isHighlight(message.getProcessedText(), contact.getMyName())
                 : false);
   } else if ((rowData & MessData.ME) != 0 || (rowData & MessData.PRESENCE) != 0) {
     messData = new MessData(contact, message.getNewDate(), text, from, rowData);
   } else {
     messData =
         Chat.buildMessage(
             contact,
             message,
             contact.isConference() ? from : chat.getFrom(message),
             rowData,
             Chat.isHighlight(message.getProcessedText(), contact.getMyName()));
   }
   if (!message.isIncoming() && !messData.isMe()) {
     messData.setIconIndex((byte) sendingState);
   }
   return messData;
 }
Esempio n. 2
0
 public void addMessageToHistory(
     Contact contact, Message message, String from, boolean isSystemNotice) {
   addText(
       Chat.buildMessage(
           contact,
           message,
           from,
           isSystemNotice,
           Chat.isHighlight(message.getProcessedText(), contact.getMyName())));
 }
Esempio n. 3
0
 public synchronized boolean hasLastMessage(Chat chat, Message message) {
   Contact contact = chat.getContact();
   boolean hasMessage = false;
   Cursor cursor = null;
   try {
     cursor =
         SawimApplication.getDatabaseHelper()
             .getReadableDatabase()
             .query(
                 DatabaseHelper.TABLE_CHAT_HISTORY,
                 null,
                 DatabaseHelper.CONTACT_ID + " = ?",
                 new String[] {uniqueUserId},
                 null,
                 null,
                 DatabaseHelper.DATE + " DESC",
                 String.valueOf(60));
     if (cursor.moveToLast()) {
       do {
         short rowData = cursor.getShort(cursor.getColumnIndex(DatabaseHelper.ROW_DATA));
         MessData mess =
             Chat.buildMessage(
                 contact,
                 message,
                 contact.isConference() ? message.getName() : chat.getFrom(message),
                 false,
                 Chat.isHighlight(message.getProcessedText(), contact.getMyName()));
         MessData messFromDataBase = buildMessage(chat, cursor);
         boolean isMessage =
             (rowData & MessData.PRESENCE) == 0
                 && (rowData & MessData.SERVICE) == 0
                 && (rowData & MessData.PROGRESS) == 0;
         if (isMessage) {
           hasMessage = hasMessage(mess, messFromDataBase);
           if (hasMessage) {
             return true;
           }
         }
       } while (cursor.moveToPrevious());
     }
   } catch (Exception e) {
     DebugLog.panic(e);
   } finally {
     if (cursor != null) {
       cursor.close();
     }
   }
   return hasMessage;
 }