Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ configurations.configureEach {
exclude(module = "commons-logging")
}

val canonicalVersionCode = 433
val canonicalVersionName = "1.30.0"
val canonicalVersionCode = 434
val canonicalVersionName = "1.30.1"

val postFixSize = 10
val abiPostFix = mapOf(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ package org.thoughtcrime.securesms
import android.content.ClipData
import android.content.ClipboardManager
import android.content.Context
import android.content.Intent
import android.net.Uri
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup.LayoutParams.MATCH_PARENT
Expand All @@ -15,9 +13,7 @@ import android.widget.LinearLayout
import android.widget.LinearLayout.VERTICAL
import android.widget.Space
import android.widget.TextView
import androidx.annotation.AttrRes
import androidx.annotation.ColorRes
import androidx.annotation.DrawableRes
import androidx.annotation.LayoutRes
import androidx.annotation.StringRes
import androidx.annotation.StyleRes
Expand Down Expand Up @@ -195,9 +191,6 @@ public fun Context.copyURLToClipboard(url: String) {
clipboard.setPrimaryClip(clip)
}

// Method to actually open a given URL via an Intent that will use the default browser
fun Context.openUrl(url: String) = Intent(Intent.ACTION_VIEW, Uri.parse(url)).let(::startActivity)

fun Fragment.showSessionDialog(build: SessionDialogBuilder.() -> Unit): AlertDialog =
SessionDialogBuilder(requireContext()).apply { build() }.show()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,11 +121,7 @@ class AvatarUploadManager @Inject constructor(
val result = it.userProfile.getPic()
val userPic = remoteFile.toUserPic()
if (isReupload) {
it.userProfile.setPic(userPic)

// TODO: We'll need to call this when the libsession re-enables the re-uploaded
// avatar logic.
// it.userProfile.setReuploadedPic(userPic)
it.userProfile.setReuploadedPic(userPic)
} else {
it.userProfile.setPic(userPic)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,6 @@ class ConfigToDatabaseSync @Inject constructor(
private val lokiAPIDatabase: LokiAPIDatabase,
private val receivedMessageHashDatabase: ReceivedMessageHashDatabase,
private val clock: SnodeClock,
private val preferences: TextSecurePreferences,
private val conversationRepository: ConversationRepository,
private val mmsSmsDatabase: MmsSmsDatabase,
private val lokiMessageDatabase: LokiMessageDatabase,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ import org.thoughtcrime.securesms.media.MediaOverviewViewModel
import org.thoughtcrime.securesms.ui.NavigationAction
import org.thoughtcrime.securesms.ui.ObserveAsEvents
import org.thoughtcrime.securesms.ui.UINavigator
import org.thoughtcrime.securesms.ui.handleIntent
import org.thoughtcrime.securesms.ui.horizontalSlideComposable

// Destinations
Expand Down Expand Up @@ -129,7 +130,7 @@ fun ConversationSettingsNavHost(
NavigationAction.NavigateUp -> handleBack()

is NavigationAction.NavigateToIntent -> {
navController.context.startActivity(action.intent)
navController.handleIntent(action.intent)
}

is NavigationAction.ReturnResult -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import kotlinx.serialization.Serializable
import org.thoughtcrime.securesms.ui.NavigationAction
import org.thoughtcrime.securesms.ui.ObserveAsEvents
import org.thoughtcrime.securesms.ui.UINavigator
import org.thoughtcrime.securesms.ui.handleIntent
import org.thoughtcrime.securesms.ui.horizontalSlideComposable

// Destinations
Expand Down Expand Up @@ -63,7 +64,7 @@ fun DebugMenuNavHost(
NavigationAction.NavigateUp -> handleBack()

is NavigationAction.NavigateToIntent -> {
navController.context.startActivity(action.intent)
navController.handleIntent(action.intent)
}

else -> {}
Expand Down
17 changes: 4 additions & 13 deletions app/src/main/java/org/thoughtcrime/securesms/home/PathActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ import org.session.libsignal.utilities.Snode
import org.thoughtcrime.securesms.ScreenLockActionBarActivity
import org.thoughtcrime.securesms.reviews.InAppReviewManager
import org.thoughtcrime.securesms.ui.getSubbedString
import org.thoughtcrime.securesms.ui.openUrl
import org.thoughtcrime.securesms.util.GlowViewUtilities
import org.thoughtcrime.securesms.util.IP2Country
import org.thoughtcrime.securesms.util.PathDotView
Expand Down Expand Up @@ -71,7 +72,9 @@ class PathActivity : ScreenLockActionBarActivity() {
binding.pathDescription.text = txt

binding.pathRowsContainer.disableClipping()
binding.learnMoreButton.setOnClickListener { learnMore() }
binding.learnMoreButton.setOnClickListener {
openUrl("https://getsession.org/faq/#onion-routing")
}
update(false)
registerObservers()

Expand Down Expand Up @@ -199,18 +202,6 @@ class PathActivity : ScreenLockActionBarActivity() {
}
// endregion

// region Interaction
private fun learnMore() {
try {
val url = "https://getsession.org/faq/#onion-routing"
val intent = Intent(Intent.ACTION_VIEW, Uri.parse(url))
startActivity(intent)
} catch (e: Exception) {
Toast.makeText(this, R.string.communityEnterUrlErrorInvalid, Toast.LENGTH_SHORT).show()
}
}
// endregion

// region Line View
private class LineView : RelativeLayout {
private lateinit var location: Location
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,12 @@ import org.thoughtcrime.securesms.home.startconversation.invitefriend.InviteFrie
import org.thoughtcrime.securesms.home.startconversation.newmessage.NewMessage
import org.thoughtcrime.securesms.home.startconversation.newmessage.NewMessageViewModel
import org.thoughtcrime.securesms.home.startconversation.newmessage.State
import org.thoughtcrime.securesms.openUrl
import org.thoughtcrime.securesms.ui.NavigationAction
import org.thoughtcrime.securesms.ui.ObserveAsEvents
import org.thoughtcrime.securesms.ui.OpenURLAlertDialog
import org.thoughtcrime.securesms.ui.UINavigator
import org.thoughtcrime.securesms.ui.components.BaseBottomSheet
import org.thoughtcrime.securesms.ui.handleIntent
import org.thoughtcrime.securesms.ui.horizontalSlideComposable
import org.thoughtcrime.securesms.ui.theme.PreviewTheme

Expand Down Expand Up @@ -126,7 +126,7 @@ fun StartConversationNavHost(
NavigationAction.NavigateUp -> navController.navigateUp()

is NavigationAction.NavigateToIntent -> {
navController.context.startActivity(action.intent)
navController.handleIntent(action.intent)
}

else -> {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,4 @@ class LandingActivity: BaseActionBarActivity() {
// AC: This is a temporary workaround to trick the old code that the screen is unlocked.
KeyCachingService.setMasterSecret(applicationContext, Object())
}

private fun open(url: String) {
Intent(Intent.ACTION_VIEW, Uri.parse(url)).let(::startActivity)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,11 @@ import android.view.View
import androidx.activity.viewModels
import androidx.compose.runtime.collectAsState
import androidx.compose.runtime.getValue
import androidx.lifecycle.Lifecycle
import androidx.lifecycle.lifecycleScope
import androidx.lifecycle.repeatOnLifecycle
import dagger.hilt.android.AndroidEntryPoint
import kotlinx.coroutines.flow.first
import kotlinx.coroutines.launch
import network.loki.messenger.R
import org.session.libsession.utilities.TextSecurePreferences
Expand Down Expand Up @@ -44,9 +47,11 @@ class LoadAccountActivity : BaseActionBarActivity() {
supportActionBar?.setTitle(R.string.loadAccount)
prefs.setConfigurationMessageSynced(false)


lifecycleScope.launch {
viewModel.events.collect {
loadAccountManager.load(it.mnemonic)
repeatOnLifecycle(Lifecycle.State.STARTED) {
val mnemonic = viewModel.events.first().mnemonic
loadAccountManager.load(mnemonic)
start<MessageNotificationsActivity>()
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,47 +1,46 @@
package org.thoughtcrime.securesms.onboarding.manager

import android.app.Application
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.withContext
import network.loki.messenger.libsession_util.PRIORITY_HIDDEN
import org.session.libsession.snode.SnodeModule
import org.session.libsession.utilities.ConfigFactoryProtocol
import org.session.libsession.utilities.TextSecurePreferences
import org.session.libsignal.database.LokiAPIDatabaseProtocol
import org.session.libsignal.utilities.Log
import org.thoughtcrime.securesms.auth.LoggedInState
import org.thoughtcrime.securesms.auth.LoginStateRepository
import org.thoughtcrime.securesms.database.ReceivedMessageHashDatabase
import org.thoughtcrime.securesms.util.VersionDataFetcher
import javax.inject.Inject
import javax.inject.Singleton

@Singleton
class CreateAccountManager @Inject constructor(
private val versionDataFetcher: VersionDataFetcher,
private val configFactory: ConfigFactoryProtocol,
private val receivedMessageHashDatabase: ReceivedMessageHashDatabase,
private val loginStateRepository: LoginStateRepository,
private val database: LokiAPIDatabaseProtocol,
) {
private val database: LokiAPIDatabaseProtocol
get() = SnodeModule.shared.storage
suspend fun createAccount(displayName: String) {
withContext(Dispatchers.Default) {
// This is here to resolve a case where the app restarts before a user completes onboarding
// which can result in an invalid database state
database.clearAllLastMessageHashes()
receivedMessageHashDatabase.removeAll()

fun createAccount(displayName: String) {
// This is here to resolve a case where the app restarts before a user completes onboarding
// which can result in an invalid database state
database.clearAllLastMessageHashes()
receivedMessageHashDatabase.removeAll()
loginStateRepository.update { oldState ->
if (oldState != null) {
Log.wtf("CreateAccountManager", "Tried to create account when already logged in!")
return@update oldState
}

loginStateRepository.update { oldState ->
require(oldState == null) {
"Attempting to create a new account when one already exists!"
LoggedInState.generate(seed = null)
}

LoggedInState.generate(seed = null)
}
configFactory.withMutableUserConfigs {
it.userProfile.setName(displayName)
it.userProfile.setNtsPriority(PRIORITY_HIDDEN)
}

configFactory.withMutableUserConfigs {
it.userProfile.setName(displayName)
it.userProfile.setNtsPriority(PRIORITY_HIDDEN)
versionDataFetcher.startTimedVersionCheck()
}

versionDataFetcher.startTimedVersionCheck()
}
}
Original file line number Diff line number Diff line change
@@ -1,48 +1,35 @@
package org.thoughtcrime.securesms.onboarding.manager

import android.content.Context
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.Job
import kotlinx.coroutines.launch
import org.session.libsession.snode.SnodeModule
import kotlinx.coroutines.withContext
import org.session.libsession.utilities.TextSecurePreferences
import org.session.libsignal.database.LokiAPIDatabaseProtocol
import org.session.libsignal.utilities.Log
import org.thoughtcrime.securesms.auth.LoggedInState
import org.thoughtcrime.securesms.auth.LoginStateRepository
import org.thoughtcrime.securesms.database.ReceivedMessageHashDatabase
import org.thoughtcrime.securesms.util.VersionDataFetcher
import javax.inject.Inject
import javax.inject.Singleton

@Singleton
class LoadAccountManager @Inject constructor(
@param:dagger.hilt.android.qualifiers.ApplicationContext private val context: Context,
private val prefs: TextSecurePreferences,
private val versionDataFetcher: VersionDataFetcher,
private val receivedMessageHashDatabase: ReceivedMessageHashDatabase,
private val loginStateRepository: LoginStateRepository,
) {
private val database: LokiAPIDatabaseProtocol
get() = SnodeModule.shared.storage

private var restoreJob: Job? = null

private val scope = CoroutineScope(Dispatchers.IO)

fun load(seed: ByteArray) {
// only have one sync job running at a time (prevent QR from trying to spawn a new job)
if (restoreJob?.isActive == true) return
) {

restoreJob = scope.launch {
suspend fun load(seed: ByteArray) {
withContext(Dispatchers.Default) {
// This is here to resolve a case where the app restarts before a user completes onboarding
// which can result in an invalid database state
database.clearAllLastMessageHashes()
receivedMessageHashDatabase.removeAll()

loginStateRepository.update {
require(it == null) {
"Attempting to restore an account when one already exists!"
loginStateRepository.update { old ->
if (old != null) {
Log.wtf("LoadAccountManager", "Tried to load account when already logged in!")
return@update old
}

LoggedInState.generate(seed)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import androidx.lifecycle.ViewModelProvider
import androidx.lifecycle.viewModelScope
import dagger.assisted.Assisted
import dagger.assisted.AssistedInject
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.flow.MutableSharedFlow
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.asSharedFlow
Expand Down Expand Up @@ -37,7 +36,7 @@ internal class MessageNotificationsViewModel(
}

fun onContinue() {
viewModelScope.launch(Dispatchers.IO) {
viewModelScope.launch {
if (state is State.CreateAccount) createAccountManager.createAccount(state.displayName)

prefs.setPushEnabled(uiStates.value.pushEnabled)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import org.thoughtcrime.securesms.ScreenLockActionBarActivity
import org.thoughtcrime.securesms.permissions.Permissions
import org.thoughtcrime.securesms.ui.getSubbedCharSequence
import org.thoughtcrime.securesms.ui.getSubbedString
import org.thoughtcrime.securesms.ui.openUrl

@AndroidEntryPoint
class HelpSettingsActivity: ScreenLockActionBarActivity() {
Expand Down Expand Up @@ -68,19 +69,19 @@ class HelpSettingsFragment: CorrectedPreferenceFragment() {
true
}
TRANSLATE -> {
openLink(CROWDIN_URL)
requireContext().openUrl(CROWDIN_URL)
true
}
FEEDBACK -> {
openLink(FEEDBACK_URL)
requireContext().openUrl(FEEDBACK_URL)
true
}
FAQ -> {
openLink(FAQ_URL)
requireContext().openUrl(FAQ_URL)
true
}
SUPPORT -> {
openLink(SUPPORT_URL)
requireContext().openUrl(SUPPORT_URL)
true
}
else -> super.onPreferenceTreeClick(preference)
Expand Down Expand Up @@ -115,14 +116,4 @@ class HelpSettingsFragment: CorrectedPreferenceFragment() {
}
.execute()
}

private fun openLink(url: String) {
try {
val intent = Intent(Intent.ACTION_VIEW, Uri.parse(url))
startActivity(intent)
} catch (e: Exception) {
Toast.makeText(requireActivity(), requireContext().getString(R.string.errorUnknown), Toast.LENGTH_LONG).show()
}
}

}
Loading