fix: 收藏未知错误

This commit is contained in:
HuanCheng65 2023-07-21 21:28:43 +08:00
parent 2edc0f249b
commit d0ad2a6a02
No known key found for this signature in database
GPG Key ID: 5EC9DD60A32C7360
4 changed files with 47 additions and 17 deletions

View File

@ -39,6 +39,7 @@ import com.huanchengfly.tieba.post.api.models.ThreadContentBean.PostListItemBean
import com.huanchengfly.tieba.post.api.retrofit.doIfFailure import com.huanchengfly.tieba.post.api.retrofit.doIfFailure
import com.huanchengfly.tieba.post.api.retrofit.doIfSuccess import com.huanchengfly.tieba.post.api.retrofit.doIfSuccess
import com.huanchengfly.tieba.post.api.retrofit.exception.TiebaException import com.huanchengfly.tieba.post.api.retrofit.exception.TiebaException
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.components.FillVirtualLayoutManager import com.huanchengfly.tieba.post.components.FillVirtualLayoutManager
import com.huanchengfly.tieba.post.components.dialogs.EditTextDialog import com.huanchengfly.tieba.post.components.dialogs.EditTextDialog
@ -613,25 +614,16 @@ class ThreadActivity : BaseActivity(), View.OnClickListener, IThreadMenuFragment
private fun collect(commonCallback: CommonCallback<CommonResponse>?, update: Boolean) { private fun collect(commonCallback: CommonCallback<CommonResponse>?, update: Boolean) {
if (dataBean == null || threadId == null) return if (dataBean == null || threadId == null) return
val postListItemBean = firstVisibleItem ?: return val postListItemBean = firstVisibleItem ?: return
TiebaApi.getInstance() launchIO {
.addStore(threadId!!, postListItemBean.id!!, tbs = dataBean!!.anti?.tbs!!) TiebaApi.getInstance()
.enqueue(object : Callback<CommonResponse> { .addStoreAsync(threadId!!.toLong(), postListItemBean.id!!.toLong())
override fun onFailure(call: Call<CommonResponse>, t: Throwable) { .doIfSuccess {
if (t is TiebaException) { commonCallback?.onSuccess(it)
commonCallback?.onFailure(t.code, t.message)
} else {
commonCallback?.onFailure(-1, t.message)
}
} }
.doIfFailure {
override fun onResponse( commonCallback?.onFailure(it.getErrorCode(), it.getErrorMessage())
call: Call<CommonResponse>,
response: Response<CommonResponse>
) {
commonCallback?.onSuccess(response.body()!!)
} }
}
})
if (!update) Util.miuiFav( if (!update) Util.miuiFav(
this, this,
getString(R.string.title_miui_fav, dataBean!!.thread?.title), getString(R.string.title_miui_fav, dataBean!!.thread?.title),

View File

@ -571,6 +571,19 @@ interface ITiebaApi {
tbs: String tbs: String
): Call<CommonResponse> ): Call<CommonResponse>
/**
* 添加/更新收藏
*
* **需登录**
*
* @param threadId 贴子 ID
* @param postId 收藏到的回复 ID
*/
fun addStoreAsync(
threadId: Long,
postId: Long
): Deferred<ApiResult<CommonResponse>>
/** /**
* 添加/更新收藏 * 添加/更新收藏
* *

View File

@ -435,6 +435,17 @@ object MixedTiebaApiImpl : ITiebaApi {
tbs tbs
) )
override fun addStoreAsync(threadId: Long, postId: Long): Deferred<ApiResult<CommonResponse>> =
RetrofitTiebaApi.OFFICIAL_TIEBA_API.addStoreAsync(
listOf(
NewCollectDataBean(
threadId.toString(),
postId.toString(),
status = 1
)
).toJson()
)
override fun addStoreFlow(threadId: Long, postId: Long): Flow<CommonResponse> = override fun addStoreFlow(threadId: Long, postId: Long): Flow<CommonResponse> =
RetrofitTiebaApi.OFFICIAL_TIEBA_API.addStoreFlow( RetrofitTiebaApi.OFFICIAL_TIEBA_API.addStoreFlow(
listOf( listOf(

View File

@ -423,6 +423,20 @@ interface OfficialTiebaApi {
@retrofit2.http.Header("client_user_token") client_user_token: String? = user_id, @retrofit2.http.Header("client_user_token") client_user_token: String? = user_id,
): Flow<CommonResponse> ): Flow<CommonResponse>
@POST("/c/c/post/addstore")
@FormUrlEncoded
@Headers(
"${Header.FORCE_LOGIN}: ${Header.FORCE_LOGIN_TRUE}",
"${Header.COOKIE}: ka=open",
"${Header.DROP_HEADERS}: ${Header.CHARSET},${Header.CLIENT_TYPE}",
"${Header.NO_COMMON_PARAMS}: ${Param.OAID}",
)
fun addStoreAsync(
@Field("data") data: String,
@Field("stoken") stoken: String = AccountUtil.getSToken()!!,
@retrofit2.http.Header("client_user_token") client_user_token: String? = AccountUtil.getUid(),
): Deferred<ApiResult<CommonResponse>>
@POST("/c/c/post/addstore") @POST("/c/c/post/addstore")
@FormUrlEncoded @FormUrlEncoded
@Headers( @Headers(