Added database to map thread to loki friend request
parent
d7bb828d67
commit
d44081d040
@ -0,0 +1,17 @@
|
||||
package org.thoughtcrime.securesms.loki;
|
||||
|
||||
public class LokiFriendRequestStatus {
|
||||
// New conversation; no messages sent or received.
|
||||
public static final int NONE = 0;
|
||||
// This state is used to lock the input early while sending.
|
||||
public static final int REQUEST_SENDING = 1;
|
||||
// Friend request sent; awaiting response.
|
||||
public static final int REQUEST_SENT = 2;
|
||||
// Friend request received; awaiting user input.
|
||||
public static final int REQUEST_RECEIVED = 3;
|
||||
// We are friends with the user in this thread.
|
||||
public static final int 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;
|
||||
}
|
||||
|
@ -0,0 +1,38 @@
|
||||
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
|
||||
|
||||
/**
|
||||
* A database for associating friend request data to Threads
|
||||
*/
|
||||
class LokiThreadFriendRequestDatabase(context: Context, helper: SQLCipherOpenHelper) : Database(context, helper) {
|
||||
|
||||
companion object {
|
||||
private val tableName = "loki_thread_friend_request_database"
|
||||
private val threadId = "_id"
|
||||
private val friendRequestStatus = "friend_request_status"
|
||||
|
||||
@JvmStatic
|
||||
val createTableCommand = "CREATE TABLE $tableName ($threadId INTEGER PRIMARY KEY, $friendRequestStatus INTEGER DEFAULT 0);"
|
||||
}
|
||||
|
||||
fun getFriendRequestStatus(threadId: Long): Int {
|
||||
val db = databaseHelper.readableDatabase
|
||||
return db.get(tableName, ID_WHERE, arrayOf(threadId.toString())) { cursor ->
|
||||
cursor.getInt(friendRequestStatus)
|
||||
} ?: LokiFriendRequestStatus.NONE
|
||||
}
|
||||
|
||||
fun setFriendRequestStatus(threadId: Long, status: Int) {
|
||||
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()))
|
||||
notifyConversationListListeners()
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue