mirror of
https://github.com/oxen-io/session-android.git
synced 2024-11-30 21:45:20 +00:00
Added database to store public chat tokens.
This commit is contained in:
parent
67b7a1d8c2
commit
51646c98c8
@ -129,7 +129,8 @@ public class SQLCipherOpenHelper extends SQLiteOpenHelper {
|
|||||||
db.execSQL(LokiMessageDatabase.getCreateTableCommand());
|
db.execSQL(LokiMessageDatabase.getCreateTableCommand());
|
||||||
db.execSQL(LokiThreadDatabase.getCreateFriendRequestTableCommand());
|
db.execSQL(LokiThreadDatabase.getCreateFriendRequestTableCommand());
|
||||||
db.execSQL(LokiThreadDatabase.getCreateSessionResetTableCommand());
|
db.execSQL(LokiThreadDatabase.getCreateSessionResetTableCommand());
|
||||||
db.execSQL(LokiUserDatabase.getCreateTableCommand());
|
db.execSQL(LokiUserDatabase.getCreateDisplayNameTableCommand());
|
||||||
|
db.execSQL(LokiUserDatabase.getCreatePublicChatTokenTableCommand());
|
||||||
|
|
||||||
executeStatements(db, SmsDatabase.CREATE_INDEXS);
|
executeStatements(db, SmsDatabase.CREATE_INDEXS);
|
||||||
executeStatements(db, MmsDatabase.CREATE_INDEXS);
|
executeStatements(db, MmsDatabase.CREATE_INDEXS);
|
||||||
|
@ -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
|
||||||
@ -43,7 +44,8 @@ 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 lokiUserDatabase = DatabaseFactory.getLokiUserDatabase(context)
|
val lokiUserDatabase = DatabaseFactory.getLokiUserDatabase(context)
|
||||||
LokiGroupChatAPI(userHexEncodedPublicKey, lokiUserDatabase).getMessages(groupID).success { messages ->
|
val identityKeyPair = IdentityKeyUtil.getIdentityKeyPair(context)
|
||||||
|
LokiGroupChatAPI(userHexEncodedPublicKey, identityKeyPair.privateKey.serialize(), 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,15 @@ 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 createDisplayNameTableCommand = "CREATE TABLE $displayNameTable ($hexEncodedPublicKey TEXT PRIMARY KEY, $displayName TEXT);"
|
||||||
|
|
||||||
|
private val publicChatTokenTable = "loki_user_public_chat_token_database"
|
||||||
|
private val server = "server"
|
||||||
|
private val token = "token"
|
||||||
|
@JvmStatic val createPublicChatTokenTableCommand = "CREATE TABLE $publicChatTokenTable ($server TEXT PRIMARY KEY, $token TEXT);"
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun getDisplayName(hexEncodedPublicKey: String): String? {
|
override fun getDisplayName(hexEncodedPublicKey: String): String? {
|
||||||
@ -23,7 +28,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 +39,22 @@ 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()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun getToken(server: String): String? {
|
||||||
|
val database = databaseHelper.readableDatabase
|
||||||
|
return database.get(publicChatTokenTable, "${Companion.server} = ?", arrayOf( server )) { cursor ->
|
||||||
|
cursor.getString(cursor.getColumnIndexOrThrow(token))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun setToken(token: String, server: String) {
|
||||||
|
val database = databaseHelper.writableDatabase
|
||||||
|
val row = ContentValues(2)
|
||||||
|
row.put(Companion.server, server)
|
||||||
|
row.put(Companion.token, token)
|
||||||
|
database.insertOrUpdate(publicChatTokenTable, row, "${Companion.server} = ?", arrayOf( server ))
|
||||||
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user