Skip to content
This repository has been archived by the owner on Feb 17, 2024. It is now read-only.

Commit

Permalink
feat: 回复成功全局事件
Browse files Browse the repository at this point in the history
  • Loading branch information
HuanCheng65 committed Jul 21, 2023
1 parent 117c401 commit a5e365a
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
Original file line number Diff line number Diff line change
@@ -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))
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit a5e365a

Please sign in to comment.