Skip to content

Commit

Permalink
Implement new zap settings
Browse files Browse the repository at this point in the history
  • Loading branch information
AleksandarIlic committed Jan 22, 2024
1 parent 129334f commit 94b3097
Show file tree
Hide file tree
Showing 27 changed files with 836 additions and 464 deletions.
2 changes: 2 additions & 0 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,8 @@ dependencies {
implementation(libs.constraintlayout)

implementation(libs.androidx.material.icons.extended)
implementation(libs.androidx.emoji2.emojipicker)
implementation("com.google.guava:guava:33.0.0-android")

implementation(libs.navigation.material)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,14 @@ import kotlinx.coroutines.flow.asStateFlow
import kotlinx.coroutines.flow.getAndUpdate
import kotlinx.coroutines.flow.receiveAsFlow
import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext
import net.primal.android.auth.AuthRepository
import net.primal.android.auth.create.CreateAccountContract.SideEffect
import net.primal.android.auth.create.CreateAccountContract.UiEvent
import net.primal.android.auth.create.CreateAccountContract.UiState
import net.primal.android.auth.create.api.RecommendedFollowsApi
import net.primal.android.auth.create.ui.RecommendedFollow
import net.primal.android.core.coroutines.CoroutineDispatcherProvider
import net.primal.android.core.files.error.UnsuccessfulFileUpload
import net.primal.android.core.serialization.json.NostrJson
import net.primal.android.networking.relays.errors.NostrPublishException
Expand All @@ -27,9 +29,11 @@ import net.primal.android.profile.repository.ProfileRepository
import net.primal.android.settings.repository.SettingsRepository
import net.primal.android.user.accounts.BOOTSTRAP_RELAYS
import net.primal.android.user.repository.UserRepository
import timber.log.Timber

@HiltViewModel
class CreateAccountViewModel @Inject constructor(
private val dispatcherProvider: CoroutineDispatcherProvider,
private val authRepository: AuthRepository,
private val settingsRepository: SettingsRepository,
private val profileRepository: ProfileRepository,
Expand Down Expand Up @@ -165,19 +169,23 @@ class CreateAccountViewModel @Inject constructor(
try {
setState { copy(loading = true) }
val userId = state.value.userId!!
profileRepository.setContactsAndRelays(
userId = userId,
contacts = state.value.recommendedFollows
.filter { it.isCurrentUserFollowing }
.map { it.pubkey }.toSet(),
relays = BOOTSTRAP_RELAYS,
)
settingsRepository.fetchAndPersistAppSettings(userId = userId)
withContext(dispatcherProvider.io()) {
profileRepository.setContactsAndRelays(
userId = userId,
contacts = state.value.recommendedFollows
.filter { it.isCurrentUserFollowing }
.map { it.pubkey }.toSet(),
relays = BOOTSTRAP_RELAYS,
)
settingsRepository.fetchAndPersistAppSettings(userId = userId)
}
setEffect(SideEffect.AccountCreatedAndPersisted(pubkey = userId))
} catch (e: NostrPublishException) {
setState { copy(error = UiState.CreateError.FailedToFollow(e)) }
} catch (e: WssException) {
setState { copy(error = UiState.CreateError.FailedToFollow(e)) }
} catch (error: NostrPublishException) {
Timber.e(error)
setState { copy(error = UiState.CreateError.FailedToFollow(error)) }
} catch (error: WssException) {
Timber.e(error)
setState { copy(error = UiState.CreateError.FailedToFollow(error)) }
} finally {
setState { copy(loading = false) }
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,21 @@ import kotlinx.coroutines.flow.asStateFlow
import kotlinx.coroutines.flow.getAndUpdate
import kotlinx.coroutines.flow.receiveAsFlow
import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext
import net.primal.android.auth.AuthRepository
import net.primal.android.auth.login.LoginContract.SideEffect
import net.primal.android.auth.login.LoginContract.UiEvent
import net.primal.android.auth.login.LoginContract.UiState
import net.primal.android.core.coroutines.CoroutineDispatcherProvider
import net.primal.android.networking.sockets.errors.WssException
import net.primal.android.settings.muted.repository.MutedUserRepository
import net.primal.android.settings.repository.SettingsRepository
import net.primal.android.user.repository.UserRepository
import timber.log.Timber

@HiltViewModel
class LoginViewModel @Inject constructor(
private val dispatcherProvider: CoroutineDispatcherProvider,
private val settingsRepository: SettingsRepository,
private val authRepository: AuthRepository,
private val userRepository: UserRepository,
Expand Down Expand Up @@ -66,11 +70,14 @@ class LoginViewModel @Inject constructor(
setState { copy(loading = true) }
try {
val pubkey = authRepository.login(nostrKey = nostrKey)
userRepository.fetchAndUpdateUserAccount(userId = pubkey)
settingsRepository.fetchAndPersistAppSettings(userId = pubkey)
mutedUserRepository.fetchAndPersistMuteList(userId = pubkey)
withContext(dispatcherProvider.io()) {
userRepository.fetchAndUpdateUserAccount(userId = pubkey)
settingsRepository.fetchAndPersistAppSettings(userId = pubkey)
mutedUserRepository.fetchAndPersistMuteList(userId = pubkey)
}
setEffect(SideEffect.LoginSuccess(pubkey = pubkey))
} catch (error: WssException) {
Timber.e(error)
setErrorState(error = UiState.LoginError.GenericError(error))
} finally {
setState { copy(loading = false) }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ fun FeedLazyColumn(
zappingState = zappingState,
onZap = { zapAmount, zapDescription ->
if (zappingState.canZap(zapAmount)) {
onZapClick(post, zapAmount, zapDescription)
onZapClick(post, zapAmount.toULong(), zapDescription)
} else {
showCantZapWarning = true
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
package net.primal.android.core.compose.feed.model

import net.primal.android.nostr.model.primal.content.ContentZapConfigItem
import net.primal.android.nostr.model.primal.content.ContentZapDefault
import net.primal.android.nostr.model.primal.content.DEFAULT_ZAP_CONFIG
import net.primal.android.nostr.model.primal.content.DEFAULT_ZAP_DEFAULT
import net.primal.android.user.domain.WalletPreference

data class ZappingState(
val walletConnected: Boolean = false,
val walletPreference: WalletPreference = WalletPreference.Undefined,
val walletBalanceInBtc: String? = null,
val defaultZapAmount: ULong = 42.toULong(),
val zapOptions: List<ULong> = emptyList(),
val zapDefault: ContentZapDefault = DEFAULT_ZAP_DEFAULT,
val zapsConfig: List<ContentZapConfigItem> = DEFAULT_ZAP_CONFIG,
)
Loading

0 comments on commit 94b3097

Please sign in to comment.