From 2cb9a7e1c0632281aa66f3e17b394d33f981f2b0 Mon Sep 17 00:00:00 2001 From: Pierre HUBERT Date: Tue, 23 Apr 2019 18:15:29 +0200 Subject: [PATCH] Remove current user name from conversations members names. --- lib/helpers/conversations_helper.dart | 18 ++++++++++++++---- lib/utils/account_utils.dart | 10 ++++++++++ 2 files changed, 24 insertions(+), 4 deletions(-) create mode 100644 lib/utils/account_utils.dart diff --git a/lib/helpers/conversations_helper.dart b/lib/helpers/conversations_helper.dart index 1d798a8..6990930 100644 --- a/lib/helpers/conversations_helper.dart +++ b/lib/helpers/conversations_helper.dart @@ -2,6 +2,7 @@ import 'package:comunic/lists/conversations_list.dart'; import 'package:comunic/lists/users_list.dart'; import 'package:comunic/models/api_request.dart'; import 'package:comunic/models/conversation.dart'; +import 'package:comunic/utils/account_utils.dart'; /// Conversation helper /// @@ -36,14 +37,23 @@ class ConversationsHelper { /// Get the name of a [conversation]. This requires information about the /// users of this conversation - static String getConversationName(Conversation conversation, UsersList users) { + static String getConversationName( + Conversation conversation, UsersList users) { if (conversation.has_name) return conversation.name; - // TODO : exclude current user name String name = ""; + int count = 0; for (int i = 0; i < 3 && i < conversation.members.length; i++) - name += - (i > 0 ? ", " : "") + users.getUser(conversation.members[i]).fullName; + if (conversation.members[i] != userID()) { + name += (count > 0 ? ", " : "") + + users + .getUser(conversation.members[i]) + .fullName; + count++; + } + + if(conversation.members.length > 3) + name += ", ..."; return name; } diff --git a/lib/utils/account_utils.dart b/lib/utils/account_utils.dart new file mode 100644 index 0000000..f9d28f0 --- /dev/null +++ b/lib/utils/account_utils.dart @@ -0,0 +1,10 @@ +import 'package:comunic/helpers/account_helper.dart'; + +/// Account utilities +/// +/// @author Pierre HUBERT + +/// Get the ID of the current user +int userID() { + return AccountHelper.getCurrentUserID(); +} \ No newline at end of file