mirror of
https://github.com/oxen-io/session-android.git
synced 2024-11-28 20:45:17 +00:00
feat: add some config db basics and DI for it, make the user profile optional, start looking at integrate building from initial dump
This commit is contained in:
parent
961f445390
commit
a9c34dd3d1
@ -0,0 +1,13 @@
|
|||||||
|
package org.thoughtcrime.securesms.database
|
||||||
|
|
||||||
|
import android.content.Context
|
||||||
|
import org.thoughtcrime.securesms.database.helpers.SQLCipherOpenHelper
|
||||||
|
|
||||||
|
class ConfigDatabase(context: Context, helper: SQLCipherOpenHelper): Database(context, helper) {
|
||||||
|
|
||||||
|
companion object {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
@ -46,4 +46,5 @@ interface DatabaseComponent {
|
|||||||
fun attachmentProvider(): MessageDataProvider
|
fun attachmentProvider(): MessageDataProvider
|
||||||
fun blindedIdMappingDatabase(): BlindedIdMappingDatabase
|
fun blindedIdMappingDatabase(): BlindedIdMappingDatabase
|
||||||
fun groupMemberDatabase(): GroupMemberDatabase
|
fun groupMemberDatabase(): GroupMemberDatabase
|
||||||
|
fun configDatabase(): ConfigDatabase
|
||||||
}
|
}
|
@ -141,4 +141,8 @@ object DatabaseModule {
|
|||||||
@Singleton
|
@Singleton
|
||||||
fun provideAttachmentProvider(@ApplicationContext context: Context, openHelper: SQLCipherOpenHelper): MessageDataProvider = DatabaseAttachmentProvider(context, openHelper)
|
fun provideAttachmentProvider(@ApplicationContext context: Context, openHelper: SQLCipherOpenHelper): MessageDataProvider = DatabaseAttachmentProvider(context, openHelper)
|
||||||
|
|
||||||
|
@Provides
|
||||||
|
@Singleton
|
||||||
|
fun provideConfigDatabase(@ApplicationContext context: Context, openHelper: SQLCipherOpenHelper): ConfigDatabase = ConfigDatabase(context, openHelper)
|
||||||
|
|
||||||
}
|
}
|
@ -1,30 +1,33 @@
|
|||||||
package org.thoughtcrime.securesms.dependencies
|
package org.thoughtcrime.securesms.dependencies
|
||||||
|
|
||||||
|
import android.content.Context
|
||||||
import dagger.Module
|
import dagger.Module
|
||||||
import dagger.Provides
|
import dagger.Provides
|
||||||
import dagger.hilt.InstallIn
|
import dagger.hilt.InstallIn
|
||||||
import dagger.hilt.android.components.ActivityRetainedComponent
|
import dagger.hilt.android.components.ActivityRetainedComponent
|
||||||
|
import dagger.hilt.android.qualifiers.ApplicationContext
|
||||||
import dagger.hilt.android.scopes.ActivityRetainedScoped
|
import dagger.hilt.android.scopes.ActivityRetainedScoped
|
||||||
import network.loki.messenger.libsession_util.UserProfile
|
import network.loki.messenger.libsession_util.UserProfile
|
||||||
import org.thoughtcrime.securesms.ApplicationContext
|
import org.session.libsignal.utilities.guava.Optional
|
||||||
import org.thoughtcrime.securesms.crypto.KeyPairUtilities
|
import org.thoughtcrime.securesms.crypto.KeyPairUtilities
|
||||||
|
import org.thoughtcrime.securesms.database.ConfigDatabase
|
||||||
|
|
||||||
@Module
|
@Module
|
||||||
@InstallIn(ActivityRetainedComponent::class)
|
@InstallIn(ActivityRetainedComponent::class)
|
||||||
object SessionUtilModule {
|
object SessionUtilModule {
|
||||||
|
|
||||||
private fun maybeUserEdSecretKey(context: ApplicationContext): ByteArray? {
|
private fun maybeUserEdSecretKey(context: Context): ByteArray? {
|
||||||
val edKey = KeyPairUtilities.getUserED25519KeyPair(context) ?: return null
|
val edKey = KeyPairUtilities.getUserED25519KeyPair(context) ?: return null
|
||||||
return edKey.secretKey.asBytes
|
return edKey.secretKey.asBytes
|
||||||
}
|
}
|
||||||
|
|
||||||
@Provides
|
@Provides
|
||||||
@ActivityRetainedScoped
|
@ActivityRetainedScoped
|
||||||
fun provideUser(context: ApplicationContext): UserProfile {
|
fun provideUser(@ApplicationContext context: Context, configDatabase: ConfigDatabase): Optional<UserProfile> =
|
||||||
val key = maybeUserEdSecretKey(context)
|
maybeUserEdSecretKey(context)?.let { key ->
|
||||||
return UserProfile.newInstance(key ?: byteArrayOf())
|
// also get the currently stored dump
|
||||||
}
|
val instance = UserProfile.newInstance(key)
|
||||||
|
Optional.of(instance)
|
||||||
|
} ?: Optional.absent()
|
||||||
|
|
||||||
}
|
}
|
@ -25,6 +25,7 @@ import kotlinx.coroutines.withContext
|
|||||||
import network.loki.messenger.R
|
import network.loki.messenger.R
|
||||||
import network.loki.messenger.databinding.ActivityHomeBinding
|
import network.loki.messenger.databinding.ActivityHomeBinding
|
||||||
import network.loki.messenger.databinding.ViewMessageRequestBannerBinding
|
import network.loki.messenger.databinding.ViewMessageRequestBannerBinding
|
||||||
|
import network.loki.messenger.libsession_util.UserProfile
|
||||||
import org.greenrobot.eventbus.EventBus
|
import org.greenrobot.eventbus.EventBus
|
||||||
import org.greenrobot.eventbus.Subscribe
|
import org.greenrobot.eventbus.Subscribe
|
||||||
import org.greenrobot.eventbus.ThreadMode
|
import org.greenrobot.eventbus.ThreadMode
|
||||||
@ -37,6 +38,7 @@ import org.session.libsession.utilities.TextSecurePreferences
|
|||||||
import org.session.libsession.utilities.recipients.Recipient
|
import org.session.libsession.utilities.recipients.Recipient
|
||||||
import org.session.libsignal.utilities.Log
|
import org.session.libsignal.utilities.Log
|
||||||
import org.session.libsignal.utilities.ThreadUtils
|
import org.session.libsignal.utilities.ThreadUtils
|
||||||
|
import org.session.libsignal.utilities.guava.Optional
|
||||||
import org.session.libsignal.utilities.toHexString
|
import org.session.libsignal.utilities.toHexString
|
||||||
import org.thoughtcrime.securesms.ApplicationContext
|
import org.thoughtcrime.securesms.ApplicationContext
|
||||||
import org.thoughtcrime.securesms.MuteDialog
|
import org.thoughtcrime.securesms.MuteDialog
|
||||||
@ -61,15 +63,9 @@ import org.thoughtcrime.securesms.mms.GlideRequests
|
|||||||
import org.thoughtcrime.securesms.onboarding.SeedActivity
|
import org.thoughtcrime.securesms.onboarding.SeedActivity
|
||||||
import org.thoughtcrime.securesms.onboarding.SeedReminderViewDelegate
|
import org.thoughtcrime.securesms.onboarding.SeedReminderViewDelegate
|
||||||
import org.thoughtcrime.securesms.preferences.SettingsActivity
|
import org.thoughtcrime.securesms.preferences.SettingsActivity
|
||||||
import org.thoughtcrime.securesms.util.ConfigurationMessageUtilities
|
import org.thoughtcrime.securesms.util.*
|
||||||
import org.thoughtcrime.securesms.util.DateUtils
|
|
||||||
import org.thoughtcrime.securesms.util.IP2Country
|
|
||||||
import org.thoughtcrime.securesms.util.disableClipping
|
|
||||||
import org.thoughtcrime.securesms.util.push
|
|
||||||
import org.thoughtcrime.securesms.util.show
|
|
||||||
import org.thoughtcrime.securesms.util.themeState
|
|
||||||
import java.io.IOException
|
import java.io.IOException
|
||||||
import java.util.Locale
|
import java.util.*
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
|
|
||||||
@AndroidEntryPoint
|
@AndroidEntryPoint
|
||||||
@ -87,6 +83,7 @@ class HomeActivity : PassphraseRequiredActionBarActivity(),
|
|||||||
@Inject lateinit var recipientDatabase: RecipientDatabase
|
@Inject lateinit var recipientDatabase: RecipientDatabase
|
||||||
@Inject lateinit var groupDatabase: GroupDatabase
|
@Inject lateinit var groupDatabase: GroupDatabase
|
||||||
@Inject lateinit var textSecurePreferences: TextSecurePreferences
|
@Inject lateinit var textSecurePreferences: TextSecurePreferences
|
||||||
|
@Inject lateinit var userProfile: Optional<UserProfile>
|
||||||
|
|
||||||
private val globalSearchViewModel by viewModels<GlobalSearchViewModel>()
|
private val globalSearchViewModel by viewModels<GlobalSearchViewModel>()
|
||||||
private val homeViewModel by viewModels<HomeViewModel>()
|
private val homeViewModel by viewModels<HomeViewModel>()
|
||||||
|
Loading…
Reference in New Issue
Block a user