mirror of
https://github.com/krille-chan/fluffychat
synced 2024-09-10 13:05:11 +00:00
fix: Only load first pinned event
This commit is contained in:
parent
2f1720a770
commit
3d06006ca4
1 changed files with 21 additions and 24 deletions
|
@ -5,6 +5,7 @@ import 'package:flutter/material.dart';
|
||||||
import 'package:adaptive_dialog/adaptive_dialog.dart';
|
import 'package:adaptive_dialog/adaptive_dialog.dart';
|
||||||
import 'package:flutter_gen/gen_l10n/l10n.dart';
|
import 'package:flutter_gen/gen_l10n/l10n.dart';
|
||||||
import 'package:flutter_linkify/flutter_linkify.dart';
|
import 'package:flutter_linkify/flutter_linkify.dart';
|
||||||
|
import 'package:future_loading_dialog/future_loading_dialog.dart';
|
||||||
import 'package:matrix/matrix.dart';
|
import 'package:matrix/matrix.dart';
|
||||||
|
|
||||||
import 'package:fluffychat/config/app_config.dart';
|
import 'package:fluffychat/config/app_config.dart';
|
||||||
|
@ -17,10 +18,18 @@ class PinnedEvents extends StatelessWidget {
|
||||||
|
|
||||||
const PinnedEvents(this.controller, {super.key});
|
const PinnedEvents(this.controller, {super.key});
|
||||||
|
|
||||||
Future<void> _displayPinnedEventsDialog(
|
Future<void> _displayPinnedEventsDialog(BuildContext context) async {
|
||||||
BuildContext context,
|
final eventsResult = await showFutureLoadingDialog(
|
||||||
List<Event?> events,
|
context: context,
|
||||||
) async {
|
future: () => Future.wait(
|
||||||
|
controller.room.pinnedEventIds.map(
|
||||||
|
(eventId) => controller.room.getEventById(eventId),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
final events = eventsResult.result;
|
||||||
|
if (events == null) return;
|
||||||
|
|
||||||
final eventId = events.length == 1
|
final eventId = events.length == 1
|
||||||
? events.single?.eventId
|
? events.single?.eventId
|
||||||
: await showConfirmationDialog<String>(
|
: await showConfirmationDialog<String>(
|
||||||
|
@ -51,23 +60,14 @@ class PinnedEvents extends StatelessWidget {
|
||||||
if (pinnedEventIds.isEmpty) {
|
if (pinnedEventIds.isEmpty) {
|
||||||
return const SizedBox.shrink();
|
return const SizedBox.shrink();
|
||||||
}
|
}
|
||||||
final completers = pinnedEventIds.map<Completer<Event?>>((e) {
|
|
||||||
final completer = Completer<Event?>();
|
|
||||||
controller.room
|
|
||||||
.getEventById(e)
|
|
||||||
.then((value) => completer.complete(value));
|
|
||||||
return completer;
|
|
||||||
});
|
|
||||||
return FutureBuilder<List<Event?>>(
|
|
||||||
future: Future.wait(completers.map((e) => e.future).toList()),
|
|
||||||
builder: (context, snapshot) {
|
|
||||||
final pinnedEvents = snapshot.data;
|
|
||||||
final event = (pinnedEvents != null && pinnedEvents.isNotEmpty)
|
|
||||||
? snapshot.data?.last
|
|
||||||
: null;
|
|
||||||
|
|
||||||
if (event == null || pinnedEvents == null) {
|
return FutureBuilder<Event?>(
|
||||||
return Container();
|
future: controller.room.getEventById(pinnedEventIds.last),
|
||||||
|
builder: (context, snapshot) {
|
||||||
|
final event = snapshot.data;
|
||||||
|
|
||||||
|
if (event == null) {
|
||||||
|
return const SizedBox.shrink();
|
||||||
}
|
}
|
||||||
|
|
||||||
final fontSize = AppConfig.messageFontSize * AppConfig.fontSizeFactor;
|
final fontSize = AppConfig.messageFontSize * AppConfig.fontSizeFactor;
|
||||||
|
@ -80,10 +80,7 @@ class PinnedEvents extends StatelessWidget {
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
child: InkWell(
|
child: InkWell(
|
||||||
onTap: () => _displayPinnedEventsDialog(
|
onTap: () => _displayPinnedEventsDialog(context),
|
||||||
context,
|
|
||||||
pinnedEvents,
|
|
||||||
),
|
|
||||||
child: Row(
|
child: Row(
|
||||||
children: [
|
children: [
|
||||||
IconButton(
|
IconButton(
|
||||||
|
|
Loading…
Reference in a new issue