profile view
This commit is contained in:
parent
534e31e634
commit
2c4eee1526
|
@ -123,3 +123,59 @@ Future<Map<int, RelationshipModel?>> getRelationship(
|
|||
|
||||
return {404: null};
|
||||
}
|
||||
|
||||
Future<Map<int, AccountModel?>> searchModel(
|
||||
String identityName, String url) async {
|
||||
final identity = global.settings!.identities[identityName]!;
|
||||
|
||||
Map<String, String> headers = identity.getAuthHeaders();
|
||||
headers.addAll(global.defaultHeaders);
|
||||
|
||||
Map<String, String> params = {
|
||||
"type": "accounts",
|
||||
"q": url,
|
||||
};
|
||||
|
||||
final uri1 = Uri(
|
||||
scheme: "https",
|
||||
host: identity.instanceUrl,
|
||||
path: "/api/v1/search",
|
||||
queryParameters: params,
|
||||
);
|
||||
final uri2 = Uri(
|
||||
scheme: "https",
|
||||
host: identity.instanceUrl,
|
||||
path: "/api/v2/search",
|
||||
queryParameters: params,
|
||||
);
|
||||
|
||||
final r1 = await http.get(uri1, headers: headers);
|
||||
|
||||
if (r1.statusCode == 200) {
|
||||
List<dynamic> accounts = jsonDecode(r1.body)["accounts"];
|
||||
if (accounts.isEmpty) {
|
||||
return {r1.statusCode: null};
|
||||
}
|
||||
return {
|
||||
r1.statusCode: AccountModel.fromJson(
|
||||
jsonDecode(r1.body)["accounts"][0],
|
||||
identityName,
|
||||
)
|
||||
};
|
||||
}
|
||||
|
||||
final r2 = await http.get(uri2, headers: headers);
|
||||
if (r2.statusCode == 200) {
|
||||
List<dynamic> accounts = jsonDecode(r2.body)["accounts"];
|
||||
if (accounts.isEmpty) {
|
||||
return {r2.statusCode: null};
|
||||
}
|
||||
return {
|
||||
r2.statusCode: AccountModel.fromJson(
|
||||
jsonDecode(r2.body)["accounts"][0],
|
||||
identityName,
|
||||
)
|
||||
};
|
||||
}
|
||||
return {r2.statusCode: null};
|
||||
}
|
||||
|
|
|
@ -65,7 +65,7 @@
|
|||
"day-6": "saturday",
|
||||
"day-7": "sunday",
|
||||
"user-is-bot": "this account is a bot",
|
||||
"you-are-mufos": "you are mufos",
|
||||
"you-are-mufos": "you are mutuals",
|
||||
"they-follow-you": "they follow you",
|
||||
"you-follow-them": "you follow them",
|
||||
"you-do-not-follow-each-other": "you don't follow each other"
|
||||
|
|
|
@ -17,15 +17,60 @@ class ProfileView extends StatefulWidget {
|
|||
}
|
||||
|
||||
class _ProfileViewState extends State<ProfileView> {
|
||||
Map<String, AccountModel> identities = {};
|
||||
String activeIdentity = "";
|
||||
|
||||
void update() async {
|
||||
for (var element in global.settings!.identities.keys) {
|
||||
final m = await searchModel(element, widget.model.url);
|
||||
if (m.values.first != null) {
|
||||
setState(() {
|
||||
identities.addAll({element: m.values.first!});
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
activeIdentity = widget.model.identity;
|
||||
identities.addAll({widget.model.identity: widget.model});
|
||||
super.initState();
|
||||
update();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
List<DropdownMenuItem<String>> dmenuItems = [];
|
||||
identities.forEach((key, value) {
|
||||
dmenuItems.add(DropdownMenuItem(
|
||||
alignment: Alignment.center,
|
||||
value: key,
|
||||
child: Text(
|
||||
key,
|
||||
style: Theme.of(context).textTheme.bodyMedium,
|
||||
),
|
||||
));
|
||||
});
|
||||
return SimpleDialog(
|
||||
alignment: Alignment.center,
|
||||
contentPadding: const EdgeInsets.all(24),
|
||||
children: [
|
||||
DropdownButton(items: [], onChanged: null),
|
||||
DropdownButtonHideUnderline(
|
||||
child: DropdownButton(
|
||||
isExpanded: false,
|
||||
alignment: Alignment.center,
|
||||
iconEnabledColor: Theme.of(context).colorScheme.onSurface,
|
||||
value: activeIdentity,
|
||||
items: dmenuItems,
|
||||
onChanged: (value) {
|
||||
setState(() {
|
||||
activeIdentity = value.toString();
|
||||
});
|
||||
},
|
||||
),
|
||||
),
|
||||
ProfileViewDisplay(
|
||||
model: widget.model,
|
||||
model: identities[activeIdentity]!,
|
||||
)
|
||||
],
|
||||
);
|
||||
|
@ -81,7 +126,7 @@ class StatusIndicators extends StatelessWidget {
|
|||
// account is a bot
|
||||
if (model.bot != null) {
|
||||
if (model.bot!) {
|
||||
c.addAll(getTextWithIcon(Icons.code, "user-is-bot".i18n()));
|
||||
c.addAll(getTextWithIcon(Icons.smart_toy, "user-is-bot".i18n()));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue