chore: Follow up fix stories sorting

This commit is contained in:
Krille Fear 2022-04-08 10:12:58 +02:00
parent cb8ede3daa
commit fa0b08f57c
2 changed files with 44 additions and 38 deletions

View File

@ -1,6 +1,7 @@
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:adaptive_dialog/adaptive_dialog.dart'; import 'package:adaptive_dialog/adaptive_dialog.dart';
import 'package:collection/collection.dart';
import 'package:flutter_gen/gen_l10n/l10n.dart'; import 'package:flutter_gen/gen_l10n/l10n.dart';
import 'package:future_loading_dialog/future_loading_dialog.dart'; import 'package:future_loading_dialog/future_loading_dialog.dart';
import 'package:matrix/matrix.dart'; import 'package:matrix/matrix.dart';
@ -107,11 +108,12 @@ class StoriesHeader extends StatelessWidget {
if (client.storiesRooms.isEmpty) { if (client.storiesRooms.isEmpty) {
return Container(); return Container();
} }
final stories = client.storiesRooms final ownStoryRoom = client.storiesRooms
..sort((a, b) => .firstWhereOrNull((r) => r.creatorId == client.userID);
a.getState(EventTypes.RoomCreate)?.senderId == client.userID final stories = [
? -1 if (ownStoryRoom != null) ownStoryRoom,
: 1); ...client.storiesRooms..remove(ownStoryRoom),
];
return SizedBox( return SizedBox(
height: 106, height: 106,
child: ListView.builder( child: ListView.builder(
@ -125,16 +127,16 @@ class StoriesHeader extends StatelessWidget {
child: FutureBuilder<Profile>( child: FutureBuilder<Profile>(
future: room.getCreatorProfile(), future: room.getCreatorProfile(),
builder: (context, snapshot) { builder: (context, snapshot) {
final userId = final userId = room.creatorId;
room.getState(EventTypes.RoomCreate)!.senderId; final displayname = snapshot.data?.displayName ??
final displayname = userId?.localpart ??
snapshot.data?.displayName ?? userId.localpart!; 'Unknown';
final avatarUrl = snapshot.data?.avatarUrl; final avatarUrl = snapshot.data?.avatarUrl;
return _StoryButton( return _StoryButton(
profile: Profile( profile: Profile(
displayName: displayname, displayName: displayname,
avatarUrl: avatarUrl, avatarUrl: avatarUrl,
userId: userId, userId: userId ?? 'Unknown',
), ),
showEditFab: userId == client.userID, showEditFab: userId == client.userID,
unread: room.membership == Membership.invite || unread: room.membership == Membership.invite ||
@ -284,3 +286,7 @@ class _StoryButton extends StatelessWidget {
); );
} }
} }
extension on Room {
String? get creatorId => getState(EventTypes.RoomCreate)?.senderId;
}

View File

@ -225,34 +225,34 @@ class StoryView extends StatelessWidget {
); );
}, },
), ),
AnimatedContainer( GestureDetector(
duration: const Duration(milliseconds: 200), onTapDown: controller.hold,
padding: const EdgeInsets.all(16.0), onTapUp: controller.unhold,
decoration: BoxDecoration( onTapCancel: controller.unhold,
gradient: event.messageType == MessageTypes.Text onVerticalDragStart: controller.hold,
? LinearGradient( onVerticalDragEnd: controller.unhold,
colors: [ onHorizontalDragStart: controller.hold,
backgroundColorDark, onHorizontalDragEnd: controller.unhold,
backgroundColor, child: AnimatedContainer(
], duration: const Duration(milliseconds: 200),
begin: Alignment.topCenter, padding: const EdgeInsets.all(16.0),
end: Alignment.bottomCenter, decoration: BoxDecoration(
) gradient: event.messageType == MessageTypes.Text
: null, ? LinearGradient(
), colors: [
alignment: Alignment( backgroundColorDark,
controller.storyThemeData.alignmentX.toDouble() / 100, backgroundColor,
controller.storyThemeData.alignmentY.toDouble() / 100, ],
), begin: Alignment.topCenter,
child: SafeArea( end: Alignment.bottomCenter,
child: GestureDetector( )
onTapDown: controller.hold, : null,
onTapUp: controller.unhold, ),
onTapCancel: controller.unhold, alignment: Alignment(
onVerticalDragStart: controller.hold, controller.storyThemeData.alignmentX.toDouble() / 100,
onVerticalDragEnd: controller.unhold, controller.storyThemeData.alignmentY.toDouble() / 100,
onHorizontalDragStart: controller.hold, ),
onHorizontalDragEnd: controller.unhold, child: SafeArea(
child: LinkText( child: LinkText(
text: controller.loadingMode text: controller.loadingMode
? L10n.of(context)!.loadingPleaseWait ? L10n.of(context)!.loadingPleaseWait