mirror of
https://github.com/oxen-io/session-android.git
synced 2024-11-27 20:15:21 +00:00
Fix messed up database table
This commit is contained in:
parent
86fa15d0c9
commit
7e99aec410
@ -6,9 +6,10 @@ import android.content.Context;
|
||||
import android.database.Cursor;
|
||||
import android.net.Uri;
|
||||
import android.os.SystemClock;
|
||||
import androidx.annotation.NonNull;
|
||||
import android.text.TextUtils;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
|
||||
import net.sqlcipher.database.SQLiteDatabase;
|
||||
import net.sqlcipher.database.SQLiteDatabaseHook;
|
||||
import net.sqlcipher.database.SQLiteOpenHelper;
|
||||
@ -87,8 +88,9 @@ public class SQLCipherOpenHelper extends SQLiteOpenHelper {
|
||||
private static final int lokiV10 = 31;
|
||||
private static final int lokiV11 = 32;
|
||||
private static final int lokiV12 = 33;
|
||||
private static final int lokiV13 = 34;
|
||||
|
||||
private static final int DATABASE_VERSION = lokiV12; // Loki - onUpgrade(...) must be updated to use Loki version numbers if Signal makes any database changes
|
||||
private static final int DATABASE_VERSION = lokiV13; // Loki - onUpgrade(...) must be updated to use Loki version numbers if Signal makes any database changes
|
||||
private static final String DATABASE_NAME = "signal.db";
|
||||
|
||||
private final Context context;
|
||||
@ -140,7 +142,7 @@ public class SQLCipherOpenHelper extends SQLiteOpenHelper {
|
||||
db.execSQL(LokiAPIDatabase.getCreateOnionRequestPathTableCommand());
|
||||
db.execSQL(LokiAPIDatabase.getCreateSwarmTableCommand());
|
||||
db.execSQL(LokiAPIDatabase.getCreateLastMessageHashValueTable2Command());
|
||||
db.execSQL(LokiAPIDatabase.getCreateReceivedMessageHashValuesTable2Command());
|
||||
db.execSQL(LokiAPIDatabase.getCreateReceivedMessageHashValuesTable3Command());
|
||||
db.execSQL(LokiAPIDatabase.getCreateOpenGroupAuthTokenTableCommand());
|
||||
db.execSQL(LokiAPIDatabase.getCreateLastMessageServerIDTableCommand());
|
||||
db.execSQL(LokiAPIDatabase.getCreateLastDeletionServerIDTableCommand());
|
||||
@ -609,11 +611,14 @@ public class SQLCipherOpenHelper extends SQLiteOpenHelper {
|
||||
|
||||
if (oldVersion < lokiV12) {
|
||||
db.execSQL(LokiAPIDatabase.getCreateLastMessageHashValueTable2Command());
|
||||
db.execSQL(LokiAPIDatabase.getCreateReceivedMessageHashValuesTable2Command());
|
||||
db.execSQL(SharedSenderKeysDatabase.getCreateClosedGroupRatchetTableCommand());
|
||||
db.execSQL(SharedSenderKeysDatabase.getCreateClosedGroupPrivateKeyTableCommand());
|
||||
}
|
||||
|
||||
if (oldVersion < lokiV13) {
|
||||
db.execSQL(LokiAPIDatabase.getCreateReceivedMessageHashValuesTable3Command());
|
||||
}
|
||||
|
||||
db.setTransactionSuccessful();
|
||||
} finally {
|
||||
db.endTransaction();
|
||||
|
@ -38,10 +38,10 @@ class LokiAPIDatabase(context: Context, helper: SQLCipherOpenHelper) : Database(
|
||||
@JvmStatic val createLastMessageHashValueTable2Command
|
||||
= "CREATE TABLE $lastMessageHashValueTable2 ($snode TEXT, $publicKey TEXT, $lastMessageHashValue TEXT, PRIMARY KEY ($snode, $publicKey));"
|
||||
// Received message hash values
|
||||
private val receivedMessageHashValuesTable2 = "received_message_hash_values_table"
|
||||
private val receivedMessageHashValuesTable3 = "received_message_hash_values_table_3"
|
||||
private val receivedMessageHashValues = "received_message_hash_values"
|
||||
@JvmStatic val createReceivedMessageHashValuesTable2Command
|
||||
= "CREATE TABLE $receivedMessageHashValuesTable2 ($snode STRING, $publicKey STRING, $receivedMessageHashValues TEXT, PRIMARY KEY ($snode, $publicKey));"
|
||||
@JvmStatic val createReceivedMessageHashValuesTable3Command
|
||||
= "CREATE TABLE $receivedMessageHashValuesTable3 ($publicKey STRING PRIMARY KEY, $receivedMessageHashValues TEXT);"
|
||||
// Open group auth tokens
|
||||
private val openGroupAuthTokenTable = "loki_api_group_chat_auth_token_database"
|
||||
private val server = "server"
|
||||
@ -216,7 +216,7 @@ class LokiAPIDatabase(context: Context, helper: SQLCipherOpenHelper) : Database(
|
||||
override fun getReceivedMessageHashValues(publicKey: String): Set<String>? {
|
||||
val database = databaseHelper.readableDatabase
|
||||
val query = "${Companion.publicKey} = ?"
|
||||
return database.get(receivedMessageHashValuesTable2, query, arrayOf( publicKey )) { cursor ->
|
||||
return database.get(receivedMessageHashValuesTable3, query, arrayOf( publicKey )) { cursor ->
|
||||
val receivedMessageHashValuesAsString = cursor.getString(cursor.getColumnIndexOrThrow(Companion.receivedMessageHashValues))
|
||||
receivedMessageHashValuesAsString.split("-").toSet()
|
||||
}
|
||||
@ -227,7 +227,7 @@ class LokiAPIDatabase(context: Context, helper: SQLCipherOpenHelper) : Database(
|
||||
val receivedMessageHashValuesAsString = newValue.joinToString("-")
|
||||
val row = wrap(mapOf( Companion.publicKey to publicKey, Companion.receivedMessageHashValues to receivedMessageHashValuesAsString ))
|
||||
val query = "${Companion.publicKey} = ?"
|
||||
database.insertOrUpdate(receivedMessageHashValuesTable2, row, query, arrayOf( publicKey ))
|
||||
database.insertOrUpdate(receivedMessageHashValuesTable3, row, query, arrayOf( publicKey ))
|
||||
}
|
||||
|
||||
override fun getAuthToken(server: String): String? {
|
||||
|
@ -19,7 +19,3 @@ fun toPx(dp: Int, resources: Resources): Int {
|
||||
val scale = resources.displayMetrics.density
|
||||
return (dp * scale).roundToInt()
|
||||
}
|
||||
|
||||
fun isPublicChat(context: Context, recipient: String): Boolean {
|
||||
return DatabaseFactory.getLokiThreadDatabase(context).getAllPublicChats().values.map { it.server }.contains(recipient)
|
||||
}
|
||||
|
@ -23,15 +23,15 @@ object OpenGroupUtilities {
|
||||
val displayName = TextSecurePreferences.getProfileName(context)
|
||||
val lokiPublicChatAPI = application.publicChatAPI ?: throw Error("LokiPublicChatAPI is not initialized.")
|
||||
return application.publicChatManager.addChat(url, channel).then { group ->
|
||||
DatabaseFactory.getLokiAPIDatabase(context).removeLastMessageServerID(channel, url)
|
||||
DatabaseFactory.getLokiAPIDatabase(context).removeLastDeletionServerID(channel, url)
|
||||
lokiPublicChatAPI.getMessages(channel, url)
|
||||
lokiPublicChatAPI.setDisplayName(displayName, url)
|
||||
lokiPublicChatAPI.join(channel, url)
|
||||
val profileKey: ByteArray = ProfileKeyUtil.getProfileKey(context)
|
||||
val profileUrl: String? = TextSecurePreferences.getProfilePictureURL(context)
|
||||
lokiPublicChatAPI.setProfilePicture(url, profileKey, profileUrl)
|
||||
group
|
||||
DatabaseFactory.getLokiAPIDatabase(context).removeLastMessageServerID(channel, url)
|
||||
DatabaseFactory.getLokiAPIDatabase(context).removeLastDeletionServerID(channel, url)
|
||||
lokiPublicChatAPI.getMessages(channel, url)
|
||||
lokiPublicChatAPI.setDisplayName(displayName, url)
|
||||
lokiPublicChatAPI.join(channel, url)
|
||||
val profileKey: ByteArray = ProfileKeyUtil.getProfileKey(context)
|
||||
val profileUrl: String? = TextSecurePreferences.getProfilePictureURL(context)
|
||||
lokiPublicChatAPI.setProfilePicture(url, profileKey, profileUrl)
|
||||
group
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user