2020-01-01 18:10:13 +00:00
|
|
|
import 'package:famedlysdk/famedlysdk.dart';
|
2020-10-06 19:59:36 +00:00
|
|
|
import 'package:furrychat/components/dialogs/simple_dialogs.dart';
|
|
|
|
import 'package:furrychat/utils/app_route.dart';
|
|
|
|
import 'package:furrychat/views/chat.dart';
|
2020-01-01 18:10:13 +00:00
|
|
|
import 'package:flutter/material.dart';
|
2020-10-03 11:11:07 +00:00
|
|
|
import 'package:flutter_gen/gen_l10n/l10n.dart';
|
2020-01-01 18:10:13 +00:00
|
|
|
|
|
|
|
import '../avatar.dart';
|
|
|
|
import '../matrix.dart';
|
|
|
|
|
|
|
|
class ParticipantListItem extends StatelessWidget {
|
|
|
|
final User user;
|
|
|
|
|
|
|
|
const ParticipantListItem(this.user);
|
|
|
|
|
2020-05-13 13:58:59 +00:00
|
|
|
void participantAction(BuildContext context, String action) async {
|
2020-01-01 18:10:13 +00:00
|
|
|
switch (action) {
|
2020-05-13 13:58:59 +00:00
|
|
|
case 'ban':
|
2020-02-16 10:41:08 +00:00
|
|
|
if (await SimpleDialogs(context).askConfirmation()) {
|
2020-04-27 11:36:39 +00:00
|
|
|
await SimpleDialogs(context).tryRequestWithLoadingDialog(user.ban());
|
2020-02-16 10:41:08 +00:00
|
|
|
}
|
2020-01-01 18:10:13 +00:00
|
|
|
break;
|
2020-05-13 13:58:59 +00:00
|
|
|
case 'unban':
|
2020-02-16 10:41:08 +00:00
|
|
|
if (await SimpleDialogs(context).askConfirmation()) {
|
2020-04-27 11:36:39 +00:00
|
|
|
await SimpleDialogs(context)
|
|
|
|
.tryRequestWithLoadingDialog(user.unban());
|
2020-02-16 10:41:08 +00:00
|
|
|
}
|
2020-01-01 18:10:13 +00:00
|
|
|
break;
|
2020-05-13 13:58:59 +00:00
|
|
|
case 'kick':
|
2020-02-16 10:41:08 +00:00
|
|
|
if (await SimpleDialogs(context).askConfirmation()) {
|
2020-04-27 11:36:39 +00:00
|
|
|
await SimpleDialogs(context).tryRequestWithLoadingDialog(user.kick());
|
2020-02-16 10:41:08 +00:00
|
|
|
}
|
2020-01-01 18:10:13 +00:00
|
|
|
break;
|
2020-05-13 13:58:59 +00:00
|
|
|
case 'admin':
|
2020-02-16 10:41:08 +00:00
|
|
|
if (await SimpleDialogs(context).askConfirmation()) {
|
2020-04-27 11:36:39 +00:00
|
|
|
await SimpleDialogs(context)
|
|
|
|
.tryRequestWithLoadingDialog(user.setPower(100));
|
2020-02-16 10:41:08 +00:00
|
|
|
}
|
|
|
|
break;
|
2020-05-13 13:58:59 +00:00
|
|
|
case 'moderator':
|
2020-02-16 10:41:08 +00:00
|
|
|
if (await SimpleDialogs(context).askConfirmation()) {
|
2020-04-27 11:36:39 +00:00
|
|
|
await SimpleDialogs(context)
|
|
|
|
.tryRequestWithLoadingDialog(user.setPower(50));
|
2020-02-16 10:41:08 +00:00
|
|
|
}
|
2020-01-01 18:10:13 +00:00
|
|
|
break;
|
2020-05-13 13:58:59 +00:00
|
|
|
case 'user':
|
2020-02-16 10:41:08 +00:00
|
|
|
if (await SimpleDialogs(context).askConfirmation()) {
|
2020-04-27 11:36:39 +00:00
|
|
|
await SimpleDialogs(context)
|
|
|
|
.tryRequestWithLoadingDialog(user.setPower(0));
|
2020-02-16 10:41:08 +00:00
|
|
|
}
|
2020-01-01 18:10:13 +00:00
|
|
|
break;
|
2020-05-13 13:58:59 +00:00
|
|
|
case 'message':
|
|
|
|
final roomId = await user.startDirectChat();
|
2020-01-02 21:31:39 +00:00
|
|
|
await Navigator.of(context).pushAndRemoveUntil(
|
2020-01-01 18:10:13 +00:00
|
|
|
AppRoute.defaultRoute(
|
|
|
|
context,
|
2020-01-27 09:14:38 +00:00
|
|
|
ChatView(roomId),
|
2020-01-01 18:10:13 +00:00
|
|
|
),
|
|
|
|
(Route r) => r.isFirst);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
2020-05-13 13:58:59 +00:00
|
|
|
var membershipBatch = <Membership, String>{
|
|
|
|
Membership.join: '',
|
2020-05-07 05:52:40 +00:00
|
|
|
Membership.ban: L10n.of(context).banned,
|
|
|
|
Membership.invite: L10n.of(context).invited,
|
|
|
|
Membership.leave: L10n.of(context).leftTheChat,
|
2020-01-01 18:10:13 +00:00
|
|
|
};
|
2020-05-13 13:58:59 +00:00
|
|
|
final permissionBatch = user.powerLevel == 100
|
2020-05-07 05:52:40 +00:00
|
|
|
? L10n.of(context).admin
|
2020-10-02 06:56:28 +00:00
|
|
|
: user.powerLevel >= 50
|
|
|
|
? L10n.of(context).moderator
|
|
|
|
: '';
|
2020-05-13 13:58:59 +00:00
|
|
|
var items = <PopupMenuEntry<String>>[];
|
2020-02-16 10:41:08 +00:00
|
|
|
|
|
|
|
if (user.id != Matrix.of(context).client.userID) {
|
|
|
|
items.add(
|
|
|
|
PopupMenuItem(
|
2020-05-13 13:58:59 +00:00
|
|
|
child: Text(L10n.of(context).sendAMessage), value: 'message'),
|
2020-02-16 10:41:08 +00:00
|
|
|
);
|
|
|
|
}
|
2020-01-01 18:10:13 +00:00
|
|
|
if (user.canChangePowerLevel &&
|
|
|
|
user.room.ownPowerLevel == 100 &&
|
2020-01-02 21:31:39 +00:00
|
|
|
user.powerLevel != 100) {
|
2020-01-01 18:10:13 +00:00
|
|
|
items.add(
|
2020-01-20 12:46:39 +00:00
|
|
|
PopupMenuItem(
|
2020-05-13 13:58:59 +00:00
|
|
|
child: Text(L10n.of(context).makeAnAdmin), value: 'admin'),
|
2020-01-01 18:10:13 +00:00
|
|
|
);
|
2020-01-02 21:31:39 +00:00
|
|
|
}
|
2020-02-16 10:41:08 +00:00
|
|
|
if (user.canChangePowerLevel &&
|
|
|
|
user.room.ownPowerLevel >= 50 &&
|
|
|
|
user.powerLevel != 50) {
|
|
|
|
items.add(
|
|
|
|
PopupMenuItem(
|
2020-05-13 13:58:59 +00:00
|
|
|
child: Text(L10n.of(context).makeAModerator), value: 'moderator'),
|
2020-02-16 10:41:08 +00:00
|
|
|
);
|
|
|
|
}
|
2020-01-02 21:31:39 +00:00
|
|
|
if (user.canChangePowerLevel && user.powerLevel != 0) {
|
2020-01-01 18:10:13 +00:00
|
|
|
items.add(
|
2020-01-20 12:46:39 +00:00
|
|
|
PopupMenuItem(
|
2020-05-13 13:58:59 +00:00
|
|
|
child: Text(L10n.of(context).revokeAllPermissions), value: 'user'),
|
2020-01-01 18:10:13 +00:00
|
|
|
);
|
2020-01-02 21:31:39 +00:00
|
|
|
}
|
|
|
|
if (user.canKick) {
|
2020-01-01 18:10:13 +00:00
|
|
|
items.add(
|
2020-01-20 12:46:39 +00:00
|
|
|
PopupMenuItem(
|
2020-05-13 13:58:59 +00:00
|
|
|
child: Text(L10n.of(context).kickFromChat), value: 'kick'),
|
2020-01-01 18:10:13 +00:00
|
|
|
);
|
2020-01-02 21:31:39 +00:00
|
|
|
}
|
|
|
|
if (user.canBan && user.membership != Membership.ban) {
|
2020-01-01 18:10:13 +00:00
|
|
|
items.add(
|
2020-05-13 13:58:59 +00:00
|
|
|
PopupMenuItem(child: Text(L10n.of(context).banFromChat), value: 'ban'),
|
2020-01-01 18:10:13 +00:00
|
|
|
);
|
2020-01-02 21:31:39 +00:00
|
|
|
} else if (user.canBan && user.membership == Membership.ban) {
|
2020-01-01 18:10:13 +00:00
|
|
|
items.add(
|
2020-01-20 12:46:39 +00:00
|
|
|
PopupMenuItem(
|
2020-05-13 13:58:59 +00:00
|
|
|
child: Text(L10n.of(context).removeExile), value: 'unban'),
|
2020-01-01 18:10:13 +00:00
|
|
|
);
|
2020-01-02 21:31:39 +00:00
|
|
|
}
|
2020-01-01 18:10:13 +00:00
|
|
|
return PopupMenuButton(
|
|
|
|
onSelected: (action) => participantAction(context, action),
|
|
|
|
itemBuilder: (c) => items,
|
|
|
|
child: ListTile(
|
|
|
|
title: Row(
|
|
|
|
children: <Widget>[
|
|
|
|
Text(user.calcDisplayname()),
|
|
|
|
permissionBatch.isEmpty
|
|
|
|
? Container()
|
|
|
|
: Container(
|
|
|
|
padding: EdgeInsets.all(4),
|
|
|
|
margin: EdgeInsets.symmetric(horizontal: 8),
|
|
|
|
decoration: BoxDecoration(
|
2020-01-03 10:57:00 +00:00
|
|
|
color: Theme.of(context).secondaryHeaderColor,
|
2020-01-01 18:10:13 +00:00
|
|
|
borderRadius: BorderRadius.circular(8),
|
|
|
|
),
|
|
|
|
child: Center(child: Text(permissionBatch)),
|
|
|
|
),
|
|
|
|
membershipBatch[user.membership].isEmpty
|
|
|
|
? Container()
|
|
|
|
: Container(
|
|
|
|
padding: EdgeInsets.all(4),
|
|
|
|
margin: EdgeInsets.symmetric(horizontal: 8),
|
|
|
|
decoration: BoxDecoration(
|
2020-01-03 10:57:00 +00:00
|
|
|
color: Theme.of(context).secondaryHeaderColor,
|
2020-01-01 18:10:13 +00:00
|
|
|
borderRadius: BorderRadius.circular(8),
|
|
|
|
),
|
|
|
|
child:
|
|
|
|
Center(child: Text(membershipBatch[user.membership])),
|
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
subtitle: Text(user.id),
|
2020-01-18 12:22:22 +00:00
|
|
|
leading: Avatar(user.avatarUrl, user.calcDisplayname()),
|
2020-01-01 18:10:13 +00:00
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|