Search in sources :

Example 1 with MessageRecord

use of org.thoughtcrime.securesms.database.model.MessageRecord in project Signal-Android by WhisperSystems.

the class ConversationAdapter method findLastSeenPosition.

public int findLastSeenPosition(long lastSeen) {
    if (lastSeen <= 0)
        return -1;
    if (!isActiveCursor())
        return -1;
    int count = getItemCount();
    for (int i = 0; i < count; i++) {
        Cursor cursor = getCursorAtPositionOrThrow(i);
        MessageRecord messageRecord = getMessageRecord(cursor);
        if (messageRecord.isOutgoing() || messageRecord.getDateReceived() <= lastSeen) {
            return i;
        }
    }
    return -1;
}
Also used : MessageRecord(org.thoughtcrime.securesms.database.model.MessageRecord) MmsMessageRecord(org.thoughtcrime.securesms.database.model.MmsMessageRecord) Cursor(android.database.Cursor)

Example 2 with MessageRecord

use of org.thoughtcrime.securesms.database.model.MessageRecord in project Signal-Android by WhisperSystems.

the class ConversationAdapter method getReceivedTimestamp.

public long getReceivedTimestamp(int position) {
    if (!isActiveCursor())
        return 0;
    if (isHeaderPosition(position))
        return 0;
    if (isFooterPosition(position))
        return 0;
    if (position >= getItemCount())
        return 0;
    if (position < 0)
        return 0;
    Cursor cursor = getCursorAtPositionOrThrow(position);
    MessageRecord messageRecord = getMessageRecord(cursor);
    if (messageRecord.isOutgoing())
        return 0;
    else
        return messageRecord.getDateReceived();
}
Also used : MessageRecord(org.thoughtcrime.securesms.database.model.MessageRecord) MmsMessageRecord(org.thoughtcrime.securesms.database.model.MmsMessageRecord) Cursor(android.database.Cursor)

Example 3 with MessageRecord

use of org.thoughtcrime.securesms.database.model.MessageRecord in project Signal-Android by WhisperSystems.

the class ConversationAdapter method getHeaderId.

@Override
public long getHeaderId(int position) {
    if (!isActiveCursor())
        return -1;
    if (isHeaderPosition(position))
        return -1;
    if (isFooterPosition(position))
        return -1;
    if (position >= getItemCount())
        return -1;
    if (position < 0)
        return -1;
    Cursor cursor = getCursorAtPositionOrThrow(position);
    MessageRecord record = getMessageRecord(cursor);
    calendar.setTime(new Date(record.getDateSent()));
    return Util.hashCode(calendar.get(Calendar.YEAR), calendar.get(Calendar.DAY_OF_YEAR));
}
Also used : MessageRecord(org.thoughtcrime.securesms.database.model.MessageRecord) MmsMessageRecord(org.thoughtcrime.securesms.database.model.MmsMessageRecord) Cursor(android.database.Cursor) Date(java.util.Date)

Example 4 with MessageRecord

use of org.thoughtcrime.securesms.database.model.MessageRecord in project Signal-Android by WhisperSystems.

the class ConversationAdapter method getMessageRecord.

private MessageRecord getMessageRecord(Cursor cursor) {
    long messageId = cursor.getLong(cursor.getColumnIndexOrThrow(MmsSmsColumns.ID));
    String type = cursor.getString(cursor.getColumnIndexOrThrow(MmsSmsDatabase.TRANSPORT));
    final SoftReference<MessageRecord> reference = messageRecordCache.get(type + messageId);
    if (reference != null) {
        final MessageRecord record = reference.get();
        if (record != null)
            return record;
    }
    final MessageRecord messageRecord = db.readerFor(cursor, masterSecret).getCurrent();
    messageRecordCache.put(type + messageId, new SoftReference<>(messageRecord));
    return messageRecord;
}
Also used : MessageRecord(org.thoughtcrime.securesms.database.model.MessageRecord) MmsMessageRecord(org.thoughtcrime.securesms.database.model.MmsMessageRecord)

Example 5 with MessageRecord

use of org.thoughtcrime.securesms.database.model.MessageRecord in project Signal-Android by WhisperSystems.

the class ConversationFragment method handleDeleteMessages.

private void handleDeleteMessages(final Set<MessageRecord> messageRecords) {
    int messagesCount = messageRecords.size();
    AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
    builder.setIconAttribute(R.attr.dialog_alert_icon);
    builder.setTitle(getActivity().getResources().getQuantityString(R.plurals.ConversationFragment_delete_selected_messages, messagesCount, messagesCount));
    builder.setMessage(getActivity().getResources().getQuantityString(R.plurals.ConversationFragment_this_will_permanently_delete_all_n_selected_messages, messagesCount, messagesCount));
    builder.setCancelable(true);
    builder.setPositiveButton(R.string.delete, new DialogInterface.OnClickListener() {

        @Override
        public void onClick(DialogInterface dialog, int which) {
            new ProgressDialogAsyncTask<MessageRecord, Void, Void>(getActivity(), R.string.ConversationFragment_deleting, R.string.ConversationFragment_deleting_messages) {

                @Override
                protected Void doInBackground(MessageRecord... messageRecords) {
                    for (MessageRecord messageRecord : messageRecords) {
                        boolean threadDeleted;
                        if (messageRecord.isMms()) {
                            threadDeleted = DatabaseFactory.getMmsDatabase(getActivity()).delete(messageRecord.getId());
                        } else {
                            threadDeleted = DatabaseFactory.getSmsDatabase(getActivity()).deleteMessage(messageRecord.getId());
                        }
                        if (threadDeleted) {
                            threadId = -1;
                            listener.setThreadId(threadId);
                        }
                    }
                    return null;
                }
            }.execute(messageRecords.toArray(new MessageRecord[messageRecords.size()]));
        }
    });
    builder.setNegativeButton(android.R.string.cancel, null);
    builder.show();
}
Also used : AlertDialog(android.support.v7.app.AlertDialog) DialogInterface(android.content.DialogInterface) MessageRecord(org.thoughtcrime.securesms.database.model.MessageRecord) MediaMmsMessageRecord(org.thoughtcrime.securesms.database.model.MediaMmsMessageRecord) ProgressDialogAsyncTask(org.thoughtcrime.securesms.util.task.ProgressDialogAsyncTask)

Aggregations

MessageRecord (org.thoughtcrime.securesms.database.model.MessageRecord)12 MediaMmsMessageRecord (org.thoughtcrime.securesms.database.model.MediaMmsMessageRecord)6 MmsMessageRecord (org.thoughtcrime.securesms.database.model.MmsMessageRecord)5 Cursor (android.database.Cursor)3 Context (android.content.Context)1 DialogInterface (android.content.DialogInterface)1 AlertDialog (android.support.v7.app.AlertDialog)1 ClipboardManager (android.text.ClipboardManager)1 Date (java.util.Date)1 LinkedList (java.util.LinkedList)1 MasterSecretUnion (org.thoughtcrime.securesms.crypto.MasterSecretUnion)1 EncryptingSmsDatabase (org.thoughtcrime.securesms.database.EncryptingSmsDatabase)1 MmsDatabase (org.thoughtcrime.securesms.database.MmsDatabase)1 MmsSmsDatabase (org.thoughtcrime.securesms.database.MmsSmsDatabase)1 SmsDatabase (org.thoughtcrime.securesms.database.SmsDatabase)1 SmsMessageRecord (org.thoughtcrime.securesms.database.model.SmsMessageRecord)1 SlideDeck (org.thoughtcrime.securesms.mms.SlideDeck)1 Recipient (org.thoughtcrime.securesms.recipients.Recipient)1 Recipients (org.thoughtcrime.securesms.recipients.Recipients)1 ProgressDialogAsyncTask (org.thoughtcrime.securesms.util.task.ProgressDialogAsyncTask)1