mirror of
https://github.com/oxen-io/session-android.git
synced 2025-03-31 10:52:14 +00:00
feat: add basic last sent legacy message DB migration and creation for banner
This commit is contained in:
parent
806cb216ae
commit
d12bce54bd
@ -698,7 +698,7 @@ class ConversationActivityV2 : PassphraseRequiredActionBarActivity(), InputBarDe
|
|||||||
|
|
||||||
private fun setUpOutdatedClientBanner() {
|
private fun setUpOutdatedClientBanner() {
|
||||||
val recipient = viewModel.recipient?.takeIf { !it.isLocalNumber } ?: return
|
val recipient = viewModel.recipient?.takeIf { !it.isLocalNumber } ?: return
|
||||||
if (ExpirationConfiguration.isNewConfigEnabled && recipient.isContactRecipient &&
|
if (ExpirationConfiguration.isNewConfigEnabled &&
|
||||||
recipient.disappearingState == DisappearingState.LEGACY &&
|
recipient.disappearingState == DisappearingState.LEGACY &&
|
||||||
viewModel.expirationConfiguration?.isEnabled == true
|
viewModel.expirationConfiguration?.isEnabled == true
|
||||||
) {
|
) {
|
||||||
|
@ -97,6 +97,16 @@ class LokiAPIDatabase(context: Context, helper: SQLCipherOpenHelper) : Database(
|
|||||||
public val groupPublicKey = "group_public_key"
|
public val groupPublicKey = "group_public_key"
|
||||||
@JvmStatic
|
@JvmStatic
|
||||||
val createClosedGroupPublicKeysTable = "CREATE TABLE $closedGroupPublicKeysTable ($groupPublicKey STRING PRIMARY KEY)"
|
val createClosedGroupPublicKeysTable = "CREATE TABLE $closedGroupPublicKeysTable ($groupPublicKey STRING PRIMARY KEY)"
|
||||||
|
|
||||||
|
private const val LAST_LEGACY_MESSAGE_TABLE = "last_legacy_messages"
|
||||||
|
// The overall "thread recipient
|
||||||
|
private const val LAST_LEGACY_THREAD_RECIPIENT = "last_legacy_thread_recipient"
|
||||||
|
// The individual 'last' person who sent the message with legacy expiration attached
|
||||||
|
private const val LAST_LEGACY_SENDER_RECIPIENT = "last_legacy_sender_recipient"
|
||||||
|
private const val LEGACY_THREAD_RECIPIENT_QUERY = "$LAST_LEGACY_THREAD_RECIPIENT = ?"
|
||||||
|
|
||||||
|
const val CREATE_LAST_LEGACY_MESSAGE_TABLE = "CREATE TABLE $LAST_LEGACY_MESSAGE_TABLE ($LAST_LEGACY_THREAD_RECIPIENT STRING PRIMARY KEY, $LAST_LEGACY_SENDER_RECIPIENT STRING NOT NULL);"
|
||||||
|
|
||||||
// Hard fork service node info
|
// Hard fork service node info
|
||||||
const val FORK_INFO_TABLE = "fork_info"
|
const val FORK_INFO_TABLE = "fork_info"
|
||||||
const val DUMMY_KEY = "dummy_key"
|
const val DUMMY_KEY = "dummy_key"
|
||||||
@ -415,6 +425,33 @@ class LokiAPIDatabase(context: Context, helper: SQLCipherOpenHelper) : Database(
|
|||||||
database.endTransaction()
|
database.endTransaction()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun getLastLegacySenderAddress(threadRecipientAddress: String): String? {
|
||||||
|
val database = databaseHelper.readableDatabase
|
||||||
|
return database.get(LAST_LEGACY_MESSAGE_TABLE, LEGACY_THREAD_RECIPIENT_QUERY, wrap(threadRecipientAddress)) { cursor ->
|
||||||
|
cursor.getString(LAST_LEGACY_SENDER_RECIPIENT)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun setLastLegacySenderAddress(
|
||||||
|
threadRecipientAddress: String,
|
||||||
|
senderRecipientAddress: String?
|
||||||
|
) {
|
||||||
|
val database = databaseHelper.writableDatabase
|
||||||
|
if (senderRecipientAddress == null) {
|
||||||
|
// delete
|
||||||
|
database.delete(LAST_LEGACY_MESSAGE_TABLE, LEGACY_THREAD_RECIPIENT_QUERY, wrap(threadRecipientAddress))
|
||||||
|
} else {
|
||||||
|
// just update the value to a new one
|
||||||
|
val values = wrap(
|
||||||
|
mapOf(
|
||||||
|
LAST_LEGACY_THREAD_RECIPIENT to threadRecipientAddress,
|
||||||
|
LAST_LEGACY_SENDER_RECIPIENT to senderRecipientAddress
|
||||||
|
)
|
||||||
|
)
|
||||||
|
database.insertOrUpdate(LAST_LEGACY_MESSAGE_TABLE, values, LEGACY_THREAD_RECIPIENT_QUERY, wrap(threadRecipientAddress))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fun getUserCount(room: String, server: String): Int? {
|
fun getUserCount(room: String, server: String): Int? {
|
||||||
val database = databaseHelper.readableDatabase
|
val database = databaseHelper.readableDatabase
|
||||||
val index = "$server.$room"
|
val index = "$server.$room"
|
||||||
|
@ -366,6 +366,7 @@ public class SQLCipherOpenHelper extends SQLiteOpenHelper {
|
|||||||
executeStatements(db, ReactionDatabase.CREATE_REACTION_TRIGGERS);
|
executeStatements(db, ReactionDatabase.CREATE_REACTION_TRIGGERS);
|
||||||
db.execSQL(RecipientDatabase.getAddWrapperHash());
|
db.execSQL(RecipientDatabase.getAddWrapperHash());
|
||||||
db.execSQL(RecipientDatabase.getAddBlocksCommunityMessageRequests());
|
db.execSQL(RecipientDatabase.getAddBlocksCommunityMessageRequests());
|
||||||
|
db.execSQL(LokiAPIDatabase.CREATE_LAST_LEGACY_MESSAGE_TABLE);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -629,6 +630,7 @@ public class SQLCipherOpenHelper extends SQLiteOpenHelper {
|
|||||||
if (oldVersion < lokiV46) {
|
if (oldVersion < lokiV46) {
|
||||||
executeStatements(db, SmsDatabase.ADD_AUTOINCREMENT);
|
executeStatements(db, SmsDatabase.ADD_AUTOINCREMENT);
|
||||||
executeStatements(db, MmsDatabase.ADD_AUTOINCREMENT);
|
executeStatements(db, MmsDatabase.ADD_AUTOINCREMENT);
|
||||||
|
db.execSQL(LokiAPIDatabase.CREATE_LAST_LEGACY_MESSAGE_TABLE);
|
||||||
}
|
}
|
||||||
|
|
||||||
db.setTransactionSuccessful();
|
db.setTransactionSuccessful();
|
||||||
|
@ -38,4 +38,7 @@ interface LokiAPIDatabaseProtocol {
|
|||||||
fun getForkInfo(): ForkInfo
|
fun getForkInfo(): ForkInfo
|
||||||
fun setForkInfo(forkInfo: ForkInfo)
|
fun setForkInfo(forkInfo: ForkInfo)
|
||||||
fun migrateLegacyOpenGroup(legacyServerId: String, newServerId: String)
|
fun migrateLegacyOpenGroup(legacyServerId: String, newServerId: String)
|
||||||
|
fun getLastLegacySenderAddress(threadRecipientAddress: String): String?
|
||||||
|
fun setLastLegacySenderAddress(threadRecipientAddress: String, senderRecipientAddress: String?)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user