Example #1
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())));
 }
Example #2
0
 public static void saveUnreadMessages() {
   for (int i = ChatHistory.instance.getTotal() - 1; 0 <= i; --i) {
     Chat chat = ChatHistory.instance.chatAt(i);
     int unreadMessageCount = chat.getAllUnreadMessageCount();
     if (unreadMessageCount == 0) {
       if (!Options.getBoolean(JLocale.getString(R.string.pref_history))) {
         HistoryStorage historyStorage = chat.getHistory();
         historyStorage.removeHistory();
       }
     }
   }
 }
Example #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;
 }
Example #4
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;
 }
Example #5
0
 public static Drawable getImageChat(Chat chat, boolean showMess) {
   if (chat.getContact().isTyping()) {
     return Message.getIcon(Message.ICON_TYPE);
   } else {
     Icon icStatus =
         RosterHelper.getInstance()
             .getProtocol()
             .getStatusInfo()
             .getIcon(chat.getContact().getStatusIndex());
     Drawable icMess = Message.getIcon(chat.getNewMessageIcon());
     if (icMess != null) {
       if (icMess == SawimResources.PERSONAL_MESSAGE_ICON) {
         icMess = icMess.getConstantState().newDrawable();
         icMess.setColorFilter(
             Scheme.getColor(R.attr.personal_unread_message), PorterDuff.Mode.MULTIPLY);
       } else {
         icMess = icMess.getConstantState().newDrawable();
         icMess.setColorFilter(Scheme.getColor(R.attr.unread_message), PorterDuff.Mode.MULTIPLY);
       }
     }
     return icMess == null || !showMess ? icStatus.getImage() : icMess;
   }
 }