This commit is contained in:
nielsandriesse 2020-08-12 10:00:35 +10:00
parent c9c902218e
commit fcb2bbb768
7 changed files with 29 additions and 21 deletions

View File

@ -1169,7 +1169,7 @@ public class ConversationActivity extends PassphraseRequiredActionBarActivity
builder.setPositiveButton(R.string.yes, (dialog, which) -> { builder.setPositiveButton(R.string.yes, (dialog, which) -> {
Recipient groupRecipient = getRecipient(); Recipient groupRecipient = getRecipient();
try { try {
String groupPublicKey = HexEncodingKt.toHexString(GroupUtil.getDecodedId(groupRecipient.getAddress().toString())); String groupPublicKey = HexEncodingKt.toHexString(GroupUtil.getDecodedId(GroupUtil.getDecodedStringId(groupRecipient.getAddress().toString())));
boolean isSSKBasedClosedGroup = DatabaseFactory.getSSKDatabase(this).isSSKBasedClosedGroup(groupPublicKey); boolean isSSKBasedClosedGroup = DatabaseFactory.getSSKDatabase(this).isSSKBasedClosedGroup(groupPublicKey);
if (isSSKBasedClosedGroup) { if (isSSKBasedClosedGroup) {
ClosedGroupsProtocol.leave(this, groupPublicKey); ClosedGroupsProtocol.leave(this, groupPublicKey);

View File

@ -303,7 +303,7 @@ public class PushDecryptJob extends BaseJob implements InjectableType {
SessionMetaProtocol.handleProfileKeyUpdate(context, content); SessionMetaProtocol.handleProfileKeyUpdate(context, content);
} }
if (content.isNeedsReceipt()) { if (content.isNeedsReceipt() && SessionMetaProtocol.shouldSendDeliveryReceipt(Address.fromSerialized(content.getSender()))) {
handleNeedsDeliveryReceipt(content, message); handleNeedsDeliveryReceipt(content, message);
} }
} }

View File

@ -10,6 +10,7 @@ import org.thoughtcrime.securesms.jobmanager.Data;
import org.thoughtcrime.securesms.jobmanager.Job; import org.thoughtcrime.securesms.jobmanager.Job;
import org.thoughtcrime.securesms.jobmanager.impl.NetworkConstraint; import org.thoughtcrime.securesms.jobmanager.impl.NetworkConstraint;
import org.thoughtcrime.securesms.logging.Log; import org.thoughtcrime.securesms.logging.Log;
import org.thoughtcrime.securesms.loki.protocol.SessionMetaProtocol;
import org.thoughtcrime.securesms.recipients.Recipient; import org.thoughtcrime.securesms.recipients.Recipient;
import org.whispersystems.signalservice.api.SignalServiceMessageSender; import org.whispersystems.signalservice.api.SignalServiceMessageSender;
import org.whispersystems.signalservice.api.crypto.UntrustedIdentityException; import org.whispersystems.signalservice.api.crypto.UntrustedIdentityException;
@ -83,6 +84,8 @@ public class SendDeliveryReceiptJob extends BaseJob implements InjectableType {
Collections.singletonList(messageId), Collections.singletonList(messageId),
timestamp); timestamp);
if (!SessionMetaProtocol.shouldSendDeliveryReceipt(Address.fromSerialized(address))) { return; }
messageSender.sendReceipt(remoteAddress, messageSender.sendReceipt(remoteAddress,
UnidentifiedAccessUtil.getAccessFor(context, Recipient.from(context, Address.fromSerialized(address), false)), UnidentifiedAccessUtil.getAccessFor(context, Recipient.from(context, Address.fromSerialized(address), false)),
receiptMessage); receiptMessage);

View File

@ -335,7 +335,7 @@ class HomeActivity : PassphraseRequiredActionBarActivity, ConversationClickListe
val isClosedGroup = recipient.address.isClosedGroup val isClosedGroup = recipient.address.isClosedGroup
// Send a leave group message if this is an active closed group // Send a leave group message if this is an active closed group
if (isClosedGroup && DatabaseFactory.getGroupDatabase(this).isActive(recipient.address.toGroupString())) { if (isClosedGroup && DatabaseFactory.getGroupDatabase(this).isActive(recipient.address.toGroupString())) {
val groupPublicKey = GroupUtil.getDecodedId(recipient.address.toString()).toHexString() val groupPublicKey = GroupUtil.getDecodedId(GroupUtil.getDecodedStringId(recipient.address.toString())).toHexString()
val isSSKBasedClosedGroup = DatabaseFactory.getSSKDatabase(this).isSSKBasedClosedGroup(groupPublicKey) val isSSKBasedClosedGroup = DatabaseFactory.getSSKDatabase(this).isSSKBasedClosedGroup(groupPublicKey)
if (isSSKBasedClosedGroup) { if (isSSKBasedClosedGroup) {
ClosedGroupsProtocol.leave(this, groupPublicKey) ClosedGroupsProtocol.leave(this, groupPublicKey)

View File

@ -36,7 +36,7 @@ class LokiAPIDatabase(context: Context, helper: SQLCipherOpenHelper) : Database(
private val lastMessageHashValueTable2 = "last_message_hash_value_table" private val lastMessageHashValueTable2 = "last_message_hash_value_table"
private val lastMessageHashValue = "last_message_hash_value" private val lastMessageHashValue = "last_message_hash_value"
@JvmStatic val createLastMessageHashValueTable2Command @JvmStatic val createLastMessageHashValueTable2Command
= "CREATE TABLE $lastMessageHashValueTable2 ($snode STRING, $publicKey STRING, $lastMessageHashValue TEXT, PRIMARY KEY ($snode, $publicKey));" = "CREATE TABLE $lastMessageHashValueTable2 ($snode TEXT, $publicKey TEXT, $lastMessageHashValue TEXT, PRIMARY KEY ($snode, $publicKey));"
// Received message hash values // Received message hash values
private val receivedMessageHashValuesTable2 = "received_message_hash_values_table" private val receivedMessageHashValuesTable2 = "received_message_hash_values_table"
private val receivedMessageHashValues = "received_message_hash_values" private val receivedMessageHashValues = "received_message_hash_values"
@ -201,16 +201,16 @@ class LokiAPIDatabase(context: Context, helper: SQLCipherOpenHelper) : Database(
override fun getLastMessageHashValue(snode: Snode, publicKey: String): String? { override fun getLastMessageHashValue(snode: Snode, publicKey: String): String? {
val database = databaseHelper.readableDatabase val database = databaseHelper.readableDatabase
val query = "${Companion.snode} = ? AND ${Companion.publicKey} = ?" val query = "${Companion.snode} = ? AND ${Companion.publicKey} = ?"
return database.get(lastMessageHashValueTable2, query, arrayOf( snode.address, publicKey )) { cursor -> return database.get(lastMessageHashValueTable2, query, arrayOf( snode.toString(), publicKey )) { cursor ->
cursor.getString(cursor.getColumnIndexOrThrow(lastMessageHashValue)) cursor.getString(cursor.getColumnIndexOrThrow(lastMessageHashValue))
} }
} }
override fun setLastMessageHashValue(snode: Snode, publicKey: String, newValue: String) { override fun setLastMessageHashValue(snode: Snode, publicKey: String, newValue: String) {
val database = databaseHelper.writableDatabase val database = databaseHelper.writableDatabase
val row = wrap(mapOf(Companion.snode to snode.address, Companion.publicKey to publicKey, lastMessageHashValue to newValue)) val row = wrap(mapOf( Companion.snode to snode.toString(), Companion.publicKey to publicKey, lastMessageHashValue to newValue ))
val query = "${Companion.snode} = ? AND ${Companion.publicKey} = ?" val query = "${Companion.snode} = ? AND ${Companion.publicKey} = ?"
database.insertOrUpdate(lastMessageHashValueTable2, row, query, arrayOf( snode.address, publicKey )) database.insertOrUpdate(lastMessageHashValueTable2, row, query, arrayOf( snode.toString(), publicKey ))
} }
override fun getReceivedMessageHashValues(publicKey: String): Set<String>? { override fun getReceivedMessageHashValues(publicKey: String): Set<String>? {
@ -218,13 +218,13 @@ class LokiAPIDatabase(context: Context, helper: SQLCipherOpenHelper) : Database(
val query = "$Companion.publicKey = ?" val query = "$Companion.publicKey = ?"
return database.get(receivedMessageHashValuesTable2, query, arrayOf( publicKey )) { cursor -> return database.get(receivedMessageHashValuesTable2, query, arrayOf( publicKey )) { cursor ->
val receivedMessageHashValuesAsString = cursor.getString(cursor.getColumnIndexOrThrow(receivedMessageHashValues)) val receivedMessageHashValuesAsString = cursor.getString(cursor.getColumnIndexOrThrow(receivedMessageHashValues))
receivedMessageHashValuesAsString.split(", ").toSet() receivedMessageHashValuesAsString.split("-").toSet()
} }
} }
override fun setReceivedMessageHashValues(publicKey: String, newValue: Set<String>) { override fun setReceivedMessageHashValues(publicKey: String, newValue: Set<String>) {
val database = databaseHelper.writableDatabase val database = databaseHelper.writableDatabase
val receivedMessageHashValuesAsString = newValue.joinToString(", ") val receivedMessageHashValuesAsString = newValue.joinToString("-")
val row = wrap(mapOf( Companion.publicKey to publicKey, receivedMessageHashValues to receivedMessageHashValuesAsString )) val row = wrap(mapOf( Companion.publicKey to publicKey, receivedMessageHashValues to receivedMessageHashValuesAsString ))
val query = "$Companion.publicKey = ?" val query = "$Companion.publicKey = ?"
database.insertOrUpdate(receivedMessageHashValuesTable2, row, query, arrayOf( publicKey )) database.insertOrUpdate(receivedMessageHashValuesTable2, row, query, arrayOf( publicKey ))

View File

@ -78,6 +78,11 @@ object SessionMetaProtocol {
return !recipient.address.isRSSFeed return !recipient.address.isRSSFeed
} }
@JvmStatic
fun shouldSendDeliveryReceipt(address: Address): Boolean {
return !address.isGroup
}
/** /**
* Should be invoked for the recipient's master device. * Should be invoked for the recipient's master device.
*/ */