126 lines
3.1 KiB
Dart
126 lines
3.1 KiB
Dart
import 'dart:convert';
|
|
|
|
import 'package:http/http.dart' as http;
|
|
import 'package:loris/global.dart' as global;
|
|
|
|
class AccountModel {
|
|
final String acct;
|
|
final String displayName;
|
|
final String avatar;
|
|
final String url;
|
|
final String id;
|
|
final String note;
|
|
final String header;
|
|
final bool locked;
|
|
final bool? discoverable;
|
|
final List<dynamic>? fields;
|
|
final bool? bot;
|
|
final bool? suspended;
|
|
final String identity;
|
|
|
|
AccountModel({
|
|
required this.identity,
|
|
required this.note,
|
|
required this.header,
|
|
required this.locked,
|
|
this.discoverable,
|
|
this.fields,
|
|
this.bot,
|
|
this.suspended,
|
|
required this.acct,
|
|
required this.displayName,
|
|
required this.avatar,
|
|
required this.url,
|
|
required this.id,
|
|
});
|
|
|
|
factory AccountModel.fromJson(Map<String, dynamic> json, String identity) {
|
|
return AccountModel(
|
|
identity: identity,
|
|
id: json["id"],
|
|
acct: json["acct"],
|
|
displayName: json["display_name"],
|
|
avatar: json["avatar"],
|
|
url: json["url"],
|
|
note: json["note"],
|
|
discoverable: json["discoverable"],
|
|
header: json["header"],
|
|
locked: json["locked"],
|
|
bot: json["bot"],
|
|
fields: json["fields"],
|
|
suspended: json["suspended"],
|
|
);
|
|
}
|
|
}
|
|
|
|
class RelationshipModel {
|
|
final bool blockedBy;
|
|
final bool blocking;
|
|
final bool endorsed;
|
|
final bool followedBy;
|
|
final bool following;
|
|
final String id;
|
|
final bool muting;
|
|
final bool mutingNotifications;
|
|
final String note;
|
|
final bool notifying;
|
|
final bool requested;
|
|
final bool showingReblogs;
|
|
|
|
RelationshipModel({
|
|
required this.blockedBy,
|
|
required this.blocking,
|
|
required this.endorsed,
|
|
required this.followedBy,
|
|
required this.following,
|
|
required this.id,
|
|
required this.muting,
|
|
required this.mutingNotifications,
|
|
required this.note,
|
|
required this.notifying,
|
|
required this.requested,
|
|
required this.showingReblogs,
|
|
});
|
|
|
|
factory RelationshipModel.fromJson(Map<String, dynamic> json) {
|
|
return RelationshipModel(
|
|
blockedBy: json["blocked_by"],
|
|
blocking: json["blocking"],
|
|
endorsed: json["endorsed"],
|
|
followedBy: json["followed_by"],
|
|
following: json["following"],
|
|
id: json["id"],
|
|
muting: json["muting"],
|
|
mutingNotifications: json["muting_notifications"],
|
|
note: json["note"],
|
|
notifying: json["notifying"],
|
|
requested: json["requested"],
|
|
showingReblogs: json["showing_reblogs"]);
|
|
}
|
|
}
|
|
|
|
Future<Map<int, RelationshipModel?>> getRelationship(
|
|
String identityName, String id) async {
|
|
final identity = global.settings!.identities[identityName]!;
|
|
|
|
Map<String, String> headers = identity.getAuthHeaders();
|
|
headers.addAll(global.defaultHeaders);
|
|
|
|
final uri = Uri(
|
|
scheme: "https",
|
|
host: identity.instanceUrl,
|
|
path: "/api/v1/accounts/relationships",
|
|
queryParameters: {"id": id},
|
|
);
|
|
|
|
final response = await http.get(uri, headers: headers);
|
|
if (response.statusCode == 200) {
|
|
return {
|
|
response.statusCode:
|
|
RelationshipModel.fromJson(jsonDecode(response.body)[0])
|
|
};
|
|
}
|
|
|
|
return {404: null};
|
|
}
|