Fixed sorting on talk chats

This commit is contained in:
Elias Müller 2023-07-09 21:44:28 +02:00
parent 2ddaa17a81
commit 5d62f1b863
3 changed files with 16 additions and 11 deletions

View File

@ -15,20 +15,22 @@ class GetRoomResponse extends ApiResponse {
Map<String, dynamic> toJson() => _$GetRoomResponseToJson(this); Map<String, dynamic> toJson() => _$GetRoomResponseToJson(this);
List<GetRoomResponseObject> sortBy({bool lastActivity = true, required bool favoritesToTop, required bool unreadToTop}) { List<GetRoomResponseObject> 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) { if(unreadToTop) {
int unreadStatus = b.unreadMessages.compareTo(a.unreadMessages); buffer.write(chat.unreadMessages > 0 ? "b" : "a");
if(unreadStatus != 0) return unreadStatus;
} }
// Favorites buffer.write(chat.lastActivity);
if(favoritesToTop) if(a.isFavorite) return -1;
// Activity chat.sort = buffer.toString();
return b.lastActivity.compareTo(a.lastActivity); }
});
return data.toList()..sort((a, b) => b.sort!.compareTo(a.sort!));
} }
} }
@ -64,6 +66,7 @@ class GetRoomResponseObject {
String? status; String? status;
String? statusIcon; String? statusIcon;
String? statusMessage; String? statusMessage;
String? sort;
GetRoomResponseObject( GetRoomResponseObject(
this.id, this.id,

View File

@ -1,3 +1,5 @@
import 'dart:convert';
import 'package:http/http.dart' as http; import 'package:http/http.dart' as http;
import '../../apiError.dart'; import '../../apiError.dart';
import '../../apiRequest.dart'; import '../../apiRequest.dart';
@ -17,6 +19,6 @@ abstract class MessageApi<T> extends ApiRequest {
throw ApiError("Request could not be dispatched!"); throw ApiError("Request could not be dispatched!");
} }
return assemble(data.body); return assemble(utf8.decode(data.bodyBytes));
} }
} }

View File

@ -175,7 +175,7 @@ class _ChatBubbleState extends State<ChatBubble> {
), ),
onLongPress: () { onLongPress: () {
showDialog(context: context, builder: (context) { showDialog(context: context, builder: (context) {
List<String> commonReactions = ["😆", "👍", "👎", "❤️", "💔", "😍"]; List<String> commonReactions = ["👍", "👎", "😆", "❤️", "💔", "😍"];
return SimpleDialog( return SimpleDialog(
children: [ children: [
Wrap( Wrap(