account display is done!
This commit is contained in:
parent
2b0671d785
commit
0f01665ad0
|
@ -198,9 +198,10 @@ Future<MapEntry<int, List<ThreadModel>?>> getPostsForAccount(
|
|||
headers.addAll(global.defaultHeaders);
|
||||
final params = {
|
||||
"limit": global.settings!.batchSize.toString(),
|
||||
if (maxid != null) "maxid": maxid,
|
||||
if (maxid != null) "max_id": maxid,
|
||||
};
|
||||
final uri = Uri(
|
||||
scheme: "https",
|
||||
host: identity.instanceUrl,
|
||||
path: "/api/v1/accounts/${model.id}/statuses",
|
||||
queryParameters: params,
|
||||
|
@ -211,17 +212,16 @@ Future<MapEntry<int, List<ThreadModel>?>> getPostsForAccount(
|
|||
return MapEntry(r.statusCode, null);
|
||||
}
|
||||
|
||||
final List<Map<String, dynamic>> rb = jsonDecode(r.body);
|
||||
final List<dynamic> rb = jsonDecode(r.body);
|
||||
List<ThreadModel> threads = [];
|
||||
// ignore: avoid_function_literals_in_foreach_calls
|
||||
rb.forEach((element) async {
|
||||
for (var element in rb) {
|
||||
threads.add(
|
||||
await PostModel.fromJson(
|
||||
element,
|
||||
model.identity,
|
||||
).getThread(),
|
||||
);
|
||||
});
|
||||
}
|
||||
return MapEntry(r.statusCode, threads);
|
||||
}
|
||||
|
||||
|
|
|
@ -168,7 +168,7 @@ class _MakePostState extends State<MakePost> {
|
|||
},
|
||||
),
|
||||
),
|
||||
OutlinedButton.icon(
|
||||
ElevatedButton.icon(
|
||||
label: Text(
|
||||
"send-post".i18n(),
|
||||
),
|
||||
|
|
|
@ -4,9 +4,12 @@ import 'package:flutter/material.dart';
|
|||
import 'package:localization/localization.dart';
|
||||
import 'package:loris/business_logic/account/account.dart';
|
||||
import 'package:loris/business_logic/settings.dart';
|
||||
import 'package:loris/business_logic/timeline/timeline.dart';
|
||||
import 'package:loris/partials/loadingbox.dart';
|
||||
import 'package:loris/partials/post.dart';
|
||||
import 'package:loris/partials/post_text_renderer.dart';
|
||||
import 'package:loris/global.dart' as global;
|
||||
import 'package:loris/partials/thread.dart';
|
||||
|
||||
class ProfileView extends StatefulWidget {
|
||||
const ProfileView({
|
||||
|
@ -25,6 +28,9 @@ class _ProfileViewState extends State<ProfileView> {
|
|||
Map<String, RelationshipModel?> relationships = {};
|
||||
String activeIdentity = "";
|
||||
bool loading = true;
|
||||
List<ThreadModel> threads = [];
|
||||
String? maxid;
|
||||
final ScrollController _scrollController = ScrollController();
|
||||
|
||||
Future<void> addRelationship(AccountModel m) async {
|
||||
final r = await getRelationship(m.identity, m.id);
|
||||
|
@ -50,12 +56,39 @@ class _ProfileViewState extends State<ProfileView> {
|
|||
await addRelationship(m.values.first!);
|
||||
}
|
||||
if (i >= global.settings!.identities.length) {
|
||||
if (mounted) {
|
||||
setState(() {
|
||||
loading = false;
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void loadPosts() async {
|
||||
if (threads.isNotEmpty) {
|
||||
maxid = threads.last.posts.last.id;
|
||||
}
|
||||
|
||||
final t = await getPostsForAccount(identities[activeIdentity]!, maxid);
|
||||
if (t.value == null) {
|
||||
return;
|
||||
}
|
||||
if (mounted) {
|
||||
setState(() {
|
||||
loading = false;
|
||||
threads.addAll(t.value!);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
void reloadPosts() async {
|
||||
_scrollController.animateTo(0,
|
||||
duration: const Duration(seconds: 1), curve: Curves.ease);
|
||||
setState(() {
|
||||
threads = [];
|
||||
});
|
||||
loadPosts();
|
||||
}
|
||||
|
||||
void update() async {
|
||||
int i = 0;
|
||||
await Future.forEach<MapEntry<String, AccountSettings>>(
|
||||
|
@ -74,6 +107,7 @@ class _ProfileViewState extends State<ProfileView> {
|
|||
|
||||
@override
|
||||
void dispose() {
|
||||
_scrollController.dispose();
|
||||
_relationshipStream.close();
|
||||
super.dispose();
|
||||
}
|
||||
|
@ -83,6 +117,15 @@ class _ProfileViewState extends State<ProfileView> {
|
|||
activeIdentity = widget.model.identity;
|
||||
identities.addAll({widget.model.identity: widget.model});
|
||||
update();
|
||||
loadPosts();
|
||||
_scrollController.addListener(() {
|
||||
if (_scrollController.offset >=
|
||||
_scrollController.position.maxScrollExtent -
|
||||
MediaQuery.of(context).size.height &&
|
||||
!_scrollController.position.outOfRange) {
|
||||
loadPosts();
|
||||
}
|
||||
});
|
||||
_relationshipStream.stream.listen((event) {
|
||||
setState(() {
|
||||
relationships.addEntries([event]);
|
||||
|
@ -106,6 +149,13 @@ class _ProfileViewState extends State<ProfileView> {
|
|||
),
|
||||
);
|
||||
});
|
||||
|
||||
final profileViewDisplay = ProfileViewDisplay(
|
||||
accountModel: identities[activeIdentity]!,
|
||||
relationshipModel: relationships[activeIdentity],
|
||||
relationshipStream: _relationshipStream,
|
||||
);
|
||||
|
||||
return SimpleDialog(
|
||||
alignment: Alignment.center,
|
||||
title: DisplayName(
|
||||
|
@ -136,16 +186,31 @@ class _ProfileViewState extends State<ProfileView> {
|
|||
setState(() {
|
||||
activeIdentity = value.toString();
|
||||
});
|
||||
reloadPosts();
|
||||
},
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
ProfileViewDisplay(
|
||||
accountModel: identities[activeIdentity]!,
|
||||
relationshipModel: relationships[activeIdentity],
|
||||
stream: _relationshipStream,
|
||||
)
|
||||
Container(
|
||||
constraints: global.getConstraints(context),
|
||||
width: global.getWidth(context),
|
||||
height: MediaQuery.of(context).size.height * 2 / 3,
|
||||
child: ListView.builder(
|
||||
controller: _scrollController,
|
||||
shrinkWrap: true,
|
||||
itemCount: threads.length + 2,
|
||||
itemBuilder: (context, index) {
|
||||
if (index == 0) {
|
||||
return profileViewDisplay;
|
||||
} else if (index > 0 && index <= threads.length) {
|
||||
return Thread(model: threads[index - 1]);
|
||||
}
|
||||
|
||||
return const LoadingBox();
|
||||
},
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
@ -247,11 +312,11 @@ class ProfileViewDisplay extends StatelessWidget {
|
|||
super.key,
|
||||
required this.accountModel,
|
||||
this.relationshipModel,
|
||||
required this.stream,
|
||||
required this.relationshipStream,
|
||||
});
|
||||
final AccountModel accountModel;
|
||||
final RelationshipModel? relationshipModel;
|
||||
final StreamController stream;
|
||||
final StreamController relationshipStream;
|
||||
static const d = SizedBox(
|
||||
height: 8,
|
||||
);
|
||||
|
@ -275,11 +340,8 @@ class ProfileViewDisplay extends StatelessWidget {
|
|||
AccountInteractionButtons(
|
||||
account: accountModel,
|
||||
relationship: relationshipModel!,
|
||||
stream: stream,
|
||||
stream: relationshipStream,
|
||||
),
|
||||
AccountPostList(
|
||||
accountModel: accountModel,
|
||||
),
|
||||
];
|
||||
|
||||
return Container(
|
||||
|
@ -293,29 +355,6 @@ class ProfileViewDisplay extends StatelessWidget {
|
|||
}
|
||||
}
|
||||
|
||||
class AccountPostList extends StatefulWidget {
|
||||
const AccountPostList({
|
||||
super.key,
|
||||
required this.accountModel,
|
||||
});
|
||||
final AccountModel accountModel;
|
||||
|
||||
@override
|
||||
State<AccountPostList> createState() => _AccountPostListState();
|
||||
}
|
||||
|
||||
class _AccountPostListState extends State<AccountPostList> {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Container(
|
||||
constraints: BoxConstraints(
|
||||
maxHeight: MediaQuery.of(context).size.height,
|
||||
),
|
||||
child: ListView(),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class AccountInteractionButton extends StatefulWidget {
|
||||
const AccountInteractionButton({
|
||||
super.key,
|
||||
|
|
|
@ -231,7 +231,7 @@ class _PostBodyState extends State<PostBody> {
|
|||
TextSpan(
|
||||
children: [
|
||||
WidgetSpan(
|
||||
child: OutlinedButton.icon(
|
||||
child: ElevatedButton.icon(
|
||||
onPressed: () {
|
||||
setState(() {
|
||||
visible = !visible;
|
||||
|
|
|
@ -57,7 +57,7 @@ class _ThreadState extends State<Thread> {
|
|||
Expanded(
|
||||
child: SelectableText(s),
|
||||
),
|
||||
OutlinedButton.icon(
|
||||
ElevatedButton.icon(
|
||||
onPressed: () {
|
||||
setState(() {
|
||||
showSensitive = !showSensitive;
|
||||
|
|
Loading…
Reference in New Issue