mirror of
https://github.com/oxen-io/session-android.git
synced 2025-07-14 22:38:32 +00:00
commit
42dec85884
@ -124,6 +124,7 @@ public class SQLCipherOpenHelper extends SQLiteOpenHelper {
|
|||||||
db.execSQL(LokiAPIDatabase.getCreateSwarmCacheTableCommand());
|
db.execSQL(LokiAPIDatabase.getCreateSwarmCacheTableCommand());
|
||||||
db.execSQL(LokiAPIDatabase.getCreateLastMessageHashValueTableCommand());
|
db.execSQL(LokiAPIDatabase.getCreateLastMessageHashValueTableCommand());
|
||||||
db.execSQL(LokiAPIDatabase.getCreateReceivedMessageHashValuesTableCommand());
|
db.execSQL(LokiAPIDatabase.getCreateReceivedMessageHashValuesTableCommand());
|
||||||
|
db.execSQL(LokiAPIDatabase.getCreateGroupChatAuthTokenTableCommand());
|
||||||
db.execSQL(LokiPreKeyBundleDatabase.getCreateTableCommand());
|
db.execSQL(LokiPreKeyBundleDatabase.getCreateTableCommand());
|
||||||
db.execSQL(LokiPreKeyRecordDatabase.getCreateTableCommand());
|
db.execSQL(LokiPreKeyRecordDatabase.getCreateTableCommand());
|
||||||
db.execSQL(LokiMessageDatabase.getCreateTableCommand());
|
db.execSQL(LokiMessageDatabase.getCreateTableCommand());
|
||||||
|
@ -28,6 +28,11 @@ class LokiAPIDatabase(context: Context, helper: SQLCipherOpenHelper) : Database(
|
|||||||
private val userID = "user_id"
|
private val userID = "user_id"
|
||||||
private val receivedMessageHashValues = "received_message_hash_values"
|
private val receivedMessageHashValues = "received_message_hash_values"
|
||||||
@JvmStatic val createReceivedMessageHashValuesTableCommand = "CREATE TABLE $receivedMessageHashValuesCache ($userID TEXT PRIMARY KEY, $receivedMessageHashValues TEXT);"
|
@JvmStatic val createReceivedMessageHashValuesTableCommand = "CREATE TABLE $receivedMessageHashValuesCache ($userID TEXT PRIMARY KEY, $receivedMessageHashValues TEXT);"
|
||||||
|
// Group chat auth token cache
|
||||||
|
private val groupChatAuthTokenTable = "loki_api_group_chat_auth_token_database"
|
||||||
|
private val serverURL = "server_url"
|
||||||
|
private val token = "token"
|
||||||
|
@JvmStatic val createGroupChatAuthTokenTableCommand = "CREATE TABLE $groupChatAuthTokenTable ($serverURL TEXT PRIMARY KEY, $token TEXT);"
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun getSwarmCache(hexEncodedPublicKey: String): Set<LokiAPITarget>? {
|
override fun getSwarmCache(hexEncodedPublicKey: String): Set<LokiAPITarget>? {
|
||||||
@ -77,6 +82,23 @@ class LokiAPIDatabase(context: Context, helper: SQLCipherOpenHelper) : Database(
|
|||||||
val row = wrap(mapOf( userID to userPublicKey, receivedMessageHashValues to receivedMessageHashValuesAsString ))
|
val row = wrap(mapOf( userID to userPublicKey, receivedMessageHashValues to receivedMessageHashValuesAsString ))
|
||||||
database.insertOrUpdate(receivedMessageHashValuesCache, row, "$userID = ?", wrap(userPublicKey))
|
database.insertOrUpdate(receivedMessageHashValuesCache, row, "$userID = ?", wrap(userPublicKey))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun getGroupChatAuthToken(serverURL: String): String? {
|
||||||
|
val database = databaseHelper.readableDatabase
|
||||||
|
return database.get(groupChatAuthTokenTable, "${Companion.serverURL} = ?", wrap(serverURL)) { cursor ->
|
||||||
|
cursor.getString(cursor.getColumnIndexOrThrow(token))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun setGroupChatAuthToken(token: String?, serverURL: String) {
|
||||||
|
val database = databaseHelper.writableDatabase
|
||||||
|
if (token != null) {
|
||||||
|
val row = wrap(mapOf(Companion.serverURL to serverURL, Companion.token to token!!))
|
||||||
|
database.insertOrUpdate(groupChatAuthTokenTable, row, "${Companion.serverURL} = ?", wrap(serverURL))
|
||||||
|
} else {
|
||||||
|
database.delete(groupChatAuthTokenTable, "${Companion.serverURL} = ?", wrap(serverURL))
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// region Convenience
|
// region Convenience
|
||||||
|
@ -3,6 +3,7 @@ package org.thoughtcrime.securesms.loki
|
|||||||
import android.content.Context
|
import android.content.Context
|
||||||
import android.os.Handler
|
import android.os.Handler
|
||||||
import android.util.Log
|
import android.util.Log
|
||||||
|
import org.thoughtcrime.securesms.crypto.IdentityKeyUtil
|
||||||
import org.thoughtcrime.securesms.database.DatabaseFactory
|
import org.thoughtcrime.securesms.database.DatabaseFactory
|
||||||
import org.thoughtcrime.securesms.jobs.PushDecryptJob
|
import org.thoughtcrime.securesms.jobs.PushDecryptJob
|
||||||
import org.thoughtcrime.securesms.util.TextSecurePreferences
|
import org.thoughtcrime.securesms.util.TextSecurePreferences
|
||||||
@ -42,8 +43,10 @@ class LokiGroupChatPoller(private val context: Context, private val groupID: Lon
|
|||||||
|
|
||||||
private fun poll() {
|
private fun poll() {
|
||||||
val userHexEncodedPublicKey = TextSecurePreferences.getLocalNumber(context)
|
val userHexEncodedPublicKey = TextSecurePreferences.getLocalNumber(context)
|
||||||
|
val lokiAPIDatabase = DatabaseFactory.getLokiAPIDatabase(context)
|
||||||
val lokiUserDatabase = DatabaseFactory.getLokiUserDatabase(context)
|
val lokiUserDatabase = DatabaseFactory.getLokiUserDatabase(context)
|
||||||
LokiGroupChatAPI(userHexEncodedPublicKey, lokiUserDatabase).getMessages(groupID).success { messages ->
|
val userPrivateKey = IdentityKeyUtil.getIdentityKeyPair(context).privateKey.serialize()
|
||||||
|
LokiGroupChatAPI(userHexEncodedPublicKey, userPrivateKey, lokiAPIDatabase, lokiUserDatabase).getMessages(groupID).success { messages ->
|
||||||
messages.reversed().map { message ->
|
messages.reversed().map { message ->
|
||||||
val id = "${LokiGroupChatAPI.serverURL}.$groupID".toByteArray()
|
val id = "${LokiGroupChatAPI.serverURL}.$groupID".toByteArray()
|
||||||
val x1 = SignalServiceGroup(SignalServiceGroup.Type.UPDATE, id, null, null, null)
|
val x1 = SignalServiceGroup(SignalServiceGroup.Type.UPDATE, id, null, null, null)
|
||||||
|
@ -12,10 +12,10 @@ import org.whispersystems.signalservice.loki.messaging.LokiUserDatabaseProtocol
|
|||||||
class LokiUserDatabase(context: Context, helper: SQLCipherOpenHelper) : Database(context, helper), LokiUserDatabaseProtocol {
|
class LokiUserDatabase(context: Context, helper: SQLCipherOpenHelper) : Database(context, helper), LokiUserDatabaseProtocol {
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
private val tableName = "loki_user_display_name_database"
|
private val displayNameTable = "loki_user_display_name_database"
|
||||||
private val hexEncodedPublicKey = "hex_encoded_public_key"
|
private val hexEncodedPublicKey = "hex_encoded_public_key"
|
||||||
private val displayName = "display_name"
|
private val displayName = "display_name"
|
||||||
@JvmStatic val createTableCommand = "CREATE TABLE $tableName ($hexEncodedPublicKey TEXT PRIMARY KEY, $displayName TEXT);"
|
@JvmStatic val createTableCommand = "CREATE TABLE $displayNameTable ($hexEncodedPublicKey TEXT PRIMARY KEY, $displayName TEXT);"
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun getDisplayName(hexEncodedPublicKey: String): String? {
|
override fun getDisplayName(hexEncodedPublicKey: String): String? {
|
||||||
@ -23,7 +23,7 @@ class LokiUserDatabase(context: Context, helper: SQLCipherOpenHelper) : Database
|
|||||||
return TextSecurePreferences.getProfileName(context)
|
return TextSecurePreferences.getProfileName(context)
|
||||||
} else {
|
} else {
|
||||||
val database = databaseHelper.readableDatabase
|
val database = databaseHelper.readableDatabase
|
||||||
return database.get(tableName, "${Companion.hexEncodedPublicKey} = ?", arrayOf(hexEncodedPublicKey)) { cursor ->
|
return database.get(displayNameTable, "${Companion.hexEncodedPublicKey} = ?", arrayOf(hexEncodedPublicKey)) { cursor ->
|
||||||
cursor.getString(cursor.getColumnIndexOrThrow(displayName))
|
cursor.getString(cursor.getColumnIndexOrThrow(displayName))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -34,7 +34,7 @@ class LokiUserDatabase(context: Context, helper: SQLCipherOpenHelper) : Database
|
|||||||
val row = ContentValues(2)
|
val row = ContentValues(2)
|
||||||
row.put(Companion.hexEncodedPublicKey, hexEncodedPublicKey)
|
row.put(Companion.hexEncodedPublicKey, hexEncodedPublicKey)
|
||||||
row.put(Companion.displayName, displayName)
|
row.put(Companion.displayName, displayName)
|
||||||
database.insertOrUpdate(tableName, row, "${Companion.hexEncodedPublicKey} = ?", arrayOf( hexEncodedPublicKey ))
|
database.insertOrUpdate(displayNameTable, row, "${Companion.hexEncodedPublicKey} = ?", arrayOf( hexEncodedPublicKey ))
|
||||||
Recipient.from(context, Address.fromSerialized(hexEncodedPublicKey), false).notifyListeners()
|
Recipient.from(context, Address.fromSerialized(hexEncodedPublicKey), false).notifyListeners()
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user