Skip to content

Commit

Permalink
fix comment novel error
Browse files Browse the repository at this point in the history
  • Loading branch information
Notsfsssf committed Jan 31, 2022
1 parent 5f2e148 commit 96b1cd8
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 11 deletions.
26 changes: 20 additions & 6 deletions lib/network/api_client.dart
Original file line number Diff line number Diff line change
Expand Up @@ -455,14 +455,16 @@ class ApiClient {

// @GET("/v1/illust/comments")
// fun getIllustComments(@Header("Authorization") paramString: String, @Query("illust_id") paramLong: Long): Observable<IllustCommentsResponse>
Future<Response> getIllustComments(int illust_id) {
return httpClient
.get("/v3/illust/comments", queryParameters: {"illust_id": illust_id});
Future<Response> getIllustComments(int illust_id, {bool force = false}) {
return httpClient.get("/v3/illust/comments",
queryParameters: {"illust_id": illust_id},
options: buildCacheOptions(Duration(minutes: 2), forceRefresh: force));
}

Future<Response> getNovelComments(int illust_id) {
return httpClient
.get("/v3/novel/comments", queryParameters: {"novel_id": illust_id});
Future<Response> getNovelComments(int illust_id, {bool force = false}) {
return httpClient.get("/v3/novel/comments",
queryParameters: {"novel_id": illust_id},
options: buildCacheOptions(Duration(minutes: 2), forceRefresh: force));
}

Future<Response> getIllustCommentsReplies(int comment_id) {
Expand All @@ -474,6 +476,7 @@ class ApiClient {
return httpClient.get("/v2/novel/comment/replies",
queryParameters: {"comment_id": comment_id});
}

/* @FormUrlEncoded
@POST("v1/illust/comment/add")
fun postIllustComment(@Header("Authorization") paramString1: String, @Field("illust_id") illust_id: Long, @Field("comment") comment: String, @Field("parent_comment_id") parent_comment_id: Int?): Observable<ResponseBody>
Expand All @@ -489,6 +492,17 @@ class ApiClient {
options: Options(contentType: Headers.formUrlEncodedContentType));
}

Future<Response> postNovelComment(int illust_id, String comment,
{int? parent_comment_id}) {
return httpClient.post("/v1/novel/comment/add",
data: notNullMap({
"novel_id": illust_id,
"comment": comment,
"parent_comment_id": parent_comment_id
}),
options: Options(contentType: Headers.formUrlEncodedContentType));
}

//
// @GET("/v1/ugoira/metadata")
// fun getUgoiraMetadata(@Header("Authorization") paramString: String, @Query("illust_id") paramLong: Long): Observable<UgoiraMetadataResponse>
Expand Down
14 changes: 11 additions & 3 deletions lib/page/comment/comment_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,8 @@ class _CommentPageState extends State<CommentPage> {
parentCommentName = widget.isReplay ? widget.name : null;
_editController = TextEditingController();
easyRefreshController = RefreshController();
_store = CommentStore(
easyRefreshController, widget.id, widget.pId, widget.isReplay, widget.type)
_store = CommentStore(easyRefreshController, widget.id, widget.pId,
widget.isReplay, widget.type)
..fetch();
super.initState();
}
Expand Down Expand Up @@ -389,11 +389,19 @@ class _CommentPageState extends State<CommentPage> {
if (banList
.where((element) =>
txt.contains(element))
.isEmpty)
.isEmpty) if (widget
.type ==
CommentArtWorkType.ILLUST)
await client.postIllustComment(
widget.id, txt,
parent_comment_id:
parentCommentId);
else if (widget.type ==
CommentArtWorkType.NOVEL)
await client.postNovelComment(
widget.id, txt,
parent_comment_id:
parentCommentId);
}
_editController.clear();
_store.fetch();
Expand Down
4 changes: 2 additions & 2 deletions lib/page/comment/comment_store.dart
Original file line number Diff line number Diff line change
Expand Up @@ -96,10 +96,10 @@ abstract class _CommentStoreBase with Store {
Response response = type == CommentArtWorkType.ILLUST
? (isReplay
? await apiClient.getIllustCommentsReplies(pId!)
: await apiClient.getIllustComments(id))
: await apiClient.getIllustComments(id, force: true))
: (isReplay
? await apiClient.getNovelCommentsReplies(pId!)
: await apiClient.getNovelComments(id));
: await apiClient.getNovelComments(id, force: true));
CommentResponse commentResponse = CommentResponse.fromJson(response.data);
nextUrl = commentResponse.nextUrl;
comments.clear();
Expand Down

0 comments on commit 96b1cd8

Please sign in to comment.