Skip to content

Commit abd2083

Browse files
authored
SES-1112 : Message request push notifications suppressed (#1504)
* Remove duplicate message request. Avoid clearing MR notifs * Removed image and name of MR sender * Cleanup * Notif cleanup changes * Split queries in two, add merger function * Cleanup * cleanup * cleanup * convert list to sequence to save memory
1 parent 5b9e8b7 commit abd2083

File tree

4 files changed

+368
-137
lines changed

4 files changed

+368
-137
lines changed

app/src/main/java/org/thoughtcrime/securesms/database/MmsSmsDatabase.java

Lines changed: 29 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -399,56 +399,37 @@ public MessageRecord getLastMessage(long threadId) {
399399
}
400400
}
401401

402-
/**
403-
* Get all incoming unread + unnotified messages
404-
* or
405-
* all outgoing messages with unread reactions
406-
*/
407-
public Cursor getUnreadOrUnseenReactions() {
408-
409-
// ──────────────────────────────────────────────────────────────
410-
// 1) Build “is-outgoing” condition that works for both MMS & SMS
411-
// ──────────────────────────────────────────────────────────────
412-
// MMS rows → use MESSAGE_BOX
413-
// SMS rows → use TYPE
414-
//
415-
// TRANSPORT lets us be sure we’re looking at the right column,
416-
// so an incoming MMS/SMS can never be mistaken for outgoing.
417-
//
418-
String outgoingCondition =
419-
/* MMS */
420-
"(" + TRANSPORT + " = '" + MMS_TRANSPORT + "' AND " +
421-
"(" + MESSAGE_BOX + " & " +
422-
MmsSmsColumns.Types.BASE_TYPE_MASK + ") IN (" +
423-
buildOutgoingTypesList() + "))" +
424-
425-
" OR " +
426-
427-
/* SMS */
428-
"(" + TRANSPORT + " = '" + SMS_TRANSPORT + "' AND " +
429-
"(" + SmsDatabase.TYPE + " & " +
430-
MmsSmsColumns.Types.BASE_TYPE_MASK + ") IN (" +
431-
buildOutgoingTypesList() + "))";
432-
433-
final String lastSeenQuery = "SELECT " + ThreadDatabase.LAST_SEEN +
434-
" FROM " + ThreadDatabase.TABLE_NAME +
435-
" WHERE " + ThreadDatabase.ID + " = " + MmsSmsColumns.THREAD_ID;
436-
437-
// ──────────────────────────────────────────────────────────────
438-
// 2) Selection:
439-
// A) incoming unread+un-notified, NOT outgoing
440-
// B) outgoing with unseen reactions, IS outgoing
441-
// To query unseen reactions, we compare the date received on the reaction with the "last seen timestamp" on this thread
442-
// ──────────────────────────────────────────────────────────────
402+
private String buildOutgoingConditionForNotifications() {
403+
return "(" + TRANSPORT + " = '" + MMS_TRANSPORT + "' AND " +
404+
"(" + MESSAGE_BOX + " & " + MmsSmsColumns.Types.BASE_TYPE_MASK + ") IN (" + buildOutgoingTypesList() + "))" +
405+
" OR " +
406+
"(" + TRANSPORT + " = '" + SMS_TRANSPORT + "' AND " +
407+
"(" + SmsDatabase.TYPE + " & " + MmsSmsColumns.Types.BASE_TYPE_MASK + ") IN (" + buildOutgoingTypesList() + "))";
408+
}
409+
410+
public Cursor getUnreadIncomingForNotifications(int maxRows) {
411+
String outgoing = buildOutgoingConditionForNotifications();
412+
String selection = "(" + READ + " = 0 AND " + NOTIFIED + " = 0 AND NOT (" + outgoing + "))";
413+
String order = MmsSmsColumns.NORMALIZED_DATE_SENT + " DESC";
414+
String limitStr = maxRows > 0 ? String.valueOf(maxRows) : null;
415+
return queryTables(PROJECTION, selection, order, limitStr);
416+
}
417+
418+
public Cursor getOutgoingWithUnseenReactionsForNotifications(int maxRows) {
419+
String outgoing = buildOutgoingConditionForNotifications();
420+
String lastSeenQuery =
421+
"SELECT " + ThreadDatabase.LAST_SEEN +
422+
" FROM " + ThreadDatabase.TABLE_NAME +
423+
" WHERE " + ThreadDatabase.ID + " = " + MmsSmsColumns.THREAD_ID;
424+
443425
String selection =
444-
"(" + READ + " = 0 AND " +
445-
NOTIFIED + " = 0 AND NOT (" + outgoingCondition + "))" + // A
446-
" OR (" +
447-
ReactionDatabase.TABLE_NAME + "." + ReactionDatabase.DATE_SENT + " > (" + lastSeenQuery +") AND (" +
448-
outgoingCondition + "))"; // B
426+
"(" + outgoing + ")" +
427+
" AND " + ReactionDatabase.TABLE_NAME + "." + ReactionDatabase.DATE_SENT + " IS NOT NULL" +
428+
" AND " + ReactionDatabase.TABLE_NAME + "." + ReactionDatabase.DATE_SENT + " > (" + lastSeenQuery + ")";
449429

450-
String order = MmsSmsColumns.NORMALIZED_DATE_SENT + " ASC";
451-
return queryTables(PROJECTION, selection, order, null);
430+
String order = MmsSmsColumns.NORMALIZED_DATE_SENT + " DESC";
431+
String limitStr = maxRows > 0 ? String.valueOf(maxRows) : null;
432+
return queryTables(PROJECTION, selection, order, limitStr);
452433
}
453434

454435
public Set<Address> getAllReferencedAddresses() {

0 commit comments

Comments
 (0)