mirror of
https://github.com/signalapp/Signal-Android.git
synced 2026-04-23 02:10:44 +01:00
Implement additional message request improvements.
This commit is contained in:
@@ -15,7 +15,6 @@ import com.annimon.stream.Stream;
|
||||
import net.sqlcipher.database.SQLiteDatabase;
|
||||
|
||||
import org.thoughtcrime.securesms.database.helpers.SQLCipherOpenHelper;
|
||||
import org.thoughtcrime.securesms.dependencies.ApplicationDependencies;
|
||||
import org.thoughtcrime.securesms.recipients.Recipient;
|
||||
import org.thoughtcrime.securesms.recipients.RecipientId;
|
||||
import org.thoughtcrime.securesms.util.BitmapUtil;
|
||||
|
||||
@@ -282,16 +282,31 @@ public class MmsDatabase extends MessagingDatabase {
|
||||
|
||||
public int getMessageCountForThread(long threadId) {
|
||||
SQLiteDatabase db = databaseHelper.getReadableDatabase();
|
||||
Cursor cursor = null;
|
||||
|
||||
try {
|
||||
cursor = db.query(TABLE_NAME, new String[] {"COUNT(*)"}, THREAD_ID + " = ?", new String[] {threadId+""}, null, null, null);
|
||||
String[] cols = new String[] {"COUNT(*)"};
|
||||
String query = THREAD_ID + " = ?";
|
||||
String[] args = new String[]{String.valueOf(threadId)};
|
||||
|
||||
if (cursor != null && cursor.moveToFirst())
|
||||
try (Cursor cursor = db.query(TABLE_NAME, cols, query, args, null, null, null)) {
|
||||
if (cursor != null && cursor.moveToFirst()) {
|
||||
return cursor.getInt(0);
|
||||
} finally {
|
||||
if (cursor != null)
|
||||
cursor.close();
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
public int getMessageCountForThread(long threadId, long beforeTime) {
|
||||
SQLiteDatabase db = databaseHelper.getReadableDatabase();
|
||||
|
||||
String[] cols = new String[] {"COUNT(*)"};
|
||||
String query = THREAD_ID + " = ? AND " + DATE_RECEIVED + " < ?";
|
||||
String[] args = new String[]{String.valueOf(threadId), String.valueOf(beforeTime)};
|
||||
|
||||
try (Cursor cursor = db.query(TABLE_NAME, cols, query, args, null, null, null)) {
|
||||
if (cursor != null && cursor.moveToFirst()) {
|
||||
return cursor.getInt(0);
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
||||
@@ -22,8 +22,6 @@ import android.database.Cursor;
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
|
||||
import com.annimon.stream.Stream;
|
||||
|
||||
import net.sqlcipher.database.SQLiteDatabase;
|
||||
import net.sqlcipher.database.SQLiteQueryBuilder;
|
||||
|
||||
@@ -35,7 +33,6 @@ import org.thoughtcrime.securesms.recipients.RecipientId;
|
||||
import org.whispersystems.libsignal.util.Pair;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
public class MmsSmsDatabase extends Database {
|
||||
@@ -88,24 +85,27 @@ public class MmsSmsDatabase extends Database {
|
||||
super(context, databaseHelper);
|
||||
}
|
||||
|
||||
public @Nullable RecipientId getRecipientIdForLatestAdd(long threadId) {
|
||||
/**
|
||||
* @return The user that added you to the group, otherwise null.
|
||||
*/
|
||||
public @Nullable RecipientId getGroupAddedBy(long threadId) {
|
||||
long lastQuitChecked = System.currentTimeMillis();
|
||||
Pair<RecipientId, Long> pair;
|
||||
|
||||
do {
|
||||
pair = getRecipientIdForLatestAdd(threadId, lastQuitChecked);
|
||||
pair = getGroupAddedBy(threadId, lastQuitChecked);
|
||||
if (pair.first() != null) {
|
||||
return pair.first();
|
||||
} else {
|
||||
lastQuitChecked = pair.second();
|
||||
}
|
||||
|
||||
} while (pair.second() != -1L);
|
||||
} while (pair.second() != -1);
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
private @NonNull Pair<RecipientId, Long> getRecipientIdForLatestAdd(long threadId, long lastQuitChecked) {
|
||||
private @NonNull Pair<RecipientId, Long> getGroupAddedBy(long threadId, long lastQuitChecked) {
|
||||
MmsDatabase mmsDatabase = DatabaseFactory.getMmsDatabase(context);
|
||||
SmsDatabase smsDatabase = DatabaseFactory.getSmsDatabase(context);
|
||||
long latestQuit = mmsDatabase.getLatestGroupQuitTimestamp(threadId, lastQuitChecked);
|
||||
@@ -225,6 +225,11 @@ public class MmsSmsDatabase extends Database {
|
||||
return count;
|
||||
}
|
||||
|
||||
public int getConversationCount(long threadId, long beforeTime) {
|
||||
return DatabaseFactory.getSmsDatabase(context).getMessageCountForThread(threadId, beforeTime) +
|
||||
DatabaseFactory.getMmsDatabase(context).getMessageCountForThread(threadId, beforeTime);
|
||||
}
|
||||
|
||||
public int getInsecureSentCount(long threadId) {
|
||||
int count = DatabaseFactory.getSmsDatabase(context).getInsecureMessagesSentForThread(threadId);
|
||||
count += DatabaseFactory.getMmsDatabase(context).getInsecureMessagesSentForThread(threadId);
|
||||
|
||||
@@ -1222,6 +1222,7 @@ public class RecipientDatabase extends Database {
|
||||
|
||||
ContentValues setBlocked = new ContentValues();
|
||||
setBlocked.put(BLOCKED, 1);
|
||||
setBlocked.put(PROFILE_SHARING, 0);
|
||||
|
||||
for (String e164 : blockedE164) {
|
||||
db.update(TABLE_NAME, setBlocked, PHONE + " = ?", new String[] { e164 });
|
||||
|
||||
@@ -216,17 +216,31 @@ public class SmsDatabase extends MessagingDatabase {
|
||||
|
||||
public int getMessageCountForThread(long threadId) {
|
||||
SQLiteDatabase db = databaseHelper.getReadableDatabase();
|
||||
Cursor cursor = null;
|
||||
|
||||
try {
|
||||
cursor = db.query(TABLE_NAME, new String[] {"COUNT(*)"}, THREAD_ID + " = ?",
|
||||
new String[] {threadId+""}, null, null, null);
|
||||
String[] cols = new String[] {"COUNT(*)"};
|
||||
String query = THREAD_ID + " = ?";
|
||||
String[] args = new String[]{String.valueOf(threadId)};
|
||||
|
||||
if (cursor != null && cursor.moveToFirst())
|
||||
try (Cursor cursor = db.query(TABLE_NAME, cols, query, args, null, null, null)) {
|
||||
if (cursor != null && cursor.moveToFirst()) {
|
||||
return cursor.getInt(0);
|
||||
} finally {
|
||||
if (cursor != null)
|
||||
cursor.close();
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
public int getMessageCountForThread(long threadId, long beforeTime) {
|
||||
SQLiteDatabase db = databaseHelper.getReadableDatabase();
|
||||
|
||||
String[] cols = new String[] {"COUNT(*)"};
|
||||
String query = THREAD_ID + " = ? AND " + DATE_RECEIVED + " < ?";
|
||||
String[] args = new String[]{String.valueOf(threadId), String.valueOf(beforeTime)};
|
||||
|
||||
try (Cursor cursor = db.query(TABLE_NAME, cols, query, args, null, null, null)) {
|
||||
if (cursor != null && cursor.moveToFirst()) {
|
||||
return cursor.getInt(0);
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
||||
@@ -705,13 +705,13 @@ public class ThreadDatabase extends Database {
|
||||
}
|
||||
|
||||
private @Nullable Extra getExtrasFor(MessageRecord record) {
|
||||
boolean messageRequestAccepted = RecipientUtil.isThreadMessageRequestAccepted(context, record.getThreadId());
|
||||
boolean messageRequestAccepted = RecipientUtil.isMessageRequestAccepted(context, record.getThreadId());
|
||||
RecipientId threadRecipientId = getRecipientIdForThreadId(record.getThreadId());
|
||||
|
||||
if (!messageRequestAccepted && threadRecipientId != null) {
|
||||
boolean isPushGroup = Recipient.resolved(threadRecipientId).isPushGroup();
|
||||
if (isPushGroup) {
|
||||
RecipientId recipientId = DatabaseFactory.getMmsSmsDatabase(context).getRecipientIdForLatestAdd(record.getThreadId());
|
||||
RecipientId recipientId = DatabaseFactory.getMmsSmsDatabase(context).getGroupAddedBy(record.getThreadId());
|
||||
|
||||
if (recipientId != null) {
|
||||
return Extra.forGroupMessageRequest(recipientId);
|
||||
|
||||
@@ -15,6 +15,7 @@ public class ConversationLoader extends AbstractCursorLoader {
|
||||
private long lastSeen;
|
||||
private boolean hasSent;
|
||||
private boolean isMessageRequestAccepted;
|
||||
private boolean hasPreMessageRequestMessages;
|
||||
|
||||
public ConversationLoader(Context context, long threadId, int offset, int limit, long lastSeen) {
|
||||
super(context);
|
||||
@@ -49,6 +50,10 @@ public class ConversationLoader extends AbstractCursorLoader {
|
||||
return isMessageRequestAccepted;
|
||||
}
|
||||
|
||||
public boolean hasPreMessageRequestMessages() {
|
||||
return hasPreMessageRequestMessages;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Cursor getCursor() {
|
||||
Pair<Long, Boolean> lastSeenAndHasSent = DatabaseFactory.getThreadDatabase(context).getLastSeenAndHasSent(threadId);
|
||||
@@ -59,7 +64,8 @@ public class ConversationLoader extends AbstractCursorLoader {
|
||||
this.lastSeen = lastSeenAndHasSent.first();
|
||||
}
|
||||
|
||||
this.isMessageRequestAccepted = RecipientUtil.isThreadMessageRequestAccepted(context, threadId);
|
||||
this.isMessageRequestAccepted = RecipientUtil.isMessageRequestAccepted(context, threadId);
|
||||
this.hasPreMessageRequestMessages = RecipientUtil.isPreMessageRequestThread(context, threadId);
|
||||
|
||||
return DatabaseFactory.getMmsSmsDatabase(context).getConversation(threadId, offset, limit);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user