Skip to content

Commit

Permalink
Refactor for simplicity
Browse files Browse the repository at this point in the history
  • Loading branch information
nikclayton committed Feb 5, 2025
1 parent 01975aa commit 11dd50e
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ import app.pachli.core.network.model.Attachment
import app.pachli.core.network.model.NewPoll
import app.pachli.core.network.model.Status
import app.pachli.core.network.retrofit.MastodonApi
import app.pachli.core.network.retrofit.apiresult.ApiError
import app.pachli.core.preferences.SharedPreferencesRepository
import app.pachli.core.preferences.ShowSelfUsername
import app.pachli.core.ui.MentionSpan
Expand Down Expand Up @@ -146,25 +147,20 @@ class ComposeViewModel @AssistedInject constructor(
* - Ok(InReplyTo.Status) - this is a reply, with the status being replied to
* - Err() - error occurred fetching the parent
*/
internal val inReplyTo = stateFlow(viewModelScope, Ok(Loadable.Loading<InReplyTo.Status>())) {
internal val inReplyTo = stateFlow(viewModelScope, Ok(Loadable.Loaded(null))) {
loadReply.flatMapLatest {
flow {
Timber.d("Loading reply")
emit(Ok(Loadable.Loading<InReplyTo.Status>()))

val result = when (val i = composeOptions?.inReplyTo) {
when (val i = composeOptions?.inReplyTo) {
is InReplyTo.Id -> {
emit(Ok(Loadable.Loading<InReplyTo.Status>()))
api.status(i.statusId).mapEither(
{ Loadable.Loaded(InReplyTo.Status.from(it.body))},
{ UiError.ReloadReplyError(it) }
)
}
is InReplyTo.Status -> Ok(Loadable.Loaded(i))
null -> Ok(Loadable.Loaded(null))
}

// emit(Err(UiError.ReloadReplyError(RuntimeException("test exception message that's long to check formatting"))))
emit(result)
}.also { emit(it) }
}
}.flowWhileShared(SharingStarted.WhileSubscribed(5000))
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -190,23 +190,27 @@ class ComposeActivityIntent(context: Context, pachliAccountId: Long, composeOpti
END,
}

/** Composing a reply to an existing status. */
/**
* The status the user is replying to.
*/
@Parcelize
sealed class InReplyTo : Parcelable {
/** ID of the status being replied to. */
abstract val statusId: String

/**
* Holds the ID of the status being replied to.
* The ID of the status being replied to.
*
* Use when the caller only has the ID, and needs ComposeActivity to
* Used when the caller only has the ID, and needs
* [ComposeActivity][app.pachli.components.compose.ComposeActivity] to
* fetch the contents of the in-reply-to status.
*/
data class Id(override val statusId: String) : InReplyTo()

/**
* Holds the content of the status being replied to.
* The content of the status being replied to.
*
* Use when the caller already has the in-reply-to status content which
* Uses when the caller already has the in-reply-to status content which
* can be reused without a network round trip.
*/
data class Status(
Expand Down

0 comments on commit 11dd50e

Please sign in to comment.