Rotate profile key after blocking if shared via group.
This commit is contained in:
parent
7e9e2fead2
commit
a3358e5b21
2 changed files with 21 additions and 6 deletions
|
@ -26,6 +26,7 @@ import org.whispersystems.signalservice.api.messages.SignalServiceAttachmentPoin
|
||||||
import java.io.Closeable;
|
import java.io.Closeable;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.security.SecureRandom;
|
import java.security.SecureRandom;
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.LinkedList;
|
import java.util.LinkedList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
@ -163,25 +164,31 @@ public class GroupDatabase extends Database {
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<String> getGroupNamesContainingMember(RecipientId recipientId) {
|
public List<String> getGroupNamesContainingMember(RecipientId recipientId) {
|
||||||
|
return Stream.of(getGroupsContainingMember(recipientId))
|
||||||
|
.map(GroupRecord::getTitle)
|
||||||
|
.toList();
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<GroupRecord> getGroupsContainingMember(RecipientId recipientId) {
|
||||||
SQLiteDatabase database = databaseHelper.getReadableDatabase();
|
SQLiteDatabase database = databaseHelper.getReadableDatabase();
|
||||||
String table = TABLE_NAME + " INNER JOIN " + ThreadDatabase.TABLE_NAME + " ON " + TABLE_NAME + "." + RECIPIENT_ID + " = " + ThreadDatabase.TABLE_NAME + "." + ThreadDatabase.RECIPIENT_ID;
|
String table = TABLE_NAME + " INNER JOIN " + ThreadDatabase.TABLE_NAME + " ON " + TABLE_NAME + "." + RECIPIENT_ID + " = " + ThreadDatabase.TABLE_NAME + "." + ThreadDatabase.RECIPIENT_ID;
|
||||||
List<String> groupNames = new LinkedList<>();
|
|
||||||
String[] projection = new String[]{TITLE, MEMBERS};
|
|
||||||
String query = MEMBERS + " LIKE ?";
|
String query = MEMBERS + " LIKE ?";
|
||||||
String[] args = new String[]{"%" + recipientId.serialize() + "%"};
|
String[] args = new String[]{"%" + recipientId.serialize() + "%"};
|
||||||
String orderBy = ThreadDatabase.TABLE_NAME + "." + ThreadDatabase.DATE + " DESC";
|
String orderBy = ThreadDatabase.TABLE_NAME + "." + ThreadDatabase.DATE + " DESC";
|
||||||
|
|
||||||
try (Cursor cursor = database.query(table, projection, query, args, null, null, orderBy)) {
|
List<GroupRecord> groups = new LinkedList<>();
|
||||||
|
|
||||||
|
try (Cursor cursor = database.query(table, null, query, args, null, null, orderBy)) {
|
||||||
while (cursor != null && cursor.moveToNext()) {
|
while (cursor != null && cursor.moveToNext()) {
|
||||||
List<String> members = Util.split(cursor.getString(cursor.getColumnIndexOrThrow(MEMBERS)), ",");
|
List<String> members = Util.split(cursor.getString(cursor.getColumnIndexOrThrow(MEMBERS)), ",");
|
||||||
|
|
||||||
if (members.contains(recipientId.serialize())) {
|
if (members.contains(recipientId.serialize())) {
|
||||||
groupNames.add(cursor.getString(cursor.getColumnIndexOrThrow(TITLE)));
|
groups.add(new Reader(cursor).getCurrent());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return groupNames;
|
return groups;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Reader getGroups() {
|
public Reader getGroups() {
|
||||||
|
|
|
@ -7,6 +7,8 @@ import androidx.annotation.NonNull;
|
||||||
import androidx.annotation.Nullable;
|
import androidx.annotation.Nullable;
|
||||||
import androidx.annotation.WorkerThread;
|
import androidx.annotation.WorkerThread;
|
||||||
|
|
||||||
|
import com.annimon.stream.Stream;
|
||||||
|
|
||||||
import org.thoughtcrime.securesms.R;
|
import org.thoughtcrime.securesms.R;
|
||||||
import org.thoughtcrime.securesms.contacts.sync.DirectoryHelper;
|
import org.thoughtcrime.securesms.contacts.sync.DirectoryHelper;
|
||||||
import org.thoughtcrime.securesms.database.DatabaseFactory;
|
import org.thoughtcrime.securesms.database.DatabaseFactory;
|
||||||
|
@ -81,7 +83,7 @@ public class RecipientUtil {
|
||||||
leaveGroup(context, recipient);
|
leaveGroup(context, recipient);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (resolved.isSystemContact() || resolved.isProfileSharing()) {
|
if (resolved.isSystemContact() || resolved.isProfileSharing() || isProfileSharedViaGroup(context,resolved)) {
|
||||||
ApplicationDependencies.getJobManager().add(new RotateProfileKeyJob());
|
ApplicationDependencies.getJobManager().add(new RotateProfileKeyJob());
|
||||||
DatabaseFactory.getRecipientDatabase(context).setProfileSharing(resolved.getId(), false);
|
DatabaseFactory.getRecipientDatabase(context).setProfileSharing(resolved.getId(), false);
|
||||||
}
|
}
|
||||||
|
@ -229,4 +231,10 @@ public class RecipientUtil {
|
||||||
private static boolean noSecureMessagesInThread(@NonNull Context context, long threadId) {
|
private static boolean noSecureMessagesInThread(@NonNull Context context, long threadId) {
|
||||||
return DatabaseFactory.getMmsSmsDatabase(context).getSecureConversationCount(threadId) == 0;
|
return DatabaseFactory.getMmsSmsDatabase(context).getSecureConversationCount(threadId) == 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@WorkerThread
|
||||||
|
private static boolean isProfileSharedViaGroup(@NonNull Context context, @NonNull Recipient recipient) {
|
||||||
|
return Stream.of(DatabaseFactory.getGroupDatabase(context).getGroupsContainingMember(recipient.getId()))
|
||||||
|
.anyMatch(group -> Recipient.resolved(group.getRecipientId()).isProfileSharing());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue