2020-01-01 19:10:13 +01:00
|
|
|
import 'package:famedlysdk/famedlysdk.dart';
|
2020-02-16 11:41:08 +01:00
|
|
|
import 'package:fluffychat/components/dialogs/simple_dialogs.dart';
|
2020-01-20 13:46:39 +01:00
|
|
|
import 'package:fluffychat/i18n/i18n.dart';
|
2020-01-01 19:10:13 +01:00
|
|
|
import 'package:fluffychat/utils/app_route.dart';
|
|
|
|
import 'package:fluffychat/views/chat.dart';
|
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
|
|
|
|
import '../avatar.dart';
|
|
|
|
import '../matrix.dart';
|
|
|
|
|
|
|
|
class ParticipantListItem extends StatelessWidget {
|
|
|
|
final User user;
|
|
|
|
|
|
|
|
const ParticipantListItem(this.user);
|
|
|
|
|
|
|
|
participantAction(BuildContext context, String action) async {
|
|
|
|
final MatrixState matrix = Matrix.of(context);
|
|
|
|
switch (action) {
|
|
|
|
case "ban":
|
2020-02-16 11:41:08 +01:00
|
|
|
if (await SimpleDialogs(context).askConfirmation()) {
|
|
|
|
await matrix.tryRequestWithLoadingDialog(user.ban());
|
|
|
|
}
|
2020-01-01 19:10:13 +01:00
|
|
|
break;
|
|
|
|
case "unban":
|
2020-02-16 11:41:08 +01:00
|
|
|
if (await SimpleDialogs(context).askConfirmation()) {
|
|
|
|
await matrix.tryRequestWithLoadingDialog(user.unban());
|
|
|
|
}
|
2020-01-01 19:10:13 +01:00
|
|
|
break;
|
|
|
|
case "kick":
|
2020-02-16 11:41:08 +01:00
|
|
|
if (await SimpleDialogs(context).askConfirmation()) {
|
|
|
|
await matrix.tryRequestWithLoadingDialog(user.kick());
|
|
|
|
}
|
2020-01-01 19:10:13 +01:00
|
|
|
break;
|
|
|
|
case "admin":
|
2020-02-16 11:41:08 +01:00
|
|
|
if (await SimpleDialogs(context).askConfirmation()) {
|
|
|
|
await matrix.tryRequestWithLoadingDialog(user.setPower(100));
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case "moderator":
|
|
|
|
if (await SimpleDialogs(context).askConfirmation()) {
|
|
|
|
await matrix.tryRequestWithLoadingDialog(user.setPower(50));
|
|
|
|
}
|
2020-01-01 19:10:13 +01:00
|
|
|
break;
|
|
|
|
case "user":
|
2020-02-16 11:41:08 +01:00
|
|
|
if (await SimpleDialogs(context).askConfirmation()) {
|
|
|
|
await matrix.tryRequestWithLoadingDialog(user.setPower(0));
|
|
|
|
}
|
2020-01-01 19:10:13 +01:00
|
|
|
break;
|
|
|
|
case "message":
|
|
|
|
final String roomId = await user.startDirectChat();
|
2020-01-02 22:31:39 +01:00
|
|
|
await Navigator.of(context).pushAndRemoveUntil(
|
2020-01-01 19:10:13 +01:00
|
|
|
AppRoute.defaultRoute(
|
|
|
|
context,
|
2020-01-27 10:14:38 +01:00
|
|
|
ChatView(roomId),
|
2020-01-01 19:10:13 +01:00
|
|
|
),
|
|
|
|
(Route r) => r.isFirst);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
2020-01-20 13:46:39 +01:00
|
|
|
Map<Membership, String> membershipBatch = {
|
2020-01-01 19:10:13 +01:00
|
|
|
Membership.join: "",
|
2020-01-20 13:46:39 +01:00
|
|
|
Membership.ban: I18n.of(context).banned,
|
|
|
|
Membership.invite: I18n.of(context).invited,
|
|
|
|
Membership.leave: I18n.of(context).leftTheChat,
|
2020-01-01 19:10:13 +01:00
|
|
|
};
|
|
|
|
final String permissionBatch = user.powerLevel == 100
|
2020-01-20 13:46:39 +01:00
|
|
|
? I18n.of(context).admin
|
|
|
|
: user.powerLevel >= 50 ? I18n.of(context).moderator : "";
|
2020-01-01 19:10:13 +01:00
|
|
|
List<PopupMenuEntry<String>> items = <PopupMenuEntry<String>>[];
|
2020-02-16 11:41:08 +01:00
|
|
|
|
|
|
|
if (user.id != Matrix.of(context).client.userID) {
|
|
|
|
items.add(
|
|
|
|
PopupMenuItem(
|
|
|
|
child: Text(I18n.of(context).sendAMessage), value: "message"),
|
|
|
|
);
|
|
|
|
}
|
2020-01-01 19:10:13 +01:00
|
|
|
if (user.canChangePowerLevel &&
|
|
|
|
user.room.ownPowerLevel == 100 &&
|
2020-01-02 22:31:39 +01:00
|
|
|
user.powerLevel != 100) {
|
2020-01-01 19:10:13 +01:00
|
|
|
items.add(
|
2020-01-20 13:46:39 +01:00
|
|
|
PopupMenuItem(
|
|
|
|
child: Text(I18n.of(context).makeAnAdmin), value: "admin"),
|
2020-01-01 19:10:13 +01:00
|
|
|
);
|
2020-01-02 22:31:39 +01:00
|
|
|
}
|
2020-02-16 11:41:08 +01:00
|
|
|
if (user.canChangePowerLevel &&
|
|
|
|
user.room.ownPowerLevel >= 50 &&
|
|
|
|
user.powerLevel != 50) {
|
|
|
|
items.add(
|
|
|
|
PopupMenuItem(
|
|
|
|
child: Text(I18n.of(context).makeAModerator), value: "moderator"),
|
|
|
|
);
|
|
|
|
}
|
2020-01-02 22:31:39 +01:00
|
|
|
if (user.canChangePowerLevel && user.powerLevel != 0) {
|
2020-01-01 19:10:13 +01:00
|
|
|
items.add(
|
2020-01-20 13:46:39 +01:00
|
|
|
PopupMenuItem(
|
|
|
|
child: Text(I18n.of(context).revokeAllPermissions), value: "user"),
|
2020-01-01 19:10:13 +01:00
|
|
|
);
|
2020-01-02 22:31:39 +01:00
|
|
|
}
|
|
|
|
if (user.canKick) {
|
2020-01-01 19:10:13 +01:00
|
|
|
items.add(
|
2020-01-20 13:46:39 +01:00
|
|
|
PopupMenuItem(
|
|
|
|
child: Text(I18n.of(context).kickFromChat), value: "kick"),
|
2020-01-01 19:10:13 +01:00
|
|
|
);
|
2020-01-02 22:31:39 +01:00
|
|
|
}
|
|
|
|
if (user.canBan && user.membership != Membership.ban) {
|
2020-01-01 19:10:13 +01:00
|
|
|
items.add(
|
2020-01-20 13:46:39 +01:00
|
|
|
PopupMenuItem(child: Text(I18n.of(context).banFromChat), value: "ban"),
|
2020-01-01 19:10:13 +01:00
|
|
|
);
|
2020-01-02 22:31:39 +01:00
|
|
|
} else if (user.canBan && user.membership == Membership.ban) {
|
2020-01-01 19:10:13 +01:00
|
|
|
items.add(
|
2020-01-20 13:46:39 +01:00
|
|
|
PopupMenuItem(
|
|
|
|
child: Text(I18n.of(context).removeExile), value: "unban"),
|
2020-01-01 19:10:13 +01:00
|
|
|
);
|
2020-01-02 22:31:39 +01:00
|
|
|
}
|
2020-01-01 19:10:13 +01: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 11:57:00 +01:00
|
|
|
color: Theme.of(context).secondaryHeaderColor,
|
2020-01-01 19:10:13 +01: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 11:57:00 +01:00
|
|
|
color: Theme.of(context).secondaryHeaderColor,
|
2020-01-01 19:10:13 +01:00
|
|
|
borderRadius: BorderRadius.circular(8),
|
|
|
|
),
|
|
|
|
child:
|
|
|
|
Center(child: Text(membershipBatch[user.membership])),
|
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
subtitle: Text(user.id),
|
2020-01-18 13:22:22 +01:00
|
|
|
leading: Avatar(user.avatarUrl, user.calcDisplayname()),
|
2020-01-01 19:10:13 +01:00
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|