2021-09-19 13:48:23 +02:00
|
|
|
import 'dart:math';
|
|
|
|
|
2021-10-26 18:50:34 +02:00
|
|
|
import 'package:flutter/cupertino.dart';
|
|
|
|
import 'package:flutter/foundation.dart';
|
|
|
|
import 'package:flutter/material.dart';
|
2021-09-19 13:48:23 +02:00
|
|
|
import 'package:flutter/widgets.dart';
|
2021-10-26 18:50:34 +02:00
|
|
|
|
|
|
|
import 'package:async/async.dart';
|
|
|
|
import 'package:flutter_gen/gen_l10n/l10n.dart';
|
2021-06-18 10:29:48 +02:00
|
|
|
import 'package:matrix/matrix.dart';
|
2021-10-26 18:50:34 +02:00
|
|
|
import 'package:vrouter/vrouter.dart';
|
|
|
|
|
|
|
|
import 'package:fluffychat/config/app_config.dart';
|
|
|
|
import 'package:fluffychat/config/themes.dart';
|
2021-05-22 08:57:49 +02:00
|
|
|
import 'package:fluffychat/pages/chat_list.dart';
|
2021-10-26 18:50:34 +02:00
|
|
|
import 'package:fluffychat/widgets/avatar.dart';
|
2021-05-22 08:53:52 +02:00
|
|
|
import 'package:fluffychat/widgets/connection_status_header.dart';
|
|
|
|
import 'package:fluffychat/widgets/list_items/chat_list_item.dart';
|
2021-09-19 13:48:23 +02:00
|
|
|
import '../../utils/account_bundles.dart';
|
2021-07-31 12:31:31 +02:00
|
|
|
import '../../utils/stream_extension.dart';
|
2021-10-26 18:50:34 +02:00
|
|
|
import '../../widgets/matrix.dart';
|
2021-04-14 14:09:46 +02:00
|
|
|
|
2021-05-22 09:13:47 +02:00
|
|
|
class ChatListView extends StatelessWidget {
|
2021-04-14 14:09:46 +02:00
|
|
|
final ChatListController controller;
|
|
|
|
|
2021-05-22 09:13:47 +02:00
|
|
|
const ChatListView(this.controller, {Key key}) : super(key: key);
|
2021-04-14 14:09:46 +02:00
|
|
|
|
2021-09-19 13:48:23 +02:00
|
|
|
List<BottomNavigationBarItem> getBottomBarItems(BuildContext context) {
|
|
|
|
final displayClients = Matrix.of(context).currentBundle;
|
|
|
|
if (displayClients.isEmpty) {
|
|
|
|
displayClients.addAll(Matrix.of(context).widget.clients);
|
|
|
|
controller.resetActiveBundle();
|
|
|
|
}
|
|
|
|
final items = displayClients.map((client) {
|
|
|
|
return BottomNavigationBarItem(
|
|
|
|
label: client.userID,
|
|
|
|
icon: FutureBuilder<Profile>(
|
|
|
|
future: client.ownProfile,
|
|
|
|
builder: (context, snapshot) {
|
|
|
|
return InkWell(
|
|
|
|
borderRadius: BorderRadius.circular(32),
|
|
|
|
onTap: () => controller.setActiveClient(client),
|
|
|
|
onLongPress: () =>
|
|
|
|
controller.editBundlesForAccount(client.userID),
|
|
|
|
child: Avatar(
|
|
|
|
snapshot.data?.avatarUrl,
|
|
|
|
snapshot.data?.displayName ?? client.userID.localpart,
|
|
|
|
size: 32,
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}),
|
|
|
|
);
|
|
|
|
}).toList();
|
|
|
|
|
|
|
|
if (controller.displayBundles && false) {
|
|
|
|
items.insert(
|
|
|
|
0,
|
|
|
|
BottomNavigationBarItem(
|
|
|
|
label: 'Bundles',
|
|
|
|
icon: PopupMenuButton(
|
|
|
|
icon: Icon(
|
|
|
|
Icons.menu,
|
|
|
|
color: Theme.of(context).textTheme.bodyText1.color,
|
|
|
|
),
|
|
|
|
onSelected: controller.setActiveBundle,
|
|
|
|
itemBuilder: (context) => Matrix.of(context)
|
|
|
|
.accountBundles
|
|
|
|
.keys
|
|
|
|
.map(
|
|
|
|
(bundle) => PopupMenuItem(
|
|
|
|
value: bundle,
|
|
|
|
child: Text(bundle),
|
|
|
|
),
|
|
|
|
)
|
|
|
|
.toList(),
|
|
|
|
)));
|
|
|
|
}
|
|
|
|
return items;
|
|
|
|
}
|
|
|
|
|
2021-04-14 14:09:46 +02:00
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
return StreamBuilder<Object>(
|
|
|
|
stream: Matrix.of(context).onShareContentChanged.stream,
|
|
|
|
builder: (_, __) {
|
2021-05-31 20:41:46 +02:00
|
|
|
final selectMode = controller.selectMode;
|
2021-05-26 20:28:08 +02:00
|
|
|
return VWidgetGuard(
|
2021-08-01 07:45:34 +02:00
|
|
|
onSystemPop: (redirector) async {
|
|
|
|
final selMode = controller.selectMode;
|
|
|
|
if (selMode != SelectMode.normal) controller.cancelAction();
|
|
|
|
if (selMode == SelectMode.select) redirector.stopRedirection();
|
|
|
|
},
|
|
|
|
child: Scaffold(
|
|
|
|
appBar: AppBar(
|
2021-08-29 11:29:14 +02:00
|
|
|
elevation: controller.scrolledToTop ? 0 : null,
|
2021-08-12 21:10:26 +02:00
|
|
|
actionsIconTheme: IconThemeData(
|
|
|
|
color: controller.selectedRoomIds.isEmpty
|
|
|
|
? null
|
|
|
|
: Theme.of(context).colorScheme.primary,
|
|
|
|
),
|
2021-08-01 07:45:34 +02:00
|
|
|
leading: selectMode == SelectMode.normal
|
|
|
|
? controller.spaces.isEmpty
|
|
|
|
? null
|
|
|
|
: Builder(
|
|
|
|
builder: (context) => IconButton(
|
2021-10-14 18:09:30 +02:00
|
|
|
icon: const Icon(Icons.group_work_outlined),
|
2021-08-01 07:45:34 +02:00
|
|
|
onPressed: Scaffold.of(context).openDrawer,
|
|
|
|
))
|
|
|
|
: IconButton(
|
|
|
|
tooltip: L10n.of(context).cancel,
|
2021-10-14 18:09:30 +02:00
|
|
|
icon: const Icon(Icons.close_outlined),
|
2021-08-01 07:45:34 +02:00
|
|
|
onPressed: controller.cancelAction,
|
2021-08-12 21:10:26 +02:00
|
|
|
color: Theme.of(context).colorScheme.primary,
|
2021-08-01 07:45:34 +02:00
|
|
|
),
|
|
|
|
centerTitle: false,
|
|
|
|
titleSpacing: controller.spaces.isEmpty ? null : 0,
|
|
|
|
actions: selectMode == SelectMode.share
|
|
|
|
? null
|
|
|
|
: selectMode == SelectMode.select
|
|
|
|
? [
|
2021-08-12 20:46:21 +02:00
|
|
|
if (controller.selectedRoomIds.length == 1 &&
|
2021-08-12 21:11:57 +02:00
|
|
|
controller.spaces.isNotEmpty &&
|
|
|
|
!Matrix.of(context)
|
|
|
|
.client
|
|
|
|
.getRoomById(
|
|
|
|
controller.selectedRoomIds.single)
|
|
|
|
.isDirectChat)
|
2021-08-12 20:46:21 +02:00
|
|
|
IconButton(
|
|
|
|
tooltip: L10n.of(context).addToSpace,
|
2021-10-14 18:09:30 +02:00
|
|
|
icon: const Icon(Icons.group_work_outlined),
|
2021-08-12 20:46:21 +02:00
|
|
|
onPressed: controller.addOrRemoveToSpace,
|
|
|
|
),
|
2021-08-01 07:45:34 +02:00
|
|
|
if (controller.selectedRoomIds.length == 1)
|
2021-05-26 20:50:15 +02:00
|
|
|
IconButton(
|
2021-08-01 07:45:34 +02:00
|
|
|
tooltip: L10n.of(context).toggleUnread,
|
|
|
|
icon: Icon(Matrix.of(context)
|
|
|
|
.client
|
|
|
|
.getRoomById(
|
|
|
|
controller.selectedRoomIds.single)
|
|
|
|
.isUnread
|
|
|
|
? Icons.mark_chat_read_outlined
|
|
|
|
: Icons.mark_chat_unread_outlined),
|
|
|
|
onPressed: controller.toggleUnread,
|
2021-04-14 14:09:46 +02:00
|
|
|
),
|
2021-08-01 07:45:34 +02:00
|
|
|
if (controller.selectedRoomIds.length == 1)
|
2021-05-26 20:50:15 +02:00
|
|
|
IconButton(
|
2021-08-01 07:45:34 +02:00
|
|
|
tooltip: L10n.of(context).toggleFavorite,
|
2021-10-14 18:09:30 +02:00
|
|
|
icon: const Icon(Icons.push_pin_outlined),
|
2021-08-01 07:45:34 +02:00
|
|
|
onPressed: controller.toggleFavouriteRoom,
|
2021-04-14 14:09:46 +02:00
|
|
|
),
|
2021-08-01 07:45:34 +02:00
|
|
|
if (controller.selectedRoomIds.length == 1)
|
|
|
|
IconButton(
|
|
|
|
icon: Icon(Matrix.of(context)
|
|
|
|
.client
|
|
|
|
.getRoomById(controller
|
|
|
|
.selectedRoomIds.single)
|
|
|
|
.pushRuleState ==
|
|
|
|
PushRuleState.notify
|
|
|
|
? Icons.notifications_off_outlined
|
|
|
|
: Icons.notifications_outlined),
|
|
|
|
tooltip: L10n.of(context).toggleMuted,
|
|
|
|
onPressed: controller.toggleMuted,
|
|
|
|
),
|
|
|
|
IconButton(
|
2021-10-14 18:09:30 +02:00
|
|
|
icon: const Icon(Icons.delete_outlined),
|
2021-08-01 07:45:34 +02:00
|
|
|
tooltip: L10n.of(context).archive,
|
|
|
|
onPressed: controller.archiveAction,
|
|
|
|
),
|
|
|
|
]
|
|
|
|
: [
|
|
|
|
IconButton(
|
2021-10-14 18:09:30 +02:00
|
|
|
icon: const Icon(Icons.search_outlined),
|
2021-08-01 07:45:34 +02:00
|
|
|
tooltip: L10n.of(context).search,
|
|
|
|
onPressed: () =>
|
|
|
|
VRouter.of(context).to('/search'),
|
|
|
|
),
|
|
|
|
PopupMenuButton<PopupMenuAction>(
|
|
|
|
onSelected: controller.onPopupMenuSelect,
|
|
|
|
itemBuilder: (_) => [
|
|
|
|
PopupMenuItem(
|
|
|
|
value: PopupMenuAction.setStatus,
|
|
|
|
child: Row(
|
|
|
|
mainAxisSize: MainAxisSize.min,
|
|
|
|
children: [
|
2021-10-14 18:09:30 +02:00
|
|
|
const Icon(Icons.edit_outlined),
|
|
|
|
const SizedBox(width: 12),
|
2021-08-01 07:45:34 +02:00
|
|
|
Text(L10n.of(context).setStatus),
|
|
|
|
],
|
2021-05-26 20:50:15 +02:00
|
|
|
),
|
2021-08-01 07:45:34 +02:00
|
|
|
),
|
|
|
|
PopupMenuItem(
|
|
|
|
value: PopupMenuAction.newGroup,
|
|
|
|
child: Row(
|
|
|
|
mainAxisSize: MainAxisSize.min,
|
|
|
|
children: [
|
2021-10-14 18:09:30 +02:00
|
|
|
const Icon(Icons.group_add_outlined),
|
|
|
|
const SizedBox(width: 12),
|
2021-08-01 07:45:34 +02:00
|
|
|
Text(L10n.of(context).createNewGroup),
|
|
|
|
],
|
2021-05-26 20:50:15 +02:00
|
|
|
),
|
2021-08-01 07:45:34 +02:00
|
|
|
),
|
2021-08-01 08:05:40 +02:00
|
|
|
PopupMenuItem(
|
|
|
|
value: PopupMenuAction.newSpace,
|
|
|
|
child: Row(
|
|
|
|
mainAxisSize: MainAxisSize.min,
|
|
|
|
children: [
|
2021-10-14 18:09:30 +02:00
|
|
|
const Icon(Icons.group_work_outlined),
|
|
|
|
const SizedBox(width: 12),
|
2021-08-01 08:05:40 +02:00
|
|
|
Text(L10n.of(context).createNewSpace),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
),
|
2021-08-01 07:45:34 +02:00
|
|
|
PopupMenuItem(
|
|
|
|
value: PopupMenuAction.invite,
|
|
|
|
child: Row(
|
|
|
|
mainAxisSize: MainAxisSize.min,
|
|
|
|
children: [
|
2021-10-14 18:09:30 +02:00
|
|
|
const Icon(Icons.share_outlined),
|
|
|
|
const SizedBox(width: 12),
|
2021-08-01 07:45:34 +02:00
|
|
|
Text(L10n.of(context).inviteContact),
|
|
|
|
],
|
2021-04-14 14:09:46 +02:00
|
|
|
),
|
2021-08-01 07:45:34 +02:00
|
|
|
),
|
|
|
|
PopupMenuItem(
|
|
|
|
value: PopupMenuAction.archive,
|
|
|
|
child: Row(
|
2021-05-26 20:50:15 +02:00
|
|
|
mainAxisSize: MainAxisSize.min,
|
2021-08-01 07:45:34 +02:00
|
|
|
children: [
|
2021-10-14 18:09:30 +02:00
|
|
|
const Icon(Icons.archive_outlined),
|
|
|
|
const SizedBox(width: 12),
|
2021-08-01 07:45:34 +02:00
|
|
|
Text(L10n.of(context).archive),
|
2021-05-26 20:50:15 +02:00
|
|
|
],
|
2021-08-01 07:45:34 +02:00
|
|
|
),
|
|
|
|
),
|
|
|
|
PopupMenuItem(
|
|
|
|
value: PopupMenuAction.settings,
|
|
|
|
child: Row(
|
2021-06-20 12:57:46 +02:00
|
|
|
mainAxisSize: MainAxisSize.min,
|
|
|
|
children: [
|
2021-10-14 18:09:30 +02:00
|
|
|
const Icon(Icons.settings_outlined),
|
|
|
|
const SizedBox(width: 12),
|
2021-08-01 07:45:34 +02:00
|
|
|
Text(L10n.of(context).settings),
|
2021-06-20 12:57:46 +02:00
|
|
|
],
|
|
|
|
),
|
2021-08-01 07:45:34 +02:00
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
],
|
|
|
|
title: Text(selectMode == SelectMode.share
|
|
|
|
? L10n.of(context).share
|
|
|
|
: selectMode == SelectMode.select
|
2021-08-12 21:10:26 +02:00
|
|
|
? controller.selectedRoomIds.length.toString()
|
2021-08-01 07:45:34 +02:00
|
|
|
: controller.activeSpaceId == null
|
|
|
|
? AppConfig.applicationName
|
|
|
|
: Matrix.of(context)
|
|
|
|
.client
|
|
|
|
.getRoomById(controller.activeSpaceId)
|
|
|
|
.displayname),
|
|
|
|
),
|
|
|
|
body: Column(children: [
|
2021-10-14 18:09:30 +02:00
|
|
|
const ConnectionStatusHeader(),
|
2021-08-01 15:21:02 +02:00
|
|
|
Expanded(child: _ChatListViewBody(controller)),
|
2021-08-01 07:45:34 +02:00
|
|
|
]),
|
|
|
|
floatingActionButton: selectMode == SelectMode.normal
|
2021-08-29 11:29:14 +02:00
|
|
|
? controller.scrolledToTop
|
|
|
|
? FloatingActionButton.extended(
|
|
|
|
heroTag: 'main_fab',
|
|
|
|
onPressed: () =>
|
|
|
|
VRouter.of(context).to('/newprivatechat'),
|
2021-10-14 18:09:30 +02:00
|
|
|
icon: const Icon(CupertinoIcons.chat_bubble),
|
2021-08-29 11:29:14 +02:00
|
|
|
label: Text(L10n.of(context).newChat),
|
|
|
|
)
|
|
|
|
: FloatingActionButton(
|
|
|
|
heroTag: 'main_fab',
|
|
|
|
onPressed: () =>
|
|
|
|
VRouter.of(context).to('/newprivatechat'),
|
2021-10-14 18:09:30 +02:00
|
|
|
child: const Icon(CupertinoIcons.chat_bubble),
|
2021-08-29 11:29:14 +02:00
|
|
|
)
|
2021-08-01 07:45:34 +02:00
|
|
|
: null,
|
2021-09-19 13:48:23 +02:00
|
|
|
bottomNavigationBar: Matrix.of(context).isMultiAccount
|
|
|
|
? StreamBuilder(
|
|
|
|
stream: StreamGroup.merge(Matrix.of(context)
|
|
|
|
.widget
|
|
|
|
.clients
|
|
|
|
.map((client) => client.onSync.stream.where((s) =>
|
|
|
|
s.accountData != null &&
|
|
|
|
s.accountData
|
|
|
|
.any((e) => e.type == accountBundlesType)))),
|
|
|
|
builder: (context, _) => Material(
|
|
|
|
color: Theme.of(context)
|
|
|
|
.bottomNavigationBarTheme
|
|
|
|
.backgroundColor,
|
|
|
|
child: Column(
|
|
|
|
mainAxisSize: MainAxisSize.min,
|
|
|
|
children: [
|
2021-10-14 18:09:30 +02:00
|
|
|
const Divider(height: 1),
|
2021-09-19 13:48:23 +02:00
|
|
|
Builder(builder: (context) {
|
|
|
|
final items = getBottomBarItems(context);
|
|
|
|
if (items.length == 1) {
|
|
|
|
return Padding(
|
|
|
|
padding: const EdgeInsets.all(7.0),
|
|
|
|
child: Column(
|
|
|
|
mainAxisSize: MainAxisSize.min,
|
|
|
|
children: [
|
|
|
|
items.single.icon,
|
|
|
|
Text(items.single.label),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
return SingleChildScrollView(
|
|
|
|
scrollDirection: Axis.horizontal,
|
|
|
|
child: SizedBox(
|
|
|
|
width: max(
|
|
|
|
FluffyThemes.isColumnMode(context)
|
|
|
|
? FluffyThemes.columnWidth
|
|
|
|
: MediaQuery.of(context).size.width,
|
|
|
|
Matrix.of(context).widget.clients.length *
|
|
|
|
84.0,
|
|
|
|
),
|
|
|
|
child: BottomNavigationBar(
|
|
|
|
elevation: 0,
|
|
|
|
onTap: (i) => controller.setActiveClient(
|
|
|
|
Matrix.of(context).currentBundle[i]),
|
|
|
|
currentIndex: Matrix.of(context)
|
|
|
|
.currentBundle
|
|
|
|
.indexWhere(
|
|
|
|
(client) =>
|
|
|
|
client ==
|
|
|
|
Matrix.of(context).client,
|
|
|
|
),
|
|
|
|
showUnselectedLabels: false,
|
|
|
|
showSelectedLabels: true,
|
|
|
|
type: BottomNavigationBarType.shifting,
|
|
|
|
selectedItemColor:
|
2021-09-19 22:03:57 +02:00
|
|
|
Theme.of(context).colorScheme.secondary,
|
2021-09-19 13:48:23 +02:00
|
|
|
items: items,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}),
|
|
|
|
if (controller.displayBundles)
|
|
|
|
Padding(
|
|
|
|
padding: const EdgeInsets.symmetric(
|
|
|
|
vertical: 4.0,
|
|
|
|
horizontal: 12,
|
|
|
|
),
|
|
|
|
child: SizedBox(
|
|
|
|
width: double.infinity,
|
|
|
|
child: CupertinoSlidingSegmentedControl(
|
|
|
|
groupValue: controller.secureActiveBundle,
|
|
|
|
onValueChanged: controller.setActiveBundle,
|
|
|
|
children: Map.fromEntries(Matrix.of(context)
|
|
|
|
.accountBundles
|
|
|
|
.keys
|
|
|
|
.map((bundle) =>
|
|
|
|
MapEntry(bundle, Text(bundle)))),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
),
|
|
|
|
)
|
|
|
|
: null,
|
2021-08-01 07:45:34 +02:00
|
|
|
drawer: controller.spaces.isEmpty
|
|
|
|
? null
|
|
|
|
: Drawer(
|
|
|
|
child: SafeArea(
|
|
|
|
child: ListView.builder(
|
2021-09-27 08:13:50 +02:00
|
|
|
itemCount: controller.spaces.length + 1,
|
2021-08-01 07:45:34 +02:00
|
|
|
itemBuilder: (context, i) {
|
|
|
|
if (i == 0) {
|
|
|
|
return ListTile(
|
2021-08-04 10:05:58 +02:00
|
|
|
selected: controller.activeSpaceId == null,
|
|
|
|
selectedTileColor:
|
|
|
|
Theme.of(context).secondaryHeaderColor,
|
2021-08-01 07:45:34 +02:00
|
|
|
leading: CircleAvatar(
|
2021-09-19 22:03:57 +02:00
|
|
|
foregroundColor: Colors.white,
|
2021-08-04 10:05:58 +02:00
|
|
|
backgroundColor:
|
|
|
|
Theme.of(context).primaryColor,
|
2021-08-01 07:45:34 +02:00
|
|
|
radius: Avatar.defaultSize / 2,
|
2021-10-14 18:09:30 +02:00
|
|
|
child: const Icon(Icons.home_outlined),
|
2021-08-01 07:45:34 +02:00
|
|
|
),
|
2021-08-04 10:05:58 +02:00
|
|
|
title: Text(L10n.of(context).allChats),
|
2021-08-01 07:45:34 +02:00
|
|
|
onTap: () =>
|
|
|
|
controller.setActiveSpaceId(context, null),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
final space = controller.spaces[i - 1];
|
|
|
|
return ListTile(
|
2021-08-04 10:05:58 +02:00
|
|
|
selected: controller.activeSpaceId == space.id,
|
|
|
|
selectedTileColor:
|
|
|
|
Theme.of(context).secondaryHeaderColor,
|
2021-08-01 07:45:34 +02:00
|
|
|
leading: Avatar(space.avatar, space.displayname),
|
2021-08-04 10:05:58 +02:00
|
|
|
title: Text(space.displayname, maxLines: 1),
|
|
|
|
subtitle: Text(L10n.of(context).countParticipants(
|
|
|
|
(space.summary.mJoinedMemberCount +
|
|
|
|
space.summary.mInvitedMemberCount)
|
|
|
|
.toString())),
|
2021-08-01 07:45:34 +02:00
|
|
|
onTap: () => controller.setActiveSpaceId(
|
|
|
|
context, space.id),
|
2021-08-01 07:54:44 +02:00
|
|
|
trailing: IconButton(
|
2021-10-14 18:09:30 +02:00
|
|
|
icon: const Icon(Icons.edit_outlined),
|
2021-08-01 07:54:44 +02:00
|
|
|
onPressed: () =>
|
|
|
|
controller.editSpace(context, space.id),
|
|
|
|
),
|
2021-08-01 07:45:34 +02:00
|
|
|
);
|
|
|
|
},
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
);
|
2021-04-14 14:09:46 +02:00
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-08-01 15:21:02 +02:00
|
|
|
class _ChatListViewBody extends StatelessWidget {
|
|
|
|
final ChatListController controller;
|
|
|
|
const _ChatListViewBody(this.controller, {Key key}) : super(key: key);
|
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) => StreamBuilder(
|
|
|
|
stream: Matrix.of(context)
|
|
|
|
.client
|
|
|
|
.onSync
|
|
|
|
.stream
|
|
|
|
.where((s) => s.hasRoomUpdate)
|
2021-10-14 18:09:30 +02:00
|
|
|
.rateLimit(const Duration(seconds: 1)),
|
2021-08-01 15:21:02 +02:00
|
|
|
builder: (context, snapshot) {
|
|
|
|
return FutureBuilder<void>(
|
|
|
|
future: controller.waitForFirstSync(),
|
|
|
|
builder: (BuildContext context, snapshot) {
|
|
|
|
if (Matrix.of(context).client.prevBatch != null) {
|
2021-08-04 10:08:48 +02:00
|
|
|
final rooms = Matrix.of(context)
|
|
|
|
.client
|
|
|
|
.rooms
|
2021-08-01 15:33:26 +02:00
|
|
|
.where(controller.roomCheck)
|
2021-08-01 15:21:02 +02:00
|
|
|
.toList();
|
|
|
|
if (rooms.isEmpty) {
|
|
|
|
return Column(
|
|
|
|
mainAxisAlignment: MainAxisAlignment.center,
|
|
|
|
mainAxisSize: MainAxisSize.min,
|
|
|
|
children: <Widget>[
|
2021-10-14 18:09:30 +02:00
|
|
|
const Icon(
|
2021-08-01 15:21:02 +02:00
|
|
|
Icons.maps_ugc_outlined,
|
|
|
|
size: 80,
|
|
|
|
color: Colors.grey,
|
|
|
|
),
|
|
|
|
Center(
|
|
|
|
child: Text(
|
|
|
|
L10n.of(context).startYourFirstChat,
|
|
|
|
textAlign: TextAlign.start,
|
2021-10-14 18:09:30 +02:00
|
|
|
style: const TextStyle(
|
2021-08-01 15:21:02 +02:00
|
|
|
color: Colors.grey,
|
|
|
|
fontSize: 16,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
],
|
|
|
|
);
|
|
|
|
}
|
|
|
|
return ListView.builder(
|
2021-08-29 11:29:14 +02:00
|
|
|
controller: controller.scrollController,
|
2021-08-04 10:09:55 +02:00
|
|
|
itemCount: rooms.length,
|
2021-08-01 15:21:02 +02:00
|
|
|
itemBuilder: (BuildContext context, int i) {
|
|
|
|
return ChatListItem(
|
|
|
|
rooms[i],
|
|
|
|
selected: controller.selectedRoomIds.contains(rooms[i].id),
|
|
|
|
onTap: controller.selectMode == SelectMode.select
|
|
|
|
? () => controller.toggleSelection(rooms[i].id)
|
|
|
|
: null,
|
|
|
|
onLongPress: () => controller.toggleSelection(rooms[i].id),
|
|
|
|
activeChat: controller.activeChat == rooms[i].id,
|
|
|
|
);
|
|
|
|
},
|
|
|
|
);
|
|
|
|
} else {
|
|
|
|
return Center(
|
|
|
|
child: Column(
|
|
|
|
mainAxisSize: MainAxisSize.min,
|
|
|
|
children: [
|
|
|
|
Image.asset(
|
|
|
|
'assets/private_chat_wallpaper.png',
|
|
|
|
width: 100,
|
|
|
|
),
|
|
|
|
Text(
|
|
|
|
L10n.of(context).yourChatsAreBeingSynced,
|
|
|
|
textAlign: TextAlign.center,
|
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2021-04-14 14:09:46 +02:00
|
|
|
enum ChatListPopupMenuItemActions {
|
|
|
|
createGroup,
|
2021-08-01 08:05:40 +02:00
|
|
|
createSpace,
|
2021-04-14 14:09:46 +02:00
|
|
|
discover,
|
|
|
|
setStatus,
|
|
|
|
inviteContact,
|
|
|
|
settings,
|
|
|
|
}
|