2024-11-30 14:39:49 +00:00
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
import 'package:provider/provider.dart';
|
|
|
|
import 'package:surface/providers/sn_network.dart';
|
2024-12-11 15:53:03 +00:00
|
|
|
import 'package:surface/types/account.dart';
|
2024-11-30 14:39:49 +00:00
|
|
|
|
|
|
|
class SnRelationshipProvider {
|
|
|
|
late final SnNetworkProvider _sn;
|
|
|
|
|
|
|
|
SnRelationshipProvider(BuildContext context) {
|
|
|
|
_sn = context.read<SnNetworkProvider>();
|
|
|
|
}
|
|
|
|
|
2024-12-11 15:53:03 +00:00
|
|
|
Future<SnRelationship?> getRelationship(int relatedId) async {
|
|
|
|
try {
|
|
|
|
final resp = await _sn.client.get('/cgi/id/users/me/relations/$relatedId');
|
|
|
|
return SnRelationship.fromJson(resp.data);
|
|
|
|
} catch (err) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-11-30 14:39:49 +00:00
|
|
|
Future<void> updateRelationship(
|
|
|
|
int relatedId,
|
|
|
|
int status,
|
|
|
|
Map<String, dynamic> permNodes,
|
|
|
|
) async {
|
|
|
|
await _sn.client.put('/cgi/id/users/me/relations/$relatedId', data: {
|
|
|
|
'status': status,
|
|
|
|
'perm_nodes': permNodes,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
Future<void> deleteRelationship(int relatedId) async {
|
|
|
|
await _sn.client.delete('/cgi/id/users/me/relations/$relatedId');
|
|
|
|
}
|
|
|
|
|
|
|
|
Future<void> acceptFriendRequest(int relatedId) async {
|
|
|
|
await _sn.client.post('/cgi/id/users/me/relations/$relatedId/accept');
|
|
|
|
}
|
|
|
|
|
|
|
|
Future<void> declineFriendRequest(int relatedId) async {
|
|
|
|
await _sn.client.post('/cgi/id/users/me/relations/$relatedId/decline');
|
|
|
|
}
|
|
|
|
}
|