2019-06-17 00:54:38 +00:00
|
|
|
package org.thoughtcrime.securesms.loki
|
|
|
|
|
|
|
|
import android.content.ContentValues
|
|
|
|
import android.content.Context
|
|
|
|
import org.thoughtcrime.securesms.database.Database
|
|
|
|
import org.thoughtcrime.securesms.database.helpers.SQLCipherOpenHelper
|
|
|
|
|
2019-06-17 23:57:36 +00:00
|
|
|
class LokiMessageFriendRequestDatabase(context: Context, helper: SQLCipherOpenHelper) : Database(context, helper) {
|
2019-06-17 00:54:38 +00:00
|
|
|
|
|
|
|
companion object {
|
|
|
|
private val tableName = "loki_sms_friend_request_database"
|
2019-06-21 00:39:05 +00:00
|
|
|
private val messageID = "message_id"
|
2019-06-17 00:54:38 +00:00
|
|
|
private val isFriendRequest = "is_friend_request"
|
2019-06-21 00:39:05 +00:00
|
|
|
@JvmStatic val createTableCommand = "CREATE TABLE $tableName ($messageID INTEGER PRIMARY KEY, $isFriendRequest INTEGER DEFAULT 0);"
|
2019-06-17 00:54:38 +00:00
|
|
|
}
|
|
|
|
|
2019-06-21 00:39:05 +00:00
|
|
|
fun getIsFriendRequest(messageID: Long): Boolean {
|
2019-06-17 00:54:38 +00:00
|
|
|
val database = databaseHelper.readableDatabase
|
2019-06-21 00:39:05 +00:00
|
|
|
return database.get(tableName, "${Companion.messageID} = ?", arrayOf( messageID.toString() )) { cursor ->
|
2019-06-17 23:57:36 +00:00
|
|
|
val rawIsFriendRequest = cursor.getInt(isFriendRequest)
|
2019-06-17 00:54:38 +00:00
|
|
|
rawIsFriendRequest == 1
|
|
|
|
} ?: false
|
|
|
|
}
|
2019-06-17 01:57:40 +00:00
|
|
|
|
2019-06-21 00:39:05 +00:00
|
|
|
fun setIsFriendRequest(messageID: Long, isFriendRequest: Boolean) {
|
2019-06-17 01:57:40 +00:00
|
|
|
val database = databaseHelper.writableDatabase
|
|
|
|
val rawIsFriendRequest = if (isFriendRequest) 1 else 0
|
|
|
|
val contentValues = ContentValues()
|
2019-06-21 00:39:05 +00:00
|
|
|
contentValues.put(Companion.messageID, messageID)
|
2019-06-17 01:57:40 +00:00
|
|
|
contentValues.put(Companion.isFriendRequest, rawIsFriendRequest)
|
2019-06-21 00:39:05 +00:00
|
|
|
database.insertOrUpdate(tableName, contentValues, "${Companion.messageID} = ?", arrayOf( messageID.toString() ))
|
2019-06-17 01:57:40 +00:00
|
|
|
}
|
2019-06-17 00:54:38 +00:00
|
|
|
}
|