Encrypted messaging app
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

38 lines
988 B

  1. // import 'package:sqflite/sqflite.dart';
  2. import 'package:http/http.dart' as http;
  3. import 'dart:convert';
  4. import "package:pointycastle/export.dart";
  5. import '/models/friends.dart';
  6. import '/utils/storage/encryption_keys.dart';
  7. import '/utils/storage/session_cookie.dart';
  8. void getFriends() async {
  9. RSAPrivateKey privKey = await getPrivateKey();
  10. final resp = await http.get(
  11. Uri.parse('http://192.168.1.5:8080/api/v1/auth/friends'),
  12. headers: {
  13. 'cookie': await getSessionCookie(),
  14. }
  15. );
  16. if (resp.statusCode != 200) {
  17. throw Exception(resp.body);
  18. }
  19. List<Friend> friends = [];
  20. List<dynamic> friendsJson = jsonDecode(resp.body);
  21. for (var i = 0; i < friendsJson.length; i++) {
  22. friends.add(
  23. Friend.fromJson(
  24. friendsJson[i] as Map<String, dynamic>,
  25. privKey,
  26. )
  27. );
  28. }
  29. print(friends);
  30. }