feat: 屏蔽吧页面的直播广告
This commit is contained in:
parent
494923ad33
commit
a9dc88134d
|
|
@ -1,9 +1,14 @@
|
||||||
package com.huanchengfly.tieba.post.repository
|
package com.huanchengfly.tieba.post.repository
|
||||||
|
|
||||||
|
import com.huanchengfly.tieba.post.App
|
||||||
import com.huanchengfly.tieba.post.api.TiebaApi
|
import com.huanchengfly.tieba.post.api.TiebaApi
|
||||||
import com.huanchengfly.tieba.post.api.models.protos.frsPage.FrsPageResponse
|
import com.huanchengfly.tieba.post.api.models.protos.frsPage.FrsPageResponse
|
||||||
|
import com.huanchengfly.tieba.post.api.models.protos.threadList.ThreadListResponse
|
||||||
|
import com.huanchengfly.tieba.post.api.retrofit.exception.TiebaUnknownException
|
||||||
|
import com.huanchengfly.tieba.post.utils.appPreferences
|
||||||
import kotlinx.coroutines.flow.Flow
|
import kotlinx.coroutines.flow.Flow
|
||||||
import kotlinx.coroutines.flow.flowOf
|
import kotlinx.coroutines.flow.flowOf
|
||||||
|
import kotlinx.coroutines.flow.map
|
||||||
import kotlinx.coroutines.flow.onEach
|
import kotlinx.coroutines.flow.onEach
|
||||||
|
|
||||||
object FrsPageRepository {
|
object FrsPageRepository {
|
||||||
|
|
@ -24,6 +29,35 @@ object FrsPageRepository {
|
||||||
}
|
}
|
||||||
lastHash = hash
|
lastHash = hash
|
||||||
return TiebaApi.getInstance().frsPage(forumName, page, loadType, sortType, goodClassifyId)
|
return TiebaApi.getInstance().frsPage(forumName, page, loadType, sortType, goodClassifyId)
|
||||||
|
.map { response ->
|
||||||
|
if (response.data_ == null) throw TiebaUnknownException
|
||||||
|
val userList = response.data_.user_list
|
||||||
|
val threadList = response.data_.thread_list
|
||||||
|
.map { threadInfo ->
|
||||||
|
threadInfo.copy(author = userList.find { it.id == threadInfo.authorId })
|
||||||
|
}
|
||||||
|
.filter { !App.INSTANCE.appPreferences.blockVideo || it.videoInfo == null }
|
||||||
|
.filter { it.threadTypes != 3072 } // 去他妈的直播
|
||||||
|
response.copy(data_ = response.data_.copy(thread_list = threadList))
|
||||||
|
}
|
||||||
.onEach { lastResponse = it }
|
.onEach { lastResponse = it }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun threadList(
|
||||||
|
forumId: Long,
|
||||||
|
forumName: String,
|
||||||
|
page: Int,
|
||||||
|
sortType: Int,
|
||||||
|
threadIds: String = "",
|
||||||
|
): Flow<ThreadListResponse> =
|
||||||
|
TiebaApi.getInstance()
|
||||||
|
.threadList(forumId, forumName, page, sortType, threadIds)
|
||||||
|
.map { response ->
|
||||||
|
if (response.data_ == null) throw TiebaUnknownException
|
||||||
|
val userList = response.data_.user_list
|
||||||
|
val threadList = response.data_.thread_list.map { threadInfo ->
|
||||||
|
threadInfo.copy(author = userList.find { it.id == threadInfo.authorId })
|
||||||
|
}
|
||||||
|
response.copy(data_ = response.data_.copy(thread_list = threadList))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -1,11 +1,12 @@
|
||||||
package com.huanchengfly.tieba.post.ui.page.forum.threadlist
|
package com.huanchengfly.tieba.post.ui.page.forum.threadlist
|
||||||
|
|
||||||
import androidx.compose.runtime.Stable
|
import androidx.compose.runtime.Stable
|
||||||
import com.huanchengfly.tieba.post.App
|
|
||||||
import com.huanchengfly.tieba.post.api.TiebaApi
|
import com.huanchengfly.tieba.post.api.TiebaApi
|
||||||
import com.huanchengfly.tieba.post.api.models.AgreeBean
|
import com.huanchengfly.tieba.post.api.models.AgreeBean
|
||||||
import com.huanchengfly.tieba.post.api.models.protos.ThreadInfo
|
import com.huanchengfly.tieba.post.api.models.protos.ThreadInfo
|
||||||
import com.huanchengfly.tieba.post.api.models.protos.frsPage.Classify
|
import com.huanchengfly.tieba.post.api.models.protos.frsPage.Classify
|
||||||
|
import com.huanchengfly.tieba.post.api.models.protos.frsPage.FrsPageResponse
|
||||||
|
import com.huanchengfly.tieba.post.api.retrofit.exception.TiebaUnknownException
|
||||||
import com.huanchengfly.tieba.post.api.retrofit.exception.getErrorCode
|
import com.huanchengfly.tieba.post.api.retrofit.exception.getErrorCode
|
||||||
import com.huanchengfly.tieba.post.api.retrofit.exception.getErrorMessage
|
import com.huanchengfly.tieba.post.api.retrofit.exception.getErrorMessage
|
||||||
import com.huanchengfly.tieba.post.api.updateAgreeStatus
|
import com.huanchengfly.tieba.post.api.updateAgreeStatus
|
||||||
|
|
@ -19,7 +20,6 @@ import com.huanchengfly.tieba.post.arch.UiIntent
|
||||||
import com.huanchengfly.tieba.post.arch.UiState
|
import com.huanchengfly.tieba.post.arch.UiState
|
||||||
import com.huanchengfly.tieba.post.arch.wrapImmutable
|
import com.huanchengfly.tieba.post.arch.wrapImmutable
|
||||||
import com.huanchengfly.tieba.post.repository.FrsPageRepository
|
import com.huanchengfly.tieba.post.repository.FrsPageRepository
|
||||||
import com.huanchengfly.tieba.post.utils.appPreferences
|
|
||||||
import dagger.hilt.android.lifecycle.HiltViewModel
|
import dagger.hilt.android.lifecycle.HiltViewModel
|
||||||
import kotlinx.coroutines.ExperimentalCoroutinesApi
|
import kotlinx.coroutines.ExperimentalCoroutinesApi
|
||||||
import kotlinx.coroutines.flow.Flow
|
import kotlinx.coroutines.flow.Flow
|
||||||
|
|
@ -96,52 +96,36 @@ private class ForumThreadListPartialChangeProducer(val type: ForumThreadListType
|
||||||
sortType.takeIf { type == ForumThreadListType.Latest } ?: -1,
|
sortType.takeIf { type == ForumThreadListType.Latest } ?: -1,
|
||||||
goodClassifyId.takeIf { type == ForumThreadListType.Good }
|
goodClassifyId.takeIf { type == ForumThreadListType.Good }
|
||||||
)
|
)
|
||||||
.map { response ->
|
.map<FrsPageResponse, ForumThreadListPartialChange.FirstLoad> { response ->
|
||||||
if (response.data_?.page == null) ForumThreadListPartialChange.FirstLoad.Failure(
|
if (response.data_?.page == null) throw TiebaUnknownException
|
||||||
NullPointerException("未知错误")
|
ForumThreadListPartialChange.FirstLoad.Success(
|
||||||
|
response.data_.thread_list.wrapImmutable(),
|
||||||
|
response.data_.thread_id_list,
|
||||||
|
(response.data_.forum?.good_classify ?: emptyList()).wrapImmutable(),
|
||||||
|
goodClassifyId.takeIf { type == ForumThreadListType.Good },
|
||||||
|
response.data_.page.has_more == 1
|
||||||
)
|
)
|
||||||
else {
|
|
||||||
val userList = response.data_.user_list
|
|
||||||
val threadList = response.data_.thread_list.map { threadInfo ->
|
|
||||||
threadInfo.copy(author = userList.find { it.id == threadInfo.authorId })
|
|
||||||
}.filter { !App.INSTANCE.appPreferences.blockVideo || it.videoInfo == null }
|
|
||||||
ForumThreadListPartialChange.FirstLoad.Success(
|
|
||||||
threadList.wrapImmutable(),
|
|
||||||
response.data_.thread_id_list,
|
|
||||||
(response.data_.forum?.good_classify ?: emptyList()).wrapImmutable(),
|
|
||||||
goodClassifyId.takeIf { type == ForumThreadListType.Good },
|
|
||||||
response.data_.page.has_more == 1
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
.onStart { emit(ForumThreadListPartialChange.FirstLoad.Start) }
|
.onStart { emit(ForumThreadListPartialChange.FirstLoad.Start) }
|
||||||
.catch { emit(ForumThreadListPartialChange.FirstLoad.Failure(it)) }
|
.catch { emit(ForumThreadListPartialChange.FirstLoad.Failure(it)) }
|
||||||
|
|
||||||
private fun ForumThreadListUiIntent.Refresh.producePartialChange() =
|
private fun ForumThreadListUiIntent.Refresh.producePartialChange() =
|
||||||
TiebaApi.getInstance().frsPage(
|
FrsPageRepository.frsPage(
|
||||||
forumName,
|
forumName,
|
||||||
1,
|
1,
|
||||||
1,
|
1,
|
||||||
sortType.takeIf { type == ForumThreadListType.Latest } ?: -1,
|
sortType.takeIf { type == ForumThreadListType.Latest } ?: -1,
|
||||||
goodClassifyId.takeIf { type == ForumThreadListType.Good }
|
goodClassifyId.takeIf { type == ForumThreadListType.Good }
|
||||||
)
|
)
|
||||||
.map { response ->
|
.map<FrsPageResponse, ForumThreadListPartialChange.Refresh> { response ->
|
||||||
if (response.data_?.page == null) ForumThreadListPartialChange.Refresh.Failure(
|
if (response.data_?.page == null) throw TiebaUnknownException
|
||||||
NullPointerException("未知错误")
|
ForumThreadListPartialChange.Refresh.Success(
|
||||||
|
response.data_.thread_list.wrapImmutable(),
|
||||||
|
response.data_.thread_id_list,
|
||||||
|
(response.data_.forum?.good_classify ?: emptyList()).wrapImmutable(),
|
||||||
|
goodClassifyId.takeIf { type == ForumThreadListType.Good },
|
||||||
|
response.data_.page.has_more == 1
|
||||||
)
|
)
|
||||||
else {
|
|
||||||
val userList = response.data_.user_list
|
|
||||||
val threadList = response.data_.thread_list.map { threadInfo ->
|
|
||||||
threadInfo.copy(author = userList.find { it.id == threadInfo.authorId })
|
|
||||||
}
|
|
||||||
ForumThreadListPartialChange.Refresh.Success(
|
|
||||||
threadList.wrapImmutable(),
|
|
||||||
response.data_.thread_id_list,
|
|
||||||
(response.data_.forum?.good_classify ?: emptyList()).wrapImmutable(),
|
|
||||||
goodClassifyId.takeIf { type == ForumThreadListType.Good },
|
|
||||||
response.data_.page.has_more == 1
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
.onStart { emit(ForumThreadListPartialChange.Refresh.Start) }
|
.onStart { emit(ForumThreadListPartialChange.Refresh.Start) }
|
||||||
.catch { emit(ForumThreadListPartialChange.Refresh.Failure(it)) }
|
.catch { emit(ForumThreadListPartialChange.Refresh.Failure(it)) }
|
||||||
|
|
@ -149,53 +133,38 @@ private class ForumThreadListPartialChangeProducer(val type: ForumThreadListType
|
||||||
private fun ForumThreadListUiIntent.LoadMore.producePartialChange(): Flow<ForumThreadListPartialChange.LoadMore> {
|
private fun ForumThreadListUiIntent.LoadMore.producePartialChange(): Flow<ForumThreadListPartialChange.LoadMore> {
|
||||||
val flow = if (threadListIds.isNotEmpty()) {
|
val flow = if (threadListIds.isNotEmpty()) {
|
||||||
val size = min(threadListIds.size, 30)
|
val size = min(threadListIds.size, 30)
|
||||||
TiebaApi.getInstance().threadList(
|
FrsPageRepository.threadList(
|
||||||
forumId,
|
forumId,
|
||||||
forumName,
|
forumName,
|
||||||
currentPage,
|
currentPage,
|
||||||
sortType,
|
sortType,
|
||||||
threadListIds.subList(0, size).joinToString(separator = ",") { "$it" }
|
threadListIds.subList(0, size).joinToString(separator = ",") { "$it" }
|
||||||
).map { response ->
|
).map { response ->
|
||||||
if (response.data_ == null) ForumThreadListPartialChange.LoadMore.Failure(
|
if (response.data_ == null) throw TiebaUnknownException
|
||||||
NullPointerException("未知错误")
|
ForumThreadListPartialChange.LoadMore.Success(
|
||||||
|
threadList = response.data_.thread_list.wrapImmutable(),
|
||||||
|
threadListIds = threadListIds.drop(size),
|
||||||
|
currentPage = currentPage,
|
||||||
|
hasMore = response.data_.thread_list.isNotEmpty()
|
||||||
)
|
)
|
||||||
else {
|
|
||||||
val userList = response.data_.user_list
|
|
||||||
val threadList = response.data_.thread_list.map { threadInfo ->
|
|
||||||
threadInfo.copy(author = userList.find { it.id == threadInfo.authorId })
|
|
||||||
}
|
|
||||||
ForumThreadListPartialChange.LoadMore.Success(
|
|
||||||
threadList = threadList.wrapImmutable(),
|
|
||||||
threadListIds = threadListIds.drop(size),
|
|
||||||
currentPage = currentPage,
|
|
||||||
hasMore = threadList.isNotEmpty()
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
TiebaApi.getInstance().frsPage(
|
FrsPageRepository.frsPage(
|
||||||
forumName,
|
forumName,
|
||||||
currentPage + 1,
|
currentPage + 1,
|
||||||
2,
|
2,
|
||||||
sortType.takeIf { type == ForumThreadListType.Latest } ?: -1,
|
sortType.takeIf { type == ForumThreadListType.Latest } ?: -1,
|
||||||
goodClassifyId.takeIf { type == ForumThreadListType.Good }
|
goodClassifyId.takeIf { type == ForumThreadListType.Good }
|
||||||
).map { response ->
|
)
|
||||||
if (response.data_ == null) ForumThreadListPartialChange.LoadMore.Failure(
|
.map<FrsPageResponse, ForumThreadListPartialChange.LoadMore> { response ->
|
||||||
NullPointerException("未知错误")
|
if (response.data_?.page == null) throw TiebaUnknownException
|
||||||
)
|
|
||||||
else {
|
|
||||||
val userList = response.data_.user_list
|
|
||||||
val threadList = response.data_.thread_list.map { threadInfo ->
|
|
||||||
threadInfo.copy(author = userList.find { it.id == threadInfo.authorId })
|
|
||||||
}
|
|
||||||
ForumThreadListPartialChange.LoadMore.Success(
|
ForumThreadListPartialChange.LoadMore.Success(
|
||||||
threadList = threadList.wrapImmutable(),
|
threadList = response.data_.thread_list.wrapImmutable(),
|
||||||
threadListIds = response.data_.thread_id_list,
|
threadListIds = response.data_.thread_id_list,
|
||||||
currentPage = currentPage + 1,
|
currentPage = currentPage + 1,
|
||||||
hasMore = threadList.isNotEmpty()
|
response.data_.page.has_more == 1
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return flow
|
return flow
|
||||||
.onStart { emit(ForumThreadListPartialChange.LoadMore.Start) }
|
.onStart { emit(ForumThreadListPartialChange.LoadMore.Start) }
|
||||||
|
|
|
||||||
|
|
@ -504,11 +504,8 @@ fun ThreadPage(
|
||||||
initial = false
|
initial = false
|
||||||
)
|
)
|
||||||
|
|
||||||
val showFirstPostContent by remember {
|
|
||||||
derivedStateOf { firstPostContentRenders.isNotEmpty() && author != null }
|
|
||||||
}
|
|
||||||
val isEmpty by remember {
|
val isEmpty by remember {
|
||||||
derivedStateOf { data.isEmpty() && !showFirstPostContent }
|
derivedStateOf { data.isEmpty() && firstPost == null }
|
||||||
}
|
}
|
||||||
val isCollected = remember(thread) {
|
val isCollected = remember(thread) {
|
||||||
thread?.get { collectStatus != 0 } == true
|
thread?.get { collectStatus != 0 } == true
|
||||||
|
|
@ -890,7 +887,7 @@ fun ThreadPage(
|
||||||
modifier = Modifier.fillMaxWidth()
|
modifier = Modifier.fillMaxWidth()
|
||||||
) {
|
) {
|
||||||
item(key = "FirstPost") {
|
item(key = "FirstPost") {
|
||||||
if (showFirstPostContent && firstPost != null) {
|
if (firstPost != null) {
|
||||||
Column {
|
Column {
|
||||||
PostCard(
|
PostCard(
|
||||||
postHolder = firstPost!!,
|
postHolder = firstPost!!,
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue