From e690adc77fde3974f81a5101c4ea09192062026c Mon Sep 17 00:00:00 2001 From: olorin99 <36951539+olorin99@users.noreply.github.com> Date: Mon, 3 Jun 2024 23:48:32 +1000 Subject: [PATCH] Decode lemmy thread and comment responses as utf8. (#50) --- lib/src/api/comments.dart | 12 ++++++------ lib/src/api/threads.dart | 12 ++++++------ 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/lib/src/api/comments.dart b/lib/src/api/comments.dart index 07e347e..b55471f 100644 --- a/lib/src/api/comments.dart +++ b/lib/src/api/comments.dart @@ -109,7 +109,7 @@ class APIComments { httpErrorHandler(response, message: 'Failed to load comments'); return CommentListModel.fromLemmy( - jsonDecode(response.body) as Map); + jsonDecode(utf8.decode(response.bodyBytes)) as Map); } } @@ -150,7 +150,7 @@ class APIComments { httpErrorHandler(response, message: 'Failed to load user'); - final json = jsonDecode(response.body) as Map; + final json = jsonDecode(utf8.decode(response.bodyBytes)) as Map; json['next_page'] = lemmyCalcNextIntPage(json['comments'] as List, page); @@ -185,7 +185,7 @@ class APIComments { (jsonDecode(response.body)['comments'] as List) .firstWhere((item) => item['comment']['id'] == commentId), possibleChildren: - jsonDecode(response.body)['comments'] as List, + jsonDecode(utf8.decode(response.bodyBytes))['comments'] as List, ); } } @@ -224,7 +224,7 @@ class APIComments { httpErrorHandler(response, message: 'Failed to send vote'); return CommentModel.fromLemmy( - jsonDecode(response.body)['comment_view'] as Map); + jsonDecode(utf8.decode(response.bodyBytes))['comment_view'] as Map); } } @@ -282,7 +282,7 @@ class APIComments { httpErrorHandler(response, message: 'Failed to create comment'); return CommentModel.fromLemmy( - jsonDecode(response.body)['comment_view'] as Map); + jsonDecode(utf8.decode(response.bodyBytes))['comment_view'] as Map); } } @@ -322,7 +322,7 @@ class APIComments { httpErrorHandler(response, message: 'Failed to edit comment'); return CommentModel.fromLemmy( - jsonDecode(response.body)['comment_view'] as Map); + jsonDecode(utf8.decode(response.bodyBytes))['comment_view'] as Map); } } diff --git a/lib/src/api/threads.dart b/lib/src/api/threads.dart index cbb7821..5150d55 100644 --- a/lib/src/api/threads.dart +++ b/lib/src/api/threads.dart @@ -119,7 +119,7 @@ class APIThreads { httpErrorHandler(response, message: 'Failed to load posts'); return PostListModel.fromLemmy( - jsonDecode(response.body) as Map); + jsonDecode(utf8.decode(response.bodyBytes)) as Map); } } @@ -146,7 +146,7 @@ class APIThreads { httpErrorHandler(response, message: 'Failed to load post'); return PostModel.fromLemmy( - jsonDecode(response.body)['post_view'] as Map); + jsonDecode(utf8.decode(response.bodyBytes))['post_view'] as Map); } } @@ -246,7 +246,7 @@ class APIThreads { httpErrorHandler(response, message: 'Failed to edit entry'); return PostModel.fromLemmy( - jsonDecode(response.body)['post_view'] as Map); + jsonDecode(utf8.decode(response.bodyBytes))['post_view'] as Map); } } @@ -317,7 +317,7 @@ class APIThreads { httpErrorHandler(response, message: 'Failed to create entry'); return PostModel.fromLemmy( - jsonDecode(response.body)['post_view'] as Map); + jsonDecode(utf8.decode(response.bodyBytes))['post_view'] as Map); } } @@ -370,7 +370,7 @@ class APIThreads { httpErrorHandler(response, message: 'Failed to create entry'); return PostModel.fromLemmy( - jsonDecode(response.body)['post_view'] as Map); + jsonDecode(utf8.decode(response.bodyBytes))['post_view'] as Map); } } @@ -452,7 +452,7 @@ class APIThreads { httpErrorHandler(response, message: 'Failed to create entry'); return PostModel.fromLemmy( - jsonDecode(response.body)['post_view'] as Map); + jsonDecode(utf8.decode(response.bodyBytes))['post_view'] as Map); } }