feat: Nicer room creation UI
This commit is contained in:
parent
0301c83f40
commit
3faf6df558
5 changed files with 78 additions and 9 deletions
|
|
@ -261,8 +261,7 @@ class ChatController extends State<ChatPageWithRoom>
|
||||||
var readMarkerEventIndex = readMarkerEventId.isEmpty
|
var readMarkerEventIndex = readMarkerEventId.isEmpty
|
||||||
? -1
|
? -1
|
||||||
: timeline!.events
|
: timeline!.events
|
||||||
.where((e) => e.isVisibleInGui || e.eventId == readMarkerEventId)
|
.filterByVisibleInGui(exceptionEventId: readMarkerEventId)
|
||||||
.toList()
|
|
||||||
.indexWhere((e) => e.eventId == readMarkerEventId);
|
.indexWhere((e) => e.eventId == readMarkerEventId);
|
||||||
|
|
||||||
// Read marker is existing but not found in first events. Try a single
|
// Read marker is existing but not found in first events. Try a single
|
||||||
|
|
@ -270,8 +269,7 @@ class ChatController extends State<ChatPageWithRoom>
|
||||||
if (readMarkerEventId.isNotEmpty && readMarkerEventIndex == -1) {
|
if (readMarkerEventId.isNotEmpty && readMarkerEventIndex == -1) {
|
||||||
await timeline?.requestHistory(historyCount: _loadHistoryCount);
|
await timeline?.requestHistory(historyCount: _loadHistoryCount);
|
||||||
readMarkerEventIndex = timeline!.events
|
readMarkerEventIndex = timeline!.events
|
||||||
.where((e) => e.isVisibleInGui || e.eventId == readMarkerEventId)
|
.filterByVisibleInGui(exceptionEventId: readMarkerEventId)
|
||||||
.toList()
|
|
||||||
.indexWhere((e) => e.eventId == readMarkerEventId);
|
.indexWhere((e) => e.eventId == readMarkerEventId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -868,8 +866,7 @@ class ChatController extends State<ChatPageWithRoom>
|
||||||
final eventIndex = foundEvent == null
|
final eventIndex = foundEvent == null
|
||||||
? -1
|
? -1
|
||||||
: timeline!.events
|
: timeline!.events
|
||||||
.where((event) => event.isVisibleInGui || event.eventId == eventId)
|
.filterByVisibleInGui(exceptionEventId: eventId)
|
||||||
.toList()
|
|
||||||
.indexOf(foundEvent);
|
.indexOf(foundEvent);
|
||||||
|
|
||||||
if (eventIndex == -1) {
|
if (eventIndex == -1) {
|
||||||
|
|
|
||||||
|
|
@ -25,9 +25,7 @@ class ChatEventList extends StatelessWidget {
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
final horizontalPadding = FluffyThemes.isColumnMode(context) ? 8.0 : 0.0;
|
final horizontalPadding = FluffyThemes.isColumnMode(context) ? 8.0 : 0.0;
|
||||||
|
|
||||||
final events = controller.timeline!.events
|
final events = controller.timeline!.events.filterByVisibleInGui();
|
||||||
.where((event) => event.isVisibleInGui)
|
|
||||||
.toList();
|
|
||||||
final animateInEventIndex = controller.animateInEventIndex;
|
final animateInEventIndex = controller.animateInEventIndex;
|
||||||
|
|
||||||
// create a map of eventId --> index to greatly improve performance of
|
// create a map of eventId --> index to greatly improve performance of
|
||||||
|
|
|
||||||
|
|
@ -6,6 +6,7 @@ import 'package:matrix/matrix.dart';
|
||||||
import 'package:swipe_to_action/swipe_to_action.dart';
|
import 'package:swipe_to_action/swipe_to_action.dart';
|
||||||
|
|
||||||
import 'package:fluffychat/config/themes.dart';
|
import 'package:fluffychat/config/themes.dart';
|
||||||
|
import 'package:fluffychat/pages/chat/events/room_creation_state_event.dart';
|
||||||
import 'package:fluffychat/utils/date_time_extension.dart';
|
import 'package:fluffychat/utils/date_time_extension.dart';
|
||||||
import 'package:fluffychat/utils/string_color.dart';
|
import 'package:fluffychat/utils/string_color.dart';
|
||||||
import 'package:fluffychat/widgets/avatar.dart';
|
import 'package:fluffychat/widgets/avatar.dart';
|
||||||
|
|
@ -68,6 +69,9 @@ class Message extends StatelessWidget {
|
||||||
if (event.type.startsWith('m.call.')) {
|
if (event.type.startsWith('m.call.')) {
|
||||||
return const SizedBox.shrink();
|
return const SizedBox.shrink();
|
||||||
}
|
}
|
||||||
|
if (event.type == EventTypes.RoomCreate) {
|
||||||
|
return RoomCreationStateEvent(event: event);
|
||||||
|
}
|
||||||
return StateMessage(event);
|
return StateMessage(event);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
40
lib/pages/chat/events/room_creation_state_event.dart
Normal file
40
lib/pages/chat/events/room_creation_state_event.dart
Normal file
|
|
@ -0,0 +1,40 @@
|
||||||
|
import 'package:flutter/material.dart';
|
||||||
|
|
||||||
|
import 'package:flutter_gen/gen_l10n/l10n.dart';
|
||||||
|
import 'package:matrix/matrix.dart';
|
||||||
|
|
||||||
|
import 'package:fluffychat/utils/date_time_extension.dart';
|
||||||
|
import 'package:fluffychat/utils/matrix_sdk_extensions/matrix_locals.dart';
|
||||||
|
import 'package:fluffychat/widgets/avatar.dart';
|
||||||
|
|
||||||
|
class RoomCreationStateEvent extends StatelessWidget {
|
||||||
|
final Event event;
|
||||||
|
const RoomCreationStateEvent({required this.event, super.key});
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
final l10n = L10n.of(context);
|
||||||
|
final matrixLocals = MatrixLocals(l10n);
|
||||||
|
final theme = Theme.of(context);
|
||||||
|
final roomName = event.room.getLocalizedDisplayname(matrixLocals);
|
||||||
|
return Column(
|
||||||
|
mainAxisSize: MainAxisSize.min,
|
||||||
|
children: [
|
||||||
|
Avatar(
|
||||||
|
mxContent: event.room.avatar,
|
||||||
|
name: roomName,
|
||||||
|
size: Avatar.defaultSize * 2,
|
||||||
|
),
|
||||||
|
Text(
|
||||||
|
roomName,
|
||||||
|
style: theme.textTheme.headlineSmall,
|
||||||
|
),
|
||||||
|
Text(
|
||||||
|
'${event.originServerTs.localizedTime(context)} | ${l10n.countParticipants((event.room.summary.mJoinedMemberCount ?? 1) + (event.room.summary.mInvitedMemberCount ?? 0))}',
|
||||||
|
style: theme.textTheme.labelSmall,
|
||||||
|
),
|
||||||
|
const SizedBox(height: 48),
|
||||||
|
],
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -2,6 +2,36 @@ import 'package:matrix/matrix.dart';
|
||||||
|
|
||||||
import '../../config/app_config.dart';
|
import '../../config/app_config.dart';
|
||||||
|
|
||||||
|
extension VisibleInGuiExtension on List<Event> {
|
||||||
|
List<Event> filterByVisibleInGui({String? exceptionEventId}) {
|
||||||
|
final visibleEvents =
|
||||||
|
where((e) => e.isVisibleInGui || e.eventId == exceptionEventId)
|
||||||
|
.toList();
|
||||||
|
|
||||||
|
// Hide creation state events:
|
||||||
|
if (visibleEvents.isNotEmpty &&
|
||||||
|
visibleEvents.last.type == EventTypes.RoomCreate) {
|
||||||
|
var i = visibleEvents.length - 2;
|
||||||
|
while (i > 0) {
|
||||||
|
final event = visibleEvents[i];
|
||||||
|
if (!event.isState) break;
|
||||||
|
if (event.type == EventTypes.Encryption) {
|
||||||
|
i--;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (event.type == EventTypes.RoomMember &&
|
||||||
|
event.roomMemberChangeType == RoomMemberChangeType.acceptInvite) {
|
||||||
|
i--;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
visibleEvents.removeAt(i);
|
||||||
|
i--;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return visibleEvents;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
extension IsStateExtension on Event {
|
extension IsStateExtension on Event {
|
||||||
bool get isVisibleInGui =>
|
bool get isVisibleInGui =>
|
||||||
// always filter out edit and reaction relationships
|
// always filter out edit and reaction relationships
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue