feat: 屏蔽吧页面的直播广告

This commit is contained in:
HuanCheng65 2023-07-20 15:33:03 +08:00
parent 494923ad33
commit a9dc88134d
No known key found for this signature in database
GPG Key ID: 5EC9DD60A32C7360
3 changed files with 68 additions and 68 deletions

View File

@ -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))
}
} }

View File

@ -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,107 +96,76 @@ 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("未知错误")
)
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( ForumThreadListPartialChange.FirstLoad.Success(
threadList.wrapImmutable(), response.data_.thread_list.wrapImmutable(),
response.data_.thread_id_list, response.data_.thread_id_list,
(response.data_.forum?.good_classify ?: emptyList()).wrapImmutable(), (response.data_.forum?.good_classify ?: emptyList()).wrapImmutable(),
goodClassifyId.takeIf { type == ForumThreadListType.Good }, goodClassifyId.takeIf { type == ForumThreadListType.Good },
response.data_.page.has_more == 1 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("未知错误")
)
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( ForumThreadListPartialChange.Refresh.Success(
threadList.wrapImmutable(), response.data_.thread_list.wrapImmutable(),
response.data_.thread_id_list, response.data_.thread_id_list,
(response.data_.forum?.good_classify ?: emptyList()).wrapImmutable(), (response.data_.forum?.good_classify ?: emptyList()).wrapImmutable(),
goodClassifyId.takeIf { type == ForumThreadListType.Good }, goodClassifyId.takeIf { type == ForumThreadListType.Good },
response.data_.page.has_more == 1 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)) }
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("未知错误")
)
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 = threadListIds.drop(size), threadListIds = threadListIds.drop(size),
currentPage = currentPage, currentPage = currentPage,
hasMore = threadList.isNotEmpty() hasMore = response.data_.thread_list.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(
NullPointerException("未知错误")
) )
else { .map<FrsPageResponse, ForumThreadListPartialChange.LoadMore> { response ->
val userList = response.data_.user_list if (response.data_?.page == null) throw TiebaUnknownException
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) }
.catch { emit(ForumThreadListPartialChange.LoadMore.Failure(it)) } .catch { emit(ForumThreadListPartialChange.LoadMore.Failure(it)) }

View File

@ -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!!,