OpenContacts/lib/apis/message_api.dart

20 lines
729 B
Dart
Raw Normal View History

2023-04-29 15:26:12 -04:00
import 'dart:convert';
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 {
static Future<List<Message>> getUserMessages(ApiClient client, {String userId = "", DateTime? fromTime,
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;
return data.map((e) => Message.fromMap(e)).toList();
2023-04-29 15:26:12 -04:00
}
}