mirror of
https://gitlab.com/comunic/comunicmobile
synced 2025-07-03 15:13:29 +00:00
Get and show the name of conversation members
This commit is contained in:
@ -1,3 +1,5 @@
|
||||
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';
|
||||
|
||||
@ -7,16 +9,15 @@ import 'package:comunic/models/conversation.dart';
|
||||
|
||||
class ConversationsHelper {
|
||||
/// Download the list of conversations from the server
|
||||
Future<List<Conversation>> downloadList() async {
|
||||
Future<ConversationsList> downloadList() async {
|
||||
final response =
|
||||
await APIRequest(uri: "conversations/getList", needLogin: true).exec();
|
||||
|
||||
if (response.code != 200) return null;
|
||||
|
||||
try {
|
||||
List<Conversation> list = List();
|
||||
response.getArray().forEach((f) =>
|
||||
list.add(Conversation(
|
||||
ConversationsList list = ConversationsList();
|
||||
response.getArray().forEach((f) => list.add(Conversation(
|
||||
id: f["ID"],
|
||||
ownerID: f["ID_owner"],
|
||||
lastActive: f["last_active"],
|
||||
@ -27,10 +28,23 @@ class ConversationsHelper {
|
||||
)));
|
||||
|
||||
return list;
|
||||
|
||||
} on Exception catch(e){
|
||||
} on Exception catch (e) {
|
||||
print(e.toString());
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/// Get the name of a [conversation]. This requires information about the
|
||||
/// users of this conversation
|
||||
static String getConversationName(Conversation conversation, UsersList users) {
|
||||
if (conversation.has_name) return conversation.name;
|
||||
|
||||
// TODO : exclude current user name
|
||||
String name = "";
|
||||
for (int i = 0; i < 3 && i < conversation.members.length; i++)
|
||||
name +=
|
||||
(i > 0 ? ", " : "") + users.getUser(conversation.members[i]).fullName;
|
||||
|
||||
return name;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user