mirror of
https://github.com/oxen-io/session-android.git
synced 2024-11-24 02:25:19 +00:00
Update for core changes & refactor
This commit is contained in:
parent
d99a996d0e
commit
b58fce3a68
@ -143,16 +143,15 @@ import org.thoughtcrime.securesms.database.model.MessageRecord;
|
||||
import org.thoughtcrime.securesms.database.model.MmsMessageRecord;
|
||||
import org.thoughtcrime.securesms.events.ReminderUpdateEvent;
|
||||
import org.thoughtcrime.securesms.giph.ui.GiphyActivity;
|
||||
import org.thoughtcrime.securesms.linkpreview.LinkPreview;
|
||||
import org.thoughtcrime.securesms.linkpreview.LinkPreviewRepository;
|
||||
import org.thoughtcrime.securesms.linkpreview.LinkPreviewViewModel;
|
||||
import org.thoughtcrime.securesms.loki.LokiThreadFriendRequestStatus;
|
||||
import org.thoughtcrime.securesms.mediasend.MediaSendActivity;
|
||||
import org.thoughtcrime.securesms.mediasend.Media;
|
||||
import org.thoughtcrime.securesms.jobs.MultiDeviceBlockedUpdateJob;
|
||||
import org.thoughtcrime.securesms.jobs.RetrieveProfileJob;
|
||||
import org.thoughtcrime.securesms.jobs.ServiceOutageDetectionJob;
|
||||
import org.thoughtcrime.securesms.linkpreview.LinkPreview;
|
||||
import org.thoughtcrime.securesms.linkpreview.LinkPreviewRepository;
|
||||
import org.thoughtcrime.securesms.linkpreview.LinkPreviewViewModel;
|
||||
import org.thoughtcrime.securesms.logging.Log;
|
||||
import org.thoughtcrime.securesms.mediasend.Media;
|
||||
import org.thoughtcrime.securesms.mediasend.MediaSendActivity;
|
||||
import org.thoughtcrime.securesms.mms.AttachmentManager;
|
||||
import org.thoughtcrime.securesms.mms.AttachmentManager.MediaType;
|
||||
import org.thoughtcrime.securesms.mms.AudioSlide;
|
||||
@ -179,9 +178,9 @@ import org.thoughtcrime.securesms.permissions.Permissions;
|
||||
import org.thoughtcrime.securesms.profiles.GroupShareProfileView;
|
||||
import org.thoughtcrime.securesms.providers.BlobProvider;
|
||||
import org.thoughtcrime.securesms.recipients.Recipient;
|
||||
import org.thoughtcrime.securesms.recipients.RecipientExporter;
|
||||
import org.thoughtcrime.securesms.recipients.RecipientFormattingException;
|
||||
import org.thoughtcrime.securesms.recipients.RecipientModifiedListener;
|
||||
import org.thoughtcrime.securesms.recipients.RecipientExporter;
|
||||
import org.thoughtcrime.securesms.search.model.MessageResult;
|
||||
import org.thoughtcrime.securesms.service.KeyCachingService;
|
||||
import org.thoughtcrime.securesms.sms.MessageSender;
|
||||
@ -209,6 +208,7 @@ import org.thoughtcrime.securesms.util.concurrent.SettableFuture;
|
||||
import org.thoughtcrime.securesms.util.views.Stub;
|
||||
import org.whispersystems.libsignal.InvalidMessageException;
|
||||
import org.whispersystems.libsignal.util.guava.Optional;
|
||||
import org.whispersystems.signalservice.loki.messaging.LokiThreadFriendRequestStatus;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.security.SecureRandom;
|
||||
@ -2155,7 +2155,7 @@ public class ConversationActivity extends PassphraseRequiredActionBarActivity
|
||||
}
|
||||
|
||||
// Loki - Always send friend requests if we're not friends with the user
|
||||
LokiThreadFriendRequestStatus friendRequestStatus = DatabaseFactory.getLokiThreadFriendRequestDatabase(context).friendRequestStatus(threadId);
|
||||
LokiThreadFriendRequestStatus friendRequestStatus = DatabaseFactory.getLokiThreadFriendRequestDatabase(context).getFriendRequestStatus(threadId);
|
||||
message.isFriendRequest = (friendRequestStatus != LokiThreadFriendRequestStatus.FRIENDS);
|
||||
|
||||
Permissions.with(this)
|
||||
|
@ -32,7 +32,7 @@ import org.thoughtcrime.securesms.database.helpers.ClassicOpenHelper;
|
||||
import org.thoughtcrime.securesms.database.helpers.SQLCipherMigrationHelper;
|
||||
import org.thoughtcrime.securesms.database.helpers.SQLCipherOpenHelper;
|
||||
import org.thoughtcrime.securesms.loki.LokiAPIDatabase;
|
||||
import org.thoughtcrime.securesms.loki.LokiContactPreKeyDatabase;
|
||||
import org.thoughtcrime.securesms.loki.LokiPreKeyRecordDatabase;
|
||||
import org.thoughtcrime.securesms.loki.LokiPreKeyBundleDatabase;
|
||||
import org.thoughtcrime.securesms.loki.LokiMessageFriendRequestDatabase;
|
||||
import org.thoughtcrime.securesms.loki.LokiThreadFriendRequestDatabase;
|
||||
@ -66,7 +66,7 @@ public class DatabaseFactory {
|
||||
|
||||
// Loki
|
||||
private final LokiAPIDatabase lokiAPIDatabase;
|
||||
private final LokiContactPreKeyDatabase lokiContactPreKeyDatabase;
|
||||
private final LokiPreKeyRecordDatabase lokiContactPreKeyDatabase;
|
||||
private final LokiPreKeyBundleDatabase lokiPreKeyBundleDatabase;
|
||||
private final LokiMessageFriendRequestDatabase lokiMessageFriendRequestDatabase;
|
||||
private final LokiThreadFriendRequestDatabase lokiThreadFriendRequestDatabase;
|
||||
@ -161,7 +161,7 @@ public class DatabaseFactory {
|
||||
return getInstance(context).lokiAPIDatabase;
|
||||
}
|
||||
|
||||
public static LokiContactPreKeyDatabase getLokiContactPreKeyDatabase(Context context) {
|
||||
public static LokiPreKeyRecordDatabase getLokiPreKeyRecordDatabase(Context context) {
|
||||
return getInstance(context).lokiContactPreKeyDatabase;
|
||||
}
|
||||
|
||||
@ -210,7 +210,7 @@ public class DatabaseFactory {
|
||||
this.jobDatabase = new JobDatabase(context, databaseHelper);
|
||||
|
||||
this.lokiAPIDatabase = new LokiAPIDatabase(context, databaseHelper);
|
||||
this.lokiContactPreKeyDatabase = new LokiContactPreKeyDatabase(context, databaseHelper);
|
||||
this.lokiContactPreKeyDatabase = new LokiPreKeyRecordDatabase(context, databaseHelper);
|
||||
this.lokiPreKeyBundleDatabase = new LokiPreKeyBundleDatabase(context, databaseHelper);
|
||||
this.lokiMessageFriendRequestDatabase = new LokiMessageFriendRequestDatabase(context, databaseHelper);
|
||||
this.lokiThreadFriendRequestDatabase = new LokiThreadFriendRequestDatabase(context, databaseHelper);
|
||||
|
@ -37,7 +37,6 @@ import org.thoughtcrime.securesms.database.model.MessageRecord;
|
||||
import org.thoughtcrime.securesms.database.model.SmsMessageRecord;
|
||||
import org.thoughtcrime.securesms.jobs.TrimThreadJob;
|
||||
import org.thoughtcrime.securesms.logging.Log;
|
||||
import org.thoughtcrime.securesms.loki.LokiMessageFriendRequestStatus;
|
||||
import org.thoughtcrime.securesms.recipients.Recipient;
|
||||
import org.thoughtcrime.securesms.sms.IncomingGroupMessage;
|
||||
import org.thoughtcrime.securesms.sms.IncomingTextMessage;
|
||||
@ -45,6 +44,7 @@ import org.thoughtcrime.securesms.sms.OutgoingTextMessage;
|
||||
import org.thoughtcrime.securesms.util.JsonUtils;
|
||||
import org.thoughtcrime.securesms.util.TextSecurePreferences;
|
||||
import org.whispersystems.libsignal.util.guava.Optional;
|
||||
import org.whispersystems.signalservice.loki.messaging.LokiMessageFriendRequestStatus;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.security.SecureRandom;
|
||||
|
@ -35,7 +35,7 @@ import org.thoughtcrime.securesms.database.ThreadDatabase;
|
||||
import org.thoughtcrime.securesms.jobs.RefreshPreKeysJob;
|
||||
import org.thoughtcrime.securesms.logging.Log;
|
||||
import org.thoughtcrime.securesms.loki.LokiAPIDatabase;
|
||||
import org.thoughtcrime.securesms.loki.LokiContactPreKeyDatabase;
|
||||
import org.thoughtcrime.securesms.loki.LokiPreKeyRecordDatabase;
|
||||
import org.thoughtcrime.securesms.loki.LokiMessageFriendRequestDatabase;
|
||||
import org.thoughtcrime.securesms.loki.LokiPreKeyBundleDatabase;
|
||||
import org.thoughtcrime.securesms.loki.LokiThreadFriendRequestDatabase;
|
||||
@ -120,7 +120,7 @@ public class SQLCipherOpenHelper extends SQLiteOpenHelper {
|
||||
db.execSQL(LokiAPIDatabase.getCreateLastMessageHashValueTableCommand());
|
||||
db.execSQL(LokiAPIDatabase.getCreateReceivedMessageHashValuesTableCommand());
|
||||
db.execSQL(LokiPreKeyBundleDatabase.getCreateTableCommand());
|
||||
db.execSQL(LokiContactPreKeyDatabase.getCreateTableCommand());
|
||||
db.execSQL(LokiPreKeyRecordDatabase.getCreateTableCommand());
|
||||
db.execSQL(LokiMessageFriendRequestDatabase.getCreateTableCommand());
|
||||
db.execSQL(LokiThreadFriendRequestDatabase.getCreateTableCommand());
|
||||
|
||||
|
@ -2,33 +2,28 @@ package org.thoughtcrime.securesms.dependencies;
|
||||
|
||||
import android.content.Context;
|
||||
|
||||
import org.thoughtcrime.securesms.database.DatabaseFactory;
|
||||
import org.thoughtcrime.securesms.gcm.FcmService;
|
||||
import org.thoughtcrime.securesms.jobs.AttachmentUploadJob;
|
||||
import org.thoughtcrime.securesms.jobs.MultiDeviceConfigurationUpdateJob;
|
||||
import org.thoughtcrime.securesms.jobs.PushDecryptJob;
|
||||
import org.thoughtcrime.securesms.jobs.RefreshUnidentifiedDeliveryAbilityJob;
|
||||
import org.thoughtcrime.securesms.jobs.RotateProfileKeyJob;
|
||||
import org.thoughtcrime.securesms.jobs.TypingSendJob;
|
||||
import org.thoughtcrime.securesms.logging.Log;
|
||||
|
||||
import org.greenrobot.eventbus.EventBus;
|
||||
import org.thoughtcrime.securesms.BuildConfig;
|
||||
import org.thoughtcrime.securesms.CreateProfileActivity;
|
||||
import org.thoughtcrime.securesms.DeviceListFragment;
|
||||
import org.thoughtcrime.securesms.crypto.storage.SignalProtocolStoreImpl;
|
||||
import org.thoughtcrime.securesms.database.DatabaseFactory;
|
||||
import org.thoughtcrime.securesms.events.ReminderUpdateEvent;
|
||||
import org.thoughtcrime.securesms.gcm.FcmService;
|
||||
import org.thoughtcrime.securesms.jobs.AttachmentDownloadJob;
|
||||
import org.thoughtcrime.securesms.jobs.AttachmentUploadJob;
|
||||
import org.thoughtcrime.securesms.jobs.AvatarDownloadJob;
|
||||
import org.thoughtcrime.securesms.jobs.CleanPreKeysJob;
|
||||
import org.thoughtcrime.securesms.jobs.CreateSignedPreKeyJob;
|
||||
import org.thoughtcrime.securesms.jobs.FcmRefreshJob;
|
||||
import org.thoughtcrime.securesms.jobs.MultiDeviceBlockedUpdateJob;
|
||||
import org.thoughtcrime.securesms.jobs.MultiDeviceConfigurationUpdateJob;
|
||||
import org.thoughtcrime.securesms.jobs.MultiDeviceContactUpdateJob;
|
||||
import org.thoughtcrime.securesms.jobs.MultiDeviceGroupUpdateJob;
|
||||
import org.thoughtcrime.securesms.jobs.MultiDeviceProfileKeyUpdateJob;
|
||||
import org.thoughtcrime.securesms.jobs.MultiDeviceReadUpdateJob;
|
||||
import org.thoughtcrime.securesms.jobs.MultiDeviceVerifiedUpdateJob;
|
||||
import org.thoughtcrime.securesms.jobs.PushDecryptJob;
|
||||
import org.thoughtcrime.securesms.jobs.PushGroupSendJob;
|
||||
import org.thoughtcrime.securesms.jobs.PushGroupUpdateJob;
|
||||
import org.thoughtcrime.securesms.jobs.PushMediaSendJob;
|
||||
@ -36,14 +31,18 @@ import org.thoughtcrime.securesms.jobs.PushNotificationReceiveJob;
|
||||
import org.thoughtcrime.securesms.jobs.PushTextSendJob;
|
||||
import org.thoughtcrime.securesms.jobs.RefreshAttributesJob;
|
||||
import org.thoughtcrime.securesms.jobs.RefreshPreKeysJob;
|
||||
import org.thoughtcrime.securesms.jobs.RefreshUnidentifiedDeliveryAbilityJob;
|
||||
import org.thoughtcrime.securesms.jobs.RequestGroupInfoJob;
|
||||
import org.thoughtcrime.securesms.jobs.RetrieveProfileAvatarJob;
|
||||
import org.thoughtcrime.securesms.jobs.RetrieveProfileJob;
|
||||
import org.thoughtcrime.securesms.jobs.RotateCertificateJob;
|
||||
import org.thoughtcrime.securesms.jobs.RotateProfileKeyJob;
|
||||
import org.thoughtcrime.securesms.jobs.RotateSignedPreKeyJob;
|
||||
import org.thoughtcrime.securesms.jobs.SendDeliveryReceiptJob;
|
||||
import org.thoughtcrime.securesms.jobs.SendReadReceiptJob;
|
||||
import org.thoughtcrime.securesms.loki.LokiPreKeyBundleStore;
|
||||
import org.thoughtcrime.securesms.jobs.TypingSendJob;
|
||||
import org.thoughtcrime.securesms.logging.Log;
|
||||
import org.thoughtcrime.securesms.loki.LokiPreKeyBundleDatabase;
|
||||
import org.thoughtcrime.securesms.preferences.AppProtectionPreferenceFragment;
|
||||
import org.thoughtcrime.securesms.push.SecurityEventListener;
|
||||
import org.thoughtcrime.securesms.push.SignalServiceNetworkAccess;
|
||||
@ -140,7 +139,9 @@ public class SignalCommunicationModule {
|
||||
Optional.of(new SecurityEventListener(context)),
|
||||
TextSecurePreferences.getLocalNumber(context),
|
||||
DatabaseFactory.getLokiAPIDatabase(context),
|
||||
new LokiPreKeyBundleStore(context));
|
||||
DatabaseFactory.getLokiThreadFriendRequestDatabase(context),
|
||||
DatabaseFactory.getLokiMessageFriendRequestDatabase(context),
|
||||
DatabaseFactory.getLokiPreKeyBundleDatabase(context));
|
||||
} else {
|
||||
this.messageSender.setMessagePipe(IncomingMessageObserver.getPipe(), IncomingMessageObserver.getUnidentifiedPipe());
|
||||
this.messageSender.setIsMultiDevice(TextSecurePreferences.isMultiDevice(context));
|
||||
|
@ -62,7 +62,6 @@ import org.thoughtcrime.securesms.linkpreview.Link;
|
||||
import org.thoughtcrime.securesms.linkpreview.LinkPreview;
|
||||
import org.thoughtcrime.securesms.linkpreview.LinkPreviewUtil;
|
||||
import org.thoughtcrime.securesms.logging.Log;
|
||||
import org.thoughtcrime.securesms.loki.LokiThreadFriendRequestStatus;
|
||||
import org.thoughtcrime.securesms.loki.LokiPreKeyBundleDatabase;
|
||||
import org.thoughtcrime.securesms.loki.LokiThreadFriendRequestDatabase;
|
||||
import org.thoughtcrime.securesms.mms.IncomingMediaMessage;
|
||||
@ -113,6 +112,7 @@ import org.whispersystems.signalservice.api.messages.shared.SharedContact;
|
||||
import org.whispersystems.signalservice.api.push.SignalServiceAddress;
|
||||
import org.whispersystems.signalservice.loki.crypto.LokiServiceCipher;
|
||||
import org.whispersystems.signalservice.loki.messaging.LokiServiceMessage;
|
||||
import org.whispersystems.signalservice.loki.messaging.LokiThreadFriendRequestStatus;
|
||||
|
||||
import java.security.MessageDigest;
|
||||
import java.util.ArrayList;
|
||||
@ -827,7 +827,7 @@ public class PushDecryptJob extends BaseJob implements InjectableType {
|
||||
Recipient recipient = getMessageDestination(content, message);
|
||||
long threadID = DatabaseFactory.getThreadDatabase(context).getThreadIdIfExistsFor(recipient);
|
||||
LokiThreadFriendRequestDatabase database = DatabaseFactory.getLokiThreadFriendRequestDatabase(context);
|
||||
LokiThreadFriendRequestStatus friendRequestStatus = database.friendRequestStatus(threadID);
|
||||
LokiThreadFriendRequestStatus friendRequestStatus = database.getFriendRequestStatus(threadID);
|
||||
if (envelope.isFriendRequest()) {
|
||||
if (friendRequestStatus == LokiThreadFriendRequestStatus.REQUEST_SENT) {
|
||||
// This can happen if Alice sent Bob a friend request, Bob declined, but then Bob changed his
|
||||
|
@ -9,7 +9,6 @@ import org.thoughtcrime.securesms.R
|
||||
import org.thoughtcrime.securesms.util.TextSecurePreferences
|
||||
import org.whispersystems.signalservice.api.crypto.ProfileCipher
|
||||
|
||||
|
||||
class AccountDetailsActivity : BaseActionBarActivity() {
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
|
@ -3,7 +3,7 @@ package org.thoughtcrime.securesms.loki
|
||||
import android.content.ContentValues
|
||||
import net.sqlcipher.Cursor
|
||||
import net.sqlcipher.database.SQLiteDatabase
|
||||
import org.thoughtcrime.securesms.util.Base64
|
||||
import org.whispersystems.signalservice.internal.util.Base64
|
||||
|
||||
fun <T> SQLiteDatabase.get(table: String, query: String, arguments: Array<String>, get: (Cursor) -> T): T? {
|
||||
var cursor: Cursor? = null
|
||||
@ -18,10 +18,10 @@ fun <T> SQLiteDatabase.get(table: String, query: String, arguments: Array<String
|
||||
return null
|
||||
}
|
||||
|
||||
fun SQLiteDatabase.insertOrUpdate(table: String, values: ContentValues, whereClause: String, whereArgs: Array<String>) {
|
||||
fun SQLiteDatabase.insertOrUpdate(table: String, values: ContentValues, query: String, arguments: Array<String>) {
|
||||
val id = insertWithOnConflict(table, null, values, SQLiteDatabase.CONFLICT_IGNORE).toInt()
|
||||
if (id == -1) {
|
||||
update(table, values, whereClause, whereArgs)
|
||||
update(table, values, query, arguments)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -11,6 +11,7 @@ import org.thoughtcrime.securesms.R
|
||||
import org.thoughtcrime.securesms.database.DatabaseFactory
|
||||
import org.thoughtcrime.securesms.sms.IncomingTextMessage
|
||||
import org.thoughtcrime.securesms.sms.OutgoingTextMessage
|
||||
import org.whispersystems.signalservice.loki.messaging.LokiMessageFriendRequestStatus
|
||||
|
||||
class FriendRequestView(context: Context, attrs: AttributeSet?, defStyleAttr: Int) : LinearLayout(context, attrs, defStyleAttr) {
|
||||
private var isUISetUp = false
|
||||
@ -89,7 +90,7 @@ class FriendRequestView(context: Context, attrs: AttributeSet?, defStyleAttr: In
|
||||
val database = DatabaseFactory.getLokiMessageFriendRequestDatabase(context)
|
||||
if (message is IncomingTextMessage) {
|
||||
val message = this.message as IncomingTextMessage
|
||||
val friendRequestStatus = database.friendRequestStatus(0) // TODO: Message ID
|
||||
val friendRequestStatus = database.getFriendRequestStatus(0) // TODO: Message ID
|
||||
buttonLinearLayout.visibility = if (friendRequestStatus != LokiMessageFriendRequestStatus.REQUEST_PENDING) View.GONE else View.VISIBLE
|
||||
val formatID = when (friendRequestStatus) {
|
||||
LokiMessageFriendRequestStatus.NONE, LokiMessageFriendRequestStatus.REQUEST_SENDING_OR_FAILED -> throw IllegalStateException()
|
||||
@ -102,7 +103,7 @@ class FriendRequestView(context: Context, attrs: AttributeSet?, defStyleAttr: In
|
||||
label.text = resources.getString(formatID, contactID)
|
||||
} else {
|
||||
val message = this.message as OutgoingTextMessage
|
||||
val friendRequestStatus = database.friendRequestStatus(0) // TODO: Message ID
|
||||
val friendRequestStatus = database.getFriendRequestStatus(0) // TODO: Message ID
|
||||
buttonLinearLayout.visibility = View.GONE
|
||||
val formatID = when (friendRequestStatus) {
|
||||
LokiMessageFriendRequestStatus.NONE -> throw IllegalStateException()
|
||||
|
@ -3,9 +3,12 @@ package org.thoughtcrime.securesms.loki
|
||||
import android.content.ContentValues
|
||||
import android.content.Context
|
||||
import org.thoughtcrime.securesms.database.Database
|
||||
import org.thoughtcrime.securesms.database.DatabaseFactory
|
||||
import org.thoughtcrime.securesms.database.helpers.SQLCipherOpenHelper
|
||||
import org.whispersystems.signalservice.loki.messaging.LokiMessageDatabaseProtocol
|
||||
import org.whispersystems.signalservice.loki.messaging.LokiMessageFriendRequestStatus
|
||||
|
||||
class LokiMessageFriendRequestDatabase(context: Context, helper: SQLCipherOpenHelper) : Database(context, helper) {
|
||||
class LokiMessageFriendRequestDatabase(context: Context, helper: SQLCipherOpenHelper) : Database(context, helper), LokiMessageDatabaseProtocol {
|
||||
|
||||
companion object {
|
||||
private val tableName = "loki_message_friend_request_database"
|
||||
@ -14,7 +17,7 @@ class LokiMessageFriendRequestDatabase(context: Context, helper: SQLCipherOpenHe
|
||||
@JvmStatic val createTableCommand = "CREATE TABLE $tableName ($messageID INTEGER PRIMARY KEY, $friendRequestStatus INTEGER DEFAULT 0);"
|
||||
}
|
||||
|
||||
fun friendRequestStatus(messageID: Long): LokiMessageFriendRequestStatus {
|
||||
override fun getFriendRequestStatus(messageID: Long): LokiMessageFriendRequestStatus {
|
||||
val database = databaseHelper.readableDatabase
|
||||
val result = database.get(tableName, "${Companion.messageID} = ?", arrayOf( messageID.toString() )) { cursor ->
|
||||
cursor.getInt(friendRequestStatus)
|
||||
@ -26,19 +29,21 @@ class LokiMessageFriendRequestDatabase(context: Context, helper: SQLCipherOpenHe
|
||||
}
|
||||
}
|
||||
|
||||
fun setFriendRequestStatus(messageID: Long, friendRequestStatus: LokiMessageFriendRequestStatus) {
|
||||
override fun setFriendRequestStatus(messageID: Long, friendRequestStatus: LokiMessageFriendRequestStatus) {
|
||||
val database = databaseHelper.writableDatabase
|
||||
val contentValues = ContentValues(2)
|
||||
contentValues.put(Companion.messageID, messageID)
|
||||
contentValues.put(Companion.friendRequestStatus, friendRequestStatus.rawValue)
|
||||
database.insertOrUpdate(tableName, contentValues, "${Companion.messageID} = ?", arrayOf( messageID.toString() ))
|
||||
val threadID = DatabaseFactory.getSmsDatabase(context).getThreadIdForMessage(messageID)
|
||||
notifyConversationListeners(threadID)
|
||||
}
|
||||
|
||||
fun isFriendRequest(messageID: Long): Boolean {
|
||||
return friendRequestStatus(messageID) != LokiMessageFriendRequestStatus.NONE
|
||||
return getFriendRequestStatus(messageID) != LokiMessageFriendRequestStatus.NONE
|
||||
}
|
||||
|
||||
fun hasFriendRequestStatusMessage(messageID: Long): Boolean {
|
||||
return isFriendRequest(messageID) && friendRequestStatus(messageID) != LokiMessageFriendRequestStatus.REQUEST_SENDING_OR_FAILED
|
||||
return isFriendRequest(messageID) && getFriendRequestStatus(messageID) != LokiMessageFriendRequestStatus.REQUEST_SENDING_OR_FAILED
|
||||
}
|
||||
}
|
@ -1,13 +0,0 @@
|
||||
package org.thoughtcrime.securesms.loki
|
||||
|
||||
enum class LokiMessageFriendRequestStatus(val rawValue: Int) {
|
||||
NONE(0),
|
||||
REQUEST_SENDING_OR_FAILED(1),
|
||||
/**
|
||||
* Either sent or received.
|
||||
*/
|
||||
REQUEST_PENDING(2),
|
||||
REQUEST_ACCEPTED(3),
|
||||
REQUEST_REJECTED(4),
|
||||
REQUEST_EXPIRED(5)
|
||||
}
|
@ -14,8 +14,9 @@ import org.whispersystems.libsignal.IdentityKey
|
||||
import org.whispersystems.libsignal.ecc.Curve
|
||||
import org.whispersystems.libsignal.state.PreKeyBundle
|
||||
import org.whispersystems.signalservice.api.push.SignalServiceAddress
|
||||
import org.whispersystems.signalservice.loki.messaging.LokiPreKeyDatabaseProtocol
|
||||
|
||||
class LokiPreKeyBundleDatabase(context: Context, helper: SQLCipherOpenHelper) : Database(context, helper) {
|
||||
class LokiPreKeyBundleDatabase(context: Context, helper: SQLCipherOpenHelper) : Database(context, helper), LokiPreKeyDatabaseProtocol {
|
||||
|
||||
companion object {
|
||||
private val tableName = "loki_pre_key_bundle_database"
|
||||
@ -33,30 +34,17 @@ class LokiPreKeyBundleDatabase(context: Context, helper: SQLCipherOpenHelper) :
|
||||
"$signedPreKeySignature TEXT," + "$identityKey TEXT NOT NULL," + "$deviceID INTEGER," + "$registrationID INTEGER" + ");"
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate a `PreKeyBundle` for the given contact.
|
||||
* This generated bundle shouldn't be stored locally since this is used to generate bundles to send to other users.
|
||||
*
|
||||
* @param hexEncodedPublicKey String The hex encoded public key of the contact.
|
||||
* @return PreKeyBundle? A pre key bundle or `null` if something went wrong.
|
||||
*/
|
||||
fun generatePreKeyBundle(hexEncodedPublicKey: String): PreKeyBundle? {
|
||||
val identityKeyPair = IdentityKeyUtil.getIdentityKeyPair(context)
|
||||
val signedPreKey = PreKeyUtil.getActiveSignedPreKey(context) ?: return null
|
||||
val preKeyRecord = DatabaseFactory.getLokiContactPreKeyDatabase(context).getOrCreatePreKey(hexEncodedPublicKey)
|
||||
val preKeyRecord = DatabaseFactory.getLokiPreKeyRecordDatabase(context).getOrCreatePreKey(hexEncodedPublicKey)
|
||||
val registrationID = TextSecurePreferences.getLocalRegistrationId(context)
|
||||
if (registrationID == 0) return null
|
||||
val deviceID = SignalServiceAddress.DEFAULT_DEVICE_ID
|
||||
return PreKeyBundle(registrationID, deviceID,preKeyRecord.id, preKeyRecord.keyPair.publicKey, signedPreKey.id, signedPreKey.keyPair.publicKey, signedPreKey.signature, identityKeyPair.publicKey)
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the `PreKeyBundle` associated with the given contact.
|
||||
*
|
||||
* @param hexEncodedPublicKey String The hex encoded public key of the contact.
|
||||
* @return PreKeyBundle? The pre key bundle or `null` if it doesn't exist.
|
||||
*/
|
||||
fun getPreKeyBundle(hexEncodedPublicKey: String): PreKeyBundle? {
|
||||
override fun getPreKeyBundle(hexEncodedPublicKey: String): PreKeyBundle? {
|
||||
val database = databaseHelper.readableDatabase
|
||||
return database.get(tableName, "${Companion.hexEncodedPublicKey} = ?", arrayOf( hexEncodedPublicKey )) { cursor ->
|
||||
val registrationID = cursor.getInt(registrationID)
|
||||
@ -71,15 +59,9 @@ class LokiPreKeyBundleDatabase(context: Context, helper: SQLCipherOpenHelper) :
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the `PreKeyBundle` for the given contact.
|
||||
*
|
||||
* @param hexEncodedPublicKey String The hex encoded public key of the contact.
|
||||
* @param preKeyBundle PreKeyBundle The pre key bundle.
|
||||
*/
|
||||
fun setPreKeyBundle(hexEncodedPublicKey: String, preKeyBundle: PreKeyBundle) {
|
||||
val database = databaseHelper.writableDatabase
|
||||
val contentValues = ContentValues()
|
||||
val contentValues = ContentValues(9)
|
||||
contentValues.put(registrationID, preKeyBundle.registrationId)
|
||||
contentValues.put(deviceID, preKeyBundle.deviceId)
|
||||
contentValues.put(preKeyID, preKeyBundle.preKeyId)
|
||||
@ -92,12 +74,7 @@ class LokiPreKeyBundleDatabase(context: Context, helper: SQLCipherOpenHelper) :
|
||||
database.insertWithOnConflict(tableName, null, contentValues, SQLiteDatabase.CONFLICT_REPLACE)
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove the `PreKeyBundle` for the given contact.
|
||||
*
|
||||
* @param hexEncodedPublicKey String The hex encoded public key of the contact.
|
||||
*/
|
||||
fun removePreKeyBundle(hexEncodedPublicKey: String) {
|
||||
override fun removePreKeyBundle(hexEncodedPublicKey: String) {
|
||||
val database = databaseHelper.writableDatabase
|
||||
database.delete(tableName, "${Companion.hexEncodedPublicKey} = ?", arrayOf( hexEncodedPublicKey ))
|
||||
}
|
||||
|
@ -1,25 +0,0 @@
|
||||
package org.thoughtcrime.securesms.loki
|
||||
|
||||
import android.content.Context
|
||||
import org.thoughtcrime.securesms.database.DatabaseFactory
|
||||
import org.whispersystems.libsignal.state.PreKeyBundle
|
||||
import org.whispersystems.signalservice.loki.messaging.LokiPreKeyBundleStoreProtocol
|
||||
|
||||
class LokiPreKeyBundleStore(val context: Context) : LokiPreKeyBundleStoreProtocol {
|
||||
|
||||
companion object {
|
||||
private val lock = Object()
|
||||
}
|
||||
|
||||
override fun getPreKeyBundle(hexEncodedPublicKey: String): PreKeyBundle? {
|
||||
synchronized(lock) {
|
||||
return DatabaseFactory.getLokiPreKeyBundleDatabase(context).getPreKeyBundle(hexEncodedPublicKey)
|
||||
}
|
||||
}
|
||||
|
||||
override fun removePreKeyBundle(hexEncodedPublicKey: String) {
|
||||
synchronized(lock) {
|
||||
DatabaseFactory.getLokiPreKeyBundleDatabase(context).removePreKeyBundle(hexEncodedPublicKey)
|
||||
}
|
||||
}
|
||||
}
|
@ -8,10 +8,10 @@ import org.thoughtcrime.securesms.database.Database
|
||||
import org.thoughtcrime.securesms.database.helpers.SQLCipherOpenHelper
|
||||
import org.whispersystems.libsignal.state.PreKeyRecord
|
||||
|
||||
class LokiContactPreKeyDatabase(context: Context, helper: SQLCipherOpenHelper) : Database(context, helper) {
|
||||
class LokiPreKeyRecordDatabase(context: Context, helper: SQLCipherOpenHelper) : Database(context, helper) {
|
||||
|
||||
companion object {
|
||||
private val tableName = "loki_contact_pre_key_database"
|
||||
private val tableName = "loki_pre_key_record_database"
|
||||
private val preKeyID = "pre_key_id"
|
||||
private val hexEncodedPublicKey = "public_key"
|
||||
@JvmStatic val createTableCommand = "CREATE TABLE $tableName ($preKeyID INTEGER PRIMARY KEY, $hexEncodedPublicKey TEXT);"
|
||||
@ -19,14 +19,12 @@ class LokiContactPreKeyDatabase(context: Context, helper: SQLCipherOpenHelper) :
|
||||
|
||||
fun hasPreKey(hexEncodedPublicKey: String): Boolean {
|
||||
val database = databaseHelper.readableDatabase
|
||||
return database.get(tableName, "${Companion.hexEncodedPublicKey} = ?", arrayOf(hexEncodedPublicKey)) { cursor ->
|
||||
cursor.count > 0
|
||||
} ?: false
|
||||
return database.get(tableName, "${Companion.hexEncodedPublicKey} = ?", arrayOf( hexEncodedPublicKey )) { it.count > 0 } ?: false
|
||||
}
|
||||
|
||||
fun getPreKey(hexEncodedPublicKey: String): PreKeyRecord? {
|
||||
val database = databaseHelper.readableDatabase
|
||||
return database.get(tableName, "${Companion.hexEncodedPublicKey} = ?", arrayOf(hexEncodedPublicKey)) { cursor ->
|
||||
return database.get(tableName, "${Companion.hexEncodedPublicKey} = ?", arrayOf( hexEncodedPublicKey )) { cursor ->
|
||||
val preKeyID = cursor.getInt(preKeyID)
|
||||
PreKeyUtil.loadPreKey(context, preKeyID)
|
||||
}
|
||||
@ -41,7 +39,7 @@ class LokiContactPreKeyDatabase(context: Context, helper: SQLCipherOpenHelper) :
|
||||
PreKeyUtil.storePreKeyRecords(context, preKeyRecords)
|
||||
val record = preKeyRecords.first()
|
||||
val database = databaseHelper.writableDatabase
|
||||
val values = ContentValues()
|
||||
val values = ContentValues(2)
|
||||
values.put(Companion.hexEncodedPublicKey, hexEncodedPublicKey)
|
||||
values.put(preKeyID, record.id)
|
||||
database.insertWithOnConflict(tableName, null, values, SQLiteDatabase.CONFLICT_REPLACE)
|
@ -3,9 +3,12 @@ package org.thoughtcrime.securesms.loki
|
||||
import android.content.ContentValues
|
||||
import android.content.Context
|
||||
import org.thoughtcrime.securesms.database.Database
|
||||
import org.thoughtcrime.securesms.database.DatabaseFactory
|
||||
import org.thoughtcrime.securesms.database.helpers.SQLCipherOpenHelper
|
||||
import org.whispersystems.signalservice.loki.messaging.LokiThreadDatabaseProtocol
|
||||
import org.whispersystems.signalservice.loki.messaging.LokiThreadFriendRequestStatus
|
||||
|
||||
class LokiThreadFriendRequestDatabase(context: Context, helper: SQLCipherOpenHelper) : Database(context, helper) {
|
||||
class LokiThreadFriendRequestDatabase(context: Context, helper: SQLCipherOpenHelper) : Database(context, helper), LokiThreadDatabaseProtocol {
|
||||
|
||||
companion object {
|
||||
private val tableName = "loki_thread_friend_request_database"
|
||||
@ -14,7 +17,11 @@ class LokiThreadFriendRequestDatabase(context: Context, helper: SQLCipherOpenHel
|
||||
@JvmStatic val createTableCommand = "CREATE TABLE $tableName ($threadID INTEGER PRIMARY KEY, $friendRequestStatus INTEGER DEFAULT 0);"
|
||||
}
|
||||
|
||||
fun friendRequestStatus(threadID: Long): LokiThreadFriendRequestStatus {
|
||||
override fun getThreadID(messageID: Long): Long {
|
||||
return DatabaseFactory.getSmsDatabase(context).getThreadIdForMessage(messageID)
|
||||
}
|
||||
|
||||
override fun getFriendRequestStatus(threadID: Long): LokiThreadFriendRequestStatus {
|
||||
val database = databaseHelper.readableDatabase
|
||||
val result = database.get(tableName, "${Companion.threadID} = ?", arrayOf( threadID.toString() )) { cursor ->
|
||||
cursor.getInt(friendRequestStatus)
|
||||
@ -26,7 +33,7 @@ class LokiThreadFriendRequestDatabase(context: Context, helper: SQLCipherOpenHel
|
||||
}
|
||||
}
|
||||
|
||||
fun setFriendRequestStatus(threadID: Long, friendRequestStatus: LokiThreadFriendRequestStatus) {
|
||||
override fun setFriendRequestStatus(threadID: Long, friendRequestStatus: LokiThreadFriendRequestStatus) {
|
||||
val database = databaseHelper.writableDatabase
|
||||
val contentValues = ContentValues(2)
|
||||
contentValues.put(Companion.threadID, threadID)
|
||||
|
@ -1,28 +0,0 @@
|
||||
package org.thoughtcrime.securesms.loki
|
||||
|
||||
enum class LokiThreadFriendRequestStatus(val rawValue: Int) {
|
||||
/**
|
||||
* New conversation; no messages sent or received.
|
||||
*/
|
||||
NONE(0),
|
||||
/**
|
||||
* Used to lock the input early while sending.
|
||||
*/
|
||||
REQUEST_SENDING(1),
|
||||
/**
|
||||
* Friend request sent; awaiting response.
|
||||
*/
|
||||
REQUEST_SENT(2),
|
||||
/**
|
||||
* Friend request received; awaiting user input.
|
||||
*/
|
||||
REQUEST_RECEIVED(3),
|
||||
/**
|
||||
* The user is friends with the other user in this thread.
|
||||
*/
|
||||
FRIENDS(4),
|
||||
/**
|
||||
* A friend request was sent, but it timed out (i.e the other user didn't accept within the allocated time).
|
||||
*/
|
||||
REQUEST_EXPIRED(5)
|
||||
}
|
Loading…
Reference in New Issue
Block a user