mirror of
https://github.com/oxen-io/session-android.git
synced 2025-12-03 11:52:23 +00:00
Model friend request status as an enum
This commit is contained in:
@@ -1,17 +1,16 @@
|
||||
package org.thoughtcrime.securesms.loki;
|
||||
package org.thoughtcrime.securesms.loki
|
||||
|
||||
public class LokiFriendRequestStatus {
|
||||
enum class LokiFriendRequestStatus(val rawValue: Int) {
|
||||
// New conversation; no messages sent or received.
|
||||
public static final int NONE = 0;
|
||||
NONE(0),
|
||||
// This state is used to lock the input early while sending.
|
||||
public static final int REQUEST_SENDING = 1;
|
||||
REQUEST_SENDING(1),
|
||||
// Friend request sent; awaiting response.
|
||||
public static final int REQUEST_SENT = 2;
|
||||
REQUEST_SENT(2),
|
||||
// Friend request received; awaiting user input.
|
||||
public static final int REQUEST_RECEIVED = 3;
|
||||
REQUEST_RECEIVED(3),
|
||||
// We are friends with the user in this thread.
|
||||
public static final int FRIENDS = 4;
|
||||
FRIENDS(4),
|
||||
// A friend request was sent, but it timed out (i.e other user didn't accept within the allocated time)
|
||||
public static final int REQUEST_EXPIRED = 5;
|
||||
}
|
||||
|
||||
REQUEST_EXPIRED(5)
|
||||
}
|
||||
@@ -5,10 +5,7 @@ import android.content.Context
|
||||
import org.thoughtcrime.securesms.database.Database
|
||||
import org.thoughtcrime.securesms.database.helpers.SQLCipherOpenHelper
|
||||
|
||||
/**
|
||||
* A database for associating friend request data to Sms
|
||||
*/
|
||||
class LokiSmsFriendRequestDatabase(context: Context, helper: SQLCipherOpenHelper) : Database(context, helper) {
|
||||
class LokiMessageFriendRequestDatabase(context: Context, helper: SQLCipherOpenHelper) : Database(context, helper) {
|
||||
|
||||
companion object {
|
||||
private val tableName = "loki_sms_friend_request_database"
|
||||
@@ -21,8 +18,8 @@ class LokiSmsFriendRequestDatabase(context: Context, helper: SQLCipherOpenHelper
|
||||
|
||||
fun getIsFriendRequest(messageId: Long): Boolean {
|
||||
val database = databaseHelper.readableDatabase
|
||||
return database.get(tableName, ID_WHERE, arrayOf(messageId.toString())) { cursor ->
|
||||
val rawIsFriendRequest = cursor.getInt(isFriendRequest)
|
||||
return database.get(tableName, ID_WHERE, arrayOf( messageId.toString() )) { cursor ->
|
||||
val rawIsFriendRequest = cursor.getInt(isFriendRequest)
|
||||
rawIsFriendRequest == 1
|
||||
} ?: false
|
||||
}
|
||||
@@ -36,6 +33,6 @@ class LokiSmsFriendRequestDatabase(context: Context, helper: SQLCipherOpenHelper
|
||||
contentValues.put(smsId, messageId)
|
||||
contentValues.put(Companion.isFriendRequest, rawIsFriendRequest)
|
||||
|
||||
database.insertOrUpdate(tableName, contentValues, ID_WHERE, arrayOf(messageId.toString()))
|
||||
database.insertOrUpdate(tableName, contentValues, ID_WHERE, arrayOf( messageId.toString() ))
|
||||
}
|
||||
}
|
||||
@@ -5,9 +5,6 @@ import android.content.Context
|
||||
import org.thoughtcrime.securesms.database.Database
|
||||
import org.thoughtcrime.securesms.database.helpers.SQLCipherOpenHelper
|
||||
|
||||
/**
|
||||
* A database for associating friend request data to Threads
|
||||
*/
|
||||
class LokiThreadFriendRequestDatabase(context: Context, helper: SQLCipherOpenHelper) : Database(context, helper) {
|
||||
|
||||
companion object {
|
||||
@@ -19,20 +16,24 @@ class LokiThreadFriendRequestDatabase(context: Context, helper: SQLCipherOpenHel
|
||||
val createTableCommand = "CREATE TABLE $tableName ($threadId INTEGER PRIMARY KEY, $friendRequestStatus INTEGER DEFAULT 0);"
|
||||
}
|
||||
|
||||
fun getFriendRequestStatus(threadId: Long): Int {
|
||||
fun getFriendRequestStatus(threadId: Long): LokiFriendRequestStatus {
|
||||
val db = databaseHelper.readableDatabase
|
||||
return db.get(tableName, ID_WHERE, arrayOf(threadId.toString())) { cursor ->
|
||||
val result = db.get(tableName, ID_WHERE, arrayOf( threadId.toString() )) { cursor ->
|
||||
cursor.getInt(friendRequestStatus)
|
||||
} ?: LokiFriendRequestStatus.NONE
|
||||
}
|
||||
return if (result != null) {
|
||||
LokiFriendRequestStatus.values().first { it.rawValue == result }
|
||||
} else {
|
||||
LokiFriendRequestStatus.NONE
|
||||
}
|
||||
}
|
||||
|
||||
fun setFriendRequestStatus(threadId: Long, status: Int) {
|
||||
fun setFriendRequestStatus(threadId: Long, status: LokiFriendRequestStatus) {
|
||||
val database = databaseHelper.writableDatabase
|
||||
val contentValues = ContentValues(1)
|
||||
contentValues.put(Companion.threadId, threadId)
|
||||
contentValues.put(friendRequestStatus, status)
|
||||
|
||||
database.insertOrUpdate(tableName, contentValues, ID_WHERE, arrayOf(threadId.toString()))
|
||||
contentValues.put(friendRequestStatus, status.rawValue)
|
||||
database.insertOrUpdate(tableName, contentValues, ID_WHERE, arrayOf( threadId.toString() ))
|
||||
notifyConversationListListeners()
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user