mirror of
https://github.com/signalapp/Signal-Android.git
synced 2026-04-22 09:49:30 +01:00
Fix in-chat payment view not updating properly.
This commit is contained in:
@@ -542,6 +542,20 @@ public abstract class MessageTable extends DatabaseTable implements MmsSmsColumn
|
||||
return CursorExtensionsKt.readToList(cursor, c -> CursorUtil.requireLong(c, THREAD_ID));
|
||||
}
|
||||
|
||||
public @Nullable MessageId getPaymentMessage(@NonNull UUID paymentUuid) {
|
||||
Cursor cursor = SQLiteDatabaseExtensionsKt.select(getReadableDatabase(), ID)
|
||||
.from(getTableName())
|
||||
.where(getTypeField() + " & ? != 0 AND body = ?", Types.SPECIAL_TYPE_PAYMENTS_NOTIFICATION, paymentUuid)
|
||||
.run();
|
||||
|
||||
long id = CursorExtensionsKt.readToSingleLong(cursor, -1);
|
||||
if (id != -1) {
|
||||
return new MessageId(id, getTableName().equals(MmsTable.TABLE_NAME));
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void remapRecipient(@NonNull RecipientId fromId, @NonNull RecipientId toId) {
|
||||
ContentValues values = new ContentValues();
|
||||
|
||||
@@ -212,7 +212,8 @@ public class MmsTable extends MessageTable {
|
||||
"CREATE INDEX IF NOT EXISTS mms_parent_story_id_index ON " + TABLE_NAME + " (" + PARENT_STORY_ID + ");",
|
||||
"CREATE INDEX IF NOT EXISTS mms_thread_story_parent_story_index ON " + TABLE_NAME + " (" + THREAD_ID + ", " + DATE_RECEIVED + "," + STORY_TYPE + "," + PARENT_STORY_ID + ");",
|
||||
"CREATE INDEX IF NOT EXISTS mms_quote_id_quote_author_index ON " + TABLE_NAME + "(" + QUOTE_ID + ", " + QUOTE_AUTHOR + ");",
|
||||
"CREATE INDEX IF NOT EXISTS mms_exported_index ON " + TABLE_NAME + " (" + EXPORTED + ");"
|
||||
"CREATE INDEX IF NOT EXISTS mms_exported_index ON " + TABLE_NAME + " (" + EXPORTED + ");",
|
||||
"CREATE INDEX IF NOT EXISTS mms_id_msg_box_payment_transactions_index ON " + TABLE_NAME + " (" + ID + "," + MESSAGE_BOX + ") WHERE " + MESSAGE_BOX + " & " + Types.SPECIAL_TYPE_PAYMENTS_NOTIFICATION + " != 0;"
|
||||
};
|
||||
|
||||
private static final String[] MMS_PROJECTION = new String[] {
|
||||
|
||||
@@ -18,6 +18,7 @@ import org.signal.core.util.CursorExtensionsKt;
|
||||
import org.signal.core.util.SQLiteDatabaseExtensionsKt;
|
||||
import org.signal.core.util.logging.Log;
|
||||
import org.thoughtcrime.securesms.database.model.MediaMmsMessageRecord;
|
||||
import org.thoughtcrime.securesms.database.model.MessageId;
|
||||
import org.thoughtcrime.securesms.database.model.MessageRecord;
|
||||
import org.thoughtcrime.securesms.database.model.databaseprotos.CryptoValue;
|
||||
import org.thoughtcrime.securesms.dependencies.ApplicationDependencies;
|
||||
@@ -33,6 +34,7 @@ import org.thoughtcrime.securesms.recipients.RecipientId;
|
||||
import org.thoughtcrime.securesms.util.Base64;
|
||||
import org.signal.core.util.CursorUtil;
|
||||
import org.signal.core.util.SqlUtil;
|
||||
import org.thoughtcrime.securesms.util.FeatureFlags;
|
||||
import org.thoughtcrime.securesms.util.livedata.LiveDataUtil;
|
||||
import org.whispersystems.signalservice.api.payments.Money;
|
||||
import org.whispersystems.signalservice.api.util.UuidUtil;
|
||||
@@ -647,6 +649,10 @@ public final class PaymentTable extends DatabaseTable implements RecipientIdData
|
||||
private void notifyUuidChanged(@Nullable UUID uuid) {
|
||||
if (uuid != null) {
|
||||
ApplicationDependencies.getDatabaseObserver().notifyPaymentListeners(uuid);
|
||||
MessageId messageId = SignalDatabase.mms().getPaymentMessage(uuid);
|
||||
if (messageId != null) {
|
||||
ApplicationDependencies.getDatabaseObserver().notifyMessageUpdateObservers(messageId);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -20,6 +20,7 @@ import org.thoughtcrime.securesms.database.helpers.migration.V161_StorySendMessa
|
||||
import org.thoughtcrime.securesms.database.helpers.migration.V162_ThreadUnreadSelfMentionCountFixup
|
||||
import org.thoughtcrime.securesms.database.helpers.migration.V163_RemoteMegaphoneSnoozeSupportMigration
|
||||
import org.thoughtcrime.securesms.database.helpers.migration.V164_ThreadDatabaseReadIndexMigration
|
||||
import org.thoughtcrime.securesms.database.helpers.migration.V165_MmsMessageBoxPaymentTransactionIndexMigration
|
||||
|
||||
/**
|
||||
* Contains all of the database migrations for [SignalDatabase]. Broken into a separate file for cleanliness.
|
||||
@@ -28,7 +29,7 @@ object SignalDatabaseMigrations {
|
||||
|
||||
val TAG: String = Log.tag(SignalDatabaseMigrations.javaClass)
|
||||
|
||||
const val DATABASE_VERSION = 164
|
||||
const val DATABASE_VERSION = 165
|
||||
|
||||
@JvmStatic
|
||||
fun migrate(context: Application, db: SQLiteDatabase, oldVersion: Int, newVersion: Int) {
|
||||
@@ -95,6 +96,10 @@ object SignalDatabaseMigrations {
|
||||
if (oldVersion < 164) {
|
||||
V164_ThreadDatabaseReadIndexMigration.migrate(context, db, oldVersion, newVersion)
|
||||
}
|
||||
|
||||
if (oldVersion < 165) {
|
||||
V165_MmsMessageBoxPaymentTransactionIndexMigration.migrate(context, db, oldVersion, newVersion)
|
||||
}
|
||||
}
|
||||
|
||||
@JvmStatic
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
package org.thoughtcrime.securesms.database.helpers.migration
|
||||
|
||||
import android.app.Application
|
||||
import net.zetetic.database.sqlcipher.SQLiteDatabase
|
||||
|
||||
/**
|
||||
* Adds an index to MMS table that only covers id and messages with the type of payment notification to
|
||||
* speed up look ups for payment messages.
|
||||
*/
|
||||
@Suppress("ClassName")
|
||||
object V165_MmsMessageBoxPaymentTransactionIndexMigration : SignalDatabaseMigration {
|
||||
override fun migrate(context: Application, db: SQLiteDatabase, oldVersion: Int, newVersion: Int) {
|
||||
db.execSQL("CREATE INDEX IF NOT EXISTS mms_id_msg_box_payment_transactions_index ON mms (_id, msg_box) WHERE msg_box & 0x300000000 != 0")
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user