mirror of
https://gitlab.com/comunic/comunicmobile
synced 2025-06-19 00:05:16 +00:00
Get and show the list of conversations
This commit is contained in:
@ -1,6 +1,7 @@
|
||||
import 'dart:convert';
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:comunic/helpers/account_credentials_helper.dart';
|
||||
import 'package:comunic/models/api_request.dart';
|
||||
import 'package:comunic/models/api_response.dart';
|
||||
import 'package:comunic/models/config.dart';
|
||||
@ -23,7 +24,12 @@ class APIHelper {
|
||||
request.addString("serviceToken", config().serviceToken);
|
||||
|
||||
//Add user tokens (if required)
|
||||
if (request.needLogin) throw "Can add user tokens right now !";
|
||||
if (request.needLogin) {
|
||||
final tokens = await AccountCredentialsHelper().get();
|
||||
assert(tokens != null);
|
||||
request.addString("userToken1", tokens.tokenOne);
|
||||
request.addString("userToken2", tokens.tokenTwo);
|
||||
}
|
||||
|
||||
// Prepare request body
|
||||
String requestBody = "";
|
||||
|
36
lib/helpers/conversations_helper.dart
Normal file
36
lib/helpers/conversations_helper.dart
Normal file
@ -0,0 +1,36 @@
|
||||
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<List<Conversation>> 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(
|
||||
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<int>((f) => int.parse(f)).toList(),
|
||||
)));
|
||||
|
||||
return list;
|
||||
|
||||
} on Exception catch(e){
|
||||
print(e.toString());
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user