kopia lustrzana https://github.com/ryukoposting/Signal-Android
Improve thread update performance by removing need for message count.
rodzic
c78e283084
commit
6eae2d39a8
|
@ -1,11 +1,8 @@
|
|||
package org.thoughtcrime.securesms.conversationlist;
|
||||
|
||||
import android.annotation.TargetApi;
|
||||
import android.content.Context;
|
||||
import android.os.Build;
|
||||
import android.util.AttributeSet;
|
||||
import android.widget.FrameLayout;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.TextView;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
|
@ -30,7 +27,6 @@ public class ConversationListItemAction extends FrameLayout implements BindableC
|
|||
super(context, attrs);
|
||||
}
|
||||
|
||||
@TargetApi(Build.VERSION_CODES.HONEYCOMB)
|
||||
public ConversationListItemAction(Context context, AttributeSet attrs, int defStyleAttr) {
|
||||
super(context, attrs, defStyleAttr);
|
||||
}
|
||||
|
@ -49,7 +45,7 @@ public class ConversationListItemAction extends FrameLayout implements BindableC
|
|||
@NonNull Set<Long> selectedThreads,
|
||||
boolean batchMode)
|
||||
{
|
||||
this.description.setText(getContext().getString(R.string.ConversationListItemAction_archived_conversations_d, thread.getCount()));
|
||||
this.description.setText(getContext().getString(R.string.ConversationListItemAction_archived_conversations_d, thread.getUnreadCount()));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -47,7 +47,7 @@ public class ConversationReader extends ThreadDatabase.StaticReader {
|
|||
.setBody(type.toString())
|
||||
.setDate(100)
|
||||
.setRecipient(Recipient.UNKNOWN)
|
||||
.setCount(count)
|
||||
.setUnreadCount(count)
|
||||
.build();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -80,7 +80,6 @@ public abstract class MessageDatabase extends Database implements MmsSmsColumns
|
|||
public abstract long getThreadIdForMessage(long id);
|
||||
public abstract int getMessageCountForThread(long threadId);
|
||||
public abstract int getMessageCountForThread(long threadId, long beforeTime);
|
||||
abstract int getMessageCountForThreadSummary(long threadId);
|
||||
public abstract boolean hasMeaningfulMessage(long threadId);
|
||||
public abstract Optional<MmsNotificationInfo> getNotification(long messageId);
|
||||
|
||||
|
@ -173,7 +172,7 @@ public abstract class MessageDatabase extends Database implements MmsSmsColumns
|
|||
|
||||
public abstract boolean deleteMessage(long messageId);
|
||||
abstract void deleteThread(long threadId);
|
||||
abstract void deleteMessagesInThreadBeforeDate(long threadId, long date);
|
||||
abstract boolean deleteMessagesInThreadBeforeDate(long threadId, long date);
|
||||
abstract void deleteThreads(@NonNull Set<Long> threadIds);
|
||||
abstract void deleteAllThreads();
|
||||
abstract void deleteAbandonedMessages();
|
||||
|
|
|
@ -260,11 +260,6 @@ public class MmsDatabase extends MessageDatabase {
|
|||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
int getMessageCountForThreadSummary(long threadId) {
|
||||
return getMessageCountForThread(threadId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Cursor getExpirationStartedMessages() {
|
||||
String where = EXPIRE_STARTED + " > 0";
|
||||
|
@ -602,11 +597,7 @@ public class MmsDatabase extends MessageDatabase {
|
|||
public boolean hasMeaningfulMessage(long threadId) {
|
||||
SQLiteDatabase db = databaseHelper.getReadableDatabase();
|
||||
|
||||
String[] cols = new String[] { "1" };
|
||||
String query = THREAD_ID + " = ?";
|
||||
String[] args = SqlUtil.buildArgs(threadId);
|
||||
|
||||
try (Cursor cursor = db.query(TABLE_NAME, cols, query, args, null, null, null, "1")) {
|
||||
try (Cursor cursor = db.query(TABLE_NAME, new String[] { "1" }, THREAD_ID_WHERE, SqlUtil.buildArgs(threadId), null, null, null, "1")) {
|
||||
return cursor != null && cursor.moveToFirst();
|
||||
}
|
||||
}
|
||||
|
@ -1105,6 +1096,7 @@ public class MmsDatabase extends MessageDatabase {
|
|||
|
||||
try (Cursor cursor = database.query(ThreadDatabase.TABLE_NAME, new String[] { ThreadDatabase.ID }, ThreadDatabase.EXPIRES_IN + " > 0", null, null, null, null)) {
|
||||
while (cursor != null && cursor.moveToNext()) {
|
||||
DatabaseFactory.getThreadDatabase(context).setLastScrolled(cursor.getLong(0), 0);
|
||||
DatabaseFactory.getThreadDatabase(context).update(cursor.getLong(0), false);
|
||||
}
|
||||
}
|
||||
|
@ -1640,6 +1632,7 @@ public class MmsDatabase extends MessageDatabase {
|
|||
}
|
||||
|
||||
notifyConversationListeners(contentValues.getAsLong(THREAD_ID));
|
||||
DatabaseFactory.getThreadDatabase(context).setLastScrolled(contentValues.getAsLong(THREAD_ID), 0);
|
||||
DatabaseFactory.getThreadDatabase(context).update(contentValues.getAsLong(THREAD_ID), true);
|
||||
}
|
||||
}
|
||||
|
@ -1661,6 +1654,7 @@ public class MmsDatabase extends MessageDatabase {
|
|||
SQLiteDatabase database = databaseHelper.getWritableDatabase();
|
||||
database.delete(TABLE_NAME, ID_WHERE, new String[] {messageId+""});
|
||||
|
||||
DatabaseFactory.getThreadDatabase(context).setLastScrolled(threadId, 0);
|
||||
boolean threadDeleted = DatabaseFactory.getThreadDatabase(context).update(threadId, false);
|
||||
notifyConversationListeners(threadId);
|
||||
notifyStickerListeners();
|
||||
|
@ -1788,11 +1782,11 @@ public class MmsDatabase extends MessageDatabase {
|
|||
}
|
||||
|
||||
@Override
|
||||
void deleteMessagesInThreadBeforeDate(long threadId, long date) {
|
||||
boolean deleteMessagesInThreadBeforeDate(long threadId, long date) {
|
||||
SQLiteDatabase db = databaseHelper.getWritableDatabase();
|
||||
String where = THREAD_ID + " = ? AND " + DATE_RECEIVED + " < " + date;
|
||||
|
||||
db.delete(TABLE_NAME, where, SqlUtil.buildArgs(threadId));
|
||||
return db.delete(TABLE_NAME, where, SqlUtil.buildArgs(threadId)) > 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -299,13 +299,6 @@ public class MmsSmsDatabase extends Database {
|
|||
DatabaseFactory.getMmsDatabase(context).getMessageCountForThread(threadId, beforeTime);
|
||||
}
|
||||
|
||||
public int getConversationCountForThreadSummary(long threadId) {
|
||||
int count = DatabaseFactory.getSmsDatabase(context).getMessageCountForThreadSummary(threadId);
|
||||
count += DatabaseFactory.getMmsDatabase(context).getMessageCountForThreadSummary(threadId);
|
||||
|
||||
return count;
|
||||
}
|
||||
|
||||
public int getInsecureSentCount(long threadId) {
|
||||
int count = DatabaseFactory.getSmsDatabase(context).getInsecureMessagesSentForThread(threadId);
|
||||
count += DatabaseFactory.getMmsDatabase(context).getInsecureMessagesSentForThread(threadId);
|
||||
|
@ -565,10 +558,11 @@ public class MmsSmsDatabase extends Database {
|
|||
DatabaseFactory.getMmsDatabase(context).setNotifiedTimestamp(timestamp, mmsIds);
|
||||
}
|
||||
|
||||
public void deleteMessagesInThreadBeforeDate(long threadId, long trimBeforeDate) {
|
||||
public boolean deleteMessagesInThreadBeforeDate(long threadId, long trimBeforeDate) {
|
||||
Log.d(TAG, "deleteMessagesInThreadBeforeData(" + threadId + ", " + trimBeforeDate + ")");
|
||||
DatabaseFactory.getSmsDatabase(context).deleteMessagesInThreadBeforeDate(threadId, trimBeforeDate);
|
||||
DatabaseFactory.getMmsDatabase(context).deleteMessagesInThreadBeforeDate(threadId, trimBeforeDate);
|
||||
boolean deletedSms = DatabaseFactory.getSmsDatabase(context).deleteMessagesInThreadBeforeDate(threadId, trimBeforeDate);
|
||||
boolean deletedMms = DatabaseFactory.getMmsDatabase(context).deleteMessagesInThreadBeforeDate(threadId, trimBeforeDate);
|
||||
return deletedSms || deletedMms;
|
||||
}
|
||||
|
||||
public void deleteAbandonedMessages() {
|
||||
|
|
|
@ -2990,6 +2990,7 @@ public class RecipientDatabase extends Database {
|
|||
db.update(MentionDatabase.TABLE_NAME, mentionThreadValues, MentionDatabase.THREAD_ID + " = ?", SqlUtil.buildArgs(threadMerge.previousThreadId));
|
||||
}
|
||||
|
||||
DatabaseFactory.getThreadDatabase(context).setLastScrolled(threadMerge.threadId, 0);
|
||||
DatabaseFactory.getThreadDatabase(context).update(threadMerge.threadId, false, false);
|
||||
|
||||
return byUuid;
|
||||
|
|
|
@ -147,8 +147,7 @@ public class SmsDatabase extends MessageDatabase {
|
|||
REMOTE_DELETED, NOTIFIED_TIMESTAMP
|
||||
};
|
||||
|
||||
private static final long IGNORABLE_TYPESMASK_WHEN_COUNTING = Types.END_SESSION_BIT | Types.KEY_EXCHANGE_IDENTITY_UPDATE_BIT | Types.KEY_EXCHANGE_IDENTITY_VERIFIED_BIT;
|
||||
private static final String[] THREAD_SUMMARY_COUNT_PROJECTION = new String[] { "SUM(1)", "SUM(CASE WHEN " + TYPE + " & " + IGNORABLE_TYPESMASK_WHEN_COUNTING + " OR " + TYPE + " = " + Types.PROFILE_CHANGE_TYPE + " THEN 1 ELSE 0 END)" };
|
||||
private static final long IGNORABLE_TYPESMASK_WHEN_COUNTING = Types.END_SESSION_BIT | Types.KEY_EXCHANGE_IDENTITY_UPDATE_BIT | Types.KEY_EXCHANGE_IDENTITY_VERIFIED_BIT;
|
||||
|
||||
private static final EarlyReceiptCache earlyDeliveryReceiptCache = new EarlyReceiptCache("SmsDelivery");
|
||||
|
||||
|
@ -218,22 +217,6 @@ public class SmsDatabase extends MessageDatabase {
|
|||
return -1;
|
||||
}
|
||||
|
||||
@Override
|
||||
int getMessageCountForThreadSummary(long threadId) {
|
||||
SQLiteDatabase db = databaseHelper.getReadableDatabase();
|
||||
|
||||
try (Cursor cursor = db.query(TABLE_NAME, THREAD_SUMMARY_COUNT_PROJECTION, THREAD_ID_WHERE, SqlUtil.buildArgs(threadId), null, null, null)) {
|
||||
if (cursor.moveToFirst()) {
|
||||
int allMessagesCount = cursor.getInt(0);
|
||||
int ignorableMessagesCount = cursor.getInt(1);
|
||||
|
||||
return allMessagesCount == ignorableMessagesCount ? 0 : allMessagesCount;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMessageCountForThread(long threadId) {
|
||||
SQLiteDatabase db = databaseHelper.getReadableDatabase();
|
||||
|
@ -1237,6 +1220,7 @@ public class SmsDatabase extends MessageDatabase {
|
|||
}
|
||||
|
||||
if (!message.isIdentityVerified() && !message.isIdentityDefault()) {
|
||||
DatabaseFactory.getThreadDatabase(context).setLastScrolled(threadId, 0);
|
||||
DatabaseFactory.getThreadDatabase(context).updateSilently(threadId, true);
|
||||
DatabaseFactory.getThreadDatabase(context).setLastSeenSilently(threadId);
|
||||
}
|
||||
|
@ -1301,6 +1285,7 @@ public class SmsDatabase extends MessageDatabase {
|
|||
|
||||
db.delete(TABLE_NAME, ID_WHERE, new String[] { messageId + "" });
|
||||
|
||||
DatabaseFactory.getThreadDatabase(context).setLastScrolled(threadId, 0);
|
||||
threadDeleted = DatabaseFactory.getThreadDatabase(context).update(threadId, false, true);
|
||||
|
||||
db.setTransactionSuccessful();
|
||||
|
@ -1350,11 +1335,11 @@ public class SmsDatabase extends MessageDatabase {
|
|||
}
|
||||
|
||||
@Override
|
||||
void deleteMessagesInThreadBeforeDate(long threadId, long date) {
|
||||
boolean deleteMessagesInThreadBeforeDate(long threadId, long date) {
|
||||
SQLiteDatabase db = databaseHelper.getWritableDatabase();
|
||||
String where = THREAD_ID + " = ? AND " + DATE_RECEIVED + " < " + date;
|
||||
|
||||
db.delete(TABLE_NAME, where, SqlUtil.buildArgs(threadId));
|
||||
return db.delete(TABLE_NAME, where, SqlUtil.buildArgs(threadId)) > 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -195,6 +195,7 @@ public class SmsMigrator {
|
|||
|
||||
ourSmsDatabase.endTransaction(transaction);
|
||||
DatabaseFactory.getThreadDatabase(context).update(ourThreadId, true);
|
||||
DatabaseFactory.getThreadDatabase(context).setLastScrolled(ourThreadId, 0);
|
||||
DatabaseFactory.getThreadDatabase(context).notifyConversationListeners(ourThreadId);
|
||||
|
||||
} finally {
|
||||
|
|
|
@ -88,7 +88,7 @@ public class ThreadDatabase extends Database {
|
|||
public static final String TABLE_NAME = "thread";
|
||||
public static final String ID = "_id";
|
||||
public static final String DATE = "date";
|
||||
public static final String MESSAGE_COUNT = "message_count";
|
||||
public static final String MEANINGFUL_MESSAGES = "message_count";
|
||||
public static final String RECIPIENT_ID = "thread_recipient_id";
|
||||
public static final String SNIPPET = "snippet";
|
||||
private static final String SNIPPET_CHARSET = "snippet_charset";
|
||||
|
@ -112,7 +112,7 @@ public class ThreadDatabase extends Database {
|
|||
|
||||
public static final String CREATE_TABLE = "CREATE TABLE " + TABLE_NAME + " (" + ID + " INTEGER PRIMARY KEY AUTOINCREMENT, " +
|
||||
DATE + " INTEGER DEFAULT 0, " +
|
||||
MESSAGE_COUNT + " INTEGER DEFAULT 0, " +
|
||||
MEANINGFUL_MESSAGES + " INTEGER DEFAULT 0, " +
|
||||
RECIPIENT_ID + " INTEGER, " +
|
||||
SNIPPET + " TEXT, " +
|
||||
SNIPPET_CHARSET + " INTEGER DEFAULT 0, " +
|
||||
|
@ -136,12 +136,12 @@ public class ThreadDatabase extends Database {
|
|||
|
||||
public static final String[] CREATE_INDEXS = {
|
||||
"CREATE INDEX IF NOT EXISTS thread_recipient_id_index ON " + TABLE_NAME + " (" + RECIPIENT_ID + ");",
|
||||
"CREATE INDEX IF NOT EXISTS archived_count_index ON " + TABLE_NAME + " (" + ARCHIVED + ", " + MESSAGE_COUNT + ");",
|
||||
"CREATE INDEX IF NOT EXISTS archived_count_index ON " + TABLE_NAME + " (" + ARCHIVED + ", " + MEANINGFUL_MESSAGES + ");",
|
||||
"CREATE INDEX IF NOT EXISTS thread_pinned_index ON " + TABLE_NAME + " (" + PINNED + ");",
|
||||
};
|
||||
|
||||
private static final String[] THREAD_PROJECTION = {
|
||||
ID, DATE, MESSAGE_COUNT, RECIPIENT_ID, SNIPPET, SNIPPET_CHARSET, READ, UNREAD_COUNT, TYPE, ERROR, SNIPPET_TYPE,
|
||||
ID, DATE, MEANINGFUL_MESSAGES, RECIPIENT_ID, SNIPPET, SNIPPET_CHARSET, READ, UNREAD_COUNT, TYPE, ERROR, SNIPPET_TYPE,
|
||||
SNIPPET_URI, SNIPPET_CONTENT_TYPE, SNIPPET_EXTRAS, ARCHIVED, STATUS, DELIVERY_RECEIPT_COUNT, EXPIRES_IN, LAST_SEEN, READ_RECEIPT_COUNT, LAST_SCROLLED, PINNED
|
||||
};
|
||||
|
||||
|
@ -174,7 +174,7 @@ public class ThreadDatabase extends Database {
|
|||
if (group)
|
||||
contentValues.put(TYPE, distributionType);
|
||||
|
||||
contentValues.put(MESSAGE_COUNT, 0);
|
||||
contentValues.put(MEANINGFUL_MESSAGES, 0);
|
||||
|
||||
SQLiteDatabase db = databaseHelper.getWritableDatabase();
|
||||
long result = db.insert(TABLE_NAME, null, contentValues);
|
||||
|
@ -184,7 +184,7 @@ public class ThreadDatabase extends Database {
|
|||
return result;
|
||||
}
|
||||
|
||||
private void updateThread(long threadId, long count, String body, @Nullable Uri attachment,
|
||||
private void updateThread(long threadId, boolean meaningfulMessages, String body, @Nullable Uri attachment,
|
||||
@Nullable String contentType, @Nullable Extra extra,
|
||||
long date, int status, int deliveryReceiptCount, long type, boolean unarchive,
|
||||
long expiresIn, int readReceiptCount)
|
||||
|
@ -206,14 +206,13 @@ public class ThreadDatabase extends Database {
|
|||
contentValues.put(SNIPPET_TYPE, type);
|
||||
contentValues.put(SNIPPET_CONTENT_TYPE, contentType);
|
||||
contentValues.put(SNIPPET_EXTRAS, extraSerialized);
|
||||
contentValues.put(MESSAGE_COUNT, count);
|
||||
contentValues.put(MEANINGFUL_MESSAGES, meaningfulMessages ? 1 : 0);
|
||||
contentValues.put(STATUS, status);
|
||||
contentValues.put(DELIVERY_RECEIPT_COUNT, deliveryReceiptCount);
|
||||
contentValues.put(READ_RECEIPT_COUNT, readReceiptCount);
|
||||
contentValues.put(EXPIRES_IN, expiresIn);
|
||||
|
||||
SQLiteDatabase db = databaseHelper.getWritableDatabase();
|
||||
db.execSQL("UPDATE " + TABLE_NAME + " SET " + LAST_SCROLLED + " = CASE WHEN " + MESSAGE_COUNT + " = ? THEN " + LAST_SCROLLED + " ELSE 0 END WHERE " + ID_WHERE, SqlUtil.buildArgs(count, threadId));
|
||||
db.update(TABLE_NAME, contentValues, ID_WHERE, SqlUtil.buildArgs(threadId));
|
||||
|
||||
if (unarchive) {
|
||||
|
@ -341,10 +340,13 @@ public class ThreadDatabase extends Database {
|
|||
if (trimBeforeDate != NO_TRIM_BEFORE_DATE_SET) {
|
||||
Log.i(TAG, "Trimming thread: " + threadId + " before: " + trimBeforeDate);
|
||||
|
||||
DatabaseFactory.getMmsSmsDatabase(context).deleteMessagesInThreadBeforeDate(threadId, trimBeforeDate);
|
||||
boolean deletedMessages = DatabaseFactory.getMmsSmsDatabase(context).deleteMessagesInThreadBeforeDate(threadId, trimBeforeDate);
|
||||
|
||||
update(threadId, false);
|
||||
notifyConversationListeners(threadId);
|
||||
if (deletedMessages) {
|
||||
setLastScrolled(threadId, 0);
|
||||
update(threadId, false);
|
||||
notifyConversationListeners(threadId);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -478,10 +480,12 @@ public class ThreadDatabase extends Database {
|
|||
|
||||
public void incrementUnread(long threadId, int amount) {
|
||||
SQLiteDatabase db = databaseHelper.getWritableDatabase();
|
||||
db.execSQL("UPDATE " + TABLE_NAME + " SET " + READ + " = " + ReadStatus.UNREAD.serialize() + ", " +
|
||||
UNREAD_COUNT + " = " + UNREAD_COUNT + " + ? WHERE " + ID + " = ?",
|
||||
new String[] {String.valueOf(amount),
|
||||
String.valueOf(threadId)});
|
||||
db.execSQL("UPDATE " + TABLE_NAME + " SET " +
|
||||
READ + " = " + ReadStatus.UNREAD.serialize() + ", " +
|
||||
UNREAD_COUNT + " = " + UNREAD_COUNT + " + ?, " +
|
||||
LAST_SCROLLED + " = ? " +
|
||||
"WHERE " + ID + " = ?",
|
||||
SqlUtil.buildArgs(amount, 0, threadId));
|
||||
}
|
||||
|
||||
public void setDistributionType(long threadId, int distributionType) {
|
||||
|
@ -543,8 +547,8 @@ public class ThreadDatabase extends Database {
|
|||
|
||||
public Cursor getRecentConversationList(int limit, boolean includeInactiveGroups, boolean groupsOnly, boolean hideV1Groups, boolean hideSms) {
|
||||
SQLiteDatabase db = databaseHelper.getReadableDatabase();
|
||||
String query = !includeInactiveGroups ? MESSAGE_COUNT + " != 0 AND (" + GroupDatabase.TABLE_NAME + "." + GroupDatabase.ACTIVE + " IS NULL OR " + GroupDatabase.TABLE_NAME + "." + GroupDatabase.ACTIVE + " = 1)"
|
||||
: MESSAGE_COUNT + " != 0";
|
||||
String query = !includeInactiveGroups ? MEANINGFUL_MESSAGES + " != 0 AND (" + GroupDatabase.TABLE_NAME + "." + GroupDatabase.ACTIVE + " IS NULL OR " + GroupDatabase.TABLE_NAME + "." + GroupDatabase.ACTIVE + " = 1)"
|
||||
: MEANINGFUL_MESSAGES + " != 0";
|
||||
|
||||
if (groupsOnly) {
|
||||
query += " AND " + RecipientDatabase.TABLE_NAME + "." + RecipientDatabase.GROUP_ID + " NOT NULL";
|
||||
|
@ -568,7 +572,7 @@ public class ThreadDatabase extends Database {
|
|||
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 " +
|
||||
String where = MEANINGFUL_MESSAGES + " != 0 AND " +
|
||||
"(" +
|
||||
RecipientDatabase.REGISTERED + " = " + RecipientDatabase.RegisteredState.REGISTERED.getId() + " OR " +
|
||||
"(" +
|
||||
|
@ -584,7 +588,7 @@ public class ThreadDatabase extends Database {
|
|||
|
||||
public @NonNull List<ThreadRecord> getRecentV1Groups(int limit) {
|
||||
SQLiteDatabase db = databaseHelper.getReadableDatabase();
|
||||
String where = MESSAGE_COUNT + " != 0 AND " +
|
||||
String where = MEANINGFUL_MESSAGES + " != 0 AND " +
|
||||
"(" +
|
||||
GroupDatabase.TABLE_NAME + "." + GroupDatabase.ACTIVE + " = 1 AND " +
|
||||
GroupDatabase.TABLE_NAME + "." + GroupDatabase.V2_MASTER_KEY + " IS NULL AND " +
|
||||
|
@ -663,7 +667,7 @@ public class ThreadDatabase extends Database {
|
|||
|
||||
public @NonNull Map<RecipientId, Integer> getInboxPositions() {
|
||||
SQLiteDatabase db = databaseHelper.getReadableDatabase();
|
||||
String query = createQuery(MESSAGE_COUNT + " != ?", 0);
|
||||
String query = createQuery(MEANINGFUL_MESSAGES + " != ?", 0);
|
||||
|
||||
Map<RecipientId, Integer> positions = new HashMap<>();
|
||||
|
||||
|
@ -690,7 +694,7 @@ public class ThreadDatabase extends Database {
|
|||
public Cursor getUnarchivedConversationList(boolean pinned, long offset, long limit) {
|
||||
SQLiteDatabase db = databaseHelper.getReadableDatabase();
|
||||
String pinnedWhere = PINNED + (pinned ? " != 0" : " = 0");
|
||||
String where = ARCHIVED + " = 0 AND " + MESSAGE_COUNT + " != 0 AND " + pinnedWhere;
|
||||
String where = ARCHIVED + " = 0 AND " + MEANINGFUL_MESSAGES + " != 0 AND " + pinnedWhere;
|
||||
|
||||
final String query;
|
||||
|
||||
|
@ -707,7 +711,7 @@ public class ThreadDatabase extends Database {
|
|||
|
||||
private Cursor getConversationList(@NonNull String archived, long offset, long limit) {
|
||||
SQLiteDatabase db = databaseHelper.getReadableDatabase();
|
||||
String query = createQuery(ARCHIVED + " = ? AND " + MESSAGE_COUNT + " != 0", offset, limit, false);
|
||||
String query = createQuery(ARCHIVED + " = ? AND " + MEANINGFUL_MESSAGES + " != 0", offset, limit, false);
|
||||
Cursor cursor = db.rawQuery(query, new String[]{archived});
|
||||
|
||||
return cursor;
|
||||
|
@ -716,7 +720,7 @@ public class ThreadDatabase extends Database {
|
|||
public int getArchivedConversationListCount() {
|
||||
SQLiteDatabase db = databaseHelper.getReadableDatabase();
|
||||
String[] columns = new String[] { "COUNT(*)" };
|
||||
String query = ARCHIVED + " = ? AND " + MESSAGE_COUNT + " != 0";
|
||||
String query = ARCHIVED + " = ? AND " + MEANINGFUL_MESSAGES + " != 0";
|
||||
String[] args = new String[] {"1"};
|
||||
|
||||
try (Cursor cursor = db.query(TABLE_NAME, columns, query, args, null, null, null)) {
|
||||
|
@ -731,7 +735,7 @@ public class ThreadDatabase extends Database {
|
|||
public int getPinnedConversationListCount() {
|
||||
SQLiteDatabase db = databaseHelper.getReadableDatabase();
|
||||
String[] columns = new String[] { "COUNT(*)" };
|
||||
String query = ARCHIVED + " = 0 AND " + PINNED + " != 0 AND " + MESSAGE_COUNT + " != 0";
|
||||
String query = ARCHIVED + " = 0 AND " + PINNED + " != 0 AND " + MEANINGFUL_MESSAGES + " != 0";
|
||||
|
||||
try (Cursor cursor = db.query(TABLE_NAME, columns, query, null, null, null, null)) {
|
||||
if (cursor != null && cursor.moveToFirst()) {
|
||||
|
@ -745,7 +749,7 @@ public class ThreadDatabase extends Database {
|
|||
public int getUnarchivedConversationListCount() {
|
||||
SQLiteDatabase db = databaseHelper.getReadableDatabase();
|
||||
String[] columns = new String[] { "COUNT(*)" };
|
||||
String query = ARCHIVED + " = 0 AND " + MESSAGE_COUNT + " != 0";
|
||||
String query = ARCHIVED + " = 0 AND " + MEANINGFUL_MESSAGES + " != 0";
|
||||
|
||||
try (Cursor cursor = db.query(TABLE_NAME, columns, query, null, null, null, null)) {
|
||||
if (cursor != null && cursor.moveToFirst()) {
|
||||
|
@ -892,7 +896,7 @@ public class ThreadDatabase extends Database {
|
|||
|
||||
contentValues.put(LAST_SCROLLED, lastScrolledTimestamp);
|
||||
|
||||
db.update(TABLE_NAME, contentValues, ID_WHERE, new String[] {String.valueOf(threadId)});
|
||||
db.update(TABLE_NAME, contentValues, ID_WHERE, SqlUtil.buildArgs(threadId));
|
||||
}
|
||||
|
||||
public ConversationMetadata getConversationMetadata(long threadId) {
|
||||
|
@ -909,17 +913,6 @@ public class ThreadDatabase extends Database {
|
|||
}
|
||||
}
|
||||
|
||||
public int getConversationMessageCount(long threadId) {
|
||||
SQLiteDatabase db = databaseHelper.getReadableDatabase();
|
||||
|
||||
try (Cursor cursor = db.query(TABLE_NAME, new String[]{MESSAGE_COUNT}, ID_WHERE, new String[]{String.valueOf(threadId)}, null, null, null)) {
|
||||
if (cursor != null && cursor.moveToFirst()) {
|
||||
return CursorUtil.requireInt(cursor, MESSAGE_COUNT);
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
public void deleteConversation(long threadId) {
|
||||
SQLiteDatabase db = databaseHelper.getWritableDatabase();
|
||||
RecipientId recipientIdForThreadId = getRecipientIdForThreadId(threadId);
|
||||
|
@ -1234,24 +1227,21 @@ public class ThreadDatabase extends Database {
|
|||
|
||||
private boolean update(long threadId, boolean unarchive, boolean allowDeletion, boolean notifyListeners) {
|
||||
MmsSmsDatabase mmsSmsDatabase = DatabaseFactory.getMmsSmsDatabase(context);
|
||||
long count = mmsSmsDatabase.getConversationCountForThreadSummary(threadId);
|
||||
boolean meaningfulMessages = mmsSmsDatabase.hasMeaningfulMessage(threadId);
|
||||
|
||||
if (count == 0) {
|
||||
if (!meaningfulMessages) {
|
||||
if (allowDeletion) {
|
||||
deleteConversation(threadId);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
MmsSmsDatabase.Reader reader = null;
|
||||
try (MmsSmsDatabase.Reader reader = MmsSmsDatabase.readerFor(mmsSmsDatabase.getConversationSnippet(threadId))) {
|
||||
MessageRecord record = reader.getNext();
|
||||
|
||||
try {
|
||||
reader = mmsSmsDatabase.readerFor(mmsSmsDatabase.getConversationSnippet(threadId));
|
||||
MessageRecord record;
|
||||
|
||||
if (reader != null && (record = reader.getNext()) != null) {
|
||||
if (record != null) {
|
||||
updateThread(threadId,
|
||||
count,
|
||||
meaningfulMessages,
|
||||
ThreadBodyUtil.getFormattedBodyFor(context, record),
|
||||
getAttachmentUriFor(record),
|
||||
getContentTypeFor(record),
|
||||
|
@ -1271,9 +1261,6 @@ public class ThreadDatabase extends Database {
|
|||
deleteConversation(threadId);
|
||||
return true;
|
||||
}
|
||||
} finally {
|
||||
if (reader != null)
|
||||
reader.close();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1587,7 +1574,7 @@ public class ThreadDatabase extends Database {
|
|||
.setLastSeen(cursor.getLong(cursor.getColumnIndexOrThrow(ThreadDatabase.LAST_SEEN)))
|
||||
.setSnippetUri(getSnippetUri(cursor))
|
||||
.setContentType(cursor.getString(cursor.getColumnIndexOrThrow(ThreadDatabase.SNIPPET_CONTENT_TYPE)))
|
||||
.setCount(cursor.getLong(cursor.getColumnIndexOrThrow(ThreadDatabase.MESSAGE_COUNT)))
|
||||
.setMeaningfulMessages(cursor.getLong(cursor.getColumnIndexOrThrow(ThreadDatabase.MEANINGFUL_MESSAGES)) > 0)
|
||||
.setUnreadCount(cursor.getInt(cursor.getColumnIndexOrThrow(ThreadDatabase.UNREAD_COUNT)))
|
||||
.setForcedUnread(cursor.getInt(cursor.getColumnIndexOrThrow(ThreadDatabase.READ)) == ReadStatus.FORCED_UNREAD.serialize())
|
||||
.setPinned(CursorUtil.requireBoolean(cursor, ThreadDatabase.PINNED))
|
||||
|
|
|
@ -40,7 +40,6 @@ public final class ThreadRecord {
|
|||
private final long threadId;
|
||||
private final String body;
|
||||
private final Recipient recipient;
|
||||
private final Recipient sender;
|
||||
private final long type;
|
||||
private final long date;
|
||||
private final long deliveryStatus;
|
||||
|
@ -49,7 +48,7 @@ public final class ThreadRecord {
|
|||
private final Uri snippetUri;
|
||||
private final String contentType;
|
||||
private final Extra extra;
|
||||
private final long count;
|
||||
private final boolean meaningfulMessages;
|
||||
private final int unreadCount;
|
||||
private final boolean forcedUnread;
|
||||
private final int distributionType;
|
||||
|
@ -62,7 +61,6 @@ public final class ThreadRecord {
|
|||
this.threadId = builder.threadId;
|
||||
this.body = builder.body;
|
||||
this.recipient = builder.recipient;
|
||||
this.sender = builder.sender;
|
||||
this.date = builder.date;
|
||||
this.type = builder.type;
|
||||
this.deliveryStatus = builder.deliveryStatus;
|
||||
|
@ -71,7 +69,7 @@ public final class ThreadRecord {
|
|||
this.snippetUri = builder.snippetUri;
|
||||
this.contentType = builder.contentType;
|
||||
this.extra = builder.extra;
|
||||
this.count = builder.count;
|
||||
this.meaningfulMessages = builder.meaningfulMessages;
|
||||
this.unreadCount = builder.unreadCount;
|
||||
this.forcedUnread = builder.forcedUnread;
|
||||
this.distributionType = builder.distributionType;
|
||||
|
@ -105,8 +103,8 @@ public final class ThreadRecord {
|
|||
return contentType;
|
||||
}
|
||||
|
||||
public long getCount() {
|
||||
return count;
|
||||
public boolean hasMeaningfulMessages() {
|
||||
return meaningfulMessages;
|
||||
}
|
||||
|
||||
public int getUnreadCount() {
|
||||
|
@ -233,7 +231,7 @@ public final class ThreadRecord {
|
|||
deliveryStatus == that.deliveryStatus &&
|
||||
deliveryReceiptCount == that.deliveryReceiptCount &&
|
||||
readReceiptCount == that.readReceiptCount &&
|
||||
count == that.count &&
|
||||
meaningfulMessages == that.meaningfulMessages &&
|
||||
unreadCount == that.unreadCount &&
|
||||
forcedUnread == that.forcedUnread &&
|
||||
distributionType == that.distributionType &&
|
||||
|
@ -261,7 +259,7 @@ public final class ThreadRecord {
|
|||
snippetUri,
|
||||
contentType,
|
||||
extra,
|
||||
count,
|
||||
meaningfulMessages,
|
||||
unreadCount,
|
||||
forcedUnread,
|
||||
distributionType,
|
||||
|
@ -275,7 +273,6 @@ public final class ThreadRecord {
|
|||
private long threadId;
|
||||
private String body;
|
||||
private Recipient recipient = Recipient.UNKNOWN;
|
||||
private Recipient sender = Recipient.UNKNOWN;
|
||||
private long type;
|
||||
private long date;
|
||||
private long deliveryStatus;
|
||||
|
@ -284,7 +281,7 @@ public final class ThreadRecord {
|
|||
private Uri snippetUri;
|
||||
private String contentType;
|
||||
private Extra extra;
|
||||
private long count;
|
||||
private boolean meaningfulMessages;
|
||||
private int unreadCount;
|
||||
private boolean forcedUnread;
|
||||
private int distributionType;
|
||||
|
@ -307,11 +304,6 @@ public final class ThreadRecord {
|
|||
return this;
|
||||
}
|
||||
|
||||
public Builder setSender(@NonNull Recipient sender) {
|
||||
this.sender = sender;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder setType(long type) {
|
||||
this.type = type;
|
||||
return this;
|
||||
|
@ -357,8 +349,8 @@ public final class ThreadRecord {
|
|||
return this;
|
||||
}
|
||||
|
||||
public Builder setCount(long count) {
|
||||
this.count = count;
|
||||
public Builder setMeaningfulMessages(boolean meaningfulMessages) {
|
||||
this.meaningfulMessages = meaningfulMessages;
|
||||
return this;
|
||||
}
|
||||
|
||||
|
|
Ładowanie…
Reference in New Issue