Search in sources :

Example 96 with SQLiteDatabase

use of net.sqlcipher.database.SQLiteDatabase in project Signal-Android by signalapp.

the class SmsDatabase method copyMessageInbox.

public Pair<Long, Long> copyMessageInbox(long messageId) {
    try {
        SmsMessageRecord record = getMessage(messageId);
        ContentValues contentValues = new ContentValues();
        contentValues.put(TYPE, (record.getType() & ~Types.BASE_TYPE_MASK) | Types.BASE_INBOX_TYPE);
        contentValues.put(ADDRESS, record.getIndividualRecipient().getAddress().serialize());
        contentValues.put(ADDRESS_DEVICE_ID, record.getRecipientDeviceId());
        contentValues.put(DATE_RECEIVED, System.currentTimeMillis());
        contentValues.put(DATE_SENT, record.getDateSent());
        contentValues.put(PROTOCOL, 31337);
        contentValues.put(READ, 0);
        contentValues.put(BODY, record.getBody());
        contentValues.put(THREAD_ID, record.getThreadId());
        contentValues.put(EXPIRES_IN, record.getExpiresIn());
        SQLiteDatabase db = databaseHelper.getWritableDatabase();
        long newMessageId = db.insert(TABLE_NAME, null, contentValues);
        DatabaseFactory.getThreadDatabase(context).update(record.getThreadId(), true);
        notifyConversationListeners(record.getThreadId());
        jobManager.add(new TrimThreadJob(context, record.getThreadId()));
        return new Pair<>(newMessageId, record.getThreadId());
    } catch (NoSuchMessageException e) {
        throw new AssertionError(e);
    }
}
Also used : ContentValues(android.content.ContentValues) TrimThreadJob(org.thoughtcrime.securesms.jobs.TrimThreadJob) SQLiteDatabase(net.sqlcipher.database.SQLiteDatabase) SmsMessageRecord(org.thoughtcrime.securesms.database.model.SmsMessageRecord) Pair(android.util.Pair)

Example 97 with SQLiteDatabase

use of net.sqlcipher.database.SQLiteDatabase in project Signal-Android by signalapp.

the class ThreadDatabase method createThreadForRecipient.

private long createThreadForRecipient(Address address, boolean group, int distributionType) {
    ContentValues contentValues = new ContentValues(4);
    long date = System.currentTimeMillis();
    contentValues.put(DATE, date - date % 1000);
    contentValues.put(ADDRESS, address.serialize());
    if (group)
        contentValues.put(TYPE, distributionType);
    contentValues.put(MESSAGE_COUNT, 0);
    SQLiteDatabase db = databaseHelper.getWritableDatabase();
    return db.insert(TABLE_NAME, null, contentValues);
}
Also used : ContentValues(android.content.ContentValues) SQLiteDatabase(net.sqlcipher.database.SQLiteDatabase)

Example 98 with SQLiteDatabase

use of net.sqlcipher.database.SQLiteDatabase in project Signal-Android by signalapp.

the class ThreadDatabase method setRead.

public List<MarkedMessageInfo> setRead(long threadId, boolean lastSeen) {
    ContentValues contentValues = new ContentValues(1);
    contentValues.put(READ, 1);
    contentValues.put(UNREAD_COUNT, 0);
    if (lastSeen) {
        contentValues.put(LAST_SEEN, System.currentTimeMillis());
    }
    SQLiteDatabase db = databaseHelper.getWritableDatabase();
    db.update(TABLE_NAME, contentValues, ID_WHERE, new String[] { threadId + "" });
    final List<MarkedMessageInfo> smsRecords = DatabaseFactory.getSmsDatabase(context).setMessagesRead(threadId);
    final List<MarkedMessageInfo> mmsRecords = DatabaseFactory.getMmsDatabase(context).setMessagesRead(threadId);
    notifyConversationListListeners();
    return new LinkedList<MarkedMessageInfo>() {

        {
            addAll(smsRecords);
            addAll(mmsRecords);
        }
    };
}
Also used : ContentValues(android.content.ContentValues) SQLiteDatabase(net.sqlcipher.database.SQLiteDatabase) MarkedMessageInfo(org.thoughtcrime.securesms.database.MessagingDatabase.MarkedMessageInfo) LinkedList(java.util.LinkedList)

Example 99 with SQLiteDatabase

use of net.sqlcipher.database.SQLiteDatabase in project Signal-Android by signalapp.

the class ThreadDatabase method archiveConversation.

public void archiveConversation(long threadId) {
    SQLiteDatabase db = databaseHelper.getWritableDatabase();
    ContentValues contentValues = new ContentValues(1);
    contentValues.put(ARCHIVED, 1);
    db.update(TABLE_NAME, contentValues, ID_WHERE, new String[] { threadId + "" });
    notifyConversationListListeners();
}
Also used : ContentValues(android.content.ContentValues) SQLiteDatabase(net.sqlcipher.database.SQLiteDatabase)

Example 100 with SQLiteDatabase

use of net.sqlcipher.database.SQLiteDatabase in project Signal-Android by signalapp.

the class ThreadDatabase method incrementUnread.

public void incrementUnread(long threadId, int amount) {
    SQLiteDatabase db = databaseHelper.getWritableDatabase();
    db.execSQL("UPDATE " + TABLE_NAME + " SET " + READ + " = 0, " + UNREAD_COUNT + " = " + UNREAD_COUNT + " + ? WHERE " + ID + " = ?", new String[] { String.valueOf(amount), String.valueOf(threadId) });
}
Also used : SQLiteDatabase(net.sqlcipher.database.SQLiteDatabase)

Aggregations

SQLiteDatabase (net.sqlcipher.database.SQLiteDatabase)124 Cursor (android.database.Cursor)37 ContentValues (android.content.ContentValues)32 IOException (java.io.IOException)15 LinkedList (java.util.LinkedList)12 NonNull (android.support.annotation.NonNull)7 MergeCursor (android.database.MergeCursor)6 Nullable (android.support.annotation.Nullable)6 Pair (android.util.Pair)6 File (java.io.File)5 SQLiteConstraintException (net.sqlcipher.database.SQLiteConstraintException)5 FileNotFoundException (java.io.FileNotFoundException)4 StreamCorruptedException (java.io.StreamCorruptedException)4 UnsupportedEncodingException (java.io.UnsupportedEncodingException)4 AudioClipTable (org.storymaker.app.model.AudioClipTable)4 AuthTable (org.storymaker.app.model.AuthTable)4 JobTable (org.storymaker.app.model.JobTable)4 LessonTable (org.storymaker.app.model.LessonTable)4 MediaTable (org.storymaker.app.model.MediaTable)4 ProjectTable (org.storymaker.app.model.ProjectTable)4