import 'package:comunic/models/api_request.dart'; import 'package:comunic/models/conversation.dart'; /// Conversation helper /// /// @author Pierre HUBERT class ConversationsHelper { /// Download the list of conversations from the server Future> downloadList() async { final response = await APIRequest(uri: "conversations/getList", needLogin: true).exec(); if (response.code != 200) return null; try { List list = List(); response.getArray().forEach((f) => list.add(Conversation( id: f["ID"], ownerID: f["ID_owner"], lastActive: f["last_active"], name: f["name"] == false ? null : f["name"], following: f["following"] == 1, sawLastMessage: f["saw_last_message"] == 1, members: f["members"].map((f) => int.parse(f)).toList(), ))); return list; } on Exception catch(e){ print(e.toString()); return null; } } }