From 8f2574a555b1ffdfdf3406fedaebba5551aa21dd Mon Sep 17 00:00:00 2001 From: Pierre HUBERT Date: Thu, 11 Mar 2021 18:50:36 +0100 Subject: [PATCH] Fix unread conversations drop down --- lib/lists/unread_conversations_list.dart | 2 +- lib/models/conversation_message.dart | 3 +- .../screens/unread_conversations_screen.dart | 45 +++++++++++++------ 3 files changed, 35 insertions(+), 15 deletions(-) diff --git a/lib/lists/unread_conversations_list.dart b/lib/lists/unread_conversations_list.dart index 21431bc..55f18da 100644 --- a/lib/lists/unread_conversations_list.dart +++ b/lib/lists/unread_conversations_list.dart @@ -8,7 +8,7 @@ import 'package:comunic/models/unread_conversation.dart'; class UnreadConversationsList extends AbstractList { /// Get the ID of the users included in this list Set get usersID { - final set = Set(); + final set = Set(); forEach((element) => set.addAll(element.message.usersID)); return set; } diff --git a/lib/models/conversation_message.dart b/lib/models/conversation_message.dart index 8ae2c1a..b616dfd 100644 --- a/lib/models/conversation_message.dart +++ b/lib/models/conversation_message.dart @@ -224,7 +224,8 @@ class ConversationMessage extends SerializableElement { Set get usersID { if (userID != null) return Set()..add(userID); - return serverMessage.usersID; + if (serverMessage != null) return serverMessage.usersID; + return Set(); } @override diff --git a/lib/ui/screens/unread_conversations_screen.dart b/lib/ui/screens/unread_conversations_screen.dart index 233e07f..2202c15 100644 --- a/lib/ui/screens/unread_conversations_screen.dart +++ b/lib/ui/screens/unread_conversations_screen.dart @@ -3,8 +3,11 @@ import 'package:comunic/helpers/events_helper.dart'; import 'package:comunic/helpers/users_helper.dart'; import 'package:comunic/lists/unread_conversations_list.dart'; import 'package:comunic/lists/users_list.dart'; +import 'package:comunic/ui/routes/main_route/main_route.dart'; import 'package:comunic/ui/widgets/async_screen_widget.dart'; +import 'package:comunic/ui/widgets/conversation_image_widget.dart'; import 'package:comunic/ui/widgets/safe_state.dart'; +import 'package:comunic/utils/date_utils.dart'; import 'package:comunic/utils/intl_utils.dart'; import 'package:flutter/material.dart'; @@ -67,25 +70,41 @@ class _UnreadConversationsScreenState } Widget _tileBuilder(BuildContext context, int index) { - /*final conv = _list[index]; - final user = _users.getUser(conv.userID); + final conv = _list[index]; + + final message = _list[index].message; + + final singleUserConv = conv.conv.members.length < 3; + + String messageStr; + if (message.hasFile) + messageStr = tr("New file"); + else if (message.hasMessage) + messageStr = singleUserConv + ? message.message.content + : tr("%1% : %2%", args: { + "1": _users.getUser(message.userID).fullName, + "2": message.message.content, + }); + else + message.serverMessage.getText(_users); + return ListTile( - leading: AccountImageWidget(user: user), - title: Text(user.displayName), + leading: ConversationImageWidget( + conversation: conv.conv, + users: _users, + ), + title: Text(ConversationsHelper.getConversationName(conv.conv, _users)), subtitle: RichText( text: TextSpan(style: Theme.of(context).textTheme.bodyText2, children: [ - TextSpan(text: conv.convName.isNotEmpty ? conv.convName + "\n" : ""), TextSpan( - text: conv.message, + text: messageStr, style: TextStyle(fontStyle: FontStyle.italic), ), ]), - ) - trailing: Text(diffTimeFromNowToStr(conv.lastActive)), - onTap: () => MainController.of(context).openConversation(conv.id), - );*/ - - // TODO : reimplement - throw new Exception("unimplemented"); + ), + trailing: Text(diffTimeFromNowToStr(conv.message.timeSent)), + onTap: () => MainController.of(context).openConversation(conv.conv.id), + ); } }