mirror of
https://github.com/oxen-io/session-android.git
synced 2025-06-09 10:58:34 +00:00
Exclude inactive groups from search results where appropriate.
Fixes #9091 Fixes #9080
This commit is contained in:
parent
9089fc4001
commit
f1ca5fc8e2
@ -64,7 +64,7 @@ public abstract class ContactSelectionActivity extends PassphraseRequiredActionB
|
|||||||
protected void onCreate(Bundle icicle, boolean ready) {
|
protected void onCreate(Bundle icicle, boolean ready) {
|
||||||
if (!getIntent().hasExtra(ContactSelectionListFragment.DISPLAY_MODE)) {
|
if (!getIntent().hasExtra(ContactSelectionListFragment.DISPLAY_MODE)) {
|
||||||
int displayMode = TextSecurePreferences.isSmsEnabled(this) ? DisplayMode.FLAG_ALL
|
int displayMode = TextSecurePreferences.isSmsEnabled(this) ? DisplayMode.FLAG_ALL
|
||||||
: DisplayMode.FLAG_PUSH | DisplayMode.FLAG_GROUPS;
|
: DisplayMode.FLAG_PUSH | DisplayMode.FLAG_ACTIVE_GROUPS | DisplayMode.FLAG_INACTIVE_GROUPS;
|
||||||
getIntent().putExtra(ContactSelectionListFragment.DISPLAY_MODE, displayMode);
|
getIntent().putExtra(ContactSelectionListFragment.DISPLAY_MODE, displayMode);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -96,10 +96,13 @@ public class ShareActivity extends PassphraseRequiredActionBarActivity
|
|||||||
@Override
|
@Override
|
||||||
protected void onCreate(Bundle icicle, boolean ready) {
|
protected void onCreate(Bundle icicle, boolean ready) {
|
||||||
if (!getIntent().hasExtra(ContactSelectionListFragment.DISPLAY_MODE)) {
|
if (!getIntent().hasExtra(ContactSelectionListFragment.DISPLAY_MODE)) {
|
||||||
getIntent().putExtra(ContactSelectionListFragment.DISPLAY_MODE,
|
int mode = DisplayMode.FLAG_PUSH | DisplayMode.FLAG_ACTIVE_GROUPS;
|
||||||
TextSecurePreferences.isSmsEnabled(this)
|
|
||||||
? DisplayMode.FLAG_ALL
|
if (TextSecurePreferences.isSmsEnabled(this)) {
|
||||||
: DisplayMode.FLAG_PUSH | DisplayMode.FLAG_GROUPS);
|
mode |= DisplayMode.FLAG_SMS;
|
||||||
|
|
||||||
|
}
|
||||||
|
getIntent().putExtra(ContactSelectionListFragment.DISPLAY_MODE, mode);
|
||||||
}
|
}
|
||||||
|
|
||||||
getIntent().putExtra(ContactSelectionListFragment.REFRESHABLE, false);
|
getIntent().putExtra(ContactSelectionListFragment.REFRESHABLE, false);
|
||||||
|
@ -200,7 +200,7 @@ public class ContactAccessor {
|
|||||||
GroupRecord record;
|
GroupRecord record;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
reader = DatabaseFactory.getGroupDatabase(context).getGroupsFilteredByTitle(constraint);
|
reader = DatabaseFactory.getGroupDatabase(context).getGroupsFilteredByTitle(constraint, true);
|
||||||
|
|
||||||
while ((record = reader.getNext()) != null) {
|
while ((record = reader.getNext()) != null) {
|
||||||
numberList.add(record.getEncodedId());
|
numberList.add(record.getEncodedId());
|
||||||
|
@ -51,10 +51,11 @@ public class ContactsCursorLoader extends CursorLoader {
|
|||||||
private static final String TAG = ContactsCursorLoader.class.getSimpleName();
|
private static final String TAG = ContactsCursorLoader.class.getSimpleName();
|
||||||
|
|
||||||
public static final class DisplayMode {
|
public static final class DisplayMode {
|
||||||
public static final int FLAG_PUSH = 1;
|
public static final int FLAG_PUSH = 1;
|
||||||
public static final int FLAG_SMS = 1 << 1;
|
public static final int FLAG_SMS = 1 << 1;
|
||||||
public static final int FLAG_GROUPS = 1 << 2;
|
public static final int FLAG_ACTIVE_GROUPS = 1 << 2;
|
||||||
public static final int FLAG_ALL = FLAG_PUSH | FLAG_SMS | FLAG_GROUPS;
|
public static final int FLAG_INACTIVE_GROUPS = 1 << 3;
|
||||||
|
public static final int FLAG_ALL = FLAG_PUSH | FLAG_SMS | FLAG_ACTIVE_GROUPS | FLAG_INACTIVE_GROUPS;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static final String[] CONTACT_PROJECTION = new String[]{ContactRepository.ID_COLUMN,
|
private static final String[] CONTACT_PROJECTION = new String[]{ContactRepository.ID_COLUMN,
|
||||||
@ -76,6 +77,10 @@ public class ContactsCursorLoader extends CursorLoader {
|
|||||||
{
|
{
|
||||||
super(context);
|
super(context);
|
||||||
|
|
||||||
|
if (flagSet(mode, DisplayMode.FLAG_INACTIVE_GROUPS) && !flagSet(mode, DisplayMode.FLAG_ACTIVE_GROUPS)) {
|
||||||
|
throw new AssertionError("Inactive group flag set, but the active group flag isn't!");
|
||||||
|
}
|
||||||
|
|
||||||
this.filter = filter == null ? "" : filter;
|
this.filter = filter == null ? "" : filter;
|
||||||
this.mode = mode;
|
this.mode = mode;
|
||||||
this.recents = recents;
|
this.recents = recents;
|
||||||
@ -172,7 +177,7 @@ public class ContactsCursorLoader extends CursorLoader {
|
|||||||
ThreadDatabase threadDatabase = DatabaseFactory.getThreadDatabase(getContext());
|
ThreadDatabase threadDatabase = DatabaseFactory.getThreadDatabase(getContext());
|
||||||
|
|
||||||
MatrixCursor recentConversations = new MatrixCursor(CONTACT_PROJECTION, RECENT_CONVERSATION_MAX);
|
MatrixCursor recentConversations = new MatrixCursor(CONTACT_PROJECTION, RECENT_CONVERSATION_MAX);
|
||||||
try (Cursor rawConversations = threadDatabase.getRecentConversationList(RECENT_CONVERSATION_MAX)) {
|
try (Cursor rawConversations = threadDatabase.getRecentConversationList(RECENT_CONVERSATION_MAX, flagSet(mode, DisplayMode.FLAG_INACTIVE_GROUPS))) {
|
||||||
ThreadDatabase.Reader reader = threadDatabase.readerFor(rawConversations);
|
ThreadDatabase.Reader reader = threadDatabase.readerFor(rawConversations);
|
||||||
ThreadRecord threadRecord;
|
ThreadRecord threadRecord;
|
||||||
while ((threadRecord = reader.getNext()) != null) {
|
while ((threadRecord = reader.getNext()) != null) {
|
||||||
@ -208,7 +213,7 @@ public class ContactsCursorLoader extends CursorLoader {
|
|||||||
|
|
||||||
private Cursor getGroupsCursor() {
|
private Cursor getGroupsCursor() {
|
||||||
MatrixCursor groupContacts = new MatrixCursor(CONTACT_PROJECTION);
|
MatrixCursor groupContacts = new MatrixCursor(CONTACT_PROJECTION);
|
||||||
try (GroupDatabase.Reader reader = DatabaseFactory.getGroupDatabase(getContext()).getGroupsFilteredByTitle(filter)) {
|
try (GroupDatabase.Reader reader = DatabaseFactory.getGroupDatabase(getContext()).getGroupsFilteredByTitle(filter, flagSet(mode, DisplayMode.FLAG_INACTIVE_GROUPS))) {
|
||||||
GroupDatabase.GroupRecord groupRecord;
|
GroupDatabase.GroupRecord groupRecord;
|
||||||
while ((groupRecord = reader.getNext()) != null) {
|
while ((groupRecord = reader.getNext()) != null) {
|
||||||
groupContacts.addRow(new Object[] { groupRecord.getRecipientId().serialize(),
|
groupContacts.addRow(new Object[] { groupRecord.getRecipientId().serialize(),
|
||||||
@ -266,14 +271,18 @@ public class ContactsCursorLoader extends CursorLoader {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private static boolean pushEnabled(int mode) {
|
private static boolean pushEnabled(int mode) {
|
||||||
return (mode & DisplayMode.FLAG_PUSH) > 0;
|
return flagSet(mode, DisplayMode.FLAG_PUSH);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static boolean smsEnabled(int mode) {
|
private static boolean smsEnabled(int mode) {
|
||||||
return (mode & DisplayMode.FLAG_SMS) > 0;
|
return flagSet(mode, DisplayMode.FLAG_SMS);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static boolean groupsEnabled(int mode) {
|
private static boolean groupsEnabled(int mode) {
|
||||||
return (mode & DisplayMode.FLAG_GROUPS) > 0;
|
return flagSet(mode, DisplayMode.FLAG_ACTIVE_GROUPS);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static boolean flagSet(int mode, int flag) {
|
||||||
|
return (mode & flag) > 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -49,7 +49,7 @@ public class GroupDatabase extends Database {
|
|||||||
private static final String AVATAR_RELAY = "avatar_relay";
|
private static final String AVATAR_RELAY = "avatar_relay";
|
||||||
private static final String AVATAR_DIGEST = "avatar_digest";
|
private static final String AVATAR_DIGEST = "avatar_digest";
|
||||||
private static final String TIMESTAMP = "timestamp";
|
private static final String TIMESTAMP = "timestamp";
|
||||||
private static final String ACTIVE = "active";
|
static final String ACTIVE = "active";
|
||||||
static final String MMS = "mms";
|
static final String MMS = "mms";
|
||||||
|
|
||||||
public static final String CREATE_TABLE =
|
public static final String CREATE_TABLE =
|
||||||
@ -117,11 +117,19 @@ public class GroupDatabase extends Database {
|
|||||||
return !getGroup(groupId).isPresent();
|
return !getGroup(groupId).isPresent();
|
||||||
}
|
}
|
||||||
|
|
||||||
public Reader getGroupsFilteredByTitle(String constraint) {
|
public Reader getGroupsFilteredByTitle(String constraint, boolean includeInactive) {
|
||||||
@SuppressLint("Recycle")
|
String query;
|
||||||
Cursor cursor = databaseHelper.getReadableDatabase().query(TABLE_NAME, null, TITLE + " LIKE ?",
|
String[] queryArgs;
|
||||||
new String[]{"%" + constraint + "%"},
|
|
||||||
null, null, null);
|
if (includeInactive) {
|
||||||
|
query = TITLE + " LIKE ? AND (" + ACTIVE + " = ? OR " + RECIPIENT_ID + " IN (SELECT " + ThreadDatabase.RECIPIENT_ID + " FROM " + ThreadDatabase.TABLE_NAME + "))";
|
||||||
|
queryArgs = new String[]{"%" + constraint + "%", "1"};
|
||||||
|
} else {
|
||||||
|
query = TITLE + " LIKE ? AND " + ACTIVE + " = ?";
|
||||||
|
queryArgs = new String[]{"%" + constraint + "%", "1"};
|
||||||
|
}
|
||||||
|
|
||||||
|
Cursor cursor = databaseHelper.getReadableDatabase().query(TABLE_NAME, null, query, queryArgs, null, null, TITLE + " COLLATE NOCASE ASC");
|
||||||
|
|
||||||
return new Reader(cursor);
|
return new Reader(cursor);
|
||||||
}
|
}
|
||||||
|
@ -374,23 +374,25 @@ public class ThreadDatabase extends Database {
|
|||||||
return cursor;
|
return cursor;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Cursor getRecentConversationList(int limit) {
|
public Cursor getRecentConversationList(int limit, boolean includeInactiveGroups) {
|
||||||
SQLiteDatabase db = databaseHelper.getReadableDatabase();
|
SQLiteDatabase db = databaseHelper.getReadableDatabase();
|
||||||
String query = createQuery(MESSAGE_COUNT + " != 0", limit);
|
String query = !includeInactiveGroups ? MESSAGE_COUNT + " != 0 AND " + GroupDatabase.TABLE_NAME + "." + GroupDatabase.ACTIVE + " = 1"
|
||||||
|
: MESSAGE_COUNT + " != 0";
|
||||||
return db.rawQuery(query, null);
|
return db.rawQuery(createQuery(query, limit), null);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Cursor getRecentPushConversationList(int limit) {
|
public Cursor getRecentPushConversationList(int limit, boolean includeInactiveGroups) {
|
||||||
SQLiteDatabase db = databaseHelper.getReadableDatabase();
|
SQLiteDatabase db = databaseHelper.getReadableDatabase();
|
||||||
String where = MESSAGE_COUNT + " != 0 AND " +
|
String activeGroupQuery = !includeInactiveGroups ? " AND " + GroupDatabase.TABLE_NAME + "." + GroupDatabase.ACTIVE + " = 1" : "";
|
||||||
"(" +
|
String where = MESSAGE_COUNT + " != 0 AND " +
|
||||||
RecipientDatabase.REGISTERED + " = " + RecipientDatabase.RegisteredState.REGISTERED.getId() + " OR " +
|
"(" +
|
||||||
"(" +
|
RecipientDatabase.REGISTERED + " = " + RecipientDatabase.RegisteredState.REGISTERED.getId() + " OR " +
|
||||||
GroupDatabase.TABLE_NAME + "." + GroupDatabase.GROUP_ID + " NOT NULL AND " +
|
"(" +
|
||||||
GroupDatabase.TABLE_NAME + "." + GroupDatabase.MMS + " = 0" +
|
GroupDatabase.TABLE_NAME + "." + GroupDatabase.GROUP_ID + " NOT NULL AND " +
|
||||||
")" +
|
GroupDatabase.TABLE_NAME + "." + GroupDatabase.MMS + " = 0" +
|
||||||
")";
|
activeGroupQuery +
|
||||||
|
")" +
|
||||||
|
")";
|
||||||
String query = createQuery(where, limit);
|
String query = createQuery(where, limit);
|
||||||
|
|
||||||
return db.rawQuery(query, null);
|
return db.rawQuery(query, null);
|
||||||
@ -414,13 +416,6 @@ public class ThreadDatabase extends Database {
|
|||||||
return cursor;
|
return cursor;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Cursor getDirectShareList() {
|
|
||||||
SQLiteDatabase db = databaseHelper.getReadableDatabase();
|
|
||||||
String query = createQuery(MESSAGE_COUNT + " != 0", 0);
|
|
||||||
|
|
||||||
return db.rawQuery(query, null);
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getArchivedConversationListCount() {
|
public int getArchivedConversationListCount() {
|
||||||
SQLiteDatabase db = databaseHelper.getReadableDatabase();
|
SQLiteDatabase db = databaseHelper.getReadableDatabase();
|
||||||
Cursor cursor = null;
|
Cursor cursor = null;
|
||||||
|
@ -13,6 +13,7 @@ import org.thoughtcrime.securesms.attachments.Attachment;
|
|||||||
import org.thoughtcrime.securesms.crypto.UnidentifiedAccessUtil;
|
import org.thoughtcrime.securesms.crypto.UnidentifiedAccessUtil;
|
||||||
import org.thoughtcrime.securesms.database.Address;
|
import org.thoughtcrime.securesms.database.Address;
|
||||||
import org.thoughtcrime.securesms.database.DatabaseFactory;
|
import org.thoughtcrime.securesms.database.DatabaseFactory;
|
||||||
|
import org.thoughtcrime.securesms.database.GroupDatabase;
|
||||||
import org.thoughtcrime.securesms.database.GroupReceiptDatabase.GroupReceiptInfo;
|
import org.thoughtcrime.securesms.database.GroupReceiptDatabase.GroupReceiptInfo;
|
||||||
import org.thoughtcrime.securesms.database.MmsDatabase;
|
import org.thoughtcrime.securesms.database.MmsDatabase;
|
||||||
import org.thoughtcrime.securesms.database.NoSuchMessageException;
|
import org.thoughtcrime.securesms.database.NoSuchMessageException;
|
||||||
@ -90,6 +91,15 @@ public class PushGroupSendJob extends PushSendJob {
|
|||||||
@Nullable RecipientId filterAddress)
|
@Nullable RecipientId filterAddress)
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
|
Recipient group = Recipient.resolved(destination);
|
||||||
|
if (!group.isPushGroup()) {
|
||||||
|
throw new AssertionError("Not a group!");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!DatabaseFactory.getGroupDatabase(context).isActive(group.requireAddress().toGroupString())) {
|
||||||
|
throw new MmsException("Inactive group!");
|
||||||
|
}
|
||||||
|
|
||||||
MmsDatabase database = DatabaseFactory.getMmsDatabase(context);
|
MmsDatabase database = DatabaseFactory.getMmsDatabase(context);
|
||||||
OutgoingMediaMessage message = database.getOutgoingMessage(messageId);
|
OutgoingMediaMessage message = database.getOutgoingMessage(messageId);
|
||||||
JobManager.Chain compressAndUploadAttachment = createCompressingAndUploadAttachmentsChain(jobManager, message);
|
JobManager.Chain compressAndUploadAttachment = createCompressingAndUploadAttachmentsChain(jobManager, message);
|
||||||
|
@ -65,7 +65,7 @@ class CameraContactsRepository {
|
|||||||
|
|
||||||
List<Recipient> recipients = new ArrayList<>(RECENT_MAX);
|
List<Recipient> recipients = new ArrayList<>(RECENT_MAX);
|
||||||
|
|
||||||
try (ThreadDatabase.Reader threadReader = threadDatabase.readerFor(threadDatabase.getRecentPushConversationList(RECENT_MAX))) {
|
try (ThreadDatabase.Reader threadReader = threadDatabase.readerFor(threadDatabase.getRecentPushConversationList(RECENT_MAX, false))) {
|
||||||
ThreadRecord threadRecord;
|
ThreadRecord threadRecord;
|
||||||
while ((threadRecord = threadReader.getNext()) != null) {
|
while ((threadRecord = threadReader.getNext()) != null) {
|
||||||
recipients.add(threadRecord.getRecipient().resolve());
|
recipients.add(threadRecord.getRecipient().resolve());
|
||||||
@ -98,7 +98,7 @@ class CameraContactsRepository {
|
|||||||
|
|
||||||
List<Recipient> recipients = new ArrayList<>();
|
List<Recipient> recipients = new ArrayList<>();
|
||||||
|
|
||||||
try (GroupDatabase.Reader reader = groupDatabase.getGroupsFilteredByTitle(query)) {
|
try (GroupDatabase.Reader reader = groupDatabase.getGroupsFilteredByTitle(query, false)) {
|
||||||
GroupDatabase.GroupRecord groupRecord;
|
GroupDatabase.GroupRecord groupRecord;
|
||||||
while ((groupRecord = reader.getNext()) != null) {
|
while ((groupRecord = reader.getNext()) != null) {
|
||||||
RecipientId recipientId = recipientDatabase.getOrInsertFromGroupId(groupRecord.getEncodedId());
|
RecipientId recipientId = recipientDatabase.getOrInsertFromGroupId(groupRecord.getEncodedId());
|
||||||
|
@ -39,13 +39,13 @@ public class DirectShareService extends ChooserTargetService {
|
|||||||
List<ChooserTarget> results = new LinkedList<>();
|
List<ChooserTarget> results = new LinkedList<>();
|
||||||
ComponentName componentName = new ComponentName(this, ShareActivity.class);
|
ComponentName componentName = new ComponentName(this, ShareActivity.class);
|
||||||
ThreadDatabase threadDatabase = DatabaseFactory.getThreadDatabase(this);
|
ThreadDatabase threadDatabase = DatabaseFactory.getThreadDatabase(this);
|
||||||
Cursor cursor = threadDatabase.getDirectShareList();
|
Cursor cursor = threadDatabase.getRecentConversationList(10, false);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
ThreadDatabase.Reader reader = threadDatabase.readerFor(cursor);
|
ThreadDatabase.Reader reader = threadDatabase.readerFor(cursor);
|
||||||
ThreadRecord record;
|
ThreadRecord record;
|
||||||
|
|
||||||
while ((record = reader.getNext()) != null && results.size() < 10) {
|
while ((record = reader.getNext()) != null) {
|
||||||
Recipient recipient = Recipient.resolved(record.getRecipient().getId());
|
Recipient recipient = Recipient.resolved(record.getRecipient().getId());
|
||||||
String name = recipient.toShortString();
|
String name = recipient.toShortString();
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user