1
0
mirror of https://gitlab.com/comunic/comunicmobile synced 2025-06-19 08:15:16 +00:00

Get and show the name of conversation members

This commit is contained in:
2019-04-23 17:29:58 +02:00
parent c94a294252
commit 7fc03ba15c
9 changed files with 199 additions and 13 deletions

View File

@ -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;
}
}

View File

@ -0,0 +1,47 @@
import 'package:comunic/enums/user_page_visibility.dart';
import 'package:comunic/lists/users_list.dart';
import 'package:comunic/models/api_request.dart';
import 'package:comunic/models/user.dart';
/// User helper
///
/// Helper used to get information about the users of Comunic
///
/// @author Pierre HUBERT
class UsersHelper {
/// Download information about some given users ID
///
/// Return the list of users information in case of success, null in case of
/// failure
Future<UsersList> downloadInfo(List<int> users) async {
// Execute the request
final response = await APIRequest(
uri: "user/getInfoMultiple", args: {"usersID": users.join(",")}).exec();
// Check if the request did not execute correctly
if (response.code != 200) return null;
final list = UsersList();
response.getObject().forEach(
(k, v) => list.add(
User(
id: v["userID"],
firstName: v["firstName"],
lastName: v["lastName"],
pageVisibility: v["publicPage"] == "false"
? UserPageVisibility.PRIVATE
: (v["openPage"] == "false"
? UserPageVisibility.PRIVATE
: UserPageVisibility.OPEN),
virtualDirectory: v["virtualDirectory"] == ""
? null
: v["virtualDirectory"],
accountImageURL: v["accountImage"],
),
),
);
return list;
}
}