Merge branch 'krille/collapse-room-create-states' into 'main'

feat: Collapse room create states

See merge request ChristianPauly/fluffychat-flutter!294
This commit is contained in:
Christian Pauly 2020-11-22 18:54:31 +00:00
commit 500fbbf8c6
3 changed files with 45 additions and 16 deletions

View File

@ -37,6 +37,12 @@ class Message extends StatelessWidget {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
if (event.type == EventTypes.RoomCreate) {
return InkWell(
onTap: () => onSelect(event),
child: StateMessage(event),
);
}
if (![EventTypes.Message, EventTypes.Sticker, EventTypes.Encrypted] if (![EventTypes.Message, EventTypes.Sticker, EventTypes.Encrypted]
.contains(event.type)) { .contains(event.type)) {
return StateMessage(event); return StateMessage(event);

View File

@ -18,9 +18,9 @@ class StateMessage extends StatelessWidget {
), ),
child: Center( child: Center(
child: Container( child: Container(
padding: const EdgeInsets.all(4), padding: const EdgeInsets.all(8),
decoration: BoxDecoration( decoration: BoxDecoration(
color: Theme.of(context).backgroundColor.withOpacity(0.8), color: Theme.of(context).secondaryHeaderColor.withOpacity(0.9),
borderRadius: BorderRadius.circular(7), borderRadius: BorderRadius.circular(7),
), ),
child: Text( child: Text(

View File

@ -87,6 +87,8 @@ class _ChatState extends State<_Chat> {
List<Event> selectedEvents = []; List<Event> selectedEvents = [];
bool _collapseRoomCreate = true;
Event replyEvent; Event replyEvent;
Event editEvent; Event editEvent;
@ -429,7 +431,8 @@ class _ChatState extends State<_Chat> {
_updateScrollController(); _updateScrollController();
} }
List<Event> getFilteredEvents() => timeline.events List<Event> getFilteredEvents() {
final filteredEvents = timeline.events
.where((e) => .where((e) =>
// always filter out edit and reaction relationships // always filter out edit and reaction relationships
!{RelationshipTypes.Edit, RelationshipTypes.Reaction} !{RelationshipTypes.Edit, RelationshipTypes.Reaction}
@ -444,6 +447,20 @@ class _ChatState extends State<_Chat> {
(!AppConfig.hideUnknownEvents || e.isEventTypeKnown)) (!AppConfig.hideUnknownEvents || e.isEventTypeKnown))
.toList(); .toList();
// Hide state events from the room creater right after the room created event
if (_collapseRoomCreate &&
filteredEvents[filteredEvents.length - 1].type ==
EventTypes.RoomCreate) {
while (filteredEvents[filteredEvents.length - 2].senderId ==
filteredEvents[filteredEvents.length - 1].senderId &&
![EventTypes.Message, EventTypes.Sticker, EventTypes.Encrypted]
.contains(filteredEvents[filteredEvents.length - 2].type)) {
filteredEvents.removeAt(filteredEvents.length - 2);
}
}
return filteredEvents;
}
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
matrix = Matrix.of(context); matrix = Matrix.of(context);
@ -722,6 +739,12 @@ class _ChatState extends State<_Chat> {
), ),
), ),
onSelect: (Event event) { onSelect: (Event event) {
if (event.type ==
EventTypes.RoomCreate) {
return setState(() =>
_collapseRoomCreate =
false);
}
if (!event.redacted) { if (!event.redacted) {
if (selectedEvents if (selectedEvents
.contains(event)) { .contains(event)) {