2017-11-13 18:01:05 -08:00
|
|
|
/*
|
2011-12-20 10:20:44 -08:00
|
|
|
* Copyright (C) 2011 Whisper Systems
|
2017-11-13 18:01:05 -08:00
|
|
|
* Copyright (C) 2013-2017 Open Whisper Systems
|
2012-09-09 16:10:46 -07:00
|
|
|
*
|
2011-12-20 10:20:44 -08:00
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
2012-09-09 16:10:46 -07:00
|
|
|
*
|
2011-12-20 10:20:44 -08:00
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
package org.thoughtcrime.securesms.database;
|
|
|
|
|
|
|
|
import android.content.ContentValues;
|
|
|
|
import android.content.Context;
|
|
|
|
import android.database.Cursor;
|
2015-04-02 10:02:19 -07:00
|
|
|
import android.database.MergeCursor;
|
2015-10-16 13:59:40 -07:00
|
|
|
import android.net.Uri;
|
2019-06-05 15:47:14 -04:00
|
|
|
import androidx.annotation.NonNull;
|
|
|
|
import androidx.annotation.Nullable;
|
2011-12-20 10:20:44 -08:00
|
|
|
|
2017-08-06 21:43:11 -07:00
|
|
|
import com.annimon.stream.Stream;
|
2019-06-11 02:18:45 -04:00
|
|
|
import com.fasterxml.jackson.annotation.JsonProperty;
|
2017-08-06 21:43:11 -07:00
|
|
|
|
2018-01-24 19:17:44 -08:00
|
|
|
import net.sqlcipher.database.SQLiteDatabase;
|
|
|
|
|
2018-06-20 16:37:14 -07:00
|
|
|
import org.thoughtcrime.securesms.contactshare.Contact;
|
|
|
|
import org.thoughtcrime.securesms.contactshare.ContactUtil;
|
2016-10-10 11:13:37 -07:00
|
|
|
import org.thoughtcrime.securesms.database.MessagingDatabase.MarkedMessageInfo;
|
2018-01-24 19:17:44 -08:00
|
|
|
import org.thoughtcrime.securesms.database.helpers.SQLCipherOpenHelper;
|
2015-10-16 13:59:40 -07:00
|
|
|
import org.thoughtcrime.securesms.database.model.MediaMmsMessageRecord;
|
2013-04-26 11:23:43 -07:00
|
|
|
import org.thoughtcrime.securesms.database.model.MessageRecord;
|
2018-06-27 09:43:02 -07:00
|
|
|
import org.thoughtcrime.securesms.database.model.MmsMessageRecord;
|
Major storage layer refactoring to set the stage for clean GCM.
1) We now try to hand out cursors at a minimum. There has always been
a fairly clean insertion layer that handles encrypting message bodies,
but the process of decrypting message bodies has always been less than
ideal. Here we introduce a "Reader" interface that will decrypt message
bodies when appropriate and return objects that encapsulate record state.
No more MessageDisplayHelper. The MmsSmsDatabase interface is also more
sane.
2) We finally rid ourselves of the technical debt associated with TextSecure's
initial usage of the default SMS DB. In that world, we weren't able to use
anything other than the default "Inbox, Outbox, Sent" types to describe a
message, and had to overload the message content itself with a set of
local "prefixes" to describe what it was (encrypted, asymetric encrypted,
remote encrypted, a key exchange, procssed key exchange), and so on.
This includes a major schema update that transforms the "type" field into
a bitmask that describes everything that used to be encoded in a prefix,
and prefixes have been completely eliminated from the system.
No more Prefix.java
3) Refactoring of the MultipartMessageHandler code. It's less of a mess, and
hopefully more clear as to what's going on.
The next step is to remove what we can from SmsTransportDetails and genericize
that interface for a GCM equivalent.
2013-04-20 12:22:04 -07:00
|
|
|
import org.thoughtcrime.securesms.database.model.ThreadRecord;
|
2019-04-17 10:21:30 -04:00
|
|
|
import org.thoughtcrime.securesms.logging.Log;
|
2015-10-16 13:59:40 -07:00
|
|
|
import org.thoughtcrime.securesms.mms.Slide;
|
|
|
|
import org.thoughtcrime.securesms.mms.SlideDeck;
|
2017-08-01 08:56:00 -07:00
|
|
|
import org.thoughtcrime.securesms.recipients.Recipient;
|
2019-08-07 14:22:51 -04:00
|
|
|
import org.thoughtcrime.securesms.recipients.RecipientId;
|
2019-06-11 02:18:45 -04:00
|
|
|
import org.thoughtcrime.securesms.util.JsonUtils;
|
2017-09-15 22:38:53 -07:00
|
|
|
import org.thoughtcrime.securesms.util.TextSecurePreferences;
|
2015-04-02 10:02:19 -07:00
|
|
|
import org.thoughtcrime.securesms.util.Util;
|
2017-08-18 17:28:56 -07:00
|
|
|
import org.whispersystems.libsignal.util.Pair;
|
2012-09-09 16:10:46 -07:00
|
|
|
|
2018-04-06 18:15:24 -07:00
|
|
|
import java.io.Closeable;
|
2019-06-11 02:18:45 -04:00
|
|
|
import java.io.IOException;
|
2015-04-02 10:02:19 -07:00
|
|
|
import java.util.LinkedList;
|
2012-09-09 16:10:46 -07:00
|
|
|
import java.util.List;
|
|
|
|
import java.util.Set;
|
|
|
|
|
2011-12-20 10:20:44 -08:00
|
|
|
public class ThreadDatabase extends Database {
|
|
|
|
|
2015-10-16 13:59:40 -07:00
|
|
|
private static final String TAG = ThreadDatabase.class.getSimpleName();
|
|
|
|
|
2018-06-21 16:48:46 -07:00
|
|
|
public static final String TABLE_NAME = "thread";
|
2017-09-15 22:38:53 -07:00
|
|
|
public static final String ID = "_id";
|
|
|
|
public static final String DATE = "date";
|
|
|
|
public static final String MESSAGE_COUNT = "message_count";
|
2019-08-07 14:22:51 -04:00
|
|
|
public static final String RECIPIENT_ID = "recipient_ids";
|
2017-09-15 22:38:53 -07:00
|
|
|
public static final String SNIPPET = "snippet";
|
|
|
|
private static final String SNIPPET_CHARSET = "snippet_cs";
|
|
|
|
public static final String READ = "read";
|
2017-11-13 18:01:05 -08:00
|
|
|
public static final String UNREAD_COUNT = "unread_count";
|
2017-09-15 22:38:53 -07:00
|
|
|
public static final String TYPE = "type";
|
|
|
|
private static final String ERROR = "error";
|
|
|
|
public static final String SNIPPET_TYPE = "snippet_type";
|
|
|
|
public static final String SNIPPET_URI = "snippet_uri";
|
2019-06-11 02:18:45 -04:00
|
|
|
public static final String SNIPPET_CONTENT_TYPE = "snippet_content_type";
|
|
|
|
public static final String SNIPPET_EXTRAS = "snippet_extras";
|
2017-09-15 22:38:53 -07:00
|
|
|
public static final String ARCHIVED = "archived";
|
|
|
|
public static final String STATUS = "status";
|
|
|
|
public static final String DELIVERY_RECEIPT_COUNT = "delivery_receipt_count";
|
|
|
|
public static final String READ_RECEIPT_COUNT = "read_receipt_count";
|
|
|
|
public static final String EXPIRES_IN = "expires_in";
|
|
|
|
public static final String LAST_SEEN = "last_seen";
|
|
|
|
private static final String HAS_SENT = "has_sent";
|
2015-11-24 16:06:41 +01:00
|
|
|
|
|
|
|
public static final String CREATE_TABLE = "CREATE TABLE " + TABLE_NAME + " (" +
|
|
|
|
ID + " INTEGER PRIMARY KEY, " + DATE + " INTEGER DEFAULT 0, " +
|
2019-08-07 14:22:51 -04:00
|
|
|
MESSAGE_COUNT + " INTEGER DEFAULT 0, " + RECIPIENT_ID + " INTEGER, " + SNIPPET + " TEXT, " +
|
2015-11-24 16:06:41 +01:00
|
|
|
SNIPPET_CHARSET + " INTEGER DEFAULT 0, " + READ + " INTEGER DEFAULT 1, " +
|
|
|
|
TYPE + " INTEGER DEFAULT 0, " + ERROR + " INTEGER DEFAULT 0, " +
|
|
|
|
SNIPPET_TYPE + " INTEGER DEFAULT 0, " + SNIPPET_URI + " TEXT DEFAULT NULL, " +
|
2019-06-11 02:18:45 -04:00
|
|
|
SNIPPET_CONTENT_TYPE + " TEXT DEFAULT NULL, " + SNIPPET_EXTRAS + " TEXT DEFAULT NULL, " +
|
2015-11-24 16:06:41 +01:00
|
|
|
ARCHIVED + " INTEGER DEFAULT 0, " + STATUS + " INTEGER DEFAULT 0, " +
|
2017-09-15 22:38:53 -07:00
|
|
|
DELIVERY_RECEIPT_COUNT + " INTEGER DEFAULT 0, " + EXPIRES_IN + " INTEGER DEFAULT 0, " +
|
|
|
|
LAST_SEEN + " INTEGER DEFAULT 0, " + HAS_SENT + " INTEGER DEFAULT 0, " +
|
2017-11-13 18:01:05 -08:00
|
|
|
READ_RECEIPT_COUNT + " INTEGER DEFAULT 0, " + UNREAD_COUNT + " INTEGER DEFAULT 0);";
|
2011-12-20 10:20:44 -08:00
|
|
|
|
2018-01-24 19:17:44 -08:00
|
|
|
public static final String[] CREATE_INDEXS = {
|
2019-08-07 14:22:51 -04:00
|
|
|
"CREATE INDEX IF NOT EXISTS thread_recipient_ids_index ON " + TABLE_NAME + " (" + RECIPIENT_ID + ");",
|
2017-05-19 18:01:40 -07:00
|
|
|
"CREATE INDEX IF NOT EXISTS archived_count_index ON " + TABLE_NAME + " (" + ARCHIVED + ", " + MESSAGE_COUNT + ");",
|
2012-10-29 17:41:06 -07:00
|
|
|
};
|
|
|
|
|
2017-08-06 21:43:11 -07:00
|
|
|
private static final String[] THREAD_PROJECTION = {
|
2019-08-07 14:22:51 -04:00
|
|
|
ID, DATE, MESSAGE_COUNT, RECIPIENT_ID, SNIPPET, SNIPPET_CHARSET, READ, UNREAD_COUNT, TYPE, ERROR, SNIPPET_TYPE,
|
2019-06-11 02:18:45 -04:00
|
|
|
SNIPPET_URI, SNIPPET_CONTENT_TYPE, SNIPPET_EXTRAS, ARCHIVED, STATUS, DELIVERY_RECEIPT_COUNT, EXPIRES_IN, LAST_SEEN, READ_RECEIPT_COUNT
|
2017-08-06 21:43:11 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
private static final List<String> TYPED_THREAD_PROJECTION = Stream.of(THREAD_PROJECTION)
|
|
|
|
.map(columnName -> TABLE_NAME + "." + columnName)
|
|
|
|
.toList();
|
|
|
|
|
2017-08-07 16:47:38 -07:00
|
|
|
private static final List<String> COMBINED_THREAD_RECIPIENT_GROUP_PROJECTION = Stream.concat(Stream.concat(Stream.of(TYPED_THREAD_PROJECTION),
|
2017-08-21 18:37:39 -07:00
|
|
|
Stream.of(RecipientDatabase.TYPED_RECIPIENT_PROJECTION)),
|
2017-08-07 16:47:38 -07:00
|
|
|
Stream.of(GroupDatabase.TYPED_GROUP_PROJECTION))
|
|
|
|
.toList();
|
2017-08-06 21:43:11 -07:00
|
|
|
|
2018-01-24 19:17:44 -08:00
|
|
|
public ThreadDatabase(Context context, SQLCipherOpenHelper databaseHelper) {
|
2011-12-20 10:20:44 -08:00
|
|
|
super(context, databaseHelper);
|
|
|
|
}
|
|
|
|
|
2019-08-07 14:22:51 -04:00
|
|
|
private long createThreadForRecipient(@NonNull RecipientId recipientId, boolean group, int distributionType) {
|
2019-10-08 19:14:52 -07:00
|
|
|
if (recipientId.isUnknown()) {
|
|
|
|
throw new AssertionError("Cannot create a thread for an unknown recipient!");
|
|
|
|
}
|
|
|
|
|
2011-12-20 10:20:44 -08:00
|
|
|
ContentValues contentValues = new ContentValues(4);
|
|
|
|
long date = System.currentTimeMillis();
|
2012-09-09 16:10:46 -07:00
|
|
|
|
2011-12-20 10:20:44 -08:00
|
|
|
contentValues.put(DATE, date - date % 1000);
|
2019-08-07 14:22:51 -04:00
|
|
|
contentValues.put(RECIPIENT_ID, recipientId.serialize());
|
2012-09-09 16:10:46 -07:00
|
|
|
|
2017-08-01 08:56:00 -07:00
|
|
|
if (group)
|
2013-04-25 18:59:49 -07:00
|
|
|
contentValues.put(TYPE, distributionType);
|
2012-09-09 16:10:46 -07:00
|
|
|
|
2011-12-20 10:20:44 -08:00
|
|
|
contentValues.put(MESSAGE_COUNT, 0);
|
|
|
|
|
|
|
|
SQLiteDatabase db = databaseHelper.getWritableDatabase();
|
|
|
|
return db.insert(TABLE_NAME, null, contentValues);
|
|
|
|
}
|
|
|
|
|
2015-11-24 16:06:41 +01:00
|
|
|
private void updateThread(long threadId, long count, String body, @Nullable Uri attachment,
|
2019-06-11 02:18:45 -04:00
|
|
|
@Nullable String contentType, @Nullable Extra extra,
|
2017-09-15 22:38:53 -07:00
|
|
|
long date, int status, int deliveryReceiptCount, long type, boolean unarchive,
|
|
|
|
long expiresIn, int readReceiptCount)
|
2014-02-14 15:59:57 -08:00
|
|
|
{
|
2019-06-11 02:18:45 -04:00
|
|
|
String extraSerialized = null;
|
|
|
|
|
|
|
|
if (extra != null) {
|
|
|
|
try {
|
|
|
|
extraSerialized = JsonUtils.toJson(extra);
|
|
|
|
} catch (IOException e) {
|
|
|
|
throw new AssertionError(e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-11-24 16:06:41 +01:00
|
|
|
ContentValues contentValues = new ContentValues(7);
|
2011-12-20 10:20:44 -08:00
|
|
|
contentValues.put(DATE, date - date % 1000);
|
|
|
|
contentValues.put(MESSAGE_COUNT, count);
|
|
|
|
contentValues.put(SNIPPET, body);
|
2015-10-16 13:59:40 -07:00
|
|
|
contentValues.put(SNIPPET_URI, attachment == null ? null : attachment.toString());
|
Major storage layer refactoring to set the stage for clean GCM.
1) We now try to hand out cursors at a minimum. There has always been
a fairly clean insertion layer that handles encrypting message bodies,
but the process of decrypting message bodies has always been less than
ideal. Here we introduce a "Reader" interface that will decrypt message
bodies when appropriate and return objects that encapsulate record state.
No more MessageDisplayHelper. The MmsSmsDatabase interface is also more
sane.
2) We finally rid ourselves of the technical debt associated with TextSecure's
initial usage of the default SMS DB. In that world, we weren't able to use
anything other than the default "Inbox, Outbox, Sent" types to describe a
message, and had to overload the message content itself with a set of
local "prefixes" to describe what it was (encrypted, asymetric encrypted,
remote encrypted, a key exchange, procssed key exchange), and so on.
This includes a major schema update that transforms the "type" field into
a bitmask that describes everything that used to be encoded in a prefix,
and prefixes have been completely eliminated from the system.
No more Prefix.java
3) Refactoring of the MultipartMessageHandler code. It's less of a mess, and
hopefully more clear as to what's going on.
The next step is to remove what we can from SmsTransportDetails and genericize
that interface for a GCM equivalent.
2013-04-20 12:22:04 -07:00
|
|
|
contentValues.put(SNIPPET_TYPE, type);
|
2019-06-11 02:18:45 -04:00
|
|
|
contentValues.put(SNIPPET_CONTENT_TYPE, contentType);
|
|
|
|
contentValues.put(SNIPPET_EXTRAS, extraSerialized);
|
2015-11-24 16:06:41 +01:00
|
|
|
contentValues.put(STATUS, status);
|
2017-09-15 22:38:53 -07:00
|
|
|
contentValues.put(DELIVERY_RECEIPT_COUNT, deliveryReceiptCount);
|
|
|
|
contentValues.put(READ_RECEIPT_COUNT, readReceiptCount);
|
2016-08-15 20:23:56 -07:00
|
|
|
contentValues.put(EXPIRES_IN, expiresIn);
|
2012-09-09 16:10:46 -07:00
|
|
|
|
2015-11-23 15:07:41 -08:00
|
|
|
if (unarchive) {
|
|
|
|
contentValues.put(ARCHIVED, 0);
|
|
|
|
}
|
|
|
|
|
2011-12-20 10:20:44 -08:00
|
|
|
SQLiteDatabase db = databaseHelper.getWritableDatabase();
|
2013-04-26 11:23:43 -07:00
|
|
|
db.update(TABLE_NAME, contentValues, ID + " = ?", new String[] {threadId + ""});
|
2011-12-20 10:20:44 -08:00
|
|
|
notifyConversationListListeners();
|
|
|
|
}
|
2012-09-09 16:10:46 -07:00
|
|
|
|
2015-11-23 15:07:41 -08:00
|
|
|
public void updateSnippet(long threadId, String snippet, @Nullable Uri attachment, long date, long type, boolean unarchive) {
|
2015-11-24 16:06:41 +01:00
|
|
|
ContentValues contentValues = new ContentValues(4);
|
2015-04-06 13:44:18 -07:00
|
|
|
|
|
|
|
contentValues.put(DATE, date - date % 1000);
|
2014-12-11 17:13:01 -08:00
|
|
|
contentValues.put(SNIPPET, snippet);
|
|
|
|
contentValues.put(SNIPPET_TYPE, type);
|
2015-10-16 13:59:40 -07:00
|
|
|
contentValues.put(SNIPPET_URI, attachment == null ? null : attachment.toString());
|
2015-11-23 15:07:41 -08:00
|
|
|
|
|
|
|
if (unarchive) {
|
|
|
|
contentValues.put(ARCHIVED, 0);
|
|
|
|
}
|
|
|
|
|
2014-12-11 17:13:01 -08:00
|
|
|
SQLiteDatabase db = databaseHelper.getWritableDatabase();
|
|
|
|
db.update(TABLE_NAME, contentValues, ID + " = ?", new String[] {threadId + ""});
|
|
|
|
notifyConversationListListeners();
|
|
|
|
}
|
|
|
|
|
2011-12-20 10:20:44 -08:00
|
|
|
private void deleteThread(long threadId) {
|
|
|
|
SQLiteDatabase db = databaseHelper.getWritableDatabase();
|
2015-10-16 13:59:40 -07:00
|
|
|
db.delete(TABLE_NAME, ID_WHERE, new String[] {threadId + ""});
|
2011-12-20 10:20:44 -08:00
|
|
|
notifyConversationListListeners();
|
|
|
|
}
|
2012-09-09 16:10:46 -07:00
|
|
|
|
2011-12-20 10:20:44 -08:00
|
|
|
private void deleteThreads(Set<Long> threadIds) {
|
|
|
|
SQLiteDatabase db = databaseHelper.getWritableDatabase();
|
|
|
|
String where = "";
|
2012-09-09 16:10:46 -07:00
|
|
|
|
2011-12-20 10:20:44 -08:00
|
|
|
for (long threadId : threadIds) {
|
|
|
|
where += ID + " = '" + threadId + "' OR ";
|
|
|
|
}
|
2012-09-09 16:10:46 -07:00
|
|
|
|
2011-12-20 10:20:44 -08:00
|
|
|
where = where.substring(0, where.length() - 4);
|
2012-09-09 16:10:46 -07:00
|
|
|
|
2011-12-20 10:20:44 -08:00
|
|
|
db.delete(TABLE_NAME, where, null);
|
|
|
|
notifyConversationListListeners();
|
|
|
|
}
|
2012-09-09 16:10:46 -07:00
|
|
|
|
2011-12-20 10:20:44 -08:00
|
|
|
private void deleteAllThreads() {
|
|
|
|
SQLiteDatabase db = databaseHelper.getWritableDatabase();
|
2012-09-09 16:10:46 -07:00
|
|
|
db.delete(TABLE_NAME, null, null);
|
|
|
|
notifyConversationListListeners();
|
2011-12-20 10:20:44 -08:00
|
|
|
}
|
2012-09-09 16:10:46 -07:00
|
|
|
|
2013-01-09 21:06:56 -08:00
|
|
|
public void trimAllThreads(int length, ProgressListener listener) {
|
|
|
|
Cursor cursor = null;
|
|
|
|
int threadCount = 0;
|
|
|
|
int complete = 0;
|
|
|
|
|
|
|
|
try {
|
|
|
|
cursor = this.getConversationList();
|
|
|
|
|
|
|
|
if (cursor != null)
|
|
|
|
threadCount = cursor.getCount();
|
|
|
|
|
|
|
|
while (cursor != null && cursor.moveToNext()) {
|
|
|
|
long threadId = cursor.getLong(cursor.getColumnIndexOrThrow(ID));
|
|
|
|
trimThread(threadId, length);
|
|
|
|
|
|
|
|
listener.onProgress(++complete, threadCount);
|
|
|
|
}
|
|
|
|
} finally {
|
|
|
|
if (cursor != null)
|
|
|
|
cursor.close();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public void trimThread(long threadId, int length) {
|
2018-08-02 09:25:33 -04:00
|
|
|
Log.i("ThreadDatabase", "Trimming thread: " + threadId + " to: " + length);
|
2013-01-09 21:06:56 -08:00
|
|
|
Cursor cursor = null;
|
|
|
|
|
|
|
|
try {
|
|
|
|
cursor = DatabaseFactory.getMmsSmsDatabase(context).getConversation(threadId);
|
|
|
|
|
2015-09-28 16:39:39 -07:00
|
|
|
if (cursor != null && length > 0 && cursor.getCount() > length) {
|
2013-01-09 21:06:56 -08:00
|
|
|
Log.w("ThreadDatabase", "Cursor count is greater than length!");
|
2015-09-28 16:39:39 -07:00
|
|
|
cursor.moveToPosition(length - 1);
|
2013-01-09 21:06:56 -08:00
|
|
|
|
Major storage layer refactoring to set the stage for clean GCM.
1) We now try to hand out cursors at a minimum. There has always been
a fairly clean insertion layer that handles encrypting message bodies,
but the process of decrypting message bodies has always been less than
ideal. Here we introduce a "Reader" interface that will decrypt message
bodies when appropriate and return objects that encapsulate record state.
No more MessageDisplayHelper. The MmsSmsDatabase interface is also more
sane.
2) We finally rid ourselves of the technical debt associated with TextSecure's
initial usage of the default SMS DB. In that world, we weren't able to use
anything other than the default "Inbox, Outbox, Sent" types to describe a
message, and had to overload the message content itself with a set of
local "prefixes" to describe what it was (encrypted, asymetric encrypted,
remote encrypted, a key exchange, procssed key exchange), and so on.
This includes a major schema update that transforms the "type" field into
a bitmask that describes everything that used to be encoded in a prefix,
and prefixes have been completely eliminated from the system.
No more Prefix.java
3) Refactoring of the MultipartMessageHandler code. It's less of a mess, and
hopefully more clear as to what's going on.
The next step is to remove what we can from SmsTransportDetails and genericize
that interface for a GCM equivalent.
2013-04-20 12:22:04 -07:00
|
|
|
long lastTweetDate = cursor.getLong(cursor.getColumnIndexOrThrow(MmsSmsColumns.NORMALIZED_DATE_RECEIVED));
|
2013-01-09 21:06:56 -08:00
|
|
|
|
2018-08-02 09:25:33 -04:00
|
|
|
Log.i("ThreadDatabase", "Cut off tweet date: " + lastTweetDate);
|
2013-01-09 21:06:56 -08:00
|
|
|
|
|
|
|
DatabaseFactory.getSmsDatabase(context).deleteMessagesInThreadBeforeDate(threadId, lastTweetDate);
|
|
|
|
DatabaseFactory.getMmsDatabase(context).deleteMessagesInThreadBeforeDate(threadId, lastTweetDate);
|
|
|
|
|
2015-11-23 15:07:41 -08:00
|
|
|
update(threadId, false);
|
2013-01-09 21:06:56 -08:00
|
|
|
notifyConversationListeners(threadId);
|
|
|
|
}
|
|
|
|
} finally {
|
|
|
|
if (cursor != null)
|
|
|
|
cursor.close();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-10-08 18:09:46 -07:00
|
|
|
public List<MarkedMessageInfo> setAllThreadsRead() {
|
2013-05-06 13:59:40 -07:00
|
|
|
SQLiteDatabase db = databaseHelper.getWritableDatabase();
|
|
|
|
ContentValues contentValues = new ContentValues(1);
|
|
|
|
contentValues.put(READ, 1);
|
2017-11-13 18:01:05 -08:00
|
|
|
contentValues.put(UNREAD_COUNT, 0);
|
2013-05-06 13:59:40 -07:00
|
|
|
|
|
|
|
db.update(TABLE_NAME, contentValues, null, null);
|
|
|
|
|
2017-10-08 18:09:46 -07:00
|
|
|
final List<MarkedMessageInfo> smsRecords = DatabaseFactory.getSmsDatabase(context).setAllMessagesRead();
|
|
|
|
final List<MarkedMessageInfo> mmsRecords = DatabaseFactory.getMmsDatabase(context).setAllMessagesRead();
|
|
|
|
|
2013-05-06 13:59:40 -07:00
|
|
|
notifyConversationListListeners();
|
2017-10-08 18:09:46 -07:00
|
|
|
|
|
|
|
return new LinkedList<MarkedMessageInfo>() {{
|
|
|
|
addAll(smsRecords);
|
|
|
|
addAll(mmsRecords);
|
|
|
|
}};
|
2013-05-06 13:59:40 -07:00
|
|
|
}
|
|
|
|
|
2019-10-16 13:26:26 -03:00
|
|
|
public boolean hasCalledSince(@NonNull Recipient recipient, long timestamp) {
|
|
|
|
return DatabaseFactory.getMmsSmsDatabase(context).hasReceivedAnyCallsSince(getThreadIdFor(recipient), timestamp);
|
|
|
|
}
|
|
|
|
|
2017-02-22 15:05:35 -08:00
|
|
|
public List<MarkedMessageInfo> setRead(long threadId, boolean lastSeen) {
|
2011-12-20 10:20:44 -08:00
|
|
|
ContentValues contentValues = new ContentValues(1);
|
|
|
|
contentValues.put(READ, 1);
|
2017-11-13 18:01:05 -08:00
|
|
|
contentValues.put(UNREAD_COUNT, 0);
|
2011-12-20 10:20:44 -08:00
|
|
|
|
2017-02-22 15:05:35 -08:00
|
|
|
if (lastSeen) {
|
|
|
|
contentValues.put(LAST_SEEN, System.currentTimeMillis());
|
|
|
|
}
|
|
|
|
|
2011-12-20 10:20:44 -08:00
|
|
|
SQLiteDatabase db = databaseHelper.getWritableDatabase();
|
|
|
|
db.update(TABLE_NAME, contentValues, ID_WHERE, new String[] {threadId+""});
|
2012-09-09 16:10:46 -07:00
|
|
|
|
2016-10-10 11:13:37 -07:00
|
|
|
final List<MarkedMessageInfo> smsRecords = DatabaseFactory.getSmsDatabase(context).setMessagesRead(threadId);
|
|
|
|
final List<MarkedMessageInfo> mmsRecords = DatabaseFactory.getMmsDatabase(context).setMessagesRead(threadId);
|
2016-02-19 17:07:41 -08:00
|
|
|
|
2011-12-20 10:20:44 -08:00
|
|
|
notifyConversationListListeners();
|
2016-02-19 17:07:41 -08:00
|
|
|
|
2016-10-10 11:13:37 -07:00
|
|
|
return new LinkedList<MarkedMessageInfo>() {{
|
2016-02-19 17:07:41 -08:00
|
|
|
addAll(smsRecords);
|
|
|
|
addAll(mmsRecords);
|
|
|
|
}};
|
2011-12-20 10:20:44 -08:00
|
|
|
}
|
2012-09-09 16:10:46 -07:00
|
|
|
|
2017-11-13 18:01:05 -08:00
|
|
|
public void incrementUnread(long threadId, int amount) {
|
2013-04-25 18:59:49 -07:00
|
|
|
SQLiteDatabase db = databaseHelper.getWritableDatabase();
|
2017-11-13 18:01:05 -08:00
|
|
|
db.execSQL("UPDATE " + TABLE_NAME + " SET " + READ + " = 0, " +
|
|
|
|
UNREAD_COUNT + " = " + UNREAD_COUNT + " + ? WHERE " + ID + " = ?",
|
|
|
|
new String[] {String.valueOf(amount),
|
|
|
|
String.valueOf(threadId)});
|
2013-04-25 18:59:49 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
public void setDistributionType(long threadId, int distributionType) {
|
|
|
|
ContentValues contentValues = new ContentValues(1);
|
|
|
|
contentValues.put(TYPE, distributionType);
|
2011-12-20 10:20:44 -08:00
|
|
|
|
|
|
|
SQLiteDatabase db = databaseHelper.getWritableDatabase();
|
2015-10-16 13:59:40 -07:00
|
|
|
db.update(TABLE_NAME, contentValues, ID_WHERE, new String[] {threadId + ""});
|
2012-09-09 16:10:46 -07:00
|
|
|
notifyConversationListListeners();
|
2011-12-20 10:20:44 -08:00
|
|
|
}
|
2012-09-09 16:10:46 -07:00
|
|
|
|
2017-08-01 08:56:00 -07:00
|
|
|
public int getDistributionType(long threadId) {
|
|
|
|
SQLiteDatabase db = databaseHelper.getReadableDatabase();
|
|
|
|
Cursor cursor = db.query(TABLE_NAME, new String[]{TYPE}, ID_WHERE, new String[]{String.valueOf(threadId)}, null, null, null);
|
|
|
|
|
|
|
|
try {
|
|
|
|
if (cursor != null && cursor.moveToNext()) {
|
|
|
|
return cursor.getInt(cursor.getColumnIndexOrThrow(TYPE));
|
|
|
|
}
|
|
|
|
|
|
|
|
return DistributionTypes.DEFAULT;
|
|
|
|
} finally {
|
|
|
|
if (cursor != null) cursor.close();
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2019-08-07 14:22:51 -04:00
|
|
|
public Cursor getFilteredConversationList(@Nullable List<RecipientId> filter) {
|
2011-12-20 10:20:44 -08:00
|
|
|
if (filter == null || filter.size() == 0)
|
|
|
|
return null;
|
2012-09-09 16:10:46 -07:00
|
|
|
|
2019-08-07 14:22:51 -04:00
|
|
|
SQLiteDatabase db = databaseHelper.getReadableDatabase();
|
|
|
|
List<List<RecipientId>> splitRecipientIds = Util.partition(filter, 900);
|
|
|
|
List<Cursor> cursors = new LinkedList<>();
|
2012-09-09 16:10:46 -07:00
|
|
|
|
2019-08-07 14:22:51 -04:00
|
|
|
for (List<RecipientId> recipientIds : splitRecipientIds) {
|
|
|
|
String selection = TABLE_NAME + "." + RECIPIENT_ID + " = ?";
|
|
|
|
String[] selectionArgs = new String[recipientIds.size()];
|
2012-09-09 16:10:46 -07:00
|
|
|
|
2019-08-07 14:22:51 -04:00
|
|
|
for (int i=0;i<recipientIds.size()-1;i++)
|
|
|
|
selection += (" OR " + TABLE_NAME + "." + RECIPIENT_ID + " = ?");
|
2015-04-02 10:02:19 -07:00
|
|
|
|
|
|
|
int i= 0;
|
2019-08-07 14:22:51 -04:00
|
|
|
for (RecipientId recipientId : recipientIds) {
|
|
|
|
selectionArgs[i++] = recipientId.serialize();
|
2015-04-02 10:02:19 -07:00
|
|
|
}
|
|
|
|
|
2017-11-16 15:21:46 -08:00
|
|
|
String query = createQuery(selection, 0);
|
2017-09-07 13:52:25 -07:00
|
|
|
cursors.add(db.rawQuery(query, selectionArgs));
|
2011-12-20 10:20:44 -08:00
|
|
|
}
|
2012-09-09 16:10:46 -07:00
|
|
|
|
2015-04-02 10:02:19 -07:00
|
|
|
Cursor cursor = cursors.size() > 1 ? new MergeCursor(cursors.toArray(new Cursor[cursors.size()])) : cursors.get(0);
|
2012-09-09 16:10:46 -07:00
|
|
|
setNotifyConverationListListeners(cursor);
|
2011-12-20 10:20:44 -08:00
|
|
|
return cursor;
|
|
|
|
}
|
2012-09-09 16:10:46 -07:00
|
|
|
|
2019-10-22 12:09:27 -04:00
|
|
|
public Cursor getRecentConversationList(int limit, boolean includeInactiveGroups) {
|
2017-11-16 15:21:46 -08:00
|
|
|
SQLiteDatabase db = databaseHelper.getReadableDatabase();
|
2019-10-22 12:09:27 -04:00
|
|
|
String query = !includeInactiveGroups ? MESSAGE_COUNT + " != 0 AND " + GroupDatabase.TABLE_NAME + "." + GroupDatabase.ACTIVE + " = 1"
|
|
|
|
: MESSAGE_COUNT + " != 0";
|
|
|
|
return db.rawQuery(createQuery(query, limit), null);
|
2017-11-16 15:21:46 -08:00
|
|
|
}
|
|
|
|
|
2019-10-22 12:09:27 -04:00
|
|
|
public Cursor getRecentPushConversationList(int limit, boolean includeInactiveGroups) {
|
|
|
|
SQLiteDatabase db = databaseHelper.getReadableDatabase();
|
|
|
|
String activeGroupQuery = !includeInactiveGroups ? " AND " + GroupDatabase.TABLE_NAME + "." + GroupDatabase.ACTIVE + " = 1" : "";
|
|
|
|
String where = MESSAGE_COUNT + " != 0 AND " +
|
|
|
|
"(" +
|
|
|
|
RecipientDatabase.REGISTERED + " = " + RecipientDatabase.RegisteredState.REGISTERED.getId() + " OR " +
|
|
|
|
"(" +
|
|
|
|
GroupDatabase.TABLE_NAME + "." + GroupDatabase.GROUP_ID + " NOT NULL AND " +
|
|
|
|
GroupDatabase.TABLE_NAME + "." + GroupDatabase.MMS + " = 0" +
|
|
|
|
activeGroupQuery +
|
|
|
|
")" +
|
|
|
|
")";
|
2019-07-03 15:07:00 -04:00
|
|
|
String query = createQuery(where, limit);
|
|
|
|
|
|
|
|
return db.rawQuery(query, null);
|
|
|
|
}
|
|
|
|
|
2012-09-09 16:10:46 -07:00
|
|
|
public Cursor getConversationList() {
|
2017-08-06 21:43:11 -07:00
|
|
|
return getConversationList("0");
|
2015-11-23 15:07:41 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
public Cursor getArchivedConversationList() {
|
2017-08-06 21:43:11 -07:00
|
|
|
return getConversationList("1");
|
|
|
|
}
|
|
|
|
|
|
|
|
private Cursor getConversationList(String archived) {
|
2017-09-15 10:36:33 -07:00
|
|
|
SQLiteDatabase db = databaseHelper.getReadableDatabase();
|
2017-11-16 15:21:46 -08:00
|
|
|
String query = createQuery(ARCHIVED + " = ? AND " + MESSAGE_COUNT + " != 0", 0);
|
2017-09-15 10:36:33 -07:00
|
|
|
Cursor cursor = db.rawQuery(query, new String[]{archived});
|
2015-11-23 15:07:41 -08:00
|
|
|
|
2011-12-20 10:20:44 -08:00
|
|
|
setNotifyConverationListListeners(cursor);
|
2015-11-23 15:07:41 -08:00
|
|
|
|
2011-12-20 10:20:44 -08:00
|
|
|
return cursor;
|
|
|
|
}
|
2012-09-09 16:10:46 -07:00
|
|
|
|
2015-11-23 15:07:41 -08:00
|
|
|
public int getArchivedConversationListCount() {
|
|
|
|
SQLiteDatabase db = databaseHelper.getReadableDatabase();
|
|
|
|
Cursor cursor = null;
|
|
|
|
|
|
|
|
try {
|
|
|
|
cursor = db.query(TABLE_NAME, new String[] {"COUNT(*)"}, ARCHIVED + " = ?",
|
|
|
|
new String[] {"1"}, null, null, null);
|
|
|
|
|
|
|
|
if (cursor != null && cursor.moveToFirst()) {
|
|
|
|
return cursor.getInt(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
} finally {
|
|
|
|
if (cursor != null) cursor.close();
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
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();
|
|
|
|
}
|
|
|
|
|
|
|
|
public void unarchiveConversation(long threadId) {
|
|
|
|
SQLiteDatabase db = databaseHelper.getWritableDatabase();
|
|
|
|
ContentValues contentValues = new ContentValues(1);
|
|
|
|
contentValues.put(ARCHIVED, 0);
|
|
|
|
|
|
|
|
db.update(TABLE_NAME, contentValues, ID_WHERE, new String[] {threadId + ""});
|
|
|
|
notifyConversationListListeners();
|
|
|
|
}
|
|
|
|
|
2017-02-13 22:35:47 -08:00
|
|
|
public void setLastSeen(long threadId) {
|
|
|
|
SQLiteDatabase db = databaseHelper.getWritableDatabase();
|
|
|
|
ContentValues contentValues = new ContentValues(1);
|
|
|
|
contentValues.put(LAST_SEEN, System.currentTimeMillis());
|
|
|
|
|
|
|
|
db.update(TABLE_NAME, contentValues, ID_WHERE, new String[] {String.valueOf(threadId)});
|
|
|
|
notifyConversationListListeners();
|
|
|
|
}
|
|
|
|
|
2017-08-18 17:28:56 -07:00
|
|
|
public Pair<Long, Boolean> getLastSeenAndHasSent(long threadId) {
|
2017-02-13 22:35:47 -08:00
|
|
|
SQLiteDatabase db = databaseHelper.getReadableDatabase();
|
2017-08-18 17:28:56 -07:00
|
|
|
Cursor cursor = db.query(TABLE_NAME, new String[]{LAST_SEEN, HAS_SENT}, ID_WHERE, new String[]{String.valueOf(threadId)}, null, null, null);
|
2017-02-13 22:35:47 -08:00
|
|
|
|
|
|
|
try {
|
|
|
|
if (cursor != null && cursor.moveToFirst()) {
|
2017-08-18 17:28:56 -07:00
|
|
|
return new Pair<>(cursor.getLong(0), cursor.getLong(1) == 1);
|
2017-02-13 22:35:47 -08:00
|
|
|
}
|
|
|
|
|
2017-08-18 17:28:56 -07:00
|
|
|
return new Pair<>(-1L, false);
|
2017-02-13 22:35:47 -08:00
|
|
|
} finally {
|
|
|
|
if (cursor != null) cursor.close();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-12-20 10:20:44 -08:00
|
|
|
public void deleteConversation(long threadId) {
|
|
|
|
DatabaseFactory.getSmsDatabase(context).deleteThread(threadId);
|
|
|
|
DatabaseFactory.getMmsDatabase(context).deleteThread(threadId);
|
2015-01-04 00:25:35 +01:00
|
|
|
DatabaseFactory.getDraftDatabase(context).clearDrafts(threadId);
|
2011-12-20 10:20:44 -08:00
|
|
|
deleteThread(threadId);
|
|
|
|
notifyConversationListeners(threadId);
|
|
|
|
notifyConversationListListeners();
|
2012-09-09 16:10:46 -07:00
|
|
|
}
|
|
|
|
|
2011-12-20 10:20:44 -08:00
|
|
|
public void deleteConversations(Set<Long> selectedConversations) {
|
|
|
|
DatabaseFactory.getSmsDatabase(context).deleteThreads(selectedConversations);
|
|
|
|
DatabaseFactory.getMmsDatabase(context).deleteThreads(selectedConversations);
|
2015-01-04 00:25:35 +01:00
|
|
|
DatabaseFactory.getDraftDatabase(context).clearDrafts(selectedConversations);
|
2011-12-20 10:20:44 -08:00
|
|
|
deleteThreads(selectedConversations);
|
|
|
|
notifyConversationListeners(selectedConversations);
|
|
|
|
notifyConversationListListeners();
|
|
|
|
}
|
2012-09-09 16:10:46 -07:00
|
|
|
|
2011-12-20 10:20:44 -08:00
|
|
|
public void deleteAllConversations() {
|
|
|
|
DatabaseFactory.getSmsDatabase(context).deleteAllThreads();
|
|
|
|
DatabaseFactory.getMmsDatabase(context).deleteAllThreads();
|
2015-01-04 00:25:35 +01:00
|
|
|
DatabaseFactory.getDraftDatabase(context).clearAllDrafts();
|
2012-09-09 16:10:46 -07:00
|
|
|
deleteAllThreads();
|
2011-12-20 10:20:44 -08:00
|
|
|
}
|
|
|
|
|
2017-08-01 08:56:00 -07:00
|
|
|
public long getThreadIdIfExistsFor(Recipient recipient) {
|
2019-08-07 14:22:51 -04:00
|
|
|
SQLiteDatabase db = databaseHelper.getReadableDatabase();
|
|
|
|
String where = RECIPIENT_ID + " = ?";
|
|
|
|
String[] recipientsArg = new String[] {recipient.getId().serialize()};
|
|
|
|
Cursor cursor = null;
|
2012-09-09 16:10:46 -07:00
|
|
|
|
2011-12-20 10:20:44 -08:00
|
|
|
try {
|
|
|
|
cursor = db.query(TABLE_NAME, new String[]{ID}, where, recipientsArg, null, null, null);
|
2012-09-09 16:10:46 -07:00
|
|
|
|
2011-12-20 10:20:44 -08:00
|
|
|
if (cursor != null && cursor.moveToFirst())
|
2012-09-30 19:56:29 -07:00
|
|
|
return cursor.getLong(cursor.getColumnIndexOrThrow(ID));
|
2011-12-20 10:20:44 -08:00
|
|
|
else
|
2012-09-30 19:56:29 -07:00
|
|
|
return -1L;
|
2011-12-20 10:20:44 -08:00
|
|
|
} finally {
|
|
|
|
if (cursor != null)
|
2012-09-30 19:56:29 -07:00
|
|
|
cursor.close();
|
2011-12-20 10:20:44 -08:00
|
|
|
}
|
|
|
|
}
|
2012-09-09 16:10:46 -07:00
|
|
|
|
2017-08-01 08:56:00 -07:00
|
|
|
public long getThreadIdFor(Recipient recipient) {
|
|
|
|
return getThreadIdFor(recipient, DistributionTypes.DEFAULT);
|
2013-04-25 18:59:49 -07:00
|
|
|
}
|
|
|
|
|
2017-08-01 08:56:00 -07:00
|
|
|
public long getThreadIdFor(Recipient recipient, int distributionType) {
|
2017-07-26 09:59:15 -07:00
|
|
|
SQLiteDatabase db = databaseHelper.getReadableDatabase();
|
2019-08-07 14:22:51 -04:00
|
|
|
String where = RECIPIENT_ID + " = ?";
|
|
|
|
String[] recipientsArg = new String[]{recipient.getId().serialize()};
|
2017-07-26 09:59:15 -07:00
|
|
|
Cursor cursor = null;
|
2012-09-09 16:10:46 -07:00
|
|
|
|
2011-12-20 10:20:44 -08:00
|
|
|
try {
|
|
|
|
cursor = db.query(TABLE_NAME, new String[]{ID}, where, recipientsArg, null, null, null);
|
2012-09-09 16:10:46 -07:00
|
|
|
|
2017-07-26 09:59:15 -07:00
|
|
|
if (cursor != null && cursor.moveToFirst()) {
|
2012-09-30 19:56:29 -07:00
|
|
|
return cursor.getLong(cursor.getColumnIndexOrThrow(ID));
|
2017-07-26 09:59:15 -07:00
|
|
|
} else {
|
2019-08-07 14:22:51 -04:00
|
|
|
return createThreadForRecipient(recipient.getId(), recipient.isGroup(), distributionType);
|
2017-07-26 09:59:15 -07:00
|
|
|
}
|
2011-12-20 10:20:44 -08:00
|
|
|
} finally {
|
|
|
|
if (cursor != null)
|
2012-09-30 19:56:29 -07:00
|
|
|
cursor.close();
|
2011-12-20 10:20:44 -08:00
|
|
|
}
|
|
|
|
}
|
2012-09-09 16:10:46 -07:00
|
|
|
|
2017-08-01 08:56:00 -07:00
|
|
|
public @Nullable Recipient getRecipientForThreadId(long threadId) {
|
2013-02-09 15:17:55 -08:00
|
|
|
SQLiteDatabase db = databaseHelper.getReadableDatabase();
|
|
|
|
Cursor cursor = null;
|
|
|
|
|
|
|
|
try {
|
|
|
|
cursor = db.query(TABLE_NAME, null, ID + " = ?", new String[] {threadId+""}, null, null, null);
|
|
|
|
|
|
|
|
if (cursor != null && cursor.moveToFirst()) {
|
2019-08-07 14:22:51 -04:00
|
|
|
RecipientId id = RecipientId.from(cursor.getLong(cursor.getColumnIndexOrThrow(RECIPIENT_ID)));
|
|
|
|
return Recipient.resolved(id);
|
2013-02-09 15:17:55 -08:00
|
|
|
}
|
|
|
|
} finally {
|
|
|
|
if (cursor != null)
|
|
|
|
cursor.close();
|
|
|
|
}
|
|
|
|
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2017-08-18 17:28:56 -07:00
|
|
|
public void setHasSent(long threadId, boolean hasSent) {
|
|
|
|
ContentValues contentValues = new ContentValues(1);
|
|
|
|
contentValues.put(HAS_SENT, hasSent ? 1 : 0);
|
|
|
|
|
|
|
|
databaseHelper.getWritableDatabase().update(TABLE_NAME, contentValues, ID_WHERE,
|
|
|
|
new String[] {String.valueOf(threadId)});
|
|
|
|
|
|
|
|
notifyConversationListeners(threadId);
|
|
|
|
}
|
|
|
|
|
2017-11-13 18:01:05 -08:00
|
|
|
void updateReadState(long threadId) {
|
2016-02-19 17:07:41 -08:00
|
|
|
int unreadCount = DatabaseFactory.getMmsSmsDatabase(context).getUnreadCount(threadId);
|
|
|
|
|
|
|
|
ContentValues contentValues = new ContentValues();
|
|
|
|
contentValues.put(READ, unreadCount == 0);
|
2017-11-13 18:01:05 -08:00
|
|
|
contentValues.put(UNREAD_COUNT, unreadCount);
|
2016-02-19 17:07:41 -08:00
|
|
|
|
|
|
|
databaseHelper.getWritableDatabase().update(TABLE_NAME, contentValues,ID_WHERE,
|
|
|
|
new String[] {String.valueOf(threadId)});
|
|
|
|
|
|
|
|
notifyConversationListListeners();
|
|
|
|
}
|
|
|
|
|
2015-11-23 15:07:41 -08:00
|
|
|
public boolean update(long threadId, boolean unarchive) {
|
2011-12-20 10:20:44 -08:00
|
|
|
MmsSmsDatabase mmsSmsDatabase = DatabaseFactory.getMmsSmsDatabase(context);
|
|
|
|
long count = mmsSmsDatabase.getConversationCount(threadId);
|
2012-09-09 16:10:46 -07:00
|
|
|
|
2011-12-20 10:20:44 -08:00
|
|
|
if (count == 0) {
|
|
|
|
deleteThread(threadId);
|
|
|
|
notifyConversationListListeners();
|
2015-03-31 13:36:04 -07:00
|
|
|
return true;
|
2011-12-20 10:20:44 -08:00
|
|
|
}
|
2012-09-09 16:10:46 -07:00
|
|
|
|
2013-04-26 11:23:43 -07:00
|
|
|
MmsSmsDatabase.Reader reader = null;
|
2012-09-09 16:10:46 -07:00
|
|
|
|
2011-12-20 10:20:44 -08:00
|
|
|
try {
|
2014-06-12 08:59:54 -07:00
|
|
|
reader = mmsSmsDatabase.readerFor(mmsSmsDatabase.getConversationSnippet(threadId));
|
|
|
|
MessageRecord record;
|
2013-04-26 11:23:43 -07:00
|
|
|
|
|
|
|
if (reader != null && (record = reader.getNext()) != null) {
|
2018-06-20 16:37:14 -07:00
|
|
|
updateThread(threadId, count, getFormattedBodyFor(record), getAttachmentUriFor(record),
|
2019-06-11 02:18:45 -04:00
|
|
|
getContentTypeFor(record), getExtrasFor(record),
|
2017-09-15 22:38:53 -07:00
|
|
|
record.getTimestamp(), record.getDeliveryStatus(), record.getDeliveryReceiptCount(),
|
|
|
|
record.getType(), unarchive, record.getExpiresIn(), record.getReadReceiptCount());
|
2015-03-31 13:36:04 -07:00
|
|
|
notifyConversationListListeners();
|
|
|
|
return false;
|
2012-09-30 19:56:29 -07:00
|
|
|
} else {
|
|
|
|
deleteThread(threadId);
|
2015-03-31 13:36:04 -07:00
|
|
|
notifyConversationListListeners();
|
|
|
|
return true;
|
2012-09-30 19:56:29 -07:00
|
|
|
}
|
2011-12-20 10:20:44 -08:00
|
|
|
} finally {
|
2013-04-26 11:23:43 -07:00
|
|
|
if (reader != null)
|
|
|
|
reader.close();
|
2011-12-20 10:20:44 -08:00
|
|
|
}
|
|
|
|
}
|
2013-01-09 21:06:56 -08:00
|
|
|
|
2018-06-20 16:37:14 -07:00
|
|
|
private @NonNull String getFormattedBodyFor(@NonNull MessageRecord messageRecord) {
|
2018-06-27 09:43:02 -07:00
|
|
|
if (messageRecord.isMms() && ((MmsMessageRecord) messageRecord).getSharedContacts().size() > 0) {
|
|
|
|
Contact contact = ((MmsMessageRecord) messageRecord).getSharedContacts().get(0);
|
2018-06-20 16:37:14 -07:00
|
|
|
return ContactUtil.getStringSummary(context, contact).toString();
|
|
|
|
}
|
|
|
|
|
|
|
|
return messageRecord.getBody();
|
|
|
|
}
|
|
|
|
|
2015-10-16 13:59:40 -07:00
|
|
|
private @Nullable Uri getAttachmentUriFor(MessageRecord record) {
|
2015-11-04 15:39:01 -08:00
|
|
|
if (!record.isMms() || record.isMmsNotification() || record.isGroupAction()) return null;
|
2015-10-16 13:59:40 -07:00
|
|
|
|
|
|
|
SlideDeck slideDeck = ((MediaMmsMessageRecord)record).getSlideDeck();
|
|
|
|
Slide thumbnail = slideDeck.getThumbnailSlide();
|
|
|
|
|
2019-07-31 19:33:56 -04:00
|
|
|
if (thumbnail != null && !((MmsMessageRecord) record).isViewOnce()) {
|
2019-04-17 10:21:30 -04:00
|
|
|
return thumbnail.getThumbnailUri();
|
|
|
|
}
|
|
|
|
|
|
|
|
return null;
|
2015-10-16 13:59:40 -07:00
|
|
|
}
|
|
|
|
|
2019-06-11 02:18:45 -04:00
|
|
|
private @Nullable String getContentTypeFor(MessageRecord record) {
|
|
|
|
if (record.isMms()) {
|
|
|
|
SlideDeck slideDeck = ((MmsMessageRecord) record).getSlideDeck();
|
|
|
|
|
|
|
|
if (slideDeck.getSlides().size() > 0) {
|
|
|
|
return slideDeck.getSlides().get(0).getContentType();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
private @Nullable Extra getExtrasFor(MessageRecord record) {
|
2019-07-31 19:33:56 -04:00
|
|
|
if (record.isMms() && ((MmsMessageRecord) record).isViewOnce()) {
|
2019-06-11 02:18:45 -04:00
|
|
|
return Extra.forRevealableMessage();
|
|
|
|
} else if (record.isMms() && ((MmsMessageRecord) record).getSlideDeck().getStickerSlide() != null) {
|
|
|
|
return Extra.forSticker();
|
|
|
|
} else if (record.isMms() && ((MmsMessageRecord) record).getSlideDeck().getSlides().size() > 1) {
|
|
|
|
return Extra.forAlbum();
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2017-11-16 15:21:46 -08:00
|
|
|
private @NonNull String createQuery(@NonNull String where, int limit) {
|
2017-09-15 10:36:33 -07:00
|
|
|
String projection = Util.join(COMBINED_THREAD_RECIPIENT_GROUP_PROJECTION, ",");
|
2017-11-16 15:21:46 -08:00
|
|
|
String query =
|
|
|
|
"SELECT " + projection + " FROM " + TABLE_NAME +
|
2017-09-15 10:36:33 -07:00
|
|
|
" LEFT OUTER JOIN " + RecipientDatabase.TABLE_NAME +
|
2019-08-07 14:22:51 -04:00
|
|
|
" ON " + TABLE_NAME + "." + RECIPIENT_ID + " = " + RecipientDatabase.TABLE_NAME + "." + RecipientDatabase.ID +
|
2017-09-15 10:36:33 -07:00
|
|
|
" LEFT OUTER JOIN " + GroupDatabase.TABLE_NAME +
|
2019-08-07 14:22:51 -04:00
|
|
|
" ON " + TABLE_NAME + "." + RECIPIENT_ID + " = " + GroupDatabase.TABLE_NAME + "." + GroupDatabase.RECIPIENT_ID +
|
2017-09-15 10:36:33 -07:00
|
|
|
" WHERE " + where +
|
|
|
|
" ORDER BY " + TABLE_NAME + "." + DATE + " DESC";
|
2017-11-16 15:21:46 -08:00
|
|
|
|
|
|
|
if (limit > 0) {
|
|
|
|
query += " LIMIT " + limit;
|
|
|
|
}
|
|
|
|
|
|
|
|
return query;
|
2017-09-15 10:36:33 -07:00
|
|
|
}
|
|
|
|
|
2017-11-13 18:01:05 -08:00
|
|
|
public interface ProgressListener {
|
|
|
|
void onProgress(int complete, int total);
|
2013-01-09 21:06:56 -08:00
|
|
|
}
|
Major storage layer refactoring to set the stage for clean GCM.
1) We now try to hand out cursors at a minimum. There has always been
a fairly clean insertion layer that handles encrypting message bodies,
but the process of decrypting message bodies has always been less than
ideal. Here we introduce a "Reader" interface that will decrypt message
bodies when appropriate and return objects that encapsulate record state.
No more MessageDisplayHelper. The MmsSmsDatabase interface is also more
sane.
2) We finally rid ourselves of the technical debt associated with TextSecure's
initial usage of the default SMS DB. In that world, we weren't able to use
anything other than the default "Inbox, Outbox, Sent" types to describe a
message, and had to overload the message content itself with a set of
local "prefixes" to describe what it was (encrypted, asymetric encrypted,
remote encrypted, a key exchange, procssed key exchange), and so on.
This includes a major schema update that transforms the "type" field into
a bitmask that describes everything that used to be encoded in a prefix,
and prefixes have been completely eliminated from the system.
No more Prefix.java
3) Refactoring of the MultipartMessageHandler code. It's less of a mess, and
hopefully more clear as to what's going on.
The next step is to remove what we can from SmsTransportDetails and genericize
that interface for a GCM equivalent.
2013-04-20 12:22:04 -07:00
|
|
|
|
2018-01-24 19:17:44 -08:00
|
|
|
public Reader readerFor(Cursor cursor) {
|
|
|
|
return new Reader(cursor);
|
Major storage layer refactoring to set the stage for clean GCM.
1) We now try to hand out cursors at a minimum. There has always been
a fairly clean insertion layer that handles encrypting message bodies,
but the process of decrypting message bodies has always been less than
ideal. Here we introduce a "Reader" interface that will decrypt message
bodies when appropriate and return objects that encapsulate record state.
No more MessageDisplayHelper. The MmsSmsDatabase interface is also more
sane.
2) We finally rid ourselves of the technical debt associated with TextSecure's
initial usage of the default SMS DB. In that world, we weren't able to use
anything other than the default "Inbox, Outbox, Sent" types to describe a
message, and had to overload the message content itself with a set of
local "prefixes" to describe what it was (encrypted, asymetric encrypted,
remote encrypted, a key exchange, procssed key exchange), and so on.
This includes a major schema update that transforms the "type" field into
a bitmask that describes everything that used to be encoded in a prefix,
and prefixes have been completely eliminated from the system.
No more Prefix.java
3) Refactoring of the MultipartMessageHandler code. It's less of a mess, and
hopefully more clear as to what's going on.
The next step is to remove what we can from SmsTransportDetails and genericize
that interface for a GCM equivalent.
2013-04-20 12:22:04 -07:00
|
|
|
}
|
|
|
|
|
2013-04-25 18:59:49 -07:00
|
|
|
public static class DistributionTypes {
|
|
|
|
public static final int DEFAULT = 2;
|
|
|
|
public static final int BROADCAST = 1;
|
|
|
|
public static final int CONVERSATION = 2;
|
2015-11-23 15:07:41 -08:00
|
|
|
public static final int ARCHIVE = 3;
|
2017-11-13 09:11:58 -08:00
|
|
|
public static final int INBOX_ZERO = 4;
|
2013-04-25 18:59:49 -07:00
|
|
|
}
|
|
|
|
|
2018-04-06 18:15:24 -07:00
|
|
|
public class Reader implements Closeable {
|
Major storage layer refactoring to set the stage for clean GCM.
1) We now try to hand out cursors at a minimum. There has always been
a fairly clean insertion layer that handles encrypting message bodies,
but the process of decrypting message bodies has always been less than
ideal. Here we introduce a "Reader" interface that will decrypt message
bodies when appropriate and return objects that encapsulate record state.
No more MessageDisplayHelper. The MmsSmsDatabase interface is also more
sane.
2) We finally rid ourselves of the technical debt associated with TextSecure's
initial usage of the default SMS DB. In that world, we weren't able to use
anything other than the default "Inbox, Outbox, Sent" types to describe a
message, and had to overload the message content itself with a set of
local "prefixes" to describe what it was (encrypted, asymetric encrypted,
remote encrypted, a key exchange, procssed key exchange), and so on.
This includes a major schema update that transforms the "type" field into
a bitmask that describes everything that used to be encoded in a prefix,
and prefixes have been completely eliminated from the system.
No more Prefix.java
3) Refactoring of the MultipartMessageHandler code. It's less of a mess, and
hopefully more clear as to what's going on.
The next step is to remove what we can from SmsTransportDetails and genericize
that interface for a GCM equivalent.
2013-04-20 12:22:04 -07:00
|
|
|
|
2018-01-24 19:17:44 -08:00
|
|
|
private final Cursor cursor;
|
Major storage layer refactoring to set the stage for clean GCM.
1) We now try to hand out cursors at a minimum. There has always been
a fairly clean insertion layer that handles encrypting message bodies,
but the process of decrypting message bodies has always been less than
ideal. Here we introduce a "Reader" interface that will decrypt message
bodies when appropriate and return objects that encapsulate record state.
No more MessageDisplayHelper. The MmsSmsDatabase interface is also more
sane.
2) We finally rid ourselves of the technical debt associated with TextSecure's
initial usage of the default SMS DB. In that world, we weren't able to use
anything other than the default "Inbox, Outbox, Sent" types to describe a
message, and had to overload the message content itself with a set of
local "prefixes" to describe what it was (encrypted, asymetric encrypted,
remote encrypted, a key exchange, procssed key exchange), and so on.
This includes a major schema update that transforms the "type" field into
a bitmask that describes everything that used to be encoded in a prefix,
and prefixes have been completely eliminated from the system.
No more Prefix.java
3) Refactoring of the MultipartMessageHandler code. It's less of a mess, and
hopefully more clear as to what's going on.
The next step is to remove what we can from SmsTransportDetails and genericize
that interface for a GCM equivalent.
2013-04-20 12:22:04 -07:00
|
|
|
|
2018-01-24 19:17:44 -08:00
|
|
|
public Reader(Cursor cursor) {
|
|
|
|
this.cursor = cursor;
|
Major storage layer refactoring to set the stage for clean GCM.
1) We now try to hand out cursors at a minimum. There has always been
a fairly clean insertion layer that handles encrypting message bodies,
but the process of decrypting message bodies has always been less than
ideal. Here we introduce a "Reader" interface that will decrypt message
bodies when appropriate and return objects that encapsulate record state.
No more MessageDisplayHelper. The MmsSmsDatabase interface is also more
sane.
2) We finally rid ourselves of the technical debt associated with TextSecure's
initial usage of the default SMS DB. In that world, we weren't able to use
anything other than the default "Inbox, Outbox, Sent" types to describe a
message, and had to overload the message content itself with a set of
local "prefixes" to describe what it was (encrypted, asymetric encrypted,
remote encrypted, a key exchange, procssed key exchange), and so on.
This includes a major schema update that transforms the "type" field into
a bitmask that describes everything that used to be encoded in a prefix,
and prefixes have been completely eliminated from the system.
No more Prefix.java
3) Refactoring of the MultipartMessageHandler code. It's less of a mess, and
hopefully more clear as to what's going on.
The next step is to remove what we can from SmsTransportDetails and genericize
that interface for a GCM equivalent.
2013-04-20 12:22:04 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
public ThreadRecord getNext() {
|
|
|
|
if (cursor == null || !cursor.moveToNext())
|
|
|
|
return null;
|
|
|
|
|
|
|
|
return getCurrent();
|
|
|
|
}
|
|
|
|
|
|
|
|
public ThreadRecord getCurrent() {
|
2019-08-07 14:22:51 -04:00
|
|
|
long threadId = cursor.getLong(cursor.getColumnIndexOrThrow(ThreadDatabase.ID));
|
|
|
|
int distributionType = cursor.getInt(cursor.getColumnIndexOrThrow(ThreadDatabase.TYPE));
|
|
|
|
RecipientId recipientId = RecipientId.from(cursor.getLong(cursor.getColumnIndexOrThrow(ThreadDatabase.RECIPIENT_ID)));
|
2017-08-15 21:03:31 -07:00
|
|
|
|
2019-08-07 14:22:51 -04:00
|
|
|
Recipient recipient = Recipient.live(recipientId).get();
|
2018-02-01 18:29:09 -08:00
|
|
|
String body = cursor.getString(cursor.getColumnIndexOrThrow(ThreadDatabase.SNIPPET));
|
2017-09-15 22:38:53 -07:00
|
|
|
long date = cursor.getLong(cursor.getColumnIndexOrThrow(ThreadDatabase.DATE));
|
|
|
|
long count = cursor.getLong(cursor.getColumnIndexOrThrow(ThreadDatabase.MESSAGE_COUNT));
|
2017-11-13 18:01:05 -08:00
|
|
|
int unreadCount = cursor.getInt(cursor.getColumnIndexOrThrow(ThreadDatabase.UNREAD_COUNT));
|
2017-09-15 22:38:53 -07:00
|
|
|
long type = cursor.getLong(cursor.getColumnIndexOrThrow(ThreadDatabase.SNIPPET_TYPE));
|
|
|
|
boolean archived = cursor.getInt(cursor.getColumnIndex(ThreadDatabase.ARCHIVED)) != 0;
|
|
|
|
int status = cursor.getInt(cursor.getColumnIndexOrThrow(ThreadDatabase.STATUS));
|
|
|
|
int deliveryReceiptCount = cursor.getInt(cursor.getColumnIndexOrThrow(ThreadDatabase.DELIVERY_RECEIPT_COUNT));
|
|
|
|
int readReceiptCount = cursor.getInt(cursor.getColumnIndexOrThrow(ThreadDatabase.READ_RECEIPT_COUNT));
|
|
|
|
long expiresIn = cursor.getLong(cursor.getColumnIndexOrThrow(ThreadDatabase.EXPIRES_IN));
|
|
|
|
long lastSeen = cursor.getLong(cursor.getColumnIndexOrThrow(ThreadDatabase.LAST_SEEN));
|
|
|
|
Uri snippetUri = getSnippetUri(cursor);
|
2019-06-11 02:18:45 -04:00
|
|
|
String contentType = cursor.getString(cursor.getColumnIndexOrThrow(ThreadDatabase.SNIPPET_CONTENT_TYPE));
|
|
|
|
String extraString = cursor.getString(cursor.getColumnIndexOrThrow(ThreadDatabase.SNIPPET_EXTRAS));
|
2017-09-15 22:38:53 -07:00
|
|
|
|
|
|
|
if (!TextSecurePreferences.isReadReceiptsEnabled(context)) {
|
|
|
|
readReceiptCount = 0;
|
|
|
|
}
|
Major storage layer refactoring to set the stage for clean GCM.
1) We now try to hand out cursors at a minimum. There has always been
a fairly clean insertion layer that handles encrypting message bodies,
but the process of decrypting message bodies has always been less than
ideal. Here we introduce a "Reader" interface that will decrypt message
bodies when appropriate and return objects that encapsulate record state.
No more MessageDisplayHelper. The MmsSmsDatabase interface is also more
sane.
2) We finally rid ourselves of the technical debt associated with TextSecure's
initial usage of the default SMS DB. In that world, we weren't able to use
anything other than the default "Inbox, Outbox, Sent" types to describe a
message, and had to overload the message content itself with a set of
local "prefixes" to describe what it was (encrypted, asymetric encrypted,
remote encrypted, a key exchange, procssed key exchange), and so on.
This includes a major schema update that transforms the "type" field into
a bitmask that describes everything that used to be encoded in a prefix,
and prefixes have been completely eliminated from the system.
No more Prefix.java
3) Refactoring of the MultipartMessageHandler code. It's less of a mess, and
hopefully more clear as to what's going on.
The next step is to remove what we can from SmsTransportDetails and genericize
that interface for a GCM equivalent.
2013-04-20 12:22:04 -07:00
|
|
|
|
2019-06-11 02:18:45 -04:00
|
|
|
Extra extra = null;
|
|
|
|
|
|
|
|
if (extraString != null) {
|
|
|
|
try {
|
|
|
|
extra = JsonUtils.fromJson(extraString, Extra.class);
|
|
|
|
} catch (IOException e) {
|
|
|
|
Log.w(TAG, "Failed to decode extras!");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return new ThreadRecord(body, snippetUri, contentType, extra, recipient, date, count,
|
2017-11-13 18:01:05 -08:00
|
|
|
unreadCount, threadId, deliveryReceiptCount, status, type,
|
|
|
|
distributionType, archived, expiresIn, lastSeen, readReceiptCount);
|
Major storage layer refactoring to set the stage for clean GCM.
1) We now try to hand out cursors at a minimum. There has always been
a fairly clean insertion layer that handles encrypting message bodies,
but the process of decrypting message bodies has always been less than
ideal. Here we introduce a "Reader" interface that will decrypt message
bodies when appropriate and return objects that encapsulate record state.
No more MessageDisplayHelper. The MmsSmsDatabase interface is also more
sane.
2) We finally rid ourselves of the technical debt associated with TextSecure's
initial usage of the default SMS DB. In that world, we weren't able to use
anything other than the default "Inbox, Outbox, Sent" types to describe a
message, and had to overload the message content itself with a set of
local "prefixes" to describe what it was (encrypted, asymetric encrypted,
remote encrypted, a key exchange, procssed key exchange), and so on.
This includes a major schema update that transforms the "type" field into
a bitmask that describes everything that used to be encoded in a prefix,
and prefixes have been completely eliminated from the system.
No more Prefix.java
3) Refactoring of the MultipartMessageHandler code. It's less of a mess, and
hopefully more clear as to what's going on.
The next step is to remove what we can from SmsTransportDetails and genericize
that interface for a GCM equivalent.
2013-04-20 12:22:04 -07:00
|
|
|
}
|
|
|
|
|
2015-10-16 13:59:40 -07:00
|
|
|
private @Nullable Uri getSnippetUri(Cursor cursor) {
|
|
|
|
if (cursor.isNull(cursor.getColumnIndexOrThrow(ThreadDatabase.SNIPPET_URI))) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
try {
|
|
|
|
return Uri.parse(cursor.getString(cursor.getColumnIndexOrThrow(ThreadDatabase.SNIPPET_URI)));
|
|
|
|
} catch (IllegalArgumentException e) {
|
|
|
|
Log.w(TAG, e);
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-04-06 18:15:24 -07:00
|
|
|
@Override
|
Major storage layer refactoring to set the stage for clean GCM.
1) We now try to hand out cursors at a minimum. There has always been
a fairly clean insertion layer that handles encrypting message bodies,
but the process of decrypting message bodies has always been less than
ideal. Here we introduce a "Reader" interface that will decrypt message
bodies when appropriate and return objects that encapsulate record state.
No more MessageDisplayHelper. The MmsSmsDatabase interface is also more
sane.
2) We finally rid ourselves of the technical debt associated with TextSecure's
initial usage of the default SMS DB. In that world, we weren't able to use
anything other than the default "Inbox, Outbox, Sent" types to describe a
message, and had to overload the message content itself with a set of
local "prefixes" to describe what it was (encrypted, asymetric encrypted,
remote encrypted, a key exchange, procssed key exchange), and so on.
This includes a major schema update that transforms the "type" field into
a bitmask that describes everything that used to be encoded in a prefix,
and prefixes have been completely eliminated from the system.
No more Prefix.java
3) Refactoring of the MultipartMessageHandler code. It's less of a mess, and
hopefully more clear as to what's going on.
The next step is to remove what we can from SmsTransportDetails and genericize
that interface for a GCM equivalent.
2013-04-20 12:22:04 -07:00
|
|
|
public void close() {
|
2018-04-06 18:15:24 -07:00
|
|
|
if (cursor != null) {
|
|
|
|
cursor.close();
|
|
|
|
}
|
Major storage layer refactoring to set the stage for clean GCM.
1) We now try to hand out cursors at a minimum. There has always been
a fairly clean insertion layer that handles encrypting message bodies,
but the process of decrypting message bodies has always been less than
ideal. Here we introduce a "Reader" interface that will decrypt message
bodies when appropriate and return objects that encapsulate record state.
No more MessageDisplayHelper. The MmsSmsDatabase interface is also more
sane.
2) We finally rid ourselves of the technical debt associated with TextSecure's
initial usage of the default SMS DB. In that world, we weren't able to use
anything other than the default "Inbox, Outbox, Sent" types to describe a
message, and had to overload the message content itself with a set of
local "prefixes" to describe what it was (encrypted, asymetric encrypted,
remote encrypted, a key exchange, procssed key exchange), and so on.
This includes a major schema update that transforms the "type" field into
a bitmask that describes everything that used to be encoded in a prefix,
and prefixes have been completely eliminated from the system.
No more Prefix.java
3) Refactoring of the MultipartMessageHandler code. It's less of a mess, and
hopefully more clear as to what's going on.
The next step is to remove what we can from SmsTransportDetails and genericize
that interface for a GCM equivalent.
2013-04-20 12:22:04 -07:00
|
|
|
}
|
|
|
|
}
|
2019-06-11 02:18:45 -04:00
|
|
|
|
|
|
|
public static final class Extra {
|
|
|
|
|
|
|
|
@JsonProperty private final boolean isRevealable;
|
|
|
|
@JsonProperty private final boolean isSticker;
|
|
|
|
@JsonProperty private final boolean isAlbum;
|
|
|
|
|
|
|
|
public Extra(@JsonProperty("isRevealable") boolean isRevealable,
|
|
|
|
@JsonProperty("isSticker") boolean isSticker,
|
|
|
|
@JsonProperty("isAlbum") boolean isAlbum)
|
|
|
|
{
|
|
|
|
this.isRevealable = isRevealable;
|
|
|
|
this.isSticker = isSticker;
|
|
|
|
this.isAlbum = isAlbum;
|
|
|
|
}
|
|
|
|
|
|
|
|
public static @NonNull Extra forRevealableMessage() {
|
|
|
|
return new Extra(true, false, false);
|
|
|
|
}
|
|
|
|
|
|
|
|
public static @NonNull Extra forSticker() {
|
|
|
|
return new Extra(false, true, false);
|
|
|
|
}
|
|
|
|
|
|
|
|
public static @NonNull Extra forAlbum() {
|
|
|
|
return new Extra(false, false, true);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public boolean isRevealable() {
|
|
|
|
return isRevealable;
|
|
|
|
}
|
|
|
|
|
|
|
|
public boolean isSticker() {
|
|
|
|
return isSticker;
|
|
|
|
}
|
|
|
|
|
|
|
|
public boolean isAlbum() {
|
|
|
|
return isAlbum;
|
|
|
|
}
|
|
|
|
}
|
2011-12-20 10:20:44 -08:00
|
|
|
}
|