feat: New chat details design

This commit is contained in:
Krille Fear 2021-11-13 21:42:35 +01:00
parent 15ccd043d9
commit 862d23c0b9
4 changed files with 175 additions and 165 deletions

View File

@ -25,6 +25,10 @@ class ChatDetails extends StatefulWidget {
class ChatDetailsController extends State<ChatDetails> { class ChatDetailsController extends State<ChatDetails> {
List<User> members; List<User> members;
bool displaySettings = false;
void toggleDisplaySettings() =>
setState(() => displaySettings = !displaySettings);
String get roomId => VRouter.of(context).pathParameters['roomid']; String get roomId => VRouter.of(context).pathParameters['roomid'];

View File

@ -1,3 +1,4 @@
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter_gen/gen_l10n/l10n.dart'; import 'package:flutter_gen/gen_l10n/l10n.dart';
@ -106,7 +107,7 @@ class ChatDetailsView extends StatelessWidget {
.scaffoldBackgroundColor, .scaffoldBackgroundColor,
foregroundColor: Colors.grey, foregroundColor: Colors.grey,
radius: Avatar.defaultSize / 2, radius: Avatar.defaultSize / 2,
child: const Icon(Icons.edit_outlined), child: const Icon(CupertinoIcons.pen),
) )
: null, : null,
title: Text( title: Text(
@ -136,7 +137,8 @@ class ChatDetailsView extends StatelessWidget {
? controller.setTopicAction ? controller.setTopicAction
: null, : null,
), ),
const Divider(thickness: 1), const SizedBox(height: 8),
const Divider(height: 1),
ListTile( ListTile(
title: Text( title: Text(
L10n.of(context).settings, L10n.of(context).settings,
@ -146,151 +148,121 @@ class ChatDetailsView extends StatelessWidget {
fontWeight: FontWeight.bold, fontWeight: FontWeight.bold,
), ),
), ),
trailing: Icon(controller.displaySettings
? CupertinoIcons.chevron_down
: CupertinoIcons.right_chevron),
onTap: controller.toggleDisplaySettings,
), ),
if (room.canSendEvent('m.room.name')) if (controller.displaySettings) ...[
ListTile( if (room.canSendEvent('m.room.name'))
leading: CircleAvatar( ListTile(
backgroundColor: leading: CircleAvatar(
Theme.of(context).scaffoldBackgroundColor,
foregroundColor: Colors.grey,
child: const Icon(Icons.people_outlined),
),
title: Text(
L10n.of(context).changeTheNameOfTheGroup),
subtitle: Text(room.getLocalizedDisplayname(
MatrixLocals(L10n.of(context)))),
onTap: controller.setDisplaynameAction,
),
if (room.joinRules == JoinRules.public)
ListTile(
leading: CircleAvatar(
backgroundColor:
Theme.of(context).scaffoldBackgroundColor,
foregroundColor: Colors.grey,
child: const Icon(Icons.link_outlined),
),
onTap: controller.editAliases,
title: Text(L10n.of(context).editRoomAliases),
subtitle: Text(
(room.canonicalAlias?.isNotEmpty ?? false)
? room.canonicalAlias
: L10n.of(context).none),
),
ListTile(
leading: CircleAvatar(
backgroundColor:
Theme.of(context).scaffoldBackgroundColor,
foregroundColor: Colors.grey,
child:
const Icon(Icons.insert_emoticon_outlined),
),
title: Text(L10n.of(context).emoteSettings),
subtitle: Text(L10n.of(context).setCustomEmotes),
onTap: controller.goToEmoteSettings,
),
PopupMenuButton(
onSelected: controller.setJoinRulesAction,
itemBuilder: (BuildContext context) =>
<PopupMenuEntry<JoinRules>>[
if (room.canChangeJoinRules)
PopupMenuItem<JoinRules>(
value: JoinRules.public,
child: Text(JoinRules.public
.getLocalizedString(
MatrixLocals(L10n.of(context)))),
),
if (room.canChangeJoinRules)
PopupMenuItem<JoinRules>(
value: JoinRules.invite,
child: Text(JoinRules.invite
.getLocalizedString(
MatrixLocals(L10n.of(context)))),
),
],
child: ListTile(
leading: CircleAvatar(
backgroundColor: Theme.of(context) backgroundColor: Theme.of(context)
.scaffoldBackgroundColor, .scaffoldBackgroundColor,
foregroundColor: Colors.grey, foregroundColor: Colors.grey,
child: const Icon(Icons.public_outlined)), child: const Icon(CupertinoIcons.group),
title: Text(L10n.of(context) ),
.whoIsAllowedToJoinThisGroup), title: Text(
subtitle: Text( L10n.of(context).changeTheNameOfTheGroup),
room.joinRules.getLocalizedString( subtitle: Text(room.getLocalizedDisplayname(
MatrixLocals(L10n.of(context))), MatrixLocals(L10n.of(context)))),
onTap: controller.setDisplaynameAction,
), ),
), if (room.joinRules == JoinRules.public)
), ListTile(
PopupMenuButton( leading: CircleAvatar(
onSelected: controller.setHistoryVisibilityAction, backgroundColor: Theme.of(context)
itemBuilder: (BuildContext context) => .scaffoldBackgroundColor,
<PopupMenuEntry<HistoryVisibility>>[ foregroundColor: Colors.grey,
if (room.canChangeHistoryVisibility) child: const Icon(CupertinoIcons.link),
PopupMenuItem<HistoryVisibility>(
value: HistoryVisibility.invited,
child: Text(HistoryVisibility.invited
.getLocalizedString(
MatrixLocals(L10n.of(context)))),
), ),
if (room.canChangeHistoryVisibility) onTap: controller.editAliases,
PopupMenuItem<HistoryVisibility>( title: Text(L10n.of(context).editRoomAliases),
value: HistoryVisibility.joined, subtitle: Text(
child: Text(HistoryVisibility.joined (room.canonicalAlias?.isNotEmpty ?? false)
.getLocalizedString( ? room.canonicalAlias
MatrixLocals(L10n.of(context)))), : L10n.of(context).none),
), ),
if (room.canChangeHistoryVisibility) ListTile(
PopupMenuItem<HistoryVisibility>(
value: HistoryVisibility.shared,
child: Text(HistoryVisibility.shared
.getLocalizedString(
MatrixLocals(L10n.of(context)))),
),
if (room.canChangeHistoryVisibility)
PopupMenuItem<HistoryVisibility>(
value: HistoryVisibility.worldReadable,
child: Text(HistoryVisibility.worldReadable
.getLocalizedString(
MatrixLocals(L10n.of(context)))),
),
],
child: ListTile(
leading: CircleAvatar( leading: CircleAvatar(
backgroundColor: backgroundColor:
Theme.of(context).scaffoldBackgroundColor, Theme.of(context).scaffoldBackgroundColor,
foregroundColor: Colors.grey, foregroundColor: Colors.grey,
child: const Icon(Icons.visibility_outlined), child: const Icon(
Icons.insert_emoticon_outlined),
), ),
title: Text(L10n.of(context) title: Text(L10n.of(context).emoteSettings),
.visibilityOfTheChatHistory), subtitle:
subtitle: Text( Text(L10n.of(context).setCustomEmotes),
room.historyVisibility.getLocalizedString( onTap: controller.goToEmoteSettings,
MatrixLocals(L10n.of(context))) ?? ),
'', PopupMenuButton(
onSelected: controller.setJoinRulesAction,
itemBuilder: (BuildContext context) =>
<PopupMenuEntry<JoinRules>>[
if (room.canChangeJoinRules)
PopupMenuItem<JoinRules>(
value: JoinRules.public,
child: Text(JoinRules.public
.getLocalizedString(
MatrixLocals(L10n.of(context)))),
),
if (room.canChangeJoinRules)
PopupMenuItem<JoinRules>(
value: JoinRules.invite,
child: Text(JoinRules.invite
.getLocalizedString(
MatrixLocals(L10n.of(context)))),
),
],
child: ListTile(
leading: CircleAvatar(
backgroundColor: Theme.of(context)
.scaffoldBackgroundColor,
foregroundColor: Colors.grey,
child: const Icon(
CupertinoIcons.checkmark_shield)),
title: Text(L10n.of(context)
.whoIsAllowedToJoinThisGroup),
subtitle: Text(
room.joinRules.getLocalizedString(
MatrixLocals(L10n.of(context))),
),
), ),
), ),
),
if (room.joinRules == JoinRules.public)
PopupMenuButton( PopupMenuButton(
onSelected: controller.setGuestAccessAction, onSelected:
controller.setHistoryVisibilityAction,
itemBuilder: (BuildContext context) => itemBuilder: (BuildContext context) =>
<PopupMenuEntry<GuestAccess>>[ <PopupMenuEntry<HistoryVisibility>>[
if (room.canChangeGuestAccess) if (room.canChangeHistoryVisibility)
PopupMenuItem<GuestAccess>( PopupMenuItem<HistoryVisibility>(
value: GuestAccess.canJoin, value: HistoryVisibility.invited,
child: Text( child: Text(HistoryVisibility.invited
GuestAccess.canJoin.getLocalizedString( .getLocalizedString(
MatrixLocals(L10n.of(context))), MatrixLocals(L10n.of(context)))),
),
), ),
if (room.canChangeGuestAccess) if (room.canChangeHistoryVisibility)
PopupMenuItem<GuestAccess>( PopupMenuItem<HistoryVisibility>(
value: GuestAccess.forbidden, value: HistoryVisibility.joined,
child: Text( child: Text(HistoryVisibility.joined
GuestAccess.forbidden .getLocalizedString(
.getLocalizedString( MatrixLocals(L10n.of(context)))),
MatrixLocals(L10n.of(context))), ),
), if (room.canChangeHistoryVisibility)
PopupMenuItem<HistoryVisibility>(
value: HistoryVisibility.shared,
child: Text(HistoryVisibility.shared
.getLocalizedString(
MatrixLocals(L10n.of(context)))),
),
if (room.canChangeHistoryVisibility)
PopupMenuItem<HistoryVisibility>(
value: HistoryVisibility.worldReadable,
child: Text(HistoryVisibility
.worldReadable
.getLocalizedString(
MatrixLocals(L10n.of(context)))),
), ),
], ],
child: ListTile( child: ListTile(
@ -298,31 +270,74 @@ class ChatDetailsView extends StatelessWidget {
backgroundColor: Theme.of(context) backgroundColor: Theme.of(context)
.scaffoldBackgroundColor, .scaffoldBackgroundColor,
foregroundColor: Colors.grey, foregroundColor: Colors.grey,
child: const Icon(Icons.info_outline), child: const Icon(CupertinoIcons.eye),
), ),
title: Text( title: Text(L10n.of(context)
L10n.of(context).areGuestsAllowedToJoin), .visibilityOfTheChatHistory),
subtitle: Text( subtitle: Text(
room.guestAccess.getLocalizedString( room.historyVisibility.getLocalizedString(
MatrixLocals(L10n.of(context))), MatrixLocals(L10n.of(context))) ??
'',
), ),
), ),
), ),
ListTile( if (room.joinRules == JoinRules.public)
title: Text(L10n.of(context).editChatPermissions), PopupMenuButton(
subtitle: Text( onSelected: controller.setGuestAccessAction,
L10n.of(context).whoCanPerformWhichAction), itemBuilder: (BuildContext context) =>
leading: CircleAvatar( <PopupMenuEntry<GuestAccess>>[
backgroundColor: if (room.canChangeGuestAccess)
Theme.of(context).scaffoldBackgroundColor, PopupMenuItem<GuestAccess>(
foregroundColor: Colors.grey, value: GuestAccess.canJoin,
child: child: Text(
const Icon(Icons.edit_attributes_outlined), GuestAccess.canJoin
.getLocalizedString(MatrixLocals(
L10n.of(context))),
),
),
if (room.canChangeGuestAccess)
PopupMenuItem<GuestAccess>(
value: GuestAccess.forbidden,
child: Text(
GuestAccess.forbidden
.getLocalizedString(MatrixLocals(
L10n.of(context))),
),
),
],
child: ListTile(
leading: CircleAvatar(
backgroundColor: Theme.of(context)
.scaffoldBackgroundColor,
foregroundColor: Colors.grey,
child:
const Icon(CupertinoIcons.person_alt),
),
title: Text(L10n.of(context)
.areGuestsAllowedToJoin),
subtitle: Text(
room.guestAccess.getLocalizedString(
MatrixLocals(L10n.of(context))),
),
),
),
ListTile(
title:
Text(L10n.of(context).editChatPermissions),
subtitle: Text(
L10n.of(context).whoCanPerformWhichAction),
leading: CircleAvatar(
backgroundColor:
Theme.of(context).scaffoldBackgroundColor,
foregroundColor: Colors.grey,
child: const Icon(
CupertinoIcons.slider_horizontal_3),
),
onTap: () =>
VRouter.of(context).to('permissions'),
), ),
onTap: () => ],
VRouter.of(context).to('permissions'), const Divider(height: 1),
),
const Divider(thickness: 1),
ListTile( ListTile(
title: Text( title: Text(
actualMembersCount > 1 actualMembersCount > 1

View File

@ -35,19 +35,12 @@ class InvitationSelectionController extends State<InvitationSelection> {
participants.removeWhere( participants.removeWhere(
(u) => ![Membership.join, Membership.invite].contains(u.membership), (u) => ![Membership.join, Membership.invite].contains(u.membership),
); );
final contacts = <User>[]; final participantsIds = participants.map((p) => p.stateKey).toList();
final userMap = <String, bool>{}; final contacts = client.rooms
for (var i = 0; i < client.rooms.length; i++) { .where((r) => r.isDirectChat)
final roomUsers = client.rooms[i].getParticipants(); .map((r) => r.getUserByMXIDSync(r.directChatMatrixID))
.toList()
for (var j = 0; j < roomUsers.length; j++) { ..removeWhere((u) => participantsIds.contains(u.stateKey));
if (userMap[roomUsers[j].id] != true &&
participants.indexWhere((u) => u.id == roomUsers[j].id) == -1) {
contacts.add(roomUsers[j]);
}
userMap[roomUsers[j].id] = true;
}
}
contacts.sort( contacts.sort(
(a, b) => a.calcDisplayname().toLowerCase().compareTo( (a, b) => a.calcDisplayname().toLowerCase().compareTo(
b.calcDisplayname().toLowerCase(), b.calcDisplayname().toLowerCase(),

View File

@ -3,9 +3,7 @@ import 'package:flutter/material.dart';
import 'package:flutter_gen/gen_l10n/l10n.dart'; import 'package:flutter_gen/gen_l10n/l10n.dart';
import 'package:matrix/matrix.dart'; import 'package:matrix/matrix.dart';
import 'package:vrouter/vrouter.dart';
import 'package:fluffychat/config/app_config.dart';
import 'package:fluffychat/utils/fluffy_share.dart'; import 'package:fluffychat/utils/fluffy_share.dart';
import 'package:fluffychat/widgets/layouts/max_width_body.dart'; import 'package:fluffychat/widgets/layouts/max_width_body.dart';
import 'package:fluffychat/widgets/matrix.dart'; import 'package:fluffychat/widgets/matrix.dart';