2023-04-29 15:26:12 -04:00
|
|
|
import 'dart:convert';
|
|
|
|
|
2023-10-03 13:00:59 -04:00
|
|
|
import 'package:recon/clients/api_client.dart';
|
|
|
|
import 'package:recon/models/message.dart';
|
2023-04-29 15:26:12 -04:00
|
|
|
|
2023-04-30 07:39:09 -04:00
|
|
|
class MessageApi {
|
2023-05-06 10:45:26 -04:00
|
|
|
static Future<List<Message>> getUserMessages(ApiClient client, {String userId = "", DateTime? fromTime,
|
2023-05-02 12:22:18 -04:00
|
|
|
int maxItems = 50, bool unreadOnly = false}) async {
|
2023-05-02 15:34:36 -04:00
|
|
|
|
2023-04-30 07:39:09 -04:00
|
|
|
final response = await client.get("/users/${client.userId}/messages"
|
2023-04-29 15:26:12 -04:00
|
|
|
"?maxItems=$maxItems"
|
|
|
|
"${fromTime == null ? "" : "&fromTime${fromTime.toLocal().toIso8601String()}"}"
|
|
|
|
"${userId.isEmpty ? "" : "&user=$userId"}"
|
|
|
|
"&unread=$unreadOnly"
|
|
|
|
);
|
2023-05-25 09:50:38 -04:00
|
|
|
client.checkResponse(response);
|
2023-04-29 15:26:12 -04:00
|
|
|
final data = jsonDecode(response.body) as List;
|
2023-05-06 10:45:26 -04:00
|
|
|
return data.map((e) => Message.fromMap(e)).toList();
|
2023-04-29 15:26:12 -04:00
|
|
|
}
|
|
|
|
}
|