From 5d62f1b863f0f1043464a2fd9d0424a63802ed4a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Elias=20M=C3=BCller?= Date: Sun, 9 Jul 2023 21:44:28 +0200 Subject: [PATCH] Fixed sorting on talk chats --- .../talk/room/getRoomResponse.dart | 21 +++++++++++-------- lib/api/mhsl/message/messageApi.dart | 4 +++- lib/view/pages/talk/chatBubble.dart | 2 +- 3 files changed, 16 insertions(+), 11 deletions(-) diff --git a/lib/api/marianumcloud/talk/room/getRoomResponse.dart b/lib/api/marianumcloud/talk/room/getRoomResponse.dart index ec81722..41cff26 100644 --- a/lib/api/marianumcloud/talk/room/getRoomResponse.dart +++ b/lib/api/marianumcloud/talk/room/getRoomResponse.dart @@ -15,20 +15,22 @@ class GetRoomResponse extends ApiResponse { Map toJson() => _$GetRoomResponseToJson(this); List sortBy({bool lastActivity = true, required bool favoritesToTop, required bool unreadToTop}) { - return data.toList()..sort((a, b) { + for (var chat in data) { + final buffer = StringBuffer(); - // Unread messages + if(favoritesToTop) { + buffer.write(chat.isFavorite ? "b" : "a"); + } if(unreadToTop) { - int unreadStatus = b.unreadMessages.compareTo(a.unreadMessages); - if(unreadStatus != 0) return unreadStatus; + buffer.write(chat.unreadMessages > 0 ? "b" : "a"); } - // Favorites - if(favoritesToTop) if(a.isFavorite) return -1; + buffer.write(chat.lastActivity); - // Activity - return b.lastActivity.compareTo(a.lastActivity); - }); + chat.sort = buffer.toString(); + } + + return data.toList()..sort((a, b) => b.sort!.compareTo(a.sort!)); } } @@ -64,6 +66,7 @@ class GetRoomResponseObject { String? status; String? statusIcon; String? statusMessage; + String? sort; GetRoomResponseObject( this.id, diff --git a/lib/api/mhsl/message/messageApi.dart b/lib/api/mhsl/message/messageApi.dart index e85100d..d0b15e0 100644 --- a/lib/api/mhsl/message/messageApi.dart +++ b/lib/api/mhsl/message/messageApi.dart @@ -1,3 +1,5 @@ +import 'dart:convert'; + import 'package:http/http.dart' as http; import '../../apiError.dart'; import '../../apiRequest.dart'; @@ -17,6 +19,6 @@ abstract class MessageApi extends ApiRequest { throw ApiError("Request could not be dispatched!"); } - return assemble(data.body); + return assemble(utf8.decode(data.bodyBytes)); } } \ No newline at end of file diff --git a/lib/view/pages/talk/chatBubble.dart b/lib/view/pages/talk/chatBubble.dart index d8eea1b..9d4ef04 100644 --- a/lib/view/pages/talk/chatBubble.dart +++ b/lib/view/pages/talk/chatBubble.dart @@ -175,7 +175,7 @@ class _ChatBubbleState extends State { ), onLongPress: () { showDialog(context: context, builder: (context) { - List commonReactions = ["😆", "👍", "👎", "❤️", "💔", "😍"]; + List commonReactions = ["👍", "👎", "😆", "❤️", "💔", "😍"]; return SimpleDialog( children: [ Wrap(