OpenContacts/lib/apis/message_api.dart

20 lines
753 B
Dart
Raw Normal View History

2023-04-29 15:26:12 -04:00
import 'dart:convert';
import 'package:contacts_plus_plus/clients/api_client.dart';
2023-05-01 13:13:40 -04:00
import 'package:contacts_plus_plus/models/message.dart';
2023-04-29 15:26:12 -04:00
2023-04-30 07:39:09 -04:00
class MessageApi {
static Future<Iterable<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"
);
ApiClient.checkResponse(response);
final data = jsonDecode(response.body) as List;
return data.map((e) => Message.fromMap(e));
}
}