Skip to content

Commit

Permalink
Stop conversations without meaningful messages from showing in list.
Browse files Browse the repository at this point in the history
  • Loading branch information
cody-signal authored and greyson-signal committed Aug 14, 2020
1 parent 724f3e8 commit cdc2e74
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,13 @@ public int getConversationCount(long threadId, long beforeTime) {
DatabaseFactory.getMmsDatabase(context).getMessageCountForThread(threadId, beforeTime);
}

public int getConversationCountForThreadSummary(long threadId) {
int count = DatabaseFactory.getSmsDatabase(context).getMessageCountForThreadSummary(threadId);
count += DatabaseFactory.getMmsDatabase(context).getMessageCountForThread(threadId);

return count;
}

public int getInsecureSentCount(long threadId) {
int count = DatabaseFactory.getSmsDatabase(context).getInsecureMessagesSentForThread(threadId);
count += DatabaseFactory.getMmsDatabase(context).getInsecureMessagesSentForThread(threadId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
import org.thoughtcrime.securesms.sms.OutgoingTextMessage;
import org.thoughtcrime.securesms.util.Base64;
import org.thoughtcrime.securesms.util.JsonUtils;
import org.thoughtcrime.securesms.util.SqlUtil;
import org.thoughtcrime.securesms.util.TextSecurePreferences;
import org.whispersystems.libsignal.util.guava.Optional;

Expand Down Expand Up @@ -226,6 +227,26 @@ public int getMessageCount() {
}
}

public int getMessageCountForThreadSummary(long threadId) {
SQLiteDatabase db = databaseHelper.getReadableDatabase();

String[] cols = { "COUNT(*)" };
String query = THREAD_ID + " = ? AND (NOT " + TYPE + " & ? AND TYPE != ?)";
long type = Types.END_SESSION_BIT | Types.KEY_EXCHANGE_IDENTITY_UPDATE_BIT | Types.KEY_EXCHANGE_IDENTITY_VERIFIED_BIT;
String[] args = SqlUtil.buildArgs(threadId, type, Types.PROFILE_CHANGE_TYPE);

try (Cursor cursor = db.query(TABLE_NAME, cols, query, args, null, null, null)) {
if (cursor != null && cursor.moveToFirst()) {
int count = cursor.getInt(0);
if (count > 0) {
return getMessageCountForThread(threadId);
}
}
}

return 0;
}

public int getMessageCountForThread(long threadId) {
SQLiteDatabase db = databaseHelper.getReadableDatabase();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -887,7 +887,7 @@ public boolean update(long threadId, boolean unarchive) {

public boolean update(long threadId, boolean unarchive, boolean allowDeletion) {
MmsSmsDatabase mmsSmsDatabase = DatabaseFactory.getMmsSmsDatabase(context);
long count = mmsSmsDatabase.getConversationCount(threadId);
long count = mmsSmsDatabase.getConversationCountForThreadSummary(threadId);

if (count == 0) {
if (allowDeletion) {
Expand Down

0 comments on commit cdc2e74

Please sign in to comment.