feat: 回复成功全局事件

This commit is contained in:
HuanCheng65 2023-07-21 22:53:56 +08:00
parent 117c401bf5
commit a5e365a9d9
No known key found for this signature in database
GPG Key ID: 5EC9DD60A32C7360
3 changed files with 46 additions and 3 deletions

View File

@ -26,6 +26,12 @@ sealed interface GlobalEvent {
val id: String,
val images: List<Uri>
) : GlobalEvent
data class ReplySuccess(
val threadId: String,
val postId: String? = null,
val subPostId: String? = null,
) : GlobalEvent
}
private val globalEventChannel: Channel<GlobalEvent> = Channel()

View File

@ -0,0 +1,37 @@
package com.huanchengfly.tieba.post.repository
import com.huanchengfly.tieba.post.api.TiebaApi
import com.huanchengfly.tieba.post.api.models.protos.addPost.AddPostResponse
import com.huanchengfly.tieba.post.arch.GlobalEvent
import com.huanchengfly.tieba.post.arch.emitGlobalEvent
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.onEach
object AddPostRepository {
fun addPost(
content: String,
forumId: String,
forumName: String,
threadId: String,
tbs: String? = null,
nameShow: String? = null,
postId: String? = null,
subPostId: String? = null,
replyUserId: String? = null
): Flow<AddPostResponse> =
TiebaApi.getInstance()
.addPostFlow(
content,
forumId,
forumName,
threadId,
tbs,
nameShow,
postId,
subPostId,
replyUserId
)
.onEach {
emitGlobalEvent(GlobalEvent.ReplySuccess(threadId, postId, subPostId))
}
}

View File

@ -5,7 +5,6 @@ import android.util.Log
import androidx.compose.runtime.Stable
import com.huanchengfly.tieba.post.App
import com.huanchengfly.tieba.post.R
import com.huanchengfly.tieba.post.api.TiebaApi
import com.huanchengfly.tieba.post.api.models.UploadPictureResultBean
import com.huanchengfly.tieba.post.api.models.protos.addPost.AddPostResponse
import com.huanchengfly.tieba.post.api.retrofit.exception.TiebaUnknownException
@ -19,6 +18,7 @@ import com.huanchengfly.tieba.post.arch.UiEvent
import com.huanchengfly.tieba.post.arch.UiIntent
import com.huanchengfly.tieba.post.arch.UiState
import com.huanchengfly.tieba.post.components.ImageUploader
import com.huanchengfly.tieba.post.repository.AddPostRepository
import com.huanchengfly.tieba.post.utils.FileUtil
import dagger.hilt.android.lifecycle.HiltViewModel
import kotlinx.collections.immutable.ImmutableList
@ -98,8 +98,8 @@ class ReplyViewModel @Inject constructor() :
)
private fun ReplyUiIntent.Send.producePartialChange(): Flow<ReplyPartialChange.Send> {
return TiebaApi.getInstance()
.addPostFlow(
return AddPostRepository
.addPost(
content,
forumId.toString(),
forumName,